diff options
Diffstat (limited to 'users/drashna/rgb_stuff.c')
| -rw-r--r-- | users/drashna/rgb_stuff.c | 97 |
1 files changed, 79 insertions, 18 deletions
diff --git a/users/drashna/rgb_stuff.c b/users/drashna/rgb_stuff.c index 12851e261..a9af0566e 100644 --- a/users/drashna/rgb_stuff.c +++ b/users/drashna/rgb_stuff.c | |||
| @@ -5,12 +5,24 @@ | |||
| 5 | #if defined(RGBLIGHT_ENABLE) | 5 | #if defined(RGBLIGHT_ENABLE) |
| 6 | extern rgblight_config_t rgblight_config; | 6 | extern rgblight_config_t rgblight_config; |
| 7 | bool has_initialized; | 7 | bool has_initialized; |
| 8 | #endif | ||
| 9 | 8 | ||
| 10 | #ifdef RGBLIGHT_ENABLE | ||
| 11 | void rgblight_sethsv_default_helper(uint8_t index) { rgblight_sethsv_at(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, index); } | 9 | void rgblight_sethsv_default_helper(uint8_t index) { rgblight_sethsv_at(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, index); } |
| 12 | #endif // RGBLIGHT_ENABLE | 10 | #endif // RGBLIGHT_ENABLE |
| 13 | 11 | ||
| 12 | #if defined(RGB_MATRIX_ENABLE) | ||
| 13 | static uint32_t hypno_timer; | ||
| 14 | # if defined(SPLIT_KEYBOARD) || defined(KEYBOARD_ergodox_ez) || defined(KEYBOARD_crkbd) | ||
| 15 | # define RGB_MATRIX_REST_MODE RGB_MATRIX_CYCLE_OUT_IN_DUAL | ||
| 16 | # else | ||
| 17 | # define RGB_MATRIX_REST_MODE RGB_MATRIX_CYCLE_OUT_IN | ||
| 18 | # endif | ||
| 19 | #endif | ||
| 20 | |||
| 21 | /* Custom indicators for modifiers. | ||
| 22 | * This allows for certain lights to be lit up, based on what mods are active, giving some visual feedback. | ||
| 23 | * This is especially useful for One Shot Mods, since it's not always obvious if they're still lit up. | ||
| 24 | */ | ||
| 25 | #ifdef RGBLIGHT_ENABLE | ||
| 14 | #ifdef INDICATOR_LIGHTS | 26 | #ifdef INDICATOR_LIGHTS |
| 15 | void set_rgb_indicators(uint8_t this_mod, uint8_t this_led, uint8_t this_osm) { | 27 | void set_rgb_indicators(uint8_t this_mod, uint8_t this_led, uint8_t this_osm) { |
| 16 | if (userspace_config.rgb_layer_change && biton32(layer_state) == 0) { | 28 | if (userspace_config.rgb_layer_change && biton32(layer_state) == 0) { |
| @@ -77,6 +89,7 @@ void set_rgb_indicators(uint8_t this_mod, uint8_t this_led, uint8_t this_osm) { | |||
| 77 | } | 89 | } |
| 78 | } | 90 | } |
| 79 | 91 | ||
| 92 | /* Function for the indicators */ | ||
| 80 | void matrix_scan_indicator(void) { | 93 | void matrix_scan_indicator(void) { |
| 81 | if (has_initialized) { | 94 | if (has_initialized) { |
| 82 | set_rgb_indicators(get_mods(), host_keyboard_leds(), get_oneshot_mods()); | 95 | set_rgb_indicators(get_mods(), host_keyboard_leds(), get_oneshot_mods()); |
| @@ -89,6 +102,7 @@ static rgblight_fadeout lights[RGBLED_NUM]; | |||
| 89 | 102 | ||
| 90 | __attribute__((weak)) bool rgblight_twinkle_is_led_used_keymap(uint8_t index) { return false; } | 103 | __attribute__((weak)) bool rgblight_twinkle_is_led_used_keymap(uint8_t index) { return false; } |
| 91 | 104 | ||
| 105 | /* This function checks for used LEDs. This way, collisions don't occur and cause weird rendering */ | ||
| 92 | bool rgblight_twinkle_is_led_used(uint8_t index) { | 106 | bool rgblight_twinkle_is_led_used(uint8_t index) { |
| 93 | switch (index) { | 107 | switch (index) { |
| 94 | # ifdef INDICATOR_LIGHTS | 108 | # ifdef INDICATOR_LIGHTS |
| @@ -130,6 +144,7 @@ bool rgblight_twinkle_is_led_used(uint8_t index) { | |||
| 130 | } | 144 | } |
| 131 | } | 145 | } |
| 132 | 146 | ||
| 147 | /* Handler for fading/twinkling effect */ | ||
| 133 | void scan_rgblight_fadeout(void) { // Don't effing change this function .... rgblight_sethsv is supppppper intensive | 148 | void scan_rgblight_fadeout(void) { // Don't effing change this function .... rgblight_sethsv is supppppper intensive |
| 134 | bool litup = false; | 149 | bool litup = false; |
| 135 | for (uint8_t light_index = 0; light_index < RGBLED_NUM; ++light_index) { | 150 | for (uint8_t light_index = 0; light_index < RGBLED_NUM; ++light_index) { |
| @@ -156,6 +171,9 @@ void scan_rgblight_fadeout(void) { // Don't effing change this function .... rg | |||
| 156 | } | 171 | } |
| 157 | } | 172 | } |
| 158 | 173 | ||
| 174 | /* Triggers a LED to fade/twinkle. | ||
| 175 | * This function handles the selection of the LED and prepres for it to be used. | ||
| 176 | */ | ||
| 159 | void start_rgb_light(void) { | 177 | void start_rgb_light(void) { |
| 160 | uint8_t indices[RGBLED_NUM]; | 178 | uint8_t indices[RGBLED_NUM]; |
| 161 | uint8_t indices_count = 0; | 179 | uint8_t indices_count = 0; |
| @@ -194,12 +212,23 @@ void start_rgb_light(void) { | |||
| 194 | rgblight_sethsv_at(light->hue, 255, light->life, light_index); | 212 | rgblight_sethsv_at(light->hue, 255, light->life, light_index); |
| 195 | } | 213 | } |
| 196 | #endif | 214 | #endif |
| 215 | #endif // RGBLIGHT_ENABLE | ||
| 197 | 216 | ||
| 198 | bool process_record_user_rgb(uint16_t keycode, keyrecord_t *record) { | 217 | bool process_record_user_rgb(uint16_t keycode, keyrecord_t *record) { |
| 218 | uint16_t temp_keycode = keycode; | ||
| 219 | // Filter out the actual keycode from MT and LT keys. | ||
| 199 | if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { | 220 | if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { |
| 200 | keycode = keycode & 0xFF; | 221 | temp_keycode &= 0xFF; |
| 201 | } | 222 | } |
| 202 | switch (keycode) { | 223 | |
| 224 | #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) | ||
| 225 | hypno_timer = timer_read32(); | ||
| 226 | if (userspace_config.rgb_matrix_idle_anim && rgb_matrix_get_mode() == RGB_MATRIX_REST_MODE) { | ||
| 227 | rgb_matrix_mode_noeeprom(RGB_MATRIX_TYPING_HEATMAP); | ||
| 228 | } | ||
| 229 | #endif | ||
| 230 | |||
| 231 | switch (temp_keycode) { | ||
| 203 | #ifdef RGBLIGHT_TWINKLE | 232 | #ifdef RGBLIGHT_TWINKLE |
| 204 | case KC_A ... KC_SLASH: | 233 | case KC_A ... KC_SLASH: |
| 205 | case KC_F1 ... KC_F12: | 234 | case KC_F1 ... KC_F12: |
| @@ -210,40 +239,58 @@ bool process_record_user_rgb(uint16_t keycode, keyrecord_t *record) { | |||
| 210 | if (record->event.pressed) { | 239 | if (record->event.pressed) { |
| 211 | start_rgb_light(); | 240 | start_rgb_light(); |
| 212 | } | 241 | } |
| 213 | return true; | ||
| 214 | break; | 242 | break; |
| 215 | #endif // RGBLIGHT_TWINKLE | 243 | #endif // RGBLIGHT_TWINKLE |
| 216 | case KC_RGB_T: // This allows me to use underglow as layer indication, or as normal | 244 | case KC_RGB_T: // This allows me to use underglow as layer indication, or as normal |
| 217 | #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) | 245 | #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) |
| 218 | if (record->event.pressed) { | 246 | if (record->event.pressed) { |
| 219 | userspace_config.rgb_layer_change ^= 1; | 247 | userspace_config.rgb_layer_change ^= 1; |
| 220 | xprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change); | 248 | dprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change); |
| 221 | eeconfig_update_user(userspace_config.raw); | 249 | eeconfig_update_user(userspace_config.raw); |
| 222 | if (userspace_config.rgb_layer_change) { | 250 | if (userspace_config.rgb_layer_change) { |
| 223 | layer_state_set(layer_state); // This is needed to immediately set the layer color (looks better) | 251 | layer_state_set(layer_state); // This is needed to immediately set the layer color (looks better) |
| 224 | } | 252 | } |
| 225 | } | 253 | } |
| 226 | #endif // RGBLIGHT_ENABLE | 254 | #endif // RGBLIGHT_ENABLE |
| 227 | return false; | ||
| 228 | break; | 255 | break; |
| 229 | #ifdef RGBLIGHT_ENABLE | 256 | case RGB_IDL: // This allows me to use underglow as layer indication, or as normal |
| 257 | #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) | ||
| 258 | if (record->event.pressed) { | ||
| 259 | userspace_config.rgb_matrix_idle_anim ^= 1; | ||
| 260 | dprintf("RGB Matrix Idle Animation [EEPROM]: %u\n", userspace_config.rgb_matrix_idle_anim); | ||
| 261 | eeconfig_update_user(userspace_config.raw); | ||
| 262 | if (userspace_config.rgb_matrix_idle_anim) { rgb_matrix_mode_noeeprom(RGB_MATRIX_TYPING_HEATMAP); } | ||
| 263 | } | ||
| 264 | #endif | ||
| 265 | break; | ||
| 230 | case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // quantum_keycodes.h L400 for definitions | 266 | case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // quantum_keycodes.h L400 for definitions |
| 231 | if (record->event.pressed) { // This disables layer indication, as it's assumed that if you're changing this ... you want that disabled | 267 | if (record->event.pressed) { |
| 268 | bool is_eeprom_updated = false; | ||
| 269 | #ifdef RGBLIGHT_ENABLE | ||
| 270 | // This disables layer indication, as it's assumed that if you're changing this ... you want that disabled | ||
| 232 | if (userspace_config.rgb_layer_change) { | 271 | if (userspace_config.rgb_layer_change) { |
| 233 | userspace_config.rgb_layer_change = false; | 272 | userspace_config.rgb_layer_change = false; |
| 234 | xprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change); | 273 | dprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change); |
| 235 | eeconfig_update_user(userspace_config.raw); | 274 | is_eeprom_updated = true; |
| 236 | } | 275 | } |
| 276 | #endif | ||
| 277 | #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) | ||
| 278 | if (userspace_config.rgb_matrix_idle_anim) { | ||
| 279 | userspace_config.rgb_matrix_idle_anim = false; | ||
| 280 | dprintf("RGB Matrix Idle Animation [EEPROM]: %u\n", userspace_config.rgb_matrix_idle_anim); | ||
| 281 | is_eeprom_updated = true; | ||
| 282 | } | ||
| 283 | #endif | ||
| 284 | if (is_eeprom_updated) { eeconfig_update_user(userspace_config.raw); } | ||
| 237 | } | 285 | } |
| 238 | return true; | ||
| 239 | break; | 286 | break; |
| 240 | #endif // RGBLIGHT_ENABLE | ||
| 241 | } | 287 | } |
| 242 | return true; | 288 | return true; |
| 243 | } | 289 | } |
| 244 | 290 | ||
| 245 | void keyboard_post_init_rgb(void) { | 291 | void keyboard_post_init_rgb(void) { |
| 246 | #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_STARTUP_ANIMATION) | 292 | #if defined(RGBLIGHT_ENABLE) |
| 293 | # if defined(RGBLIGHT_STARTUP_ANIMATION) | ||
| 247 | bool is_enabled = rgblight_config.enable; | 294 | bool is_enabled = rgblight_config.enable; |
| 248 | if (userspace_config.rgb_layer_change) { | 295 | if (userspace_config.rgb_layer_change) { |
| 249 | rgblight_enable_noeeprom(); | 296 | rgblight_enable_noeeprom(); |
| @@ -262,17 +309,31 @@ void keyboard_post_init_rgb(void) { | |||
| 262 | rgblight_disable_noeeprom(); | 309 | rgblight_disable_noeeprom(); |
| 263 | } | 310 | } |
| 264 | 311 | ||
| 265 | #endif | 312 | # endif |
| 266 | layer_state_set_user(layer_state); | 313 | layer_state_set_user(layer_state); |
| 314 | #endif | ||
| 315 | #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) | ||
| 316 | if (userspace_config.rgb_matrix_idle_anim) { | ||
| 317 | rgb_matrix_mode_noeeprom(RGB_MATRIX_REST_MODE); | ||
| 318 | } | ||
| 319 | #endif | ||
| 267 | } | 320 | } |
| 268 | 321 | ||
| 269 | void matrix_scan_rgb(void) { | 322 | void matrix_scan_rgb(void) { |
| 270 | #ifdef RGBLIGHT_TWINKLE | 323 | #ifdef RGBLIGHT_ENABLE |
| 324 | # ifdef RGBLIGHT_TWINKLE | ||
| 271 | scan_rgblight_fadeout(); | 325 | scan_rgblight_fadeout(); |
| 272 | #endif // RGBLIGHT_ENABLE | 326 | # endif // RGBLIGHT_ENABLE |
| 273 | 327 | ||
| 274 | #ifdef INDICATOR_LIGHTS | 328 | # ifdef INDICATOR_LIGHTS |
| 275 | matrix_scan_indicator(); | 329 | matrix_scan_indicator(); |
| 330 | # endif | ||
| 331 | #endif | ||
| 332 | |||
| 333 | #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) | ||
| 334 | if (userspace_config.rgb_matrix_idle_anim && rgb_matrix_get_mode() == RGB_MATRIX_TYPING_HEATMAP && timer_elapsed32(hypno_timer) > 15000) { | ||
| 335 | rgb_matrix_mode_noeeprom(RGB_MATRIX_REST_MODE); | ||
| 336 | } | ||
| 276 | #endif | 337 | #endif |
| 277 | } | 338 | } |
| 278 | 339 | ||
