4 extern rgblight_config_t rgblight_config
;
5 extern userspace_config_t userspace_config
;
8 void rgblight_sethsv_default_helper(uint8_t index
) {
9 rgblight_sethsv_at(rgblight_config
.hue
, rgblight_config
.sat
, rgblight_config
.val
, index
);
11 #endif // RGBLIGHT_ENABLE
13 #ifdef INDICATOR_LIGHTS
22 void set_rgb_indicators(uint8_t this_mod
, uint8_t this_led
, uint8_t this_osm
) {
23 if (userspace_config
.rgb_layer_change
&& biton32(layer_state
) == 0) {
24 if (this_mod
& MODS_SHIFT_MASK
|| this_led
& (1<<USB_LED_CAPS_LOCK
) || this_osm
& MODS_SHIFT_MASK
) {
25 rgblight_sethsv_at(0, 255, 255, SHFT_LED1
);
26 rgblight_sethsv_at(0, 255, 255, SHFT_LED2
);
28 rgblight_sethsv_default_helper(SHFT_LED1
);
29 rgblight_sethsv_default_helper(SHFT_LED2
);
31 if (this_mod
& MODS_CTRL_MASK
|| this_osm
& MODS_CTRL_MASK
) {
32 rgblight_sethsv_at(51, 255, 255, CTRL_LED1
);
33 rgblight_sethsv_at(51, 255, 255, CTRL_LED2
);
35 rgblight_sethsv_default_helper(CTRL_LED1
);
36 rgblight_sethsv_default_helper(CTRL_LED2
);
38 if (this_mod
& MODS_GUI_MASK
|| this_osm
& MODS_GUI_MASK
) {
39 rgblight_sethsv_at(120, 255, 255, GUI_LED1
);
40 rgblight_sethsv_at(120, 255, 255, GUI_LED2
);
42 rgblight_sethsv_default_helper(GUI_LED1
);
43 rgblight_sethsv_default_helper(GUI_LED2
);
48 void matrix_scan_indicator(void) {
49 current_mod
= get_mods();
50 current_led
= host_keyboard_leds();
51 current_osm
= get_oneshot_mods();
53 set_rgb_indicators(current_mod
, current_led
, current_osm
);
55 last_mod
= current_mod
;
56 last_led
= current_led
;
57 last_osm
= current_osm
;
60 #endif //INDICATOR_LIGHTS
62 #ifdef RGBLIGHT_TWINKLE
63 static rgblight_fadeout lights
[RGBLED_NUM
];
65 __attribute__ ((weak
))
66 bool indicator_is_this_led_used(uint8_t index
) { return false; }
68 void scan_rgblight_fadeout(void) { // Don't effing change this function .... rgblight_sethsv is supppppper intensive
70 for (uint8_t light_index
= 0 ; light_index
< RGBLED_NUM
; ++light_index
) {
71 if (lights
[light_index
].enabled
&& timer_elapsed(lights
[light_index
].timer
) > 10) {
72 rgblight_fadeout
*light
= &lights
[light_index
];
77 if (biton32(layer_state
) == 0) {
78 sethsv(light
->hue
+ rand() % 0xF, 255, light
->life
, (LED_TYPE
*)&led
[light_index
]);
80 light
->timer
= timer_read();
83 if (light
->enabled
&& biton32(layer_state
) == 0) { rgblight_sethsv_default_helper(light_index
); }
84 litup
= light
->enabled
= false;
88 if (litup
&& biton32(layer_state
) == 0) {
93 void start_rgb_light(void) {
95 uint8_t indices
[RGBLED_NUM
];
96 uint8_t indices_count
= 0;
97 uint8_t min_life
= 0xFF;
98 uint8_t min_life_index
= -1;
99 for (uint8_t index
= 0 ; index
< RGBLED_NUM
; ++index
) {
100 if (indicator_is_this_led_used(index
)) { continue; }
101 if (lights
[index
].enabled
) {
102 if (min_life_index
== -1 ||
103 lights
[index
].life
< min_life
)
105 min_life
= lights
[index
].life
;
106 min_life_index
= index
;
111 indices
[indices_count
] = index
;
116 if (!indices_count
) {
117 light_index
= min_life_index
;
120 light_index
= indices
[rand() % indices_count
];
123 rgblight_fadeout
*light
= &lights
[light_index
];
124 light
->enabled
= true;
125 light
->timer
= timer_read();
126 light
->life
= 0xC0 + rand() % 0x40;
128 light
->hue
= rgblight_config
.hue
+ (rand() % 0xB4) - 0x54;
130 rgblight_sethsv_at(light
->hue
, 255, light
->life
, light_index
);
135 bool process_record_user_rgb(uint16_t keycode
, keyrecord_t
*record
) {
137 #ifdef RGBLIGHT_TWINKLE
138 case KC_A
... KC_SLASH
:
139 case KC_F1
... KC_F12
:
140 case KC_INSERT
... KC_UP
:
141 case KC_KP_SLASH
... KC_KP_DOT
:
142 case KC_F13
... KC_F24
:
143 case KC_AUDIO_MUTE
... KC_MEDIA_REWIND
:
144 if (record
->event
.pressed
) { start_rgb_light(); }
146 #endif // RGBLIGHT_TWINKLE
147 case KC_RGB_T
: // This allows me to use underglow as layer indication, or as normal
148 #ifdef RGBLIGHT_ENABLE
149 if (record
->event
.pressed
) {
150 userspace_config
.rgb_layer_change
^= 1;
151 xprintf("rgblight layer change [EEPROM]: %u\n", userspace_config
.rgb_layer_change
);
152 eeprom_update_byte(EECONFIG_USERSPACE
, userspace_config
.raw
);
153 if (userspace_config
.rgb_layer_change
) {
154 layer_state_set(layer_state
); // This is needed to immediately set the layer color (looks better)
157 #endif // RGBLIGHT_ENABLE
159 #ifdef RGBLIGHT_ENABLE
160 case RGB_MODE_FORWARD
... RGB_MODE_GRADIENT
: // quantum_keycodes.h L400 for definitions
161 if (record
->event
.pressed
) { //This disables layer indication, as it's assumed that if you're changing this ... you want that disabled
162 if (userspace_config
.rgb_layer_change
) {
163 userspace_config
.rgb_layer_change
= false;
164 xprintf("rgblight layer change [EEPROM]: %u\n", userspace_config
.rgb_layer_change
);
165 eeprom_update_byte(EECONFIG_USERSPACE
, userspace_config
.raw
);
169 #endif // RGBLIGHT_ENABLE
176 void matrix_init_rgb(void) {
177 #ifdef INDICATOR_LIGHTS
178 current_mod
= last_mod
= get_mods();
179 current_led
= last_led
= host_keyboard_leds();
180 current_osm
= last_osm
= get_oneshot_mods();
183 if (userspace_config
.rgb_layer_change
) {
184 uint8_t default_layer
= eeconfig_read_default_layer();
185 rgblight_enable_noeeprom();
186 if (default_layer
& (1UL << _COLEMAK
)) {
187 rgblight_sethsv_magenta();
188 } else if (default_layer
& (1UL << _DVORAK
)) {
189 rgblight_sethsv_green();
190 } else if (default_layer
& (1UL << _WORKMAN
)) {
191 rgblight_sethsv_goldenrod();
193 rgblight_sethsv_cyan();
198 void matrix_scan_rgb(void) {
199 #ifdef RGBLIGHT_TWINKLE
200 scan_rgblight_fadeout();
201 #endif // RGBLIGHT_ENABLE
203 #ifdef INDICATOR_LIGHTS
204 matrix_scan_indicator();
210 uint32_t layer_state_set_rgb(uint32_t state
) {
211 #ifdef RGBLIGHT_ENABLE
212 uint8_t default_layer
= eeconfig_read_default_layer();
213 if (userspace_config
.rgb_layer_change
) {
214 switch (biton32(state
)) {
216 rgblight_sethsv_noeeprom_orange();
217 userspace_config
.is_overwatch
? rgblight_mode_noeeprom(17) : rgblight_mode_noeeprom(18);
220 rgblight_sethsv_noeeprom_chartreuse();
221 rgblight_mode_noeeprom(22);
224 rgblight_sethsv_noeeprom_orange();
225 rgblight_mode_noeeprom(17);
228 rgblight_sethsv_noeeprom_red();
229 rgblight_mode_noeeprom(5);
232 rgblight_sethsv_noeeprom_yellow();
233 rgblight_mode_noeeprom(5);
236 rgblight_sethsv_noeeprom_orange();
237 rgblight_mode_noeeprom(5);
240 rgblight_sethsv_noeeprom_red();
241 rgblight_mode_noeeprom(23);
243 default: // for any other layers, or the default layer
244 if (default_layer
& (1UL << _COLEMAK
)) {
245 rgblight_sethsv_noeeprom_magenta();
246 } else if (default_layer
& (1UL << _DVORAK
)) {
247 rgblight_sethsv_noeeprom_green();
248 } else if (default_layer
& (1UL << _WORKMAN
)) {
249 rgblight_sethsv_noeeprom_goldenrod();
251 rgblight_sethsv_noeeprom_cyan();
253 biton32(state
) == _MODS
? rgblight_mode_noeeprom(2) : rgblight_mode_noeeprom(1); // if _MODS layer is on, then breath to denote it
256 // layer_state_set_indicator(); // Runs every scan, so need to call this here .... since I can't get it working "right" anyhow
258 #endif // RGBLIGHT_ENABLE