diff options
| author | Brandon Schlack <brandonschlack@gmail.com> | 2020-11-04 21:55:03 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-04 21:55:03 -0800 |
| commit | f12dcb0659918657d35dc599e69f1aec43a22e97 (patch) | |
| tree | 50e98a01f9103a82574390879f9989ef27b47e98 /users/brandonschlack/brandonschlack.c | |
| parent | 262a60733483a38ed998b6dc6495f748ba6b71b0 (diff) | |
| download | qmk_firmware-f12dcb0659918657d35dc599e69f1aec43a22e97.tar.gz qmk_firmware-f12dcb0659918657d35dc599e69f1aec43a22e97.zip | |
[Keymap] add brandonschlack userspace and keymaps (#10411)
Diffstat (limited to 'users/brandonschlack/brandonschlack.c')
| -rw-r--r-- | users/brandonschlack/brandonschlack.c | 214 |
1 files changed, 214 insertions, 0 deletions
diff --git a/users/brandonschlack/brandonschlack.c b/users/brandonschlack/brandonschlack.c new file mode 100644 index 000000000..1e52bd645 --- /dev/null +++ b/users/brandonschlack/brandonschlack.c | |||
| @@ -0,0 +1,214 @@ | |||
| 1 | /* Copyright 2020 Brandon Schlack | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #include "brandonschlack.h" | ||
| 17 | |||
| 18 | user_config_t user_config; | ||
| 19 | #ifdef STOPLIGHT_LED | ||
| 20 | static stoplight_led_t stoplight_led; | ||
| 21 | #endif | ||
| 22 | |||
| 23 | /** | ||
| 24 | * Resets user config in EEPROM | ||
| 25 | * | ||
| 26 | * Default is use rgb for layer indication | ||
| 27 | */ | ||
| 28 | void eeconfig_init_user(void) { | ||
| 29 | user_config.raw = 0; | ||
| 30 | user_config.rgb_layer_change = true; | ||
| 31 | user_config.rgb_theme = 0; | ||
| 32 | eeconfig_update_user(user_config.raw); | ||
| 33 | } | ||
| 34 | |||
| 35 | __attribute__((weak)) | ||
| 36 | void matrix_init_keymap(void){ } | ||
| 37 | |||
| 38 | void matrix_init_user(void) { | ||
| 39 | matrix_init_keymap(); | ||
| 40 | } | ||
| 41 | |||
| 42 | __attribute__((weak)) | ||
| 43 | void keyboard_post_init_keymap(void){ } | ||
| 44 | |||
| 45 | /** | ||
| 46 | * Reads user config from EEPROM, | ||
| 47 | * calls RGB init if RGBs enabled | ||
| 48 | */ | ||
| 49 | void keyboard_post_init_user(void){ | ||
| 50 | // Read the user config from EEPROM | ||
| 51 | user_config.raw = eeconfig_read_user(); | ||
| 52 | // Do Stoplight Animation if enabled | ||
| 53 | #ifdef STOPLIGHT_LED | ||
| 54 | led_stoplight_start(); | ||
| 55 | #endif | ||
| 56 | // Do RGB things if RGBs enabled | ||
| 57 | #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) | ||
| 58 | keyboard_post_init_rgb(); | ||
| 59 | #endif | ||
| 60 | keyboard_post_init_keymap(); | ||
| 61 | } | ||
| 62 | |||
| 63 | __attribute__ ((weak)) | ||
| 64 | void shutdown_keymap(void) {} | ||
| 65 | |||
| 66 | /** | ||
| 67 | * On shutdown, | ||
| 68 | * If RGBs enabled, | ||
| 69 | * then set RGB color to Red | ||
| 70 | */ | ||
| 71 | void shutdown_user (void) { | ||
| 72 | #ifdef RGBLIGHT_ENABLE | ||
| 73 | rgblight_enable_noeeprom(); | ||
| 74 | rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT); | ||
| 75 | rgblight_sethsv_noeeprom(0, 255, 127); | ||
| 76 | #endif // RGBLIGHT_ENABLE | ||
| 77 | #ifdef RGB_MATRIX_ENABLE | ||
| 78 | rgb_matrix_set_color_all( 0xFF, 0x00, 0x00 ); | ||
| 79 | #endif //RGB_MATRIX_ENABLE | ||
| 80 | shutdown_keymap(); | ||
| 81 | } | ||
| 82 | |||
| 83 | __attribute__ ((weak)) | ||
| 84 | void suspend_power_down_keymap(void) {} | ||
| 85 | |||
| 86 | /** | ||
| 87 | * Set rgb_matrix suspend state to true if not already | ||
| 88 | */ | ||
| 89 | void suspend_power_down_user(void) { | ||
| 90 | #ifdef RGB_MATRIX_ENABLE | ||
| 91 | if (!g_suspend_state) { | ||
| 92 | rgb_matrix_set_suspend_state(true); | ||
| 93 | } | ||
| 94 | #endif //RGB_MATRIX_ENABLE | ||
| 95 | suspend_power_down_keymap(); | ||
| 96 | } | ||
| 97 | |||
| 98 | __attribute__ ((weak)) | ||
| 99 | void suspend_wakeup_init_keymap(void) {} | ||
| 100 | |||
| 101 | /** | ||
| 102 | * Set rgb_matrix suspend state to false if not already | ||
| 103 | */ | ||
| 104 | void suspend_wakeup_init_user(void) { | ||
| 105 | #ifdef RGB_MATRIX_ENABLE | ||
| 106 | if (g_suspend_state) { | ||
| 107 | rgb_matrix_set_suspend_state(false); | ||
| 108 | } | ||
| 109 | #endif //RGB_MATRIX_ENABLE | ||
| 110 | suspend_wakeup_init_keymap(); | ||
| 111 | } | ||
| 112 | |||
| 113 | __attribute__ ((weak)) | ||
| 114 | void matrix_scan_keymap(void) {} | ||
| 115 | |||
| 116 | /** | ||
| 117 | * Checks for Super CMD↯TAB | ||
| 118 | */ | ||
| 119 | void matrix_scan_user(void) { | ||
| 120 | matrix_scan_cmd_tab(); | ||
| 121 | #ifdef STOPLIGHT_LED | ||
| 122 | matrix_scan_led_stoplight(); | ||
| 123 | #endif | ||
| 124 | matrix_scan_keymap(); | ||
| 125 | } | ||
| 126 | |||
| 127 | __attribute__ ((weak)) | ||
| 128 | layer_state_t default_layer_state_set_keymap(layer_state_t state) { | ||
| 129 | return state; | ||
| 130 | } | ||
| 131 | |||
| 132 | /** | ||
| 133 | * For macropads, if a new default layer is set from DF() | ||
| 134 | * then automatically set that layer with layer_move() | ||
| 135 | */ | ||
| 136 | layer_state_t default_layer_state_set_user(layer_state_t state) { | ||
| 137 | #if defined(IS_MACROPAD) | ||
| 138 | layer_move(get_highest_layer(state)); | ||
| 139 | #endif | ||
| 140 | return default_layer_state_set_keymap(state); | ||
| 141 | } | ||
| 142 | |||
| 143 | __attribute__ ((weak)) | ||
| 144 | layer_state_t layer_state_set_keymap(layer_state_t state) { | ||
| 145 | return state; | ||
| 146 | } | ||
| 147 | |||
| 148 | /** | ||
| 149 | * Do RGB things (like layer indication) on layer change | ||
| 150 | */ | ||
| 151 | layer_state_t layer_state_set_user(layer_state_t state) { | ||
| 152 | #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) | ||
| 153 | state = layer_state_set_rgb(state); | ||
| 154 | #endif // RGBLIGHT_ENABLE | ||
| 155 | return layer_state_set_keymap(state); | ||
| 156 | } | ||
| 157 | |||
| 158 | __attribute__((weak)) bool led_update_keymap(led_t led_state) { return true; } | ||
| 159 | |||
| 160 | bool led_update_user(led_t led_state) { | ||
| 161 | #ifdef STOPLIGHT_LED | ||
| 162 | if (stoplight_led.is_active) { | ||
| 163 | return false; | ||
| 164 | } | ||
| 165 | #endif | ||
| 166 | return led_update_keymap(led_state); | ||
| 167 | } | ||
| 168 | |||
| 169 | #ifdef STOPLIGHT_LED | ||
| 170 | void led_stoplight_start(void) { | ||
| 171 | writePin(TOP_LED, LED_ON(false)); | ||
| 172 | writePin(MIDDLE_LED, LED_ON(false)); | ||
| 173 | writePin(BOTTOM_LED, LED_ON(false)); | ||
| 174 | |||
| 175 | stoplight_led.is_active = true; | ||
| 176 | stoplight_led.timer = timer_read(); | ||
| 177 | }; | ||
| 178 | |||
| 179 | void led_stoplight_set(pin_t pin) { | ||
| 180 | writePin(pin, LED_ON(true)); | ||
| 181 | }; | ||
| 182 | |||
| 183 | void led_stoplight_end(void) { | ||
| 184 | // Reset timer and status variables | ||
| 185 | stoplight_led.is_active = false; | ||
| 186 | stoplight_led.index = 0; | ||
| 187 | stoplight_led.timer = 0; | ||
| 188 | led_update_kb(host_keyboard_led_state()); | ||
| 189 | }; | ||
| 190 | |||
| 191 | void matrix_scan_led_stoplight(void) { | ||
| 192 | if (stoplight_led.is_active) { | ||
| 193 | if (timer_elapsed(stoplight_led.timer) > (1000 * (stoplight_led.index + 1))) { | ||
| 194 | switch (stoplight_led.index){ | ||
| 195 | case 0: | ||
| 196 | led_stoplight_set(TOP_LED); | ||
| 197 | stoplight_led.index++; | ||
| 198 | break; | ||
| 199 | case 1: | ||
| 200 | led_stoplight_set(MIDDLE_LED); | ||
| 201 | stoplight_led.index++; | ||
| 202 | break; | ||
| 203 | case 2: | ||
| 204 | led_stoplight_set(BOTTOM_LED); | ||
| 205 | stoplight_led.index++; | ||
| 206 | break; | ||
| 207 | default: | ||
| 208 | led_stoplight_end(); | ||
| 209 | break; | ||
| 210 | } | ||
| 211 | } | ||
| 212 | } | ||
| 213 | }; | ||
| 214 | #endif | ||
