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
23 void set_rgb_indicators(uint8_t this_mod, uint8_t this_led, uint8_t this_osm) {
24 if (userspace_config.rgb_layer_change && biton32(layer_state) == 0) {
25 if (this_mod & MODS_SHIFT_MASK || this_led & (1<<USB_LED_CAPS_LOCK) || this_osm & MODS_SHIFT_MASK) {
27 rgblight_sethsv_at(120, 255, 255, SHFT_LED1);
30 rgblight_sethsv_at(120, 255, 255, SHFT_LED2);
34 rgblight_sethsv_default_helper(SHFT_LED1);
37 rgblight_sethsv_default_helper(SHFT_LED2);
40 if (this_mod & MODS_CTRL_MASK || this_osm & MODS_CTRL_MASK) {
42 rgblight_sethsv_at(0, 255, 255, CTRL_LED1);
45 rgblight_sethsv_at(0, 255, 255, CTRL_LED2);
49 rgblight_sethsv_default_helper(CTRL_LED1);
52 rgblight_sethsv_default_helper(CTRL_LED2);
55 if (this_mod & MODS_GUI_MASK || this_osm & MODS_GUI_MASK) {
57 rgblight_sethsv_at(51, 255, 255, GUI_LED1);
60 rgblight_sethsv_at(51, 255, 255, GUI_LED2);
64 rgblight_sethsv_default_helper(GUI_LED1);
67 rgblight_sethsv_default_helper(GUI_LED2);
70 if (this_mod & MODS_ALT_MASK || this_osm & MODS_ALT_MASK) {
72 rgblight_sethsv_at(240, 255, 255, ALT_LED1);
75 rgblight_sethsv_at(240, 255, 255, ALT_LED2);
79 rgblight_sethsv_default_helper(ALT_LED1);
82 rgblight_sethsv_default_helper(ALT_LED2);
88 void matrix_scan_indicator(void) {
89 current_mod = get_mods();
90 current_led = host_keyboard_leds();
91 current_osm = get_oneshot_mods();
93 set_rgb_indicators(current_mod, current_led, current_osm);
95 last_mod = current_mod;
96 last_led = current_led;
97 last_osm = current_osm;
100 #endif //INDICATOR_LIGHTS
102 #ifdef RGBLIGHT_TWINKLE
103 static rgblight_fadeout lights[RGBLED_NUM];
105 __attribute__ ((weak))
106 bool rgblight_twinkle_is_led_used_keymap(uint8_t index) { return false; }
108 bool rgblight_twinkle_is_led_used(uint8_t index) {
110 #ifdef INDICATOR_LIGHTS
143 #endif //INDICATOR_LIGHTS
145 return rgblight_twinkle_is_led_used_keymap(index);
149 void scan_rgblight_fadeout(void) { // Don't effing change this function .... rgblight_sethsv is supppppper intensive
151 for (uint8_t light_index = 0 ; light_index < RGBLED_NUM ; ++light_index ) {
152 if (lights[light_index].enabled && timer_elapsed(lights[light_index].timer) > 10) {
153 rgblight_fadeout *light = &lights[light_index];
158 if (biton32(layer_state) == 0) {
159 sethsv(light->hue + rand() % 0xF, 255, light->life, (LED_TYPE *)&led[light_index]);
161 light->timer = timer_read();
164 if (light->enabled && biton32(layer_state) == 0) { rgblight_sethsv_default_helper(light_index); }
165 litup = light->enabled = false;
169 if (litup && biton32(layer_state) == 0) {
174 void start_rgb_light(void) {
176 uint8_t indices[RGBLED_NUM];
177 uint8_t indices_count = 0;
178 uint8_t min_life = 0xFF;
179 uint8_t min_life_index = -1;
180 for (uint8_t index = 0 ; index < RGBLED_NUM ; ++index ) {
181 if (rgblight_twinkle_is_led_used(index)) { continue; }
182 if (lights[index].enabled) {
183 if (min_life_index == -1 ||
184 lights[index].life < min_life)
186 min_life = lights[index].life;
187 min_life_index = index;
192 indices[indices_count] = index;
197 if (!indices_count) {
198 light_index = min_life_index;
201 light_index = indices[rand() % indices_count];
204 rgblight_fadeout *light = &lights[light_index];
205 light->enabled = true;
206 light->timer = timer_read();
207 light->life = 0xC0 + rand() % 0x40;
209 light->hue = rgblight_config.hue + (rand() % 0xB4) - 0x54;
211 rgblight_sethsv_at(light->hue, 255, light->life, light_index);
216 bool process_record_user_rgb(uint16_t keycode, keyrecord_t *record) {
218 #ifdef RGBLIGHT_TWINKLE
219 case KC_A ... KC_SLASH:
220 case KC_F1 ... KC_F12:
221 case KC_INSERT ... KC_UP:
222 case KC_KP_SLASH ... KC_KP_DOT:
223 case KC_F13 ... KC_F24:
224 case KC_AUDIO_MUTE ... KC_MEDIA_REWIND:
225 if (record->event.pressed) { start_rgb_light(); }
227 #endif // RGBLIGHT_TWINKLE
228 case KC_RGB_T: // This allows me to use underglow as layer indication, or as normal
229 #ifdef RGBLIGHT_ENABLE
230 if (record->event.pressed) {
231 userspace_config.rgb_layer_change ^= 1;
232 xprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change);
233 eeconfig_update_user(userspace_config.raw);
234 if (userspace_config.rgb_layer_change) {
235 layer_state_set(layer_state); // This is needed to immediately set the layer color (looks better)
238 #endif // RGBLIGHT_ENABLE
240 #ifdef RGBLIGHT_ENABLE
241 case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // quantum_keycodes.h L400 for definitions
242 if (record->event.pressed) { //This disables layer indication, as it's assumed that if you're changing this ... you want that disabled
243 if (userspace_config.rgb_layer_change) {
244 userspace_config.rgb_layer_change = false;
245 xprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change);
246 eeconfig_update_user(userspace_config.raw);
250 #endif // RGBLIGHT_ENABLE
257 void matrix_init_rgb(void) {
258 #ifdef INDICATOR_LIGHTS
259 current_mod = last_mod = get_mods();
260 current_led = last_led = host_keyboard_leds();
261 current_osm = last_osm = get_oneshot_mods();
264 if (userspace_config.rgb_layer_change) {
265 rgblight_enable_noeeprom();
266 switch (biton32(eeconfig_read_default_layer())) {
268 rgblight_sethsv_noeeprom_magenta(); break;
270 rgblight_sethsv_noeeprom_springgreen(); break;
272 rgblight_sethsv_noeeprom_goldenrod(); break;
274 rgblight_sethsv_noeeprom_cyan(); break;
276 rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT);
280 void matrix_scan_rgb(void) {
281 #ifdef RGBLIGHT_TWINKLE
282 scan_rgblight_fadeout();
283 #endif // RGBLIGHT_ENABLE
285 #ifdef INDICATOR_LIGHTS
286 matrix_scan_indicator();
292 uint32_t layer_state_set_rgb(uint32_t state) {
293 #ifdef RGBLIGHT_ENABLE
294 if (userspace_config.rgb_layer_change) {
295 switch (biton32(state)) {
297 rgblight_sethsv_noeeprom_orange();
298 userspace_config.is_overwatch ? rgblight_effect_snake(RGBLIGHT_MODE_SNAKE + 2) : rgblight_effect_snake(RGBLIGHT_MODE_SNAKE + 3);
301 rgblight_sethsv_noeeprom_chartreuse();
302 rgblight_mode_noeeprom(RGBLIGHT_MODE_KNIGHT + 1);
305 rgblight_sethsv_noeeprom_orange();
306 rgblight_mode_noeeprom(RGBLIGHT_MODE_SNAKE + 2);
309 rgblight_sethsv_noeeprom_red();
310 rgblight_mode_noeeprom(RGBLIGHT_MODE_BREATHING + 3);
313 rgblight_sethsv_noeeprom_yellow();
314 rgblight_mode_noeeprom(RGBLIGHT_MODE_BREATHING + 3);
317 rgblight_sethsv_noeeprom_green();
318 rgblight_mode_noeeprom(RGBLIGHT_MODE_BREATHING + 3);
321 rgblight_sethsv_noeeprom_red();
322 rgblight_mode_noeeprom(RGBLIGHT_MODE_KNIGHT + 2);
324 default: // for any other layers, or the default layer
325 switch (biton32(default_layer_state)) {
327 rgblight_sethsv_noeeprom_magenta(); break;
329 rgblight_sethsv_noeeprom_springgreen(); break;
331 rgblight_sethsv_noeeprom_goldenrod(); break;
333 rgblight_sethsv_noeeprom_cyan(); break;
335 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 // layer_state_set_indicator(); // Runs every scan, so need to call this here .... since I can't get it working "right" anyhow
340 #endif // RGBLIGHT_ENABLE