diff options
| -rw-r--r-- | docs/feature_rgblight.md | 18 | ||||
| -rw-r--r-- | quantum/rgblight.c | 80 | ||||
| -rw-r--r-- | quantum/rgblight.h | 8 |
3 files changed, 90 insertions, 16 deletions
diff --git a/docs/feature_rgblight.md b/docs/feature_rgblight.md index 4610467b0..52d5c5fe8 100644 --- a/docs/feature_rgblight.md +++ b/docs/feature_rgblight.md | |||
| @@ -161,6 +161,24 @@ If you need to change your RGB lighting in code, for example in a macro to chang | |||
| 161 | |`rgblight_sethsv(h, s, v)` |Set all LEDs to the given HSV value where `h` is between 0 and 360 and `s`/`v` are between 0 and 255 | | 161 | |`rgblight_sethsv(h, s, v)` |Set all LEDs to the given HSV value where `h` is between 0 and 360 and `s`/`v` are between 0 and 255 | |
| 162 | |`rgblight_sethsv_noeeprom(h, s, v)`|Set all LEDs to the given HSV value where `h` is between 0 and 360 and `s`/`v` are between 0 and 255 (not written to EEPROM) | | 162 | |`rgblight_sethsv_noeeprom(h, s, v)`|Set all LEDs to the given HSV value where `h` is between 0 and 360 and `s`/`v` are between 0 and 255 (not written to EEPROM) | |
| 163 | |`rgblight_sethsv_at(h, s, v, led)` |Set a single LED to the given HSV value, where `h` is between 0 and 360, `s`/`v` are between 0 and 255, and `led` is between 0 and `RGBLED_NUM` (not written to EEPROM)| | 163 | |`rgblight_sethsv_at(h, s, v, led)` |Set a single LED to the given HSV value, where `h` is between 0 and 360, `s`/`v` are between 0 and 255, and `led` is between 0 and `RGBLED_NUM` (not written to EEPROM)| |
| 164 | |`rgblight_toggle()` |Toggle all LEDs between on and off | | ||
| 165 | |`rgblight_toggle_noeeprom()` |Toggle all LEDs between on and off (not written to EEPROM) | | ||
| 166 | |`rgblight_step()` |Change the mode to the next RGB animation in the list of enabled RGB animations | | ||
| 167 | |`rgblight_step_noeeprom()` |Change the mode to the next RGB animation in the list of enabled RGB animations (not written to EEPROM) | | ||
| 168 | |`rgblight_step_reverse()` |Change the mode to the previous RGB animation in the list of enabled RGB animations | | ||
| 169 | |`rgblight_step_reverse_noeeprom()` |Change the mode to the previous RGB animation in the list of enabled RGB animations (not written to EEPROM) | | ||
| 170 | |`rgblight_increase_hue()` |Increase the hue for all LEDs. This wraps around at maximum hue | | ||
| 171 | |`rgblight_increase_hue_noeeprom()` |Increase the hue for all LEDs. This wraps around at maximum hue (not written to EEPROM) | | ||
| 172 | |`rgblight_decrease_hue()` |Decrease the hue for all LEDs. This wraps around at minimum hue | | ||
| 173 | |`rgblight_decrease_hue_noeeprom()` |Decrease the hue for all LEDs. This wraps around at minimum hue (not written to EEPROM) | | ||
| 174 | |`rgblight_increase_sat()` |Increase the saturation for all LEDs. This wraps around at maximum saturation | | ||
| 175 | |`rgblight_increase_sat_noeeprom()` |Increase the saturation for all LEDs. This wraps around at maximum saturation (not written to EEPROM) | | ||
| 176 | |`rgblight_decrease_sat()` |Decrease the saturation for all LEDs. This wraps around at minimum saturation | | ||
| 177 | |`rgblight_decrease_sat_noeeprom()` |Decrease the saturation for all LEDs. This wraps around at minimum saturation (not written to EEPROM) | | ||
| 178 | |`rgblight_increase_val()` |Increase the value for all LEDs. This wraps around at maximum value | | ||
| 179 | |`rgblight_increase_val_noeeprom()` |Increase the value for all LEDs. This wraps around at maximum value (not written to EEPROM) | | ||
| 180 | |`rgblight_decrease_val()` |Decrease the value for all LEDs. This wraps around at minimum value | | ||
| 181 | |`rgblight_decrease_val_noeeprom()` |Decrease the value for all LEDs. This wraps around at minimum value (not written to EEPROM) | | ||
| 164 | 182 | ||
| 165 | Additionally, [`rgblight_list.h`](https://github.com/qmk/qmk_firmware/blob/master/quantum/rgblight_list.h) defines several predefined shortcuts for various colors. Feel free to add to this list! | 183 | Additionally, [`rgblight_list.h`](https://github.com/qmk/qmk_firmware/blob/master/quantum/rgblight_list.h) defines several predefined shortcuts for various colors. Feel free to add to this list! |
| 166 | 184 | ||
diff --git a/quantum/rgblight.c b/quantum/rgblight.c index a2d6fe7a0..ae5dca188 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c | |||
| @@ -205,21 +205,33 @@ void rgblight_decrease(void) { | |||
| 205 | } | 205 | } |
| 206 | rgblight_mode(mode); | 206 | rgblight_mode(mode); |
| 207 | } | 207 | } |
| 208 | void rgblight_step(void) { | 208 | void rgblight_step_helper(bool write_to_eeprom) { |
| 209 | uint8_t mode = 0; | 209 | uint8_t mode = 0; |
| 210 | mode = rgblight_config.mode + 1; | 210 | mode = rgblight_config.mode + 1; |
| 211 | if (mode > RGBLIGHT_MODES) { | 211 | if (mode > RGBLIGHT_MODES) { |
| 212 | mode = 1; | 212 | mode = 1; |
| 213 | } | 213 | } |
| 214 | rgblight_mode(mode); | 214 | rgblight_mode_eeprom_helper(mode, write_to_eeprom); |
| 215 | } | 215 | } |
| 216 | void rgblight_step_reverse(void) { | 216 | void rgblight_step_noeeprom(void) { |
| 217 | rgblight_step_helper(false); | ||
| 218 | } | ||
| 219 | void rgblight_step(void) { | ||
| 220 | rgblight_step_helper(true); | ||
| 221 | } | ||
| 222 | void rgblight_step_reverse_helper(bool write_to_eeprom) { | ||
| 217 | uint8_t mode = 0; | 223 | uint8_t mode = 0; |
| 218 | mode = rgblight_config.mode - 1; | 224 | mode = rgblight_config.mode - 1; |
| 219 | if (mode < 1) { | 225 | if (mode < 1) { |
| 220 | mode = RGBLIGHT_MODES; | 226 | mode = RGBLIGHT_MODES; |
| 221 | } | 227 | } |
| 222 | rgblight_mode(mode); | 228 | rgblight_mode_eeprom_helper(mode, write_to_eeprom); |
| 229 | } | ||
| 230 | void rgblight_step_reverse_noeeprom(void) { | ||
| 231 | rgblight_step_reverse_helper(false); | ||
| 232 | } | ||
| 233 | void rgblight_step_reverse(void) { | ||
| 234 | rgblight_step_reverse_helper(true); | ||
| 223 | } | 235 | } |
| 224 | 236 | ||
| 225 | uint32_t rgblight_get_mode(void) { | 237 | uint32_t rgblight_get_mode(void) { |
| @@ -337,55 +349,91 @@ static uint8_t decrement( uint8_t value, uint8_t step, uint8_t min, uint8_t max | |||
| 337 | return MIN( MAX( new_value, min ), max ); | 349 | return MIN( MAX( new_value, min ), max ); |
| 338 | } | 350 | } |
| 339 | 351 | ||
| 340 | void rgblight_increase_hue(void) { | 352 | void rgblight_increase_hue_helper(bool write_to_eeprom) { |
| 341 | uint16_t hue; | 353 | uint16_t hue; |
| 342 | hue = (rgblight_config.hue+RGBLIGHT_HUE_STEP) % 360; | 354 | hue = (rgblight_config.hue+RGBLIGHT_HUE_STEP) % 360; |
| 343 | rgblight_sethsv(hue, rgblight_config.sat, rgblight_config.val); | 355 | rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom); |
| 344 | } | 356 | } |
| 345 | void rgblight_decrease_hue(void) { | 357 | void rgblight_increase_hue_noeeprom(void) { |
| 358 | rgblight_increase_hue_helper(false); | ||
| 359 | } | ||
| 360 | void rgblight_increase_hue(void) { | ||
| 361 | rgblight_increase_hue_helper(true); | ||
| 362 | } | ||
| 363 | void rgblight_decrease_hue_helper(bool write_to_eeprom) { | ||
| 346 | uint16_t hue; | 364 | uint16_t hue; |
| 347 | if (rgblight_config.hue-RGBLIGHT_HUE_STEP < 0) { | 365 | if (rgblight_config.hue-RGBLIGHT_HUE_STEP < 0) { |
| 348 | hue = (rgblight_config.hue + 360 - RGBLIGHT_HUE_STEP) % 360; | 366 | hue = (rgblight_config.hue + 360 - RGBLIGHT_HUE_STEP) % 360; |
| 349 | } else { | 367 | } else { |
| 350 | hue = (rgblight_config.hue - RGBLIGHT_HUE_STEP) % 360; | 368 | hue = (rgblight_config.hue - RGBLIGHT_HUE_STEP) % 360; |
| 351 | } | 369 | } |
| 352 | rgblight_sethsv(hue, rgblight_config.sat, rgblight_config.val); | 370 | rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom); |
| 353 | } | 371 | } |
| 354 | void rgblight_increase_sat(void) { | 372 | void rgblight_decrease_hue_noeeprom(void) { |
| 373 | rgblight_decrease_hue_helper(false); | ||
| 374 | } | ||
| 375 | void rgblight_decrease_hue(void) { | ||
| 376 | rgblight_decrease_hue_helper(true); | ||
| 377 | } | ||
| 378 | void rgblight_increase_sat_helper(bool write_to_eeprom) { | ||
| 355 | uint8_t sat; | 379 | uint8_t sat; |
| 356 | if (rgblight_config.sat + RGBLIGHT_SAT_STEP > 255) { | 380 | if (rgblight_config.sat + RGBLIGHT_SAT_STEP > 255) { |
| 357 | sat = 255; | 381 | sat = 255; |
| 358 | } else { | 382 | } else { |
| 359 | sat = rgblight_config.sat + RGBLIGHT_SAT_STEP; | 383 | sat = rgblight_config.sat + RGBLIGHT_SAT_STEP; |
| 360 | } | 384 | } |
| 361 | rgblight_sethsv(rgblight_config.hue, sat, rgblight_config.val); | 385 | rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom); |
| 362 | } | 386 | } |
| 363 | void rgblight_decrease_sat(void) { | 387 | void rgblight_increase_sat_noeeprom(void) { |
| 388 | rgblight_increase_sat_helper(false); | ||
| 389 | } | ||
| 390 | void rgblight_increase_sat(void) { | ||
| 391 | rgblight_increase_sat_helper(true); | ||
| 392 | } | ||
| 393 | void rgblight_decrease_sat_helper(bool write_to_eeprom) { | ||
| 364 | uint8_t sat; | 394 | uint8_t sat; |
| 365 | if (rgblight_config.sat - RGBLIGHT_SAT_STEP < 0) { | 395 | if (rgblight_config.sat - RGBLIGHT_SAT_STEP < 0) { |
| 366 | sat = 0; | 396 | sat = 0; |
| 367 | } else { | 397 | } else { |
| 368 | sat = rgblight_config.sat - RGBLIGHT_SAT_STEP; | 398 | sat = rgblight_config.sat - RGBLIGHT_SAT_STEP; |
| 369 | } | 399 | } |
| 370 | rgblight_sethsv(rgblight_config.hue, sat, rgblight_config.val); | 400 | rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom); |
| 371 | } | 401 | } |
| 372 | void rgblight_increase_val(void) { | 402 | void rgblight_decrease_sat_noeeprom(void) { |
| 403 | rgblight_decrease_sat_helper(false); | ||
| 404 | } | ||
| 405 | void rgblight_decrease_sat(void) { | ||
| 406 | rgblight_decrease_sat_helper(true); | ||
| 407 | } | ||
| 408 | void rgblight_increase_val_helper(bool write_to_eeprom) { | ||
| 373 | uint8_t val; | 409 | uint8_t val; |
| 374 | if (rgblight_config.val + RGBLIGHT_VAL_STEP > RGBLIGHT_LIMIT_VAL) { | 410 | if (rgblight_config.val + RGBLIGHT_VAL_STEP > RGBLIGHT_LIMIT_VAL) { |
| 375 | val = RGBLIGHT_LIMIT_VAL; | 411 | val = RGBLIGHT_LIMIT_VAL; |
| 376 | } else { | 412 | } else { |
| 377 | val = rgblight_config.val + RGBLIGHT_VAL_STEP; | 413 | val = rgblight_config.val + RGBLIGHT_VAL_STEP; |
| 378 | } | 414 | } |
| 379 | rgblight_sethsv(rgblight_config.hue, rgblight_config.sat, val); | 415 | rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom); |
| 380 | } | 416 | } |
| 381 | void rgblight_decrease_val(void) { | 417 | void rgblight_increase_val_noeeprom(void) { |
| 418 | rgblight_increase_val_helper(false); | ||
| 419 | } | ||
| 420 | void rgblight_increase_val(void) { | ||
| 421 | rgblight_increase_val_helper(true); | ||
| 422 | } | ||
| 423 | void rgblight_decrease_val_helper(bool write_to_eeprom) { | ||
| 382 | uint8_t val; | 424 | uint8_t val; |
| 383 | if (rgblight_config.val - RGBLIGHT_VAL_STEP < 0) { | 425 | if (rgblight_config.val - RGBLIGHT_VAL_STEP < 0) { |
| 384 | val = 0; | 426 | val = 0; |
| 385 | } else { | 427 | } else { |
| 386 | val = rgblight_config.val - RGBLIGHT_VAL_STEP; | 428 | val = rgblight_config.val - RGBLIGHT_VAL_STEP; |
| 387 | } | 429 | } |
| 388 | rgblight_sethsv(rgblight_config.hue, rgblight_config.sat, val); | 430 | rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom); |
| 431 | } | ||
| 432 | void rgblight_decrease_val_noeeprom(void) { | ||
| 433 | rgblight_decrease_val_helper(false); | ||
| 434 | } | ||
| 435 | void rgblight_decrease_val(void) { | ||
| 436 | rgblight_decrease_val_helper(true); | ||
| 389 | } | 437 | } |
| 390 | void rgblight_increase_speed(void) { | 438 | void rgblight_increase_speed(void) { |
| 391 | rgblight_config.speed = increment( rgblight_config.speed, 1, 0, 3 ); | 439 | rgblight_config.speed = increment( rgblight_config.speed, 1, 0, 3 ); |
diff --git a/quantum/rgblight.h b/quantum/rgblight.h index 33b279f08..99ede43c5 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h | |||
| @@ -203,6 +203,14 @@ void rgblight_mode_noeeprom(uint8_t mode); | |||
| 203 | void rgblight_toggle_noeeprom(void); | 203 | void rgblight_toggle_noeeprom(void); |
| 204 | void rgblight_enable_noeeprom(void); | 204 | void rgblight_enable_noeeprom(void); |
| 205 | void rgblight_disable_noeeprom(void); | 205 | void rgblight_disable_noeeprom(void); |
| 206 | void rgblight_step_noeeprom(void); | ||
| 207 | void rgblight_step_reverse_noeeprom(void); | ||
| 208 | void rgblight_increase_hue_noeeprom(void); | ||
| 209 | void rgblight_decrease_hue_noeeprom(void); | ||
| 210 | void rgblight_increase_sat_noeeprom(void); | ||
| 211 | void rgblight_decrease_sat_noeeprom(void); | ||
| 212 | void rgblight_increase_val_noeeprom(void); | ||
| 213 | void rgblight_decrease_val_noeeprom(void); | ||
| 206 | 214 | ||
| 207 | void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom); | 215 | void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom); |
| 208 | void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom); | 216 | void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom); |
