diff options
Diffstat (limited to 'users/drashna/rgb_stuff.c')
| -rw-r--r-- | users/drashna/rgb_stuff.c | 302 |
1 files changed, 168 insertions, 134 deletions
diff --git a/users/drashna/rgb_stuff.c b/users/drashna/rgb_stuff.c index 7d364fa68..12851e261 100644 --- a/users/drashna/rgb_stuff.c +++ b/users/drashna/rgb_stuff.c | |||
| @@ -4,77 +4,75 @@ | |||
| 4 | 4 | ||
| 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 | 8 | #endif |
| 9 | 9 | ||
| 10 | #ifdef RGBLIGHT_ENABLE | 10 | #ifdef RGBLIGHT_ENABLE |
| 11 | void rgblight_sethsv_default_helper(uint8_t index) { | 11 | void rgblight_sethsv_default_helper(uint8_t index) { rgblight_sethsv_at(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, index); } |
| 12 | rgblight_sethsv_at(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, index); | 12 | #endif // RGBLIGHT_ENABLE |
| 13 | } | ||
| 14 | #endif // RGBLIGHT_ENABLE | ||
| 15 | 13 | ||
| 16 | #ifdef INDICATOR_LIGHTS | 14 | #ifdef INDICATOR_LIGHTS |
| 17 | void set_rgb_indicators(uint8_t this_mod, uint8_t this_led, uint8_t this_osm) { | 15 | void set_rgb_indicators(uint8_t this_mod, uint8_t this_led, uint8_t this_osm) { |
| 18 | if (userspace_config.rgb_layer_change && biton32(layer_state) == 0) { | 16 | if (userspace_config.rgb_layer_change && biton32(layer_state) == 0) { |
| 19 | if ( (this_mod | this_osm) & MOD_MASK_SHIFT || this_led & (1<<USB_LED_CAPS_LOCK) ) { | 17 | if ((this_mod | this_osm) & MOD_MASK_SHIFT || this_led & (1 << USB_LED_CAPS_LOCK)) { |
| 20 | #ifdef SHFT_LED1 | 18 | # ifdef SHFT_LED1 |
| 21 | rgblight_sethsv_at(120, 255, 255, SHFT_LED1); | 19 | rgblight_sethsv_at(120, 255, 255, SHFT_LED1); |
| 22 | #endif // SHFT_LED1 | 20 | # endif // SHFT_LED1 |
| 23 | #ifdef SHFT_LED2 | 21 | # ifdef SHFT_LED2 |
| 24 | rgblight_sethsv_at(120, 255, 255, SHFT_LED2); | 22 | rgblight_sethsv_at(120, 255, 255, SHFT_LED2); |
| 25 | #endif // SHFT_LED2 | 23 | # endif // SHFT_LED2 |
| 26 | } else { | 24 | } else { |
| 27 | #ifdef SHFT_LED1 | 25 | # ifdef SHFT_LED1 |
| 28 | rgblight_sethsv_default_helper(SHFT_LED1); | 26 | rgblight_sethsv_default_helper(SHFT_LED1); |
| 29 | #endif // SHFT_LED1 | 27 | # endif // SHFT_LED1 |
| 30 | #ifdef SHFT_LED2 | 28 | # ifdef SHFT_LED2 |
| 31 | rgblight_sethsv_default_helper(SHFT_LED2); | 29 | rgblight_sethsv_default_helper(SHFT_LED2); |
| 32 | #endif // SHFT_LED2 | 30 | # endif // SHFT_LED2 |
| 33 | } | 31 | } |
| 34 | if ( (this_mod | this_osm) & MOD_MASK_CTRL) { | 32 | if ((this_mod | this_osm) & MOD_MASK_CTRL) { |
| 35 | #ifdef CTRL_LED1 | 33 | # ifdef CTRL_LED1 |
| 36 | rgblight_sethsv_at(0, 255, 255, CTRL_LED1); | 34 | rgblight_sethsv_at(0, 255, 255, CTRL_LED1); |
| 37 | #endif // CTRL_LED1 | 35 | # endif // CTRL_LED1 |
| 38 | #ifdef CTRL_LED2 | 36 | # ifdef CTRL_LED2 |
| 39 | rgblight_sethsv_at(0, 255, 255, CTRL_LED2); | 37 | rgblight_sethsv_at(0, 255, 255, CTRL_LED2); |
| 40 | #endif // CTRL_LED2 | 38 | # endif // CTRL_LED2 |
| 41 | } else { | 39 | } else { |
| 42 | #ifdef CTRL_LED1 | 40 | # ifdef CTRL_LED1 |
| 43 | rgblight_sethsv_default_helper(CTRL_LED1); | 41 | rgblight_sethsv_default_helper(CTRL_LED1); |
| 44 | #endif // CTRL_LED1 | 42 | # endif // CTRL_LED1 |
| 45 | #ifdef CTRL_LED2 | 43 | # ifdef CTRL_LED2 |
| 46 | rgblight_sethsv_default_helper(CTRL_LED2); | 44 | rgblight_sethsv_default_helper(CTRL_LED2); |
| 47 | #endif // CTRL_LED2 | 45 | # endif // CTRL_LED2 |
| 48 | } | 46 | } |
| 49 | if ( (this_mod | this_osm) & MOD_MASK_GUI) { | 47 | if ((this_mod | this_osm) & MOD_MASK_GUI) { |
| 50 | #ifdef GUI_LED1 | 48 | # ifdef GUI_LED1 |
| 51 | rgblight_sethsv_at(51, 255, 255, GUI_LED1); | 49 | rgblight_sethsv_at(51, 255, 255, GUI_LED1); |
| 52 | #endif // GUI_LED1 | 50 | # endif // GUI_LED1 |
| 53 | #ifdef GUI_LED2 | 51 | # ifdef GUI_LED2 |
| 54 | rgblight_sethsv_at(51, 255, 255, GUI_LED2); | 52 | rgblight_sethsv_at(51, 255, 255, GUI_LED2); |
| 55 | #endif // GUI_LED2 | 53 | # endif // GUI_LED2 |
| 56 | } else { | 54 | } else { |
| 57 | #ifdef GUI_LED1 | 55 | # ifdef GUI_LED1 |
| 58 | rgblight_sethsv_default_helper(GUI_LED1); | 56 | rgblight_sethsv_default_helper(GUI_LED1); |
| 59 | #endif // GUI_LED1 | 57 | # endif // GUI_LED1 |
| 60 | #ifdef GUI_LED2 | 58 | # ifdef GUI_LED2 |
| 61 | rgblight_sethsv_default_helper(GUI_LED2); | 59 | rgblight_sethsv_default_helper(GUI_LED2); |
| 62 | #endif // GUI_LED2 | 60 | # endif // GUI_LED2 |
| 63 | } | 61 | } |
| 64 | if ( (this_mod | this_osm) & MOD_MASK_ALT) { | 62 | if ((this_mod | this_osm) & MOD_MASK_ALT) { |
| 65 | #ifdef ALT_LED1 | 63 | # ifdef ALT_LED1 |
| 66 | rgblight_sethsv_at(240, 255, 255, ALT_LED1); | 64 | rgblight_sethsv_at(240, 255, 255, ALT_LED1); |
| 67 | #endif // ALT_LED1 | 65 | # endif // ALT_LED1 |
| 68 | #ifdef GUI_LED2 | 66 | # ifdef GUI_LED2 |
| 69 | rgblight_sethsv_at(240, 255, 255, ALT_LED2); | 67 | rgblight_sethsv_at(240, 255, 255, ALT_LED2); |
| 70 | #endif // GUI_LED2 | 68 | # endif // GUI_LED2 |
| 71 | } else { | 69 | } else { |
| 72 | #ifdef GUI_LED1 | 70 | # ifdef GUI_LED1 |
| 73 | rgblight_sethsv_default_helper(ALT_LED1); | 71 | rgblight_sethsv_default_helper(ALT_LED1); |
| 74 | #endif // GUI_LED1 | 72 | # endif // GUI_LED1 |
| 75 | #ifdef GUI_LED2 | 73 | # ifdef GUI_LED2 |
| 76 | rgblight_sethsv_default_helper(ALT_LED2); | 74 | rgblight_sethsv_default_helper(ALT_LED2); |
| 77 | #endif // GUI_LED2 | 75 | # endif // GUI_LED2 |
| 78 | } | 76 | } |
| 79 | } | 77 | } |
| 80 | } | 78 | } |
| @@ -84,75 +82,73 @@ void matrix_scan_indicator(void) { | |||
| 84 | set_rgb_indicators(get_mods(), host_keyboard_leds(), get_oneshot_mods()); | 82 | set_rgb_indicators(get_mods(), host_keyboard_leds(), get_oneshot_mods()); |
| 85 | } | 83 | } |
| 86 | } | 84 | } |
| 87 | #endif //INDICATOR_LIGHTS | 85 | #endif // INDICATOR_LIGHTS |
| 88 | 86 | ||
| 89 | #ifdef RGBLIGHT_TWINKLE | 87 | #ifdef RGBLIGHT_TWINKLE |
| 90 | static rgblight_fadeout lights[RGBLED_NUM]; | 88 | static rgblight_fadeout lights[RGBLED_NUM]; |
| 91 | 89 | ||
| 92 | __attribute__ ((weak)) | 90 | __attribute__((weak)) bool rgblight_twinkle_is_led_used_keymap(uint8_t index) { return false; } |
| 93 | bool rgblight_twinkle_is_led_used_keymap(uint8_t index) { return false; } | ||
| 94 | 91 | ||
| 95 | bool rgblight_twinkle_is_led_used(uint8_t index) { | 92 | bool rgblight_twinkle_is_led_used(uint8_t index) { |
| 96 | switch (index) { | 93 | switch (index) { |
| 97 | #ifdef INDICATOR_LIGHTS | 94 | # ifdef INDICATOR_LIGHTS |
| 98 | #ifdef SHFT_LED1 | 95 | # ifdef SHFT_LED1 |
| 99 | case SHFT_LED1: | 96 | case SHFT_LED1: |
| 100 | return true; | 97 | return true; |
| 101 | #endif //SHFT_LED1 | 98 | # endif // SHFT_LED1 |
| 102 | #ifdef SHFT_LED2 | 99 | # ifdef SHFT_LED2 |
| 103 | case SHFT_LED2: | 100 | case SHFT_LED2: |
| 104 | return true; | 101 | return true; |
| 105 | #endif //SHFT_LED2 | 102 | # endif // SHFT_LED2 |
| 106 | #ifdef CTRL_LED1 | 103 | # ifdef CTRL_LED1 |
| 107 | case CTRL_LED1: | 104 | case CTRL_LED1: |
| 108 | return true; | 105 | return true; |
| 109 | #endif //CTRL_LED1 | 106 | # endif // CTRL_LED1 |
| 110 | #ifdef CTRL_LED2 | 107 | # ifdef CTRL_LED2 |
| 111 | case CTRL_LED2: | 108 | case CTRL_LED2: |
| 112 | return true; | 109 | return true; |
| 113 | #endif //CTRL_LED2 | 110 | # endif // CTRL_LED2 |
| 114 | #ifdef GUI_LED1 | 111 | # ifdef GUI_LED1 |
| 115 | case GUI_LED1: | 112 | case GUI_LED1: |
| 116 | return true; | 113 | return true; |
| 117 | #endif //GUI_LED1 | 114 | # endif // GUI_LED1 |
| 118 | #ifdef GUI_LED2 | 115 | # ifdef GUI_LED2 |
| 119 | case GUI_LED2: | 116 | case GUI_LED2: |
| 120 | return true; | 117 | return true; |
| 121 | #endif //GUI_LED2 | 118 | # endif // GUI_LED2 |
| 122 | #ifdef ALT_LED1 | 119 | # ifdef ALT_LED1 |
| 123 | case ALT_LED1: | 120 | case ALT_LED1: |
| 124 | return true; | 121 | return true; |
| 125 | #endif //ALT_LED1 | 122 | # endif // ALT_LED1 |
| 126 | #ifdef ALT_LED2 | 123 | # ifdef ALT_LED2 |
| 127 | case ALT_LED2: | 124 | case ALT_LED2: |
| 128 | return true; | 125 | return true; |
| 129 | #endif //ALT_LED2 | 126 | # endif // ALT_LED2 |
| 130 | #endif //INDICATOR_LIGHTS | 127 | # endif // INDICATOR_LIGHTS |
| 131 | default: | 128 | default: |
| 132 | return rgblight_twinkle_is_led_used_keymap(index); | 129 | return rgblight_twinkle_is_led_used_keymap(index); |
| 133 | } | 130 | } |
| 134 | } | 131 | } |
| 135 | 132 | ||
| 136 | void scan_rgblight_fadeout(void) { // Don't effing change this function .... rgblight_sethsv is supppppper intensive | 133 | void scan_rgblight_fadeout(void) { // Don't effing change this function .... rgblight_sethsv is supppppper intensive |
| 137 | bool litup = false; | 134 | bool litup = false; |
| 138 | for (uint8_t light_index = 0 ; light_index < RGBLED_NUM ; ++light_index ) { | 135 | for (uint8_t light_index = 0; light_index < RGBLED_NUM; ++light_index) { |
| 139 | if (lights[light_index].enabled && timer_elapsed(lights[light_index].timer) > 10) { | 136 | if (lights[light_index].enabled && timer_elapsed(lights[light_index].timer) > 10) { |
| 140 | rgblight_fadeout *light = &lights[light_index]; | 137 | rgblight_fadeout *light = &lights[light_index]; |
| 141 | litup = true; | 138 | litup = true; |
| 142 | 139 | ||
| 143 | if (light->life) { | 140 | if (light->life) { |
| 144 | light->life -= 1; | 141 | light->life -= 1; |
| 145 | if (biton32(layer_state) == 0) { | 142 | if (biton32(layer_state) == 0) { |
| 146 | sethsv(light->hue + rand() % 0xF, 255, light->life, (LED_TYPE *)&led[light_index]); | 143 | sethsv(light->hue + rand() % 0xF, 255, light->life, (LED_TYPE *)&led[light_index]); |
| 147 | } | 144 | } |
| 148 | light->timer = timer_read(); | 145 | light->timer = timer_read(); |
| 149 | } | 146 | } else { |
| 150 | else { | 147 | if (light->enabled && biton32(layer_state) == 0) { |
| 151 | if (light->enabled && biton32(layer_state) == 0) { | 148 | rgblight_sethsv_default_helper(light_index); |
| 152 | rgblight_sethsv_default_helper(light_index); | 149 | } |
| 150 | litup = light->enabled = false; | ||
| 153 | } | 151 | } |
| 154 | litup = light->enabled = false; | ||
| 155 | } | ||
| 156 | } | 152 | } |
| 157 | } | 153 | } |
| 158 | if (litup && biton32(layer_state) == 0) { | 154 | if (litup && biton32(layer_state) == 0) { |
| @@ -161,39 +157,37 @@ void scan_rgblight_fadeout(void) { // Don't effing change this function .... rgb | |||
| 161 | } | 157 | } |
| 162 | 158 | ||
| 163 | void start_rgb_light(void) { | 159 | void start_rgb_light(void) { |
| 164 | |||
| 165 | uint8_t indices[RGBLED_NUM]; | 160 | uint8_t indices[RGBLED_NUM]; |
| 166 | uint8_t indices_count = 0; | 161 | uint8_t indices_count = 0; |
| 167 | uint8_t min_life = 0xFF; | 162 | uint8_t min_life = 0xFF; |
| 168 | uint8_t min_life_index = -1; | 163 | uint8_t min_life_index = -1; |
| 169 | for (uint8_t index = 0 ; index < RGBLED_NUM ; ++index ) { | 164 | for (uint8_t index = 0; index < RGBLED_NUM; ++index) { |
| 170 | if (rgblight_twinkle_is_led_used(index)) { continue; } | 165 | if (rgblight_twinkle_is_led_used(index)) { |
| 171 | if (lights[index].enabled) { | 166 | continue; |
| 172 | if (min_life_index == -1 || | 167 | } |
| 173 | lights[index].life < min_life) | 168 | if (lights[index].enabled) { |
| 174 | { | 169 | if (min_life_index == -1 || lights[index].life < min_life) { |
| 175 | min_life = lights[index].life; | 170 | min_life = lights[index].life; |
| 176 | min_life_index = index; | 171 | min_life_index = index; |
| 172 | } | ||
| 173 | continue; | ||
| 177 | } | 174 | } |
| 178 | continue; | ||
| 179 | } | ||
| 180 | 175 | ||
| 181 | indices[indices_count] = index; | 176 | indices[indices_count] = index; |
| 182 | ++indices_count; | 177 | ++indices_count; |
| 183 | } | 178 | } |
| 184 | 179 | ||
| 185 | uint8_t light_index; | 180 | uint8_t light_index; |
| 186 | if (!indices_count) { | 181 | if (!indices_count) { |
| 187 | light_index = min_life_index; | 182 | light_index = min_life_index; |
| 188 | } | 183 | } else { |
| 189 | else { | 184 | light_index = indices[rand() % indices_count]; |
| 190 | light_index = indices[rand() % indices_count]; | ||
| 191 | } | 185 | } |
| 192 | 186 | ||
| 193 | rgblight_fadeout *light = &lights[light_index]; | 187 | rgblight_fadeout *light = &lights[light_index]; |
| 194 | light->enabled = true; | 188 | light->enabled = true; |
| 195 | light->timer = timer_read(); | 189 | light->timer = timer_read(); |
| 196 | light->life = 0xC0 + rand() % 0x40; | 190 | light->life = 0xC0 + rand() % 0x40; |
| 197 | 191 | ||
| 198 | light->hue = rgblight_config.hue + (rand() % 0xB4) - 0x54; | 192 | light->hue = rgblight_config.hue + (rand() % 0xB4) - 0x54; |
| 199 | 193 | ||
| @@ -201,7 +195,6 @@ void start_rgb_light(void) { | |||
| 201 | } | 195 | } |
| 202 | #endif | 196 | #endif |
| 203 | 197 | ||
| 204 | |||
| 205 | bool process_record_user_rgb(uint16_t keycode, keyrecord_t *record) { | 198 | bool process_record_user_rgb(uint16_t keycode, keyrecord_t *record) { |
| 206 | if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { | 199 | if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { |
| 207 | keycode = keycode & 0xFF; | 200 | keycode = keycode & 0xFF; |
| @@ -214,9 +207,12 @@ bool process_record_user_rgb(uint16_t keycode, keyrecord_t *record) { | |||
| 214 | case KC_KP_SLASH ... KC_KP_DOT: | 207 | case KC_KP_SLASH ... KC_KP_DOT: |
| 215 | case KC_F13 ... KC_F24: | 208 | case KC_F13 ... KC_F24: |
| 216 | case KC_AUDIO_MUTE ... KC_MEDIA_REWIND: | 209 | case KC_AUDIO_MUTE ... KC_MEDIA_REWIND: |
| 217 | if (record->event.pressed) { start_rgb_light(); } | 210 | if (record->event.pressed) { |
| 218 | return true; break; | 211 | start_rgb_light(); |
| 219 | #endif // RGBLIGHT_TWINKLE | 212 | } |
| 213 | return true; | ||
| 214 | break; | ||
| 215 | #endif // RGBLIGHT_TWINKLE | ||
| 220 | case KC_RGB_T: // This allows me to use underglow as layer indication, or as normal | 216 | case KC_RGB_T: // This allows me to use underglow as layer indication, or as normal |
| 221 | #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) | 217 | #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) |
| 222 | if (record->event.pressed) { | 218 | if (record->event.pressed) { |
| @@ -224,41 +220,48 @@ bool process_record_user_rgb(uint16_t keycode, keyrecord_t *record) { | |||
| 224 | xprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change); | 220 | xprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change); |
| 225 | eeconfig_update_user(userspace_config.raw); | 221 | eeconfig_update_user(userspace_config.raw); |
| 226 | if (userspace_config.rgb_layer_change) { | 222 | if (userspace_config.rgb_layer_change) { |
| 227 | layer_state_set(layer_state); // This is needed to immediately set the layer color (looks better) | 223 | layer_state_set(layer_state); // This is needed to immediately set the layer color (looks better) |
| 228 | } | 224 | } |
| 229 | } | 225 | } |
| 230 | #endif // RGBLIGHT_ENABLE | 226 | #endif // RGBLIGHT_ENABLE |
| 231 | return false; break; | 227 | return false; |
| 228 | break; | ||
| 232 | #ifdef RGBLIGHT_ENABLE | 229 | #ifdef RGBLIGHT_ENABLE |
| 233 | case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // quantum_keycodes.h L400 for definitions | 230 | case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // quantum_keycodes.h L400 for definitions |
| 234 | if (record->event.pressed) { //This disables layer indication, as it's assumed that if you're changing this ... you want that disabled | 231 | if (record->event.pressed) { // This disables layer indication, as it's assumed that if you're changing this ... you want that disabled |
| 235 | if (userspace_config.rgb_layer_change) { | 232 | if (userspace_config.rgb_layer_change) { |
| 236 | userspace_config.rgb_layer_change = false; | 233 | userspace_config.rgb_layer_change = false; |
| 237 | xprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change); | 234 | xprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change); |
| 238 | eeconfig_update_user(userspace_config.raw); | 235 | eeconfig_update_user(userspace_config.raw); |
| 239 | } | 236 | } |
| 240 | } | 237 | } |
| 241 | return true; break; | 238 | return true; |
| 242 | #endif // RGBLIGHT_ENABLE | 239 | break; |
| 243 | } | 240 | #endif // RGBLIGHT_ENABLE |
| 241 | } | ||
| 244 | return true; | 242 | return true; |
| 245 | } | 243 | } |
| 246 | 244 | ||
| 247 | |||
| 248 | |||
| 249 | void keyboard_post_init_rgb(void) { | 245 | void keyboard_post_init_rgb(void) { |
| 250 | #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_STARTUP_ANIMATION) | 246 | #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_STARTUP_ANIMATION) |
| 251 | if (userspace_config.rgb_layer_change) { rgblight_enable_noeeprom(); } | 247 | bool is_enabled = rgblight_config.enable; |
| 248 | if (userspace_config.rgb_layer_change) { | ||
| 249 | rgblight_enable_noeeprom(); | ||
| 250 | } | ||
| 252 | if (rgblight_config.enable) { | 251 | if (rgblight_config.enable) { |
| 253 | layer_state_set_user(layer_state); | 252 | layer_state_set_user(layer_state); |
| 254 | uint16_t old_hue = rgblight_config.hue; | 253 | uint16_t old_hue = rgblight_config.hue; |
| 255 | rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT); | 254 | rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT); |
| 256 | for (uint16_t i = 255; i > 0; i--) { | 255 | for (uint16_t i = 255; i > 0; i--) { |
| 257 | rgblight_sethsv_noeeprom( ( i + old_hue) % 255, 255, 255); | 256 | rgblight_sethsv_noeeprom((i + old_hue) % 255, 255, 255); |
| 258 | matrix_scan(); | 257 | matrix_scan(); |
| 259 | wait_ms(10); | 258 | wait_ms(10); |
| 260 | } | 259 | } |
| 261 | } | 260 | } |
| 261 | if (!is_enabled) { | ||
| 262 | rgblight_disable_noeeprom(); | ||
| 263 | } | ||
| 264 | |||
| 262 | #endif | 265 | #endif |
| 263 | layer_state_set_user(layer_state); | 266 | layer_state_set_user(layer_state); |
| 264 | } | 267 | } |
| @@ -266,15 +269,13 @@ void keyboard_post_init_rgb(void) { | |||
| 266 | void matrix_scan_rgb(void) { | 269 | void matrix_scan_rgb(void) { |
| 267 | #ifdef RGBLIGHT_TWINKLE | 270 | #ifdef RGBLIGHT_TWINKLE |
| 268 | scan_rgblight_fadeout(); | 271 | scan_rgblight_fadeout(); |
| 269 | #endif // RGBLIGHT_ENABLE | 272 | #endif // RGBLIGHT_ENABLE |
| 270 | 273 | ||
| 271 | #ifdef INDICATOR_LIGHTS | 274 | #ifdef INDICATOR_LIGHTS |
| 272 | matrix_scan_indicator(); | 275 | matrix_scan_indicator(); |
| 273 | #endif | 276 | #endif |
| 274 | |||
| 275 | } | 277 | } |
| 276 | 278 | ||
| 277 | |||
| 278 | layer_state_t layer_state_set_rgb(layer_state_t state) { | 279 | layer_state_t layer_state_set_rgb(layer_state_t state) { |
| 279 | #ifdef RGBLIGHT_ENABLE | 280 | #ifdef RGBLIGHT_ENABLE |
| 280 | if (userspace_config.rgb_layer_change) { | 281 | if (userspace_config.rgb_layer_change) { |
| @@ -307,40 +308,73 @@ layer_state_t layer_state_set_rgb(layer_state_t state) { | |||
| 307 | rgblight_sethsv_noeeprom_red(); | 308 | rgblight_sethsv_noeeprom_red(); |
| 308 | rgblight_mode_noeeprom(RGBLIGHT_MODE_KNIGHT + 2); | 309 | rgblight_mode_noeeprom(RGBLIGHT_MODE_KNIGHT + 2); |
| 309 | break; | 310 | break; |
| 310 | default: // for any other layers, or the default layer | 311 | default: // for any other layers, or the default layer |
| 311 | switch (biton32(default_layer_state)) { | 312 | switch (biton32(default_layer_state)) { |
| 312 | case _COLEMAK: | 313 | case _COLEMAK: |
| 313 | rgblight_sethsv_noeeprom_magenta(); break; | 314 | rgblight_sethsv_noeeprom_magenta(); |
| 315 | break; | ||
| 314 | case _DVORAK: | 316 | case _DVORAK: |
| 315 | rgblight_sethsv_noeeprom_springgreen(); break; | 317 | rgblight_sethsv_noeeprom_springgreen(); |
| 318 | break; | ||
| 316 | case _WORKMAN: | 319 | case _WORKMAN: |
| 317 | rgblight_sethsv_noeeprom_goldenrod(); break; | 320 | rgblight_sethsv_noeeprom_goldenrod(); |
| 321 | break; | ||
| 318 | case _NORMAN: | 322 | case _NORMAN: |
| 319 | rgblight_sethsv_noeeprom_coral(); break; | 323 | rgblight_sethsv_noeeprom_coral(); |
| 324 | break; | ||
| 320 | case _MALTRON: | 325 | case _MALTRON: |
| 321 | rgblight_sethsv_noeeprom_yellow(); break; | 326 | rgblight_sethsv_noeeprom_yellow(); |
| 327 | break; | ||
| 322 | case _EUCALYN: | 328 | case _EUCALYN: |
| 323 | rgblight_sethsv_noeeprom_pink(); break; | 329 | rgblight_sethsv_noeeprom_pink(); |
| 330 | break; | ||
| 324 | case _CARPLAX: | 331 | case _CARPLAX: |
| 325 | rgblight_sethsv_noeeprom_blue(); break; | 332 | rgblight_sethsv_noeeprom_blue(); |
| 333 | break; | ||
| 326 | default: | 334 | default: |
| 327 | rgblight_sethsv_noeeprom_cyan(); break; | 335 | rgblight_sethsv_noeeprom_cyan(); |
| 336 | break; | ||
| 328 | } | 337 | } |
| 329 | biton32(state) == _MODS ? rgblight_mode_noeeprom(RGBLIGHT_MODE_BREATHING) : rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT); // if _MODS layer is on, then breath to denote it | 338 | biton32(state) == _MODS ? rgblight_mode_noeeprom(RGBLIGHT_MODE_BREATHING) : rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT); // if _MODS layer is on, then breath to denote it |
| 330 | break; | 339 | break; |
| 331 | } | 340 | } |
| 332 | } | 341 | } |
| 333 | #endif // RGBLIGHT_ENABLE | 342 | #endif // RGBLIGHT_ENABLE |
| 334 | 343 | ||
| 335 | return state; | 344 | return state; |
| 336 | } | 345 | } |
| 337 | 346 | ||
| 338 | #ifdef RGB_MATRIX_ENABLE | 347 | #ifdef RGB_MATRIX_ENABLE |
| 348 | # include "lib/lib8tion/lib8tion.h" | ||
| 339 | extern led_config_t g_led_config; | 349 | extern led_config_t g_led_config; |
| 340 | void rgb_matrix_layer_helper (uint8_t red, uint8_t green, uint8_t blue, uint8_t led_type) { | 350 | void rgb_matrix_layer_helper(uint8_t hue, uint8_t sat, uint8_t val, uint8_t mode, uint8_t speed, uint8_t led_type) { |
| 341 | for (int i = 0; i < DRIVER_LED_TOTAL; i++) { | 351 | HSV hsv = {hue, sat, val}; |
| 342 | if (HAS_FLAGS(g_led_config.flags[i], led_type)) { | 352 | if (hsv.v > rgb_matrix_config.hsv.v) { |
| 343 | rgb_matrix_set_color( i, red, green, blue ); | 353 | hsv.v = rgb_matrix_config.hsv.v; |
| 354 | } | ||
| 355 | |||
| 356 | switch (mode) { | ||
| 357 | case 1: // breathing | ||
| 358 | { | ||
| 359 | uint16_t time = scale16by8(g_rgb_counters.tick, speed / 8); | ||
| 360 | hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v); | ||
| 361 | RGB rgb = hsv_to_rgb(hsv); | ||
| 362 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | ||
| 363 | if (HAS_FLAGS(g_led_config.flags[i], led_type)) { | ||
| 364 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 365 | } | ||
| 366 | } | ||
| 367 | break; | ||
| 368 | } | ||
| 369 | default: // Solid Color | ||
| 370 | { | ||
| 371 | RGB rgb = hsv_to_rgb(hsv); | ||
| 372 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | ||
| 373 | if (HAS_FLAGS(g_led_config.flags[i], led_type)) { | ||
| 374 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 375 | } | ||
| 376 | } | ||
| 377 | break; | ||
| 344 | } | 378 | } |
| 345 | } | 379 | } |
| 346 | } | 380 | } |
