5 extern rgblight_config_t rgblight_config;
6 extern userspace_config_t userspace_config;
9 void rgblight_sethsv_default_helper(uint8_t index) {
10 rgblight_sethsv_at(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, index);
12 #endif // RGBLIGHT_ENABLE
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 && biton32(layer_state) == 0) {
17 if (this_mod & MODS_SHIFT_MASK || this_led & (1<<USB_LED_CAPS_LOCK) || this_osm & MODS_SHIFT_MASK) {
19 rgblight_sethsv_at(120, 255, 255, SHFT_LED1);
22 rgblight_sethsv_at(120, 255, 255, SHFT_LED2);
26 rgblight_sethsv_default_helper(SHFT_LED1);
29 rgblight_sethsv_default_helper(SHFT_LED2);
32 if (this_mod & MODS_CTRL_MASK || this_osm & MODS_CTRL_MASK) {
34 rgblight_sethsv_at(0, 255, 255, CTRL_LED1);
37 rgblight_sethsv_at(0, 255, 255, CTRL_LED2);
41 rgblight_sethsv_default_helper(CTRL_LED1);
44 rgblight_sethsv_default_helper(CTRL_LED2);
47 if (this_mod & MODS_GUI_MASK || this_osm & MODS_GUI_MASK) {
49 rgblight_sethsv_at(51, 255, 255, GUI_LED1);
52 rgblight_sethsv_at(51, 255, 255, GUI_LED2);
56 rgblight_sethsv_default_helper(GUI_LED1);
59 rgblight_sethsv_default_helper(GUI_LED2);
62 if (this_mod & MODS_ALT_MASK || this_osm & MODS_ALT_MASK) {
64 rgblight_sethsv_at(240, 255, 255, ALT_LED1);
67 rgblight_sethsv_at(240, 255, 255, ALT_LED2);
71 rgblight_sethsv_default_helper(ALT_LED1);
74 rgblight_sethsv_default_helper(ALT_LED2);
80 void matrix_scan_indicator(void) {
81 set_rgb_indicators(get_mods(), host_keyboard_leds(), get_oneshot_mods());
83 #endif //INDICATOR_LIGHTS
85 #ifdef RGBLIGHT_TWINKLE
86 static rgblight_fadeout lights[RGBLED_NUM];
88 __attribute__ ((weak))
89 bool rgblight_twinkle_is_led_used_keymap(uint8_t index) { return false; }
91 bool rgblight_twinkle_is_led_used(uint8_t index) {
93 #ifdef INDICATOR_LIGHTS
126 #endif //INDICATOR_LIGHTS
128 return rgblight_twinkle_is_led_used_keymap(index);
132 void scan_rgblight_fadeout(void) { // Don't effing change this function .... rgblight_sethsv is supppppper intensive
134 for (uint8_t light_index = 0 ; light_index < RGBLED_NUM ; ++light_index ) {
135 if (lights[light_index].enabled && timer_elapsed(lights[light_index].timer) > 10) {
136 rgblight_fadeout *light = &lights[light_index];
141 if (biton32(layer_state) == 0) {
142 sethsv(light->hue + rand() % 0xF, 255, light->life, (LED_TYPE *)&led[light_index]);
144 light->timer = timer_read();
147 if (light->enabled && biton32(layer_state) == 0) { rgblight_sethsv_default_helper(light_index); }
148 litup = light->enabled = false;
152 if (litup && biton32(layer_state) == 0) {
157 void start_rgb_light(void) {
159 uint8_t indices[RGBLED_NUM];
160 uint8_t indices_count = 0;
161 uint8_t min_life = 0xFF;
162 uint8_t min_life_index = -1;
163 for (uint8_t index = 0 ; index < RGBLED_NUM ; ++index ) {
164 if (rgblight_twinkle_is_led_used(index)) { continue; }
165 if (lights[index].enabled) {
166 if (min_life_index == -1 ||
167 lights[index].life < min_life)
169 min_life = lights[index].life;
170 min_life_index = index;
175 indices[indices_count] = index;
180 if (!indices_count) {
181 light_index = min_life_index;
184 light_index = indices[rand() % indices_count];
187 rgblight_fadeout *light = &lights[light_index];
188 light->enabled = true;
189 light->timer = timer_read();
190 light->life = 0xC0 + rand() % 0x40;
192 light->hue = rgblight_config.hue + (rand() % 0xB4) - 0x54;
194 rgblight_sethsv_at(light->hue, 255, light->life, light_index);
199 bool process_record_user_rgb(uint16_t keycode, keyrecord_t *record) {
201 #ifdef RGBLIGHT_TWINKLE
202 case KC_A ... KC_SLASH:
203 case KC_F1 ... KC_F12:
204 case KC_INSERT ... KC_UP:
205 case KC_KP_SLASH ... KC_KP_DOT:
206 case KC_F13 ... KC_F24:
207 case KC_AUDIO_MUTE ... KC_MEDIA_REWIND:
208 if (record->event.pressed) { start_rgb_light(); }
210 #endif // RGBLIGHT_TWINKLE
211 case KC_RGB_T: // This allows me to use underglow as layer indication, or as normal
212 #ifdef RGBLIGHT_ENABLE
213 if (record->event.pressed) {
214 userspace_config.rgb_layer_change ^= 1;
215 xprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change);
216 eeconfig_update_user(userspace_config.raw);
217 if (userspace_config.rgb_layer_change) {
218 layer_state_set(layer_state); // This is needed to immediately set the layer color (looks better)
221 #endif // RGBLIGHT_ENABLE
223 #ifdef RGBLIGHT_ENABLE
224 case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // quantum_keycodes.h L400 for definitions
225 if (record->event.pressed) { //This disables layer indication, as it's assumed that if you're changing this ... you want that disabled
226 if (userspace_config.rgb_layer_change) {
227 userspace_config.rgb_layer_change = false;
228 xprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change);
229 eeconfig_update_user(userspace_config.raw);
233 #endif // RGBLIGHT_ENABLE
240 void matrix_init_rgb(void) {
242 if (userspace_config.rgb_layer_change) {
244 rgblight_enable_noeeprom();
245 switch (biton32(eeconfig_read_default_layer())) {
247 rgblight_sethsv_noeeprom_magenta(); break;
249 rgblight_sethsv_noeeprom_springgreen(); break;
251 rgblight_sethsv_noeeprom_goldenrod(); break;
253 rgblight_sethsv_noeeprom_cyan(); break;
255 rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT);
259 void matrix_scan_rgb(void) {
260 #ifdef RGBLIGHT_TWINKLE
261 scan_rgblight_fadeout();
262 #endif // RGBLIGHT_ENABLE
264 #ifdef INDICATOR_LIGHTS
265 matrix_scan_indicator();
271 uint32_t layer_state_set_rgb(uint32_t state) {
272 #ifdef RGBLIGHT_ENABLE
274 if (userspace_config.rgb_layer_change) {
275 switch (biton32(state)) {
277 rgblight_sethsv_noeeprom_orange();
278 userspace_config.is_overwatch ? rgblight_effect_snake(RGBLIGHT_MODE_SNAKE + 2) : rgblight_effect_snake(RGBLIGHT_MODE_SNAKE + 3);
281 rgblight_sethsv_noeeprom_chartreuse();
282 rgblight_mode_noeeprom(RGBLIGHT_MODE_KNIGHT + 1);
285 rgblight_sethsv_noeeprom_orange();
286 rgblight_mode_noeeprom(RGBLIGHT_MODE_SNAKE + 2);
289 rgblight_sethsv_noeeprom_red();
290 rgblight_mode_noeeprom(RGBLIGHT_MODE_BREATHING + 3);
293 rgblight_sethsv_noeeprom_yellow();
294 rgblight_mode_noeeprom(RGBLIGHT_MODE_BREATHING + 3);
297 rgblight_sethsv_noeeprom_green();
298 rgblight_mode_noeeprom(RGBLIGHT_MODE_BREATHING + 3);
301 rgblight_sethsv_noeeprom_red();
302 rgblight_mode_noeeprom(RGBLIGHT_MODE_KNIGHT + 2);
304 default: // for any other layers, or the default layer
305 switch (biton32(default_layer_state)) {
307 rgblight_sethsv_noeeprom_magenta(); break;
309 rgblight_sethsv_noeeprom_springgreen(); break;
311 rgblight_sethsv_noeeprom_goldenrod(); break;
313 rgblight_sethsv_noeeprom_cyan(); break;
316 biton32(state) == _MODS ? rgblight_mode(RGBLIGHT_MODE_BREATHING) : rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT); // if _MODS layer is on, then breath to denote it
318 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
323 // layer_state_set_indicator(); // Runs every scan, so need to call this here .... since I can't get it working "right" anyhow
325 #endif // RGBLIGHT_ENABLE