diff options
| author | Colin T.A. Gray <colinta@gmail.com> | 2017-12-05 11:56:15 -0700 |
|---|---|---|
| committer | Jack Humbert <jack.humb@gmail.com> | 2017-12-08 16:10:42 -0500 |
| commit | 16546ee06fa71bd9b9e9d3fda7c8816675e12185 (patch) | |
| tree | 0fb62a810727a5c0745f94573715b6c027f577a3 /quantum | |
| parent | 1620d78e73f8e01ed1d48255c655d9eb6cc1b135 (diff) | |
| download | qmk_firmware-16546ee06fa71bd9b9e9d3fda7c8816675e12185.tar.gz qmk_firmware-16546ee06fa71bd9b9e9d3fda7c8816675e12185.zip | |
Add 'rgblight_disable' and 'rgblight_setrgb_at/rgblight_sethsv_at'
Refactors rgblight_toggle to use rgblight_enable or rgblight_disable
Use 'rgblight_setrgb_at/rgblight_sethsv_at' to control an individual LED
Diffstat (limited to 'quantum')
| -rw-r--r-- | quantum/rgblight.c | 46 | ||||
| -rw-r--r-- | quantum/rgblight.h | 3 |
2 files changed, 38 insertions, 11 deletions
diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 78072a61d..63eda47cd 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c | |||
| @@ -245,17 +245,12 @@ void rgblight_mode(uint8_t mode) { | |||
| 245 | } | 245 | } |
| 246 | 246 | ||
| 247 | void rgblight_toggle(void) { | 247 | void rgblight_toggle(void) { |
| 248 | rgblight_config.enable ^= 1; | 248 | xprintf("rgblight toggle: rgblight_config.enable = %u\n", !rgblight_config.enable); |
| 249 | eeconfig_update_rgblight(rgblight_config.raw); | ||
| 250 | xprintf("rgblight toggle: rgblight_config.enable = %u\n", rgblight_config.enable); | ||
| 251 | if (rgblight_config.enable) { | 249 | if (rgblight_config.enable) { |
| 252 | rgblight_mode(rgblight_config.mode); | 250 | rgblight_disable(); |
| 253 | } else { | 251 | } |
| 254 | #ifdef RGBLIGHT_ANIMATIONS | 252 | else { |
| 255 | rgblight_timer_disable(); | 253 | rgblight_enable(); |
| 256 | #endif | ||
| 257 | _delay_ms(50); | ||
| 258 | rgblight_set(); | ||
| 259 | } | 254 | } |
| 260 | } | 255 | } |
| 261 | 256 | ||
| @@ -266,6 +261,17 @@ void rgblight_enable(void) { | |||
| 266 | rgblight_mode(rgblight_config.mode); | 261 | rgblight_mode(rgblight_config.mode); |
| 267 | } | 262 | } |
| 268 | 263 | ||
| 264 | void rgblight_disable(void) { | ||
| 265 | rgblight_config.enable = 0; | ||
| 266 | eeconfig_update_rgblight(rgblight_config.raw); | ||
| 267 | xprintf("rgblight disable: rgblight_config.enable = %u\n", rgblight_config.enable); | ||
| 268 | #ifdef RGBLIGHT_ANIMATIONS | ||
| 269 | rgblight_timer_disable(); | ||
| 270 | #endif | ||
| 271 | _delay_ms(50); | ||
| 272 | rgblight_set(); | ||
| 273 | } | ||
| 274 | |||
| 269 | 275 | ||
| 270 | void rgblight_increase_hue(void) { | 276 | void rgblight_increase_hue(void) { |
| 271 | uint16_t hue; | 277 | uint16_t hue; |
| @@ -365,7 +371,8 @@ void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { | |||
| 365 | } | 371 | } |
| 366 | 372 | ||
| 367 | void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) { | 373 | void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) { |
| 368 | // dprintf("rgblight set rgb: %u,%u,%u\n", r,g,b); | 374 | if (!rgblight_config.enable) { return; } |
| 375 | |||
| 369 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { | 376 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { |
| 370 | led[i].r = r; | 377 | led[i].r = r; |
| 371 | led[i].g = g; | 378 | led[i].g = g; |
| @@ -374,6 +381,23 @@ void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) { | |||
| 374 | rgblight_set(); | 381 | rgblight_set(); |
| 375 | } | 382 | } |
| 376 | 383 | ||
| 384 | void rgblight_setrgb_at(uint8_t r, uint8_t g, uint8_t b, uint8_t index) { | ||
| 385 | if (!rgblight_config.enable || index >= RGBLED_NUM) { return; } | ||
| 386 | |||
| 387 | led[index].r = r; | ||
| 388 | led[index].g = g; | ||
| 389 | led[index].b = b; | ||
| 390 | rgblight_set(); | ||
| 391 | } | ||
| 392 | |||
| 393 | void rgblight_sethsv_at(uint16_t hue, uint8_t sat, uint8_t val, uint8_t index) { | ||
| 394 | if (!rgblight_config.enable) { return; } | ||
| 395 | |||
| 396 | LED_TYPE tmp_led; | ||
| 397 | sethsv(hue, sat, val, &tmp_led); | ||
| 398 | rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index); | ||
| 399 | } | ||
| 400 | |||
| 377 | #ifndef RGBLIGHT_CUSTOM_DRIVER | 401 | #ifndef RGBLIGHT_CUSTOM_DRIVER |
| 378 | void rgblight_set(void) { | 402 | void rgblight_set(void) { |
| 379 | if (rgblight_config.enable) { | 403 | if (rgblight_config.enable) { |
diff --git a/quantum/rgblight.h b/quantum/rgblight.h index fb79ce6de..6d362e1d5 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h | |||
| @@ -99,6 +99,7 @@ void rgblight_increase(void); | |||
| 99 | void rgblight_decrease(void); | 99 | void rgblight_decrease(void); |
| 100 | void rgblight_toggle(void); | 100 | void rgblight_toggle(void); |
| 101 | void rgblight_enable(void); | 101 | void rgblight_enable(void); |
| 102 | void rgblight_disable(void); | ||
| 102 | void rgblight_step(void); | 103 | void rgblight_step(void); |
| 103 | void rgblight_step_reverse(void); | 104 | void rgblight_step_reverse(void); |
| 104 | uint32_t rgblight_get_mode(void); | 105 | uint32_t rgblight_get_mode(void); |
| @@ -113,6 +114,8 @@ void rgblight_increase_val(void); | |||
| 113 | void rgblight_decrease_val(void); | 114 | void rgblight_decrease_val(void); |
| 114 | void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val); | 115 | void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val); |
| 115 | void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b); | 116 | void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b); |
| 117 | void rgblight_setrgb_at(uint8_t r, uint8_t g, uint8_t b, uint8_t index); | ||
| 118 | void rgblight_sethsv_at(uint16_t hue, uint8_t sat, uint8_t val, uint8_t index); | ||
| 116 | 119 | ||
| 117 | uint32_t eeconfig_read_rgblight(void); | 120 | uint32_t eeconfig_read_rgblight(void); |
| 118 | void eeconfig_update_rgblight(uint32_t val); | 121 | void eeconfig_update_rgblight(uint32_t val); |
