diff options
| author | Takeshi ISHII <2170248+mtei@users.noreply.github.com> | 2018-09-14 02:24:10 +0900 |
|---|---|---|
| committer | skullydazed <skullydazed@users.noreply.github.com> | 2018-09-13 10:24:09 -0700 |
| commit | 6d6d91c834ef3415425e21d895d4ec91c67fd4b8 (patch) | |
| tree | 45724c30bcfe342d88899db355782250312f1704 /quantum/rgblight.c | |
| parent | ce122c4981c71d33a85db94c787d5ec7a823acc6 (diff) | |
| download | qmk_firmware-6d6d91c834ef3415425e21d895d4ec91c67fd4b8.tar.gz qmk_firmware-6d6d91c834ef3415425e21d895d4ec91c67fd4b8.zip | |
rgblight.[ch] more configurable (#3582)
* add temporary test code rgblight-macro-test1.[ch]
* rgblight.h : mode auto numberring and auto generate mode name symbol
No change in build result.
* rgblight.c use RGBLIGHT_MODE_xxx symbols
No change in build result.
* quantum.c use RGBLIGHT_MODE_xxx symbols
No change in build result.
* fix build break. when RGB_MATRIX_ENABLE defined
* add temporary test code rgblight-macro-test2.[ch]
* modify rgblight_mode_eeprom_helper() and rgblight_sethsv_eeprom_helper()
* modify rgblight_task()
* configurable each effect compile on/off in config.h
* update docs/feature_rgblight.md
* fix conflict. docs/feature_rgblight.md
* remove temporary test code rgblight-macro-test*.[ch]
* fix comment typo.
* remove old mode number from comment
* update docs/feature_rgblight.md about effect mode
* Revert "update docs/feature_rgblight.md about effect mode"
This reverts commit 43890663fcc9dda1899df7a37d382fc38b1a6d6d.
* some change docs/feature_rgblight.md
* fix typo
* docs/feature_rgblight.md update: revise mode number table
Diffstat (limited to 'quantum/rgblight.c')
| -rw-r--r-- | quantum/rgblight.c | 237 |
1 files changed, 156 insertions, 81 deletions
diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 4919ae4ab..03f77cc80 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c | |||
| @@ -14,6 +14,7 @@ | |||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | */ | 15 | */ |
| 16 | #include <math.h> | 16 | #include <math.h> |
| 17 | #include <string.h> | ||
| 17 | #ifdef __AVR__ | 18 | #ifdef __AVR__ |
| 18 | #include <avr/eeprom.h> | 19 | #include <avr/eeprom.h> |
| 19 | #include <avr/interrupt.h> | 20 | #include <avr/interrupt.h> |
| @@ -29,23 +30,27 @@ | |||
| 29 | #define RGBLIGHT_LIMIT_VAL 255 | 30 | #define RGBLIGHT_LIMIT_VAL 255 |
| 30 | #endif | 31 | #endif |
| 31 | 32 | ||
| 33 | #define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_ ## sym, | ||
| 34 | #define _RGBM_SINGLE_DYNAMIC(sym) | ||
| 35 | #define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_ ## sym, | ||
| 36 | #define _RGBM_MULTI_DYNAMIC(sym) | ||
| 37 | #define _RGBM_TMP_STATIC(sym) RGBLIGHT_MODE_ ## sym, | ||
| 38 | #define _RGBM_TMP_DYNAMIC(sym) | ||
| 39 | static uint8_t static_effect_table [] = { | ||
| 40 | #include "rgblight.h" | ||
| 41 | }; | ||
| 42 | |||
| 43 | static inline int is_static_effect(uint8_t mode) { | ||
| 44 | return memchr(static_effect_table, mode, sizeof(static_effect_table)) != NULL; | ||
| 45 | } | ||
| 46 | |||
| 32 | #define MIN(a,b) (((a)<(b))?(a):(b)) | 47 | #define MIN(a,b) (((a)<(b))?(a):(b)) |
| 33 | #define MAX(a,b) (((a)>(b))?(a):(b)) | 48 | #define MAX(a,b) (((a)>(b))?(a):(b)) |
| 34 | 49 | ||
| 35 | __attribute__ ((weak)) | 50 | #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT |
| 36 | const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; | ||
| 37 | __attribute__ ((weak)) | ||
| 38 | const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30}; | ||
| 39 | __attribute__ ((weak)) | ||
| 40 | const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20}; | ||
| 41 | __attribute__ ((weak)) | ||
| 42 | const uint8_t RGBLED_SNAKE_INTERVALS[] PROGMEM = {100, 50, 20}; | ||
| 43 | __attribute__ ((weak)) | ||
| 44 | const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31}; | ||
| 45 | __attribute__ ((weak)) | 51 | __attribute__ ((weak)) |
| 46 | const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90}; | 52 | const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90}; |
| 47 | __attribute__ ((weak)) | 53 | #endif |
| 48 | const uint16_t RGBLED_RGBTEST_INTERVALS[] PROGMEM = {1024}; | ||
| 49 | 54 | ||
| 50 | rgblight_config_t rgblight_config; | 55 | rgblight_config_t rgblight_config; |
| 51 | 56 | ||
| @@ -129,7 +134,7 @@ void eeconfig_update_rgblight(uint32_t val) { | |||
| 129 | void eeconfig_update_rgblight_default(void) { | 134 | void eeconfig_update_rgblight_default(void) { |
| 130 | //dprintf("eeconfig_update_rgblight_default\n"); | 135 | //dprintf("eeconfig_update_rgblight_default\n"); |
| 131 | rgblight_config.enable = 1; | 136 | rgblight_config.enable = 1; |
| 132 | rgblight_config.mode = 1; | 137 | rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; |
| 133 | rgblight_config.hue = 0; | 138 | rgblight_config.hue = 0; |
| 134 | rgblight_config.sat = 255; | 139 | rgblight_config.sat = 255; |
| 135 | rgblight_config.val = RGBLIGHT_LIMIT_VAL; | 140 | rgblight_config.val = RGBLIGHT_LIMIT_VAL; |
| @@ -163,9 +168,9 @@ void rgblight_init(void) { | |||
| 163 | } | 168 | } |
| 164 | eeconfig_debug_rgblight(); // display current eeprom values | 169 | eeconfig_debug_rgblight(); // display current eeprom values |
| 165 | 170 | ||
| 166 | #ifdef RGBLIGHT_ANIMATIONS | 171 | #ifdef RGBLIGHT_USE_TIMER |
| 167 | rgblight_timer_init(); // setup the timer | 172 | rgblight_timer_init(); // setup the timer |
| 168 | #endif | 173 | #endif |
| 169 | 174 | ||
| 170 | if (rgblight_config.enable) { | 175 | if (rgblight_config.enable) { |
| 171 | rgblight_mode_noeeprom(rgblight_config.mode); | 176 | rgblight_mode_noeeprom(rgblight_config.mode); |
| @@ -178,9 +183,9 @@ void rgblight_update_dword(uint32_t dword) { | |||
| 178 | if (rgblight_config.enable) | 183 | if (rgblight_config.enable) |
| 179 | rgblight_mode(rgblight_config.mode); | 184 | rgblight_mode(rgblight_config.mode); |
| 180 | else { | 185 | else { |
| 181 | #ifdef RGBLIGHT_ANIMATIONS | 186 | #ifdef RGBLIGHT_USE_TIMER |
| 182 | rgblight_timer_disable(); | 187 | rgblight_timer_disable(); |
| 183 | #endif | 188 | #endif |
| 184 | rgblight_set(); | 189 | rgblight_set(); |
| 185 | } | 190 | } |
| 186 | } | 191 | } |
| @@ -195,7 +200,7 @@ void rgblight_increase(void) { | |||
| 195 | void rgblight_decrease(void) { | 200 | void rgblight_decrease(void) { |
| 196 | uint8_t mode = 0; | 201 | uint8_t mode = 0; |
| 197 | // Mode will never be < 1. If it ever is, eeprom needs to be initialized. | 202 | // Mode will never be < 1. If it ever is, eeprom needs to be initialized. |
| 198 | if (rgblight_config.mode > 1) { | 203 | if (rgblight_config.mode > RGBLIGHT_MODE_STATIC_LIGHT) { |
| 199 | mode = rgblight_config.mode - 1; | 204 | mode = rgblight_config.mode - 1; |
| 200 | } | 205 | } |
| 201 | rgblight_mode(mode); | 206 | rgblight_mode(mode); |
| @@ -229,8 +234,8 @@ void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { | |||
| 229 | if (!rgblight_config.enable) { | 234 | if (!rgblight_config.enable) { |
| 230 | return; | 235 | return; |
| 231 | } | 236 | } |
| 232 | if (mode < 1) { | 237 | if (mode < RGBLIGHT_MODE_STATIC_LIGHT) { |
| 233 | rgblight_config.mode = 1; | 238 | rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; |
| 234 | } else if (mode > RGBLIGHT_MODES) { | 239 | } else if (mode > RGBLIGHT_MODES) { |
| 235 | rgblight_config.mode = RGBLIGHT_MODES; | 240 | rgblight_config.mode = RGBLIGHT_MODES; |
| 236 | } else { | 241 | } else { |
| @@ -242,30 +247,14 @@ void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { | |||
| 242 | } else { | 247 | } else { |
| 243 | xprintf("rgblight mode [NOEEPROM]: %u\n", rgblight_config.mode); | 248 | xprintf("rgblight mode [NOEEPROM]: %u\n", rgblight_config.mode); |
| 244 | } | 249 | } |
| 245 | if (rgblight_config.mode == 1) { | 250 | if( is_static_effect(rgblight_config.mode) ) { |
| 246 | #ifdef RGBLIGHT_ANIMATIONS | 251 | #ifdef RGBLIGHT_USE_TIMER |
| 247 | rgblight_timer_disable(); | 252 | rgblight_timer_disable(); |
| 248 | #endif | 253 | #endif |
| 249 | } else if ((rgblight_config.mode >= 2 && rgblight_config.mode <= 24) || | 254 | } else { |
| 250 | rgblight_config.mode == 35 || rgblight_config.mode == 36) { | 255 | #ifdef RGBLIGHT_USE_TIMER |
| 251 | // MODE 2-5, breathing | ||
| 252 | // MODE 6-8, rainbow mood | ||
| 253 | // MODE 9-14, rainbow swirl | ||
| 254 | // MODE 15-20, snake | ||
| 255 | // MODE 21-23, knight | ||
| 256 | // MODE 24, xmas | ||
| 257 | // MODE 35 RGB test | ||
| 258 | // MODE 36, alterating | ||
| 259 | |||
| 260 | #ifdef RGBLIGHT_ANIMATIONS | ||
| 261 | rgblight_timer_enable(); | 256 | rgblight_timer_enable(); |
| 262 | #endif | 257 | #endif |
| 263 | } else if (rgblight_config.mode >= 25 && rgblight_config.mode <= 34) { | ||
| 264 | // MODE 25-34, static gradient | ||
| 265 | |||
| 266 | #ifdef RGBLIGHT_ANIMATIONS | ||
| 267 | rgblight_timer_disable(); | ||
| 268 | #endif | ||
| 269 | } | 258 | } |
| 270 | rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, rgblight_config.val); | 259 | rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, rgblight_config.val); |
| 271 | } | 260 | } |
| @@ -317,9 +306,9 @@ void rgblight_disable(void) { | |||
| 317 | rgblight_config.enable = 0; | 306 | rgblight_config.enable = 0; |
| 318 | eeconfig_update_rgblight(rgblight_config.raw); | 307 | eeconfig_update_rgblight(rgblight_config.raw); |
| 319 | xprintf("rgblight disable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); | 308 | xprintf("rgblight disable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); |
| 320 | #ifdef RGBLIGHT_ANIMATIONS | 309 | #ifdef RGBLIGHT_USE_TIMER |
| 321 | rgblight_timer_disable(); | 310 | rgblight_timer_disable(); |
| 322 | #endif | 311 | #endif |
| 323 | wait_ms(50); | 312 | wait_ms(50); |
| 324 | rgblight_set(); | 313 | rgblight_set(); |
| 325 | } | 314 | } |
| @@ -327,9 +316,9 @@ void rgblight_disable(void) { | |||
| 327 | void rgblight_disable_noeeprom(void) { | 316 | void rgblight_disable_noeeprom(void) { |
| 328 | rgblight_config.enable = 0; | 317 | rgblight_config.enable = 0; |
| 329 | xprintf("rgblight disable [noEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); | 318 | xprintf("rgblight disable [noEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); |
| 330 | #ifdef RGBLIGHT_ANIMATIONS | 319 | #ifdef RGBLIGHT_USE_TIMER |
| 331 | rgblight_timer_disable(); | 320 | rgblight_timer_disable(); |
| 332 | #endif | 321 | #endif |
| 333 | _delay_ms(50); | 322 | _delay_ms(50); |
| 334 | rgblight_set(); | 323 | rgblight_set(); |
| 335 | } | 324 | } |
| @@ -419,24 +408,43 @@ void rgblight_sethsv_noeeprom_old(uint16_t hue, uint8_t sat, uint8_t val) { | |||
| 419 | 408 | ||
| 420 | void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) { | 409 | void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) { |
| 421 | if (rgblight_config.enable) { | 410 | if (rgblight_config.enable) { |
| 422 | if (rgblight_config.mode == 1) { | 411 | if (rgblight_config.mode == RGBLIGHT_MODE_STATIC_LIGHT) { |
| 423 | // same static color | 412 | // same static color |
| 424 | LED_TYPE tmp_led; | 413 | LED_TYPE tmp_led; |
| 425 | sethsv(hue, sat, val, &tmp_led); | 414 | sethsv(hue, sat, val, &tmp_led); |
| 426 | rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b); | 415 | rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b); |
| 427 | } else { | 416 | } else { |
| 428 | // all LEDs in same color | 417 | // all LEDs in same color |
| 429 | if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) { | 418 | if ( 1 == 0 ) { //dummy |
| 419 | } | ||
| 420 | #ifdef RGBLIGHT_EFFECT_BREATHING | ||
| 421 | else if (rgblight_config.mode >= RGBLIGHT_MODE_BREATHING && | ||
| 422 | rgblight_config.mode <= RGBLIGHT_MODE_BREATHING_end) { | ||
| 430 | // breathing mode, ignore the change of val, use in memory value instead | 423 | // breathing mode, ignore the change of val, use in memory value instead |
| 431 | val = rgblight_config.val; | 424 | val = rgblight_config.val; |
| 432 | } else if (rgblight_config.mode >= 6 && rgblight_config.mode <= 14) { | 425 | } |
| 433 | // rainbow mood and rainbow swirl, ignore the change of hue | 426 | #endif |
| 427 | #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD | ||
| 428 | else if (rgblight_config.mode >= RGBLIGHT_MODE_RAINBOW_MOOD && | ||
| 429 | rgblight_config.mode <= RGBLIGHT_MODE_RAINBOW_MOOD_end) { | ||
| 430 | // rainbow mood, ignore the change of hue | ||
| 431 | hue = rgblight_config.hue; | ||
| 432 | } | ||
| 433 | #endif | ||
| 434 | #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL | ||
| 435 | else if (rgblight_config.mode >= RGBLIGHT_MODE_RAINBOW_SWIRL && | ||
| 436 | rgblight_config.mode <= RGBLIGHT_MODE_RAINBOW_SWIRL_end) { | ||
| 437 | // rainbow swirl, ignore the change of hue | ||
| 434 | hue = rgblight_config.hue; | 438 | hue = rgblight_config.hue; |
| 435 | } else if (rgblight_config.mode >= 25 && rgblight_config.mode <= 34) { | 439 | } |
| 440 | #endif | ||
| 441 | #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT | ||
| 442 | else if (rgblight_config.mode >= RGBLIGHT_MODE_STATIC_GRADIENT && | ||
| 443 | rgblight_config.mode <= RGBLIGHT_MODE_STATIC_GRADIENT_end) { | ||
| 436 | // static gradient | 444 | // static gradient |
| 437 | uint16_t _hue; | 445 | uint16_t _hue; |
| 438 | int8_t direction = ((rgblight_config.mode - 25) % 2) ? -1 : 1; | 446 | int8_t direction = ((rgblight_config.mode - RGBLIGHT_MODE_STATIC_GRADIENT) % 2) ? -1 : 1; |
| 439 | uint16_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[(rgblight_config.mode - 25) / 2]); | 447 | uint16_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[(rgblight_config.mode - RGBLIGHT_MODE_STATIC_GRADIENT) / 2]); |
| 440 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { | 448 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { |
| 441 | _hue = (range / RGBLED_NUM * i * direction + hue + 360) % 360; | 449 | _hue = (range / RGBLED_NUM * i * direction + hue + 360) % 360; |
| 442 | dprintf("rgblight rainbow set hsv: %u,%u,%d,%u\n", i, _hue, direction, range); | 450 | dprintf("rgblight rainbow set hsv: %u,%u,%d,%u\n", i, _hue, direction, range); |
| @@ -444,6 +452,7 @@ void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool | |||
| 444 | } | 452 | } |
| 445 | rgblight_set(); | 453 | rgblight_set(); |
| 446 | } | 454 | } |
| 455 | #endif | ||
| 447 | } | 456 | } |
| 448 | rgblight_config.hue = hue; | 457 | rgblight_config.hue = hue; |
| 449 | rgblight_config.sat = sat; | 458 | rgblight_config.sat = sat; |
| @@ -528,7 +537,7 @@ void rgblight_set(void) { | |||
| 528 | } | 537 | } |
| 529 | #endif | 538 | #endif |
| 530 | 539 | ||
| 531 | #ifdef RGBLIGHT_ANIMATIONS | 540 | #ifdef RGBLIGHT_USE_TIMER |
| 532 | 541 | ||
| 533 | // Animation timer -- AVR Timer3 | 542 | // Animation timer -- AVR Timer3 |
| 534 | void rgblight_timer_init(void) { | 543 | void rgblight_timer_init(void) { |
| @@ -564,41 +573,77 @@ void rgblight_timer_toggle(void) { | |||
| 564 | 573 | ||
| 565 | void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) { | 574 | void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) { |
| 566 | rgblight_enable(); | 575 | rgblight_enable(); |
| 567 | rgblight_mode(1); | 576 | rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT); |
| 568 | rgblight_setrgb(r, g, b); | 577 | rgblight_setrgb(r, g, b); |
| 569 | } | 578 | } |
| 570 | 579 | ||
| 571 | void rgblight_task(void) { | 580 | void rgblight_task(void) { |
| 572 | if (rgblight_timer_enabled) { | 581 | if (rgblight_timer_enabled) { |
| 573 | // mode = 1, static light, do nothing here | 582 | // static light mode, do nothing here |
| 574 | if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) { | 583 | if ( 1 == 0 ) { //dummy |
| 575 | // mode = 2 to 5, breathing mode | 584 | } |
| 576 | rgblight_effect_breathing(rgblight_config.mode - 2); | 585 | #ifdef RGBLIGHT_EFFECT_BREATHING |
| 577 | } else if (rgblight_config.mode >= 6 && rgblight_config.mode <= 8) { | 586 | else if (rgblight_config.mode >= RGBLIGHT_MODE_BREATHING && |
| 578 | // mode = 6 to 8, rainbow mood mod | 587 | rgblight_config.mode <= RGBLIGHT_MODE_BREATHING_end) { |
| 579 | rgblight_effect_rainbow_mood(rgblight_config.mode - 6); | 588 | // breathing mode |
| 580 | } else if (rgblight_config.mode >= 9 && rgblight_config.mode <= 14) { | 589 | rgblight_effect_breathing(rgblight_config.mode - RGBLIGHT_MODE_BREATHING ); |
| 581 | // mode = 9 to 14, rainbow swirl mode | 590 | } |
| 582 | rgblight_effect_rainbow_swirl(rgblight_config.mode - 9); | 591 | #endif |
| 583 | } else if (rgblight_config.mode >= 15 && rgblight_config.mode <= 20) { | 592 | #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD |
| 584 | // mode = 15 to 20, snake mode | 593 | else if (rgblight_config.mode >= RGBLIGHT_MODE_RAINBOW_MOOD && |
| 585 | rgblight_effect_snake(rgblight_config.mode - 15); | 594 | rgblight_config.mode <= RGBLIGHT_MODE_RAINBOW_MOOD_end) { |
| 586 | } else if (rgblight_config.mode >= 21 && rgblight_config.mode <= 23) { | 595 | // rainbow mood mode |
| 587 | // mode = 21 to 23, knight mode | 596 | rgblight_effect_rainbow_mood(rgblight_config.mode - RGBLIGHT_MODE_RAINBOW_MOOD); |
| 588 | rgblight_effect_knight(rgblight_config.mode - 21); | 597 | } |
| 589 | } else if (rgblight_config.mode == 24) { | 598 | #endif |
| 590 | // mode = 24, christmas mode | 599 | #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL |
| 600 | else if (rgblight_config.mode >= RGBLIGHT_MODE_RAINBOW_SWIRL && | ||
| 601 | rgblight_config.mode <= RGBLIGHT_MODE_RAINBOW_SWIRL_end) { | ||
| 602 | // rainbow swirl mode | ||
| 603 | rgblight_effect_rainbow_swirl(rgblight_config.mode - RGBLIGHT_MODE_RAINBOW_SWIRL); | ||
| 604 | } | ||
| 605 | #endif | ||
| 606 | #ifdef RGBLIGHT_EFFECT_SNAKE | ||
| 607 | else if (rgblight_config.mode >= RGBLIGHT_MODE_SNAKE && | ||
| 608 | rgblight_config.mode <= RGBLIGHT_MODE_SNAKE_end) { | ||
| 609 | // snake mode | ||
| 610 | rgblight_effect_snake(rgblight_config.mode - RGBLIGHT_MODE_SNAKE); | ||
| 611 | } | ||
| 612 | #endif | ||
| 613 | #ifdef RGBLIGHT_EFFECT_KNIGHT | ||
| 614 | else if (rgblight_config.mode >= RGBLIGHT_MODE_KNIGHT && | ||
| 615 | rgblight_config.mode <= RGBLIGHT_MODE_KNIGHT_end) { | ||
| 616 | // knight mode | ||
| 617 | rgblight_effect_knight(rgblight_config.mode - RGBLIGHT_MODE_KNIGHT); | ||
| 618 | } | ||
| 619 | #endif | ||
| 620 | #ifdef RGBLIGHT_EFFECT_CHRISTMAS | ||
| 621 | else if (rgblight_config.mode == RGBLIGHT_MODE_CHRISTMAS) { | ||
| 622 | // christmas mode | ||
| 591 | rgblight_effect_christmas(); | 623 | rgblight_effect_christmas(); |
| 592 | } else if (rgblight_config.mode == 35) { | 624 | } |
| 593 | // mode = 35, RGB test | 625 | #endif |
| 626 | #ifdef RGBLIGHT_EFFECT_RGB_TEST | ||
| 627 | else if (rgblight_config.mode == RGBLIGHT_MODE_RGB_TEST) { | ||
| 628 | // RGB test mode | ||
| 594 | rgblight_effect_rgbtest(); | 629 | rgblight_effect_rgbtest(); |
| 595 | } else if (rgblight_config.mode == 36){ | 630 | } |
| 631 | #endif | ||
| 632 | #ifdef RGBLIGHT_EFFECT_ALTERNATING | ||
| 633 | else if (rgblight_config.mode == RGBLIGHT_MODE_ALTERNATING){ | ||
| 596 | rgblight_effect_alternating(); | 634 | rgblight_effect_alternating(); |
| 597 | } | 635 | } |
| 636 | #endif | ||
| 598 | } | 637 | } |
| 599 | } | 638 | } |
| 600 | 639 | ||
| 640 | #endif /* RGBLIGHT_USE_TIMER */ | ||
| 641 | |||
| 601 | // Effects | 642 | // Effects |
| 643 | #ifdef RGBLIGHT_EFFECT_BREATHING | ||
| 644 | __attribute__ ((weak)) | ||
| 645 | const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; | ||
| 646 | |||
| 602 | void rgblight_effect_breathing(uint8_t interval) { | 647 | void rgblight_effect_breathing(uint8_t interval) { |
| 603 | static uint8_t pos = 0; | 648 | static uint8_t pos = 0; |
| 604 | static uint16_t last_timer = 0; | 649 | static uint16_t last_timer = 0; |
| @@ -609,12 +654,17 @@ void rgblight_effect_breathing(uint8_t interval) { | |||
| 609 | } | 654 | } |
| 610 | last_timer = timer_read(); | 655 | last_timer = timer_read(); |
| 611 | 656 | ||
| 612 | |||
| 613 | // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ | 657 | // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ |
| 614 | val = (exp(sin((pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E)); | 658 | val = (exp(sin((pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E)); |
| 615 | rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val); | 659 | rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val); |
| 616 | pos = (pos + 1) % 256; | 660 | pos = (pos + 1) % 256; |
| 617 | } | 661 | } |
| 662 | #endif | ||
| 663 | |||
| 664 | #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD | ||
| 665 | __attribute__ ((weak)) | ||
| 666 | const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30}; | ||
| 667 | |||
| 618 | void rgblight_effect_rainbow_mood(uint8_t interval) { | 668 | void rgblight_effect_rainbow_mood(uint8_t interval) { |
| 619 | static uint16_t current_hue = 0; | 669 | static uint16_t current_hue = 0; |
| 620 | static uint16_t last_timer = 0; | 670 | static uint16_t last_timer = 0; |
| @@ -626,6 +676,12 @@ void rgblight_effect_rainbow_mood(uint8_t interval) { | |||
| 626 | rgblight_sethsv_noeeprom_old(current_hue, rgblight_config.sat, rgblight_config.val); | 676 | rgblight_sethsv_noeeprom_old(current_hue, rgblight_config.sat, rgblight_config.val); |
| 627 | current_hue = (current_hue + 1) % 360; | 677 | current_hue = (current_hue + 1) % 360; |
| 628 | } | 678 | } |
| 679 | #endif | ||
| 680 | |||
| 681 | #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL | ||
| 682 | __attribute__ ((weak)) | ||
| 683 | const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20}; | ||
| 684 | |||
| 629 | void rgblight_effect_rainbow_swirl(uint8_t interval) { | 685 | void rgblight_effect_rainbow_swirl(uint8_t interval) { |
| 630 | static uint16_t current_hue = 0; | 686 | static uint16_t current_hue = 0; |
| 631 | static uint16_t last_timer = 0; | 687 | static uint16_t last_timer = 0; |
| @@ -651,6 +707,12 @@ void rgblight_effect_rainbow_swirl(uint8_t interval) { | |||
| 651 | } | 707 | } |
| 652 | } | 708 | } |
| 653 | } | 709 | } |
| 710 | #endif | ||
| 711 | |||
| 712 | #ifdef RGBLIGHT_EFFECT_SNAKE | ||
| 713 | __attribute__ ((weak)) | ||
| 714 | const uint8_t RGBLED_SNAKE_INTERVALS[] PROGMEM = {100, 50, 20}; | ||
| 715 | |||
| 654 | void rgblight_effect_snake(uint8_t interval) { | 716 | void rgblight_effect_snake(uint8_t interval) { |
| 655 | static uint8_t pos = 0; | 717 | static uint8_t pos = 0; |
| 656 | static uint16_t last_timer = 0; | 718 | static uint16_t last_timer = 0; |
| @@ -689,6 +751,12 @@ void rgblight_effect_snake(uint8_t interval) { | |||
| 689 | pos = (pos + 1) % RGBLED_NUM; | 751 | pos = (pos + 1) % RGBLED_NUM; |
| 690 | } | 752 | } |
| 691 | } | 753 | } |
| 754 | #endif | ||
| 755 | |||
| 756 | #ifdef RGBLIGHT_EFFECT_KNIGHT | ||
| 757 | __attribute__ ((weak)) | ||
| 758 | const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31}; | ||
| 759 | |||
| 692 | void rgblight_effect_knight(uint8_t interval) { | 760 | void rgblight_effect_knight(uint8_t interval) { |
| 693 | static uint16_t last_timer = 0; | 761 | static uint16_t last_timer = 0; |
| 694 | if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval])) { | 762 | if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval])) { |
| @@ -730,8 +798,9 @@ void rgblight_effect_knight(uint8_t interval) { | |||
| 730 | increment = -increment; | 798 | increment = -increment; |
| 731 | } | 799 | } |
| 732 | } | 800 | } |
| 801 | #endif | ||
| 733 | 802 | ||
| 734 | 803 | #ifdef RGBLIGHT_EFFECT_CHRISTMAS | |
| 735 | void rgblight_effect_christmas(void) { | 804 | void rgblight_effect_christmas(void) { |
| 736 | static uint16_t current_offset = 0; | 805 | static uint16_t current_offset = 0; |
| 737 | static uint16_t last_timer = 0; | 806 | static uint16_t last_timer = 0; |
| @@ -748,6 +817,11 @@ void rgblight_effect_christmas(void) { | |||
| 748 | } | 817 | } |
| 749 | rgblight_set(); | 818 | rgblight_set(); |
| 750 | } | 819 | } |
| 820 | #endif | ||
| 821 | |||
| 822 | #ifdef RGBLIGHT_EFFECT_RGB_TEST | ||
| 823 | __attribute__ ((weak)) | ||
| 824 | const uint16_t RGBLED_RGBTEST_INTERVALS[] PROGMEM = {1024}; | ||
| 751 | 825 | ||
| 752 | void rgblight_effect_rgbtest(void) { | 826 | void rgblight_effect_rgbtest(void) { |
| 753 | static uint8_t pos = 0; | 827 | static uint8_t pos = 0; |
| @@ -774,7 +848,9 @@ void rgblight_effect_rgbtest(void) { | |||
| 774 | rgblight_setrgb(r, g, b); | 848 | rgblight_setrgb(r, g, b); |
| 775 | pos = (pos + 1) % 3; | 849 | pos = (pos + 1) % 3; |
| 776 | } | 850 | } |
| 851 | #endif | ||
| 777 | 852 | ||
| 853 | #ifdef RGBLIGHT_EFFECT_ALTERNATING | ||
| 778 | void rgblight_effect_alternating(void){ | 854 | void rgblight_effect_alternating(void){ |
| 779 | static uint16_t last_timer = 0; | 855 | static uint16_t last_timer = 0; |
| 780 | static uint16_t pos = 0; | 856 | static uint16_t pos = 0; |
| @@ -795,5 +871,4 @@ void rgblight_effect_alternating(void){ | |||
| 795 | rgblight_set(); | 871 | rgblight_set(); |
| 796 | pos = (pos + 1) % 2; | 872 | pos = (pos + 1) % 2; |
| 797 | } | 873 | } |
| 798 | 874 | #endif | |
| 799 | #endif /* RGBLIGHT_ANIMATIONS */ | ||
