diff options
| author | Drashna Jaelre <drashna@live.com> | 2020-06-15 03:41:28 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-15 03:41:28 -0700 |
| commit | 357a888d805c21c9cb4917f55d558195e8b85db5 (patch) | |
| tree | fd1e8c30c3754ff89e8efd7e94ced3a1a8d92035 /users/drashna/rgb_stuff.c | |
| parent | 7f5656996ca2f5a62a148ef9165d0681ba806f07 (diff) | |
| download | qmk_firmware-357a888d805c21c9cb4917f55d558195e8b85db5.tar.gz qmk_firmware-357a888d805c21c9cb4917f55d558195e8b85db5.zip | |
[Keymap] Drashna's Keymap Update - Display Edition (#9282)
OLED Display fixes
Add support for RGBLIGHT Layers
Add gaming layer to corn and kyria
RGBLight Startup Animation fixes and improvements (uses matrix_scan now!)
Pimoroni Trackball support added (IT'S RGB!!!)
Fix issues due to code changes
Diffstat (limited to 'users/drashna/rgb_stuff.c')
| -rw-r--r-- | users/drashna/rgb_stuff.c | 177 |
1 files changed, 32 insertions, 145 deletions
diff --git a/users/drashna/rgb_stuff.c b/users/drashna/rgb_stuff.c index 06b1e3c0c..defee9ac1 100644 --- a/users/drashna/rgb_stuff.c +++ b/users/drashna/rgb_stuff.c | |||
| @@ -2,136 +2,13 @@ | |||
| 2 | #include "rgb_stuff.h" | 2 | #include "rgb_stuff.h" |
| 3 | #include "eeprom.h" | 3 | #include "eeprom.h" |
| 4 | 4 | ||
| 5 | extern rgblight_config_t rgblight_config; | 5 | bool has_initialized; |
| 6 | bool has_initialized; | ||
| 7 | 6 | ||
| 8 | void rgblight_sethsv_default_helper(uint8_t index) { rgblight_sethsv_at(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, index); } | 7 | void rgblight_sethsv_default_helper(uint8_t index) { rgblight_sethsv_at(rgblight_get_hue(), rgblight_get_sat(), rgblight_get_val(), index); } |
| 9 | |||
| 10 | /* Custom indicators for modifiers. | ||
| 11 | * This allows for certain lights to be lit up, based on what mods are active, giving some visual feedback. | ||
| 12 | * This is especially useful for One Shot Mods, since it's not always obvious if they're still lit up. | ||
| 13 | */ | ||
| 14 | #ifdef INDICATOR_LIGHTS | ||
| 15 | void set_rgb_indicators(uint8_t this_mod, uint8_t this_led, uint8_t this_osm) { | ||
| 16 | if (userspace_config.rgb_layer_change && get_highest_layer(layer_state) == 0) { | ||
| 17 | if ((this_mod | this_osm) & MOD_MASK_SHIFT || this_led & (1 << USB_LED_CAPS_LOCK)) { | ||
| 18 | # ifdef SHFT_LED1 | ||
| 19 | rgblight_sethsv_at(120, 255, 255, SHFT_LED1); | ||
| 20 | # endif // SHFT_LED1 | ||
| 21 | # ifdef SHFT_LED2 | ||
| 22 | rgblight_sethsv_at(120, 255, 255, SHFT_LED2); | ||
| 23 | # endif // SHFT_LED2 | ||
| 24 | } else { | ||
| 25 | # ifdef SHFT_LED1 | ||
| 26 | rgblight_sethsv_default_helper(SHFT_LED1); | ||
| 27 | # endif // SHFT_LED1 | ||
| 28 | # ifdef SHFT_LED2 | ||
| 29 | rgblight_sethsv_default_helper(SHFT_LED2); | ||
| 30 | # endif // SHFT_LED2 | ||
| 31 | } | ||
| 32 | if ((this_mod | this_osm) & MOD_MASK_CTRL) { | ||
| 33 | # ifdef CTRL_LED1 | ||
| 34 | rgblight_sethsv_at(0, 255, 255, CTRL_LED1); | ||
| 35 | # endif // CTRL_LED1 | ||
| 36 | # ifdef CTRL_LED2 | ||
| 37 | rgblight_sethsv_at(0, 255, 255, CTRL_LED2); | ||
| 38 | # endif // CTRL_LED2 | ||
| 39 | } else { | ||
| 40 | # ifdef CTRL_LED1 | ||
| 41 | rgblight_sethsv_default_helper(CTRL_LED1); | ||
| 42 | # endif // CTRL_LED1 | ||
| 43 | # ifdef CTRL_LED2 | ||
| 44 | rgblight_sethsv_default_helper(CTRL_LED2); | ||
| 45 | # endif // CTRL_LED2 | ||
| 46 | } | ||
| 47 | if ((this_mod | this_osm) & MOD_MASK_GUI) { | ||
| 48 | # ifdef GUI_LED1 | ||
| 49 | rgblight_sethsv_at(51, 255, 255, GUI_LED1); | ||
| 50 | # endif // GUI_LED1 | ||
| 51 | # ifdef GUI_LED2 | ||
| 52 | rgblight_sethsv_at(51, 255, 255, GUI_LED2); | ||
| 53 | # endif // GUI_LED2 | ||
| 54 | } else { | ||
| 55 | # ifdef GUI_LED1 | ||
| 56 | rgblight_sethsv_default_helper(GUI_LED1); | ||
| 57 | # endif // GUI_LED1 | ||
| 58 | # ifdef GUI_LED2 | ||
| 59 | rgblight_sethsv_default_helper(GUI_LED2); | ||
| 60 | # endif // GUI_LED2 | ||
| 61 | } | ||
| 62 | if ((this_mod | this_osm) & MOD_MASK_ALT) { | ||
| 63 | # ifdef ALT_LED1 | ||
| 64 | rgblight_sethsv_at(240, 255, 255, ALT_LED1); | ||
| 65 | # endif // ALT_LED1 | ||
| 66 | # ifdef GUI_LED2 | ||
| 67 | rgblight_sethsv_at(240, 255, 255, ALT_LED2); | ||
| 68 | # endif // GUI_LED2 | ||
| 69 | } else { | ||
| 70 | # ifdef GUI_LED1 | ||
| 71 | rgblight_sethsv_default_helper(ALT_LED1); | ||
| 72 | # endif // GUI_LED1 | ||
| 73 | # ifdef GUI_LED2 | ||
| 74 | rgblight_sethsv_default_helper(ALT_LED2); | ||
| 75 | # endif // GUI_LED2 | ||
| 76 | } | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | /* Function for the indicators */ | ||
| 81 | void matrix_scan_indicator(void) { | ||
| 82 | if (has_initialized) { | ||
| 83 | set_rgb_indicators(get_mods(), host_keyboard_leds(), get_oneshot_mods()); | ||
| 84 | } | ||
| 85 | } | ||
| 86 | #endif // INDICATOR_LIGHTS | ||
| 87 | 8 | ||
| 88 | #ifdef RGBLIGHT_TWINKLE | 9 | #ifdef RGBLIGHT_TWINKLE |
| 89 | static rgblight_fadeout lights[RGBLED_NUM]; | 10 | static rgblight_fadeout lights[RGBLED_NUM]; |
| 90 | 11 | ||
| 91 | __attribute__((weak)) bool rgblight_twinkle_is_led_used_keymap(uint8_t index) { return false; } | ||
| 92 | |||
| 93 | /* This function checks for used LEDs. This way, collisions don't occur and cause weird rendering */ | ||
| 94 | bool rgblight_twinkle_is_led_used(uint8_t index) { | ||
| 95 | switch (index) { | ||
| 96 | # ifdef INDICATOR_LIGHTS | ||
| 97 | # ifdef SHFT_LED1 | ||
| 98 | case SHFT_LED1: | ||
| 99 | return true; | ||
| 100 | # endif // SHFT_LED1 | ||
| 101 | # ifdef SHFT_LED2 | ||
| 102 | case SHFT_LED2: | ||
| 103 | return true; | ||
| 104 | # endif // SHFT_LED2 | ||
| 105 | # ifdef CTRL_LED1 | ||
| 106 | case CTRL_LED1: | ||
| 107 | return true; | ||
| 108 | # endif // CTRL_LED1 | ||
| 109 | # ifdef CTRL_LED2 | ||
| 110 | case CTRL_LED2: | ||
| 111 | return true; | ||
| 112 | # endif // CTRL_LED2 | ||
| 113 | # ifdef GUI_LED1 | ||
| 114 | case GUI_LED1: | ||
| 115 | return true; | ||
| 116 | # endif // GUI_LED1 | ||
| 117 | # ifdef GUI_LED2 | ||
| 118 | case GUI_LED2: | ||
| 119 | return true; | ||
| 120 | # endif // GUI_LED2 | ||
| 121 | # ifdef ALT_LED1 | ||
| 122 | case ALT_LED1: | ||
| 123 | return true; | ||
| 124 | # endif // ALT_LED1 | ||
| 125 | # ifdef ALT_LED2 | ||
| 126 | case ALT_LED2: | ||
| 127 | return true; | ||
| 128 | # endif // ALT_LED2 | ||
| 129 | # endif // INDICATOR_LIGHTS | ||
| 130 | default: | ||
| 131 | return rgblight_twinkle_is_led_used_keymap(index); | ||
| 132 | } | ||
| 133 | } | ||
| 134 | |||
| 135 | /* Handler for fading/twinkling effect */ | 12 | /* Handler for fading/twinkling effect */ |
| 136 | void scan_rgblight_fadeout(void) { // Don't effing change this function .... rgblight_sethsv is supppppper intensive | 13 | void scan_rgblight_fadeout(void) { // Don't effing change this function .... rgblight_sethsv is supppppper intensive |
| 137 | bool litup = false; | 14 | bool litup = false; |
| @@ -170,9 +47,6 @@ void start_rgb_light(void) { | |||
| 170 | uint8_t min_life_index = -1; | 47 | uint8_t min_life_index = -1; |
| 171 | 48 | ||
| 172 | for (uint8_t index = 0; index < RGBLED_NUM; ++index) { | 49 | for (uint8_t index = 0; index < RGBLED_NUM; ++index) { |
| 173 | if (rgblight_twinkle_is_led_used(index)) { | ||
| 174 | continue; | ||
| 175 | } | ||
| 176 | if (lights[index].enabled) { | 50 | if (lights[index].enabled) { |
| 177 | if (min_life_index == -1 || lights[index].life < min_life) { | 51 | if (min_life_index == -1 || lights[index].life < min_life) { |
| 178 | min_life = lights[index].life; | 52 | min_life = lights[index].life; |
| @@ -197,7 +71,7 @@ void start_rgb_light(void) { | |||
| 197 | light->timer = timer_read(); | 71 | light->timer = timer_read(); |
| 198 | light->life = 0xC0 + rand() % 0x40; | 72 | light->life = 0xC0 + rand() % 0x40; |
| 199 | 73 | ||
| 200 | light->hue = rgblight_config.hue + (rand() % 0xB4) - 0x54; | 74 | light->hue = rgblight_get_hue() + (rand() % 0xB4) - 0x54; |
| 201 | 75 | ||
| 202 | rgblight_sethsv_at(light->hue, 255, light->life, light_index); | 76 | rgblight_sethsv_at(light->hue, 255, light->life, light_index); |
| 203 | } | 77 | } |
| @@ -227,39 +101,52 @@ bool process_record_user_rgb_light(uint16_t keycode, keyrecord_t *record) { | |||
| 227 | return true; | 101 | return true; |
| 228 | } | 102 | } |
| 229 | 103 | ||
| 104 | #if defined(RGBLIGHT_STARTUP_ANIMATION) | ||
| 105 | static bool is_enabled; | ||
| 106 | static bool is_rgblight_startup; | ||
| 107 | static uint8_t old_hue; | ||
| 108 | static uint16_t rgblight_startup_loop_timer; | ||
| 109 | #endif | ||
| 110 | |||
| 230 | void keyboard_post_init_rgb_light(void) { | 111 | void keyboard_post_init_rgb_light(void) { |
| 231 | #if defined(RGBLIGHT_STARTUP_ANIMATION) | 112 | #if defined(RGBLIGHT_STARTUP_ANIMATION) |
| 232 | bool is_enabled = rgblight_config.enable; | 113 | is_enabled = rgblight_is_enabled(); |
| 233 | if (userspace_config.rgb_layer_change) { | 114 | if (userspace_config.rgb_layer_change) { |
| 234 | rgblight_enable_noeeprom(); | 115 | rgblight_enable_noeeprom(); |
| 235 | } | 116 | } |
| 236 | if (rgblight_config.enable) { | 117 | if (rgblight_is_enabled()) { |
| 237 | layer_state_set_rgb_light(layer_state); | 118 | layer_state_set_rgb_light(layer_state); |
| 238 | uint16_t old_hue = rgblight_config.hue; | 119 | old_hue = rgblight_get_hue(); |
| 239 | rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT); | 120 | rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT); |
| 240 | for (uint16_t i = 255; i > 0; i--) { | 121 | is_rgblight_startup = true; |
| 241 | rgblight_sethsv_noeeprom((i + old_hue) % 255, 255, 255); | ||
| 242 | matrix_scan(); | ||
| 243 | wait_ms(10); | ||
| 244 | } | ||
| 245 | } | 122 | } |
| 246 | if (!is_enabled) { | ||
| 247 | rgblight_disable_noeeprom(); | ||
| 248 | } | ||
| 249 | |||
| 250 | #endif | 123 | #endif |
| 251 | layer_state_set_rgb_light(layer_state); | 124 | layer_state_set_rgb_light(layer_state); |
| 252 | } | 125 | } |
| 253 | 126 | ||
| 254 | void matrix_scan_rgb_light(void) { | 127 | void matrix_scan_rgb_light(void) { |
| 255 | #ifdef RGBLIGHT_ENABLE | ||
| 256 | # ifdef RGBLIGHT_TWINKLE | 128 | # ifdef RGBLIGHT_TWINKLE |
| 257 | scan_rgblight_fadeout(); | 129 | scan_rgblight_fadeout(); |
| 258 | # endif // RGBLIGHT_ENABLE | 130 | # endif // RGBLIGHT_ENABLE |
| 259 | 131 | ||
| 260 | # ifdef INDICATOR_LIGHTS | 132 | #if defined(RGBLIGHT_STARTUP_ANIMATION) |
| 261 | matrix_scan_indicator(); | 133 | if (is_rgblight_startup && is_keyboard_master()) { |
| 262 | # endif | 134 | if (timer_elapsed(rgblight_startup_loop_timer) > 10) { |
| 135 | static uint8_t counter; | ||
| 136 | counter++; | ||
| 137 | rgblight_sethsv_noeeprom((counter + old_hue) % 255, 255, 255); | ||
| 138 | rgblight_startup_loop_timer = timer_read(); | ||
| 139 | if (counter == 255) { | ||
| 140 | is_rgblight_startup = false; | ||
| 141 | if (!is_enabled) { | ||
| 142 | rgblight_disable_noeeprom(); | ||
| 143 | } | ||
| 144 | if (userspace_config.rgb_layer_change) { | ||
| 145 | layer_state_set_rgb_light(layer_state); | ||
| 146 | } | ||
| 147 | } | ||
| 148 | } | ||
| 149 | } | ||
| 263 | #endif | 150 | #endif |
| 264 | } | 151 | } |
| 265 | 152 | ||
