diff options
| author | XScorpion2 <rcalt2vt@gmail.com> | 2019-05-01 10:02:02 -0500 |
|---|---|---|
| committer | MechMerlin <30334081+mechmerlin@users.noreply.github.com> | 2019-05-01 08:02:02 -0700 |
| commit | 22ba36a4d86c06ce1b6049555525646eb16bb57a (patch) | |
| tree | 6b2d2d8551f0f2b67d6f638b8094775a95b1bf5c /quantum/rgblight.c | |
| parent | 50bc2dbe77e533959c4b8f821a31b489d25c7cb7 (diff) | |
| download | qmk_firmware-22ba36a4d86c06ce1b6049555525646eb16bb57a.tar.gz qmk_firmware-22ba36a4d86c06ce1b6049555525646eb16bb57a.zip | |
rgblight 255 hue (#5547)
Diffstat (limited to 'quantum/rgblight.c')
| -rw-r--r-- | quantum/rgblight.c | 200 |
1 files changed, 51 insertions, 149 deletions
diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 2f23768ed..98755ff08 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c | |||
| @@ -28,8 +28,10 @@ | |||
| 28 | #include "progmem.h" | 28 | #include "progmem.h" |
| 29 | #include "timer.h" | 29 | #include "timer.h" |
| 30 | #include "rgblight.h" | 30 | #include "rgblight.h" |
| 31 | #include "color.h" | ||
| 31 | #include "debug.h" | 32 | #include "debug.h" |
| 32 | #include "led_tables.h" | 33 | #include "led_tables.h" |
| 34 | #include "lib/lib8tion/lib8tion.h" | ||
| 33 | #ifdef VELOCIKEY_ENABLE | 35 | #ifdef VELOCIKEY_ENABLE |
| 34 | #include "velocikey.h" | 36 | #include "velocikey.h" |
| 35 | #endif | 37 | #endif |
| @@ -74,16 +76,13 @@ static inline int is_static_effect(uint8_t mode) { | |||
| 74 | return memchr(static_effect_table, mode, sizeof(static_effect_table)) != NULL; | 76 | return memchr(static_effect_table, mode, sizeof(static_effect_table)) != NULL; |
| 75 | } | 77 | } |
| 76 | 78 | ||
| 77 | #define MIN(a,b) (((a)<(b))?(a):(b)) | ||
| 78 | #define MAX(a,b) (((a)>(b))?(a):(b)) | ||
| 79 | |||
| 80 | #ifdef RGBLIGHT_LED_MAP | 79 | #ifdef RGBLIGHT_LED_MAP |
| 81 | const uint8_t led_map[] PROGMEM = RGBLIGHT_LED_MAP; | 80 | const uint8_t led_map[] PROGMEM = RGBLIGHT_LED_MAP; |
| 82 | #endif | 81 | #endif |
| 83 | 82 | ||
| 84 | #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT | 83 | #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT |
| 85 | __attribute__ ((weak)) | 84 | __attribute__ ((weak)) |
| 86 | const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90}; | 85 | const uint8_t RGBLED_GRADIENT_RANGES[] PROGMEM = {255, 170, 127, 85, 64}; |
| 87 | #endif | 86 | #endif |
| 88 | 87 | ||
| 89 | rgblight_config_t rgblight_config; | 88 | rgblight_config_t rgblight_config; |
| @@ -109,59 +108,10 @@ void rgblight_set_clipping_range(uint8_t start_pos, uint8_t num_leds) { | |||
| 109 | } | 108 | } |
| 110 | 109 | ||
| 111 | 110 | ||
| 112 | void sethsv(uint16_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { | 111 | void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { |
| 113 | uint8_t r = 0, g = 0, b = 0, base, color; | 112 | HSV hsv = { hue, sat, val > RGBLIGHT_LIMIT_VAL ? RGBLIGHT_LIMIT_VAL : val }; |
| 114 | 113 | RGB rgb = hsv_to_rgb(hsv); | |
| 115 | if (val > RGBLIGHT_LIMIT_VAL) { | 114 | setrgb(rgb.r, rgb.g, rgb.b, led1); |
| 116 | val=RGBLIGHT_LIMIT_VAL; // limit the val | ||
| 117 | } | ||
| 118 | |||
| 119 | if (sat == 0) { // Acromatic color (gray). Hue doesn't mind. | ||
| 120 | r = val; | ||
| 121 | g = val; | ||
| 122 | b = val; | ||
| 123 | } else { | ||
| 124 | base = ((255 - sat) * val) >> 8; | ||
| 125 | color = (val - base) * (hue % 60) / 60; | ||
| 126 | |||
| 127 | switch (hue / 60) { | ||
| 128 | case 0: | ||
| 129 | r = val; | ||
| 130 | g = base + color; | ||
| 131 | b = base; | ||
| 132 | break; | ||
| 133 | case 1: | ||
| 134 | r = val - color; | ||
| 135 | g = val; | ||
| 136 | b = base; | ||
| 137 | break; | ||
| 138 | case 2: | ||
| 139 | r = base; | ||
| 140 | g = val; | ||
| 141 | b = base + color; | ||
| 142 | break; | ||
| 143 | case 3: | ||
| 144 | r = base; | ||
| 145 | g = val - color; | ||
| 146 | b = val; | ||
| 147 | break; | ||
| 148 | case 4: | ||
| 149 | r = base + color; | ||
| 150 | g = base; | ||
| 151 | b = val; | ||
| 152 | break; | ||
| 153 | case 5: | ||
| 154 | r = val; | ||
| 155 | g = base; | ||
| 156 | b = val - color; | ||
| 157 | break; | ||
| 158 | } | ||
| 159 | } | ||
| 160 | r = pgm_read_byte(&CIE1931_CURVE[r]); | ||
| 161 | g = pgm_read_byte(&CIE1931_CURVE[g]); | ||
| 162 | b = pgm_read_byte(&CIE1931_CURVE[b]); | ||
| 163 | |||
| 164 | setrgb(r, g, b, led1); | ||
| 165 | } | 115 | } |
| 166 | 116 | ||
| 167 | void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) { | 117 | void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) { |
| @@ -180,24 +130,9 @@ void rgblight_check_config(void) { | |||
| 180 | rgblight_config.mode = RGBLIGHT_MODES; | 130 | rgblight_config.mode = RGBLIGHT_MODES; |
| 181 | } | 131 | } |
| 182 | 132 | ||
| 183 | if (rgblight_config.hue < 0) { | 133 | if (rgblight_config.val > RGBLIGHT_LIMIT_VAL) { |
| 184 | rgblight_config.hue = 0; | ||
| 185 | } else if (rgblight_config.hue > 360) { | ||
| 186 | rgblight_config.hue %= 360; | ||
| 187 | } | ||
| 188 | |||
| 189 | if (rgblight_config.sat < 0) { | ||
| 190 | rgblight_config.sat = 0; | ||
| 191 | } else if (rgblight_config.sat > 255) { | ||
| 192 | rgblight_config.sat = 255; | ||
| 193 | } | ||
| 194 | |||
| 195 | if (rgblight_config.val < 0) { | ||
| 196 | rgblight_config.val = 0; | ||
| 197 | } else if (rgblight_config.val > RGBLIGHT_LIMIT_VAL) { | ||
| 198 | rgblight_config.val = RGBLIGHT_LIMIT_VAL; | 134 | rgblight_config.val = RGBLIGHT_LIMIT_VAL; |
| 199 | } | 135 | } |
| 200 | |||
| 201 | } | 136 | } |
| 202 | 137 | ||
| 203 | uint32_t eeconfig_read_rgblight(void) { | 138 | uint32_t eeconfig_read_rgblight(void) { |
| @@ -220,7 +155,7 @@ void eeconfig_update_rgblight_default(void) { | |||
| 220 | rgblight_config.enable = 1; | 155 | rgblight_config.enable = 1; |
| 221 | rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; | 156 | rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; |
| 222 | rgblight_config.hue = 0; | 157 | rgblight_config.hue = 0; |
| 223 | rgblight_config.sat = 255; | 158 | rgblight_config.sat = UINT8_MAX; |
| 224 | rgblight_config.val = RGBLIGHT_LIMIT_VAL; | 159 | rgblight_config.val = RGBLIGHT_LIMIT_VAL; |
| 225 | rgblight_config.speed = 0; | 160 | rgblight_config.speed = 0; |
| 226 | RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; | 161 | RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; |
| @@ -442,23 +377,8 @@ void rgblight_disable_noeeprom(void) { | |||
| 442 | rgblight_set(); | 377 | rgblight_set(); |
| 443 | } | 378 | } |
| 444 | 379 | ||
| 445 | |||
| 446 | // Deals with the messy details of incrementing an integer | ||
| 447 | static uint8_t increment( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) { | ||
| 448 | int16_t new_value = value; | ||
| 449 | new_value += step; | ||
| 450 | return MIN( MAX( new_value, min ), max ); | ||
| 451 | } | ||
| 452 | |||
| 453 | static uint8_t decrement( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) { | ||
| 454 | int16_t new_value = value; | ||
| 455 | new_value -= step; | ||
| 456 | return MIN( MAX( new_value, min ), max ); | ||
| 457 | } | ||
| 458 | |||
| 459 | void rgblight_increase_hue_helper(bool write_to_eeprom) { | 380 | void rgblight_increase_hue_helper(bool write_to_eeprom) { |
| 460 | uint16_t hue; | 381 | uint8_t hue = rgblight_config.hue + RGBLIGHT_HUE_STEP; |
| 461 | hue = (rgblight_config.hue+RGBLIGHT_HUE_STEP) % 360; | ||
| 462 | rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom); | 382 | rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom); |
| 463 | } | 383 | } |
| 464 | void rgblight_increase_hue_noeeprom(void) { | 384 | void rgblight_increase_hue_noeeprom(void) { |
| @@ -468,12 +388,7 @@ void rgblight_increase_hue(void) { | |||
| 468 | rgblight_increase_hue_helper(true); | 388 | rgblight_increase_hue_helper(true); |
| 469 | } | 389 | } |
| 470 | void rgblight_decrease_hue_helper(bool write_to_eeprom) { | 390 | void rgblight_decrease_hue_helper(bool write_to_eeprom) { |
| 471 | uint16_t hue; | 391 | uint8_t hue = rgblight_config.hue - RGBLIGHT_HUE_STEP; |
| 472 | if (rgblight_config.hue-RGBLIGHT_HUE_STEP < 0) { | ||
| 473 | hue = (rgblight_config.hue + 360 - RGBLIGHT_HUE_STEP) % 360; | ||
| 474 | } else { | ||
| 475 | hue = (rgblight_config.hue - RGBLIGHT_HUE_STEP) % 360; | ||
| 476 | } | ||
| 477 | rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom); | 392 | rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom); |
| 478 | } | 393 | } |
| 479 | void rgblight_decrease_hue_noeeprom(void) { | 394 | void rgblight_decrease_hue_noeeprom(void) { |
| @@ -483,12 +398,7 @@ void rgblight_decrease_hue(void) { | |||
| 483 | rgblight_decrease_hue_helper(true); | 398 | rgblight_decrease_hue_helper(true); |
| 484 | } | 399 | } |
| 485 | void rgblight_increase_sat_helper(bool write_to_eeprom) { | 400 | void rgblight_increase_sat_helper(bool write_to_eeprom) { |
| 486 | uint8_t sat; | 401 | uint8_t sat = qadd8(rgblight_config.sat, RGBLIGHT_SAT_STEP); |
| 487 | if (rgblight_config.sat + RGBLIGHT_SAT_STEP > 255) { | ||
| 488 | sat = 255; | ||
| 489 | } else { | ||
| 490 | sat = rgblight_config.sat + RGBLIGHT_SAT_STEP; | ||
| 491 | } | ||
| 492 | rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom); | 402 | rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom); |
| 493 | } | 403 | } |
| 494 | void rgblight_increase_sat_noeeprom(void) { | 404 | void rgblight_increase_sat_noeeprom(void) { |
| @@ -498,12 +408,7 @@ void rgblight_increase_sat(void) { | |||
| 498 | rgblight_increase_sat_helper(true); | 408 | rgblight_increase_sat_helper(true); |
| 499 | } | 409 | } |
| 500 | void rgblight_decrease_sat_helper(bool write_to_eeprom) { | 410 | void rgblight_decrease_sat_helper(bool write_to_eeprom) { |
| 501 | uint8_t sat; | 411 | uint8_t sat = qsub8(rgblight_config.sat, RGBLIGHT_SAT_STEP); |
| 502 | if (rgblight_config.sat - RGBLIGHT_SAT_STEP < 0) { | ||
| 503 | sat = 0; | ||
| 504 | } else { | ||
| 505 | sat = rgblight_config.sat - RGBLIGHT_SAT_STEP; | ||
| 506 | } | ||
| 507 | rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom); | 412 | rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom); |
| 508 | } | 413 | } |
| 509 | void rgblight_decrease_sat_noeeprom(void) { | 414 | void rgblight_decrease_sat_noeeprom(void) { |
| @@ -513,12 +418,7 @@ void rgblight_decrease_sat(void) { | |||
| 513 | rgblight_decrease_sat_helper(true); | 418 | rgblight_decrease_sat_helper(true); |
| 514 | } | 419 | } |
| 515 | void rgblight_increase_val_helper(bool write_to_eeprom) { | 420 | void rgblight_increase_val_helper(bool write_to_eeprom) { |
| 516 | uint8_t val; | 421 | uint8_t val = qadd8(rgblight_config.val, RGBLIGHT_VAL_STEP); |
| 517 | if (rgblight_config.val + RGBLIGHT_VAL_STEP > RGBLIGHT_LIMIT_VAL) { | ||
| 518 | val = RGBLIGHT_LIMIT_VAL; | ||
| 519 | } else { | ||
| 520 | val = rgblight_config.val + RGBLIGHT_VAL_STEP; | ||
| 521 | } | ||
| 522 | rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom); | 422 | rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom); |
| 523 | } | 423 | } |
| 524 | void rgblight_increase_val_noeeprom(void) { | 424 | void rgblight_increase_val_noeeprom(void) { |
| @@ -528,12 +428,7 @@ void rgblight_increase_val(void) { | |||
| 528 | rgblight_increase_val_helper(true); | 428 | rgblight_increase_val_helper(true); |
| 529 | } | 429 | } |
| 530 | void rgblight_decrease_val_helper(bool write_to_eeprom) { | 430 | void rgblight_decrease_val_helper(bool write_to_eeprom) { |
| 531 | uint8_t val; | 431 | uint8_t val = qsub8(rgblight_config.val, RGBLIGHT_VAL_STEP); |
| 532 | if (rgblight_config.val - RGBLIGHT_VAL_STEP < 0) { | ||
| 533 | val = 0; | ||
| 534 | } else { | ||
| 535 | val = rgblight_config.val - RGBLIGHT_VAL_STEP; | ||
| 536 | } | ||
| 537 | rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom); | 432 | rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom); |
| 538 | } | 433 | } |
| 539 | void rgblight_decrease_val_noeeprom(void) { | 434 | void rgblight_decrease_val_noeeprom(void) { |
| @@ -543,18 +438,20 @@ void rgblight_decrease_val(void) { | |||
| 543 | rgblight_decrease_val_helper(true); | 438 | rgblight_decrease_val_helper(true); |
| 544 | } | 439 | } |
| 545 | void rgblight_increase_speed(void) { | 440 | void rgblight_increase_speed(void) { |
| 546 | rgblight_config.speed = increment( rgblight_config.speed, 1, 0, 3 ); | 441 | if (rgblight_config.speed < 3) |
| 442 | rgblight_config.speed++; | ||
| 547 | //RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED? | 443 | //RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED? |
| 548 | eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this | 444 | eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this |
| 549 | } | 445 | } |
| 550 | 446 | ||
| 551 | void rgblight_decrease_speed(void) { | 447 | void rgblight_decrease_speed(void) { |
| 552 | rgblight_config.speed = decrement( rgblight_config.speed, 1, 0, 3 ); | 448 | if (rgblight_config.speed > 0) |
| 449 | rgblight_config.speed--; | ||
| 553 | //RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED?? | 450 | //RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED?? |
| 554 | eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this | 451 | eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this |
| 555 | } | 452 | } |
| 556 | 453 | ||
| 557 | void rgblight_sethsv_noeeprom_old(uint16_t hue, uint8_t sat, uint8_t val) { | 454 | void rgblight_sethsv_noeeprom_old(uint8_t hue, uint8_t sat, uint8_t val) { |
| 558 | if (rgblight_config.enable) { | 455 | if (rgblight_config.enable) { |
| 559 | LED_TYPE tmp_led; | 456 | LED_TYPE tmp_led; |
| 560 | sethsv(hue, sat, val, &tmp_led); | 457 | sethsv(hue, sat, val, &tmp_led); |
| @@ -563,7 +460,7 @@ void rgblight_sethsv_noeeprom_old(uint16_t hue, uint8_t sat, uint8_t val) { | |||
| 563 | } | 460 | } |
| 564 | } | 461 | } |
| 565 | 462 | ||
| 566 | void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) { | 463 | void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) { |
| 567 | if (rgblight_config.enable) { | 464 | if (rgblight_config.enable) { |
| 568 | rgblight_status.base_mode = mode_base_table[rgblight_config.mode]; | 465 | rgblight_status.base_mode = mode_base_table[rgblight_config.mode]; |
| 569 | if (rgblight_config.mode == RGBLIGHT_MODE_STATIC_LIGHT) { | 466 | if (rgblight_config.mode == RGBLIGHT_MODE_STATIC_LIGHT) { |
| @@ -596,13 +493,22 @@ void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool | |||
| 596 | #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT | 493 | #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT |
| 597 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_STATIC_GRADIENT) { | 494 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_STATIC_GRADIENT) { |
| 598 | // static gradient | 495 | // static gradient |
| 599 | uint16_t _hue; | ||
| 600 | uint8_t delta = rgblight_config.mode - rgblight_status.base_mode; | 496 | uint8_t delta = rgblight_config.mode - rgblight_status.base_mode; |
| 601 | int8_t direction = (delta % 2) ? -1 : 1; | 497 | bool direction = (delta % 2) == 0; |
| 602 | uint16_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[delta / 2]); | 498 | #ifdef __AVR__ |
| 499 | // probably due to how pgm_read_word is defined for ARM, but the ARM compiler really hates this line | ||
| 500 | uint8_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[delta / 2]); | ||
| 501 | #else | ||
| 502 | uint8_t range = RGBLED_GRADIENT_RANGES[delta / 2]; | ||
| 503 | #endif | ||
| 603 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { | 504 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { |
| 604 | _hue = (range / RGBLED_NUM * i * direction + hue + 360) % 360; | 505 | uint8_t _hue = ((uint16_t)i * (uint16_t)range) / RGBLED_NUM; |
| 605 | dprintf("rgblight rainbow set hsv: %u,%u,%d,%u\n", i, _hue, direction, range); | 506 | if (direction) { |
| 507 | _hue = hue + _hue; | ||
| 508 | } else { | ||
| 509 | _hue = hue - _hue; | ||
| 510 | } | ||
| 511 | dprintf("rgblight rainbow set hsv: %d,%d,%d,%u\n", i, _hue, direction, range); | ||
| 606 | sethsv(_hue, sat, val, (LED_TYPE *)&led[i]); | 512 | sethsv(_hue, sat, val, (LED_TYPE *)&led[i]); |
| 607 | } | 513 | } |
| 608 | rgblight_set(); | 514 | rgblight_set(); |
| @@ -628,15 +534,15 @@ void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool | |||
| 628 | } | 534 | } |
| 629 | } | 535 | } |
| 630 | 536 | ||
| 631 | void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { | 537 | void rgblight_sethsv(uint8_t hue, uint8_t sat, uint8_t val) { |
| 632 | rgblight_sethsv_eeprom_helper(hue, sat, val, true); | 538 | rgblight_sethsv_eeprom_helper(hue, sat, val, true); |
| 633 | } | 539 | } |
| 634 | 540 | ||
| 635 | void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { | 541 | void rgblight_sethsv_noeeprom(uint8_t hue, uint8_t sat, uint8_t val) { |
| 636 | rgblight_sethsv_eeprom_helper(hue, sat, val, false); | 542 | rgblight_sethsv_eeprom_helper(hue, sat, val, false); |
| 637 | } | 543 | } |
| 638 | 544 | ||
| 639 | uint16_t rgblight_get_hue(void) { | 545 | uint8_t rgblight_get_hue(void) { |
| 640 | return rgblight_config.hue; | 546 | return rgblight_config.hue; |
| 641 | } | 547 | } |
| 642 | 548 | ||
| @@ -668,7 +574,7 @@ void rgblight_setrgb_at(uint8_t r, uint8_t g, uint8_t b, uint8_t index) { | |||
| 668 | rgblight_set(); | 574 | rgblight_set(); |
| 669 | } | 575 | } |
| 670 | 576 | ||
| 671 | void rgblight_sethsv_at(uint16_t hue, uint8_t sat, uint8_t val, uint8_t index) { | 577 | void rgblight_sethsv_at(uint8_t hue, uint8_t sat, uint8_t val, uint8_t index) { |
| 672 | if (!rgblight_config.enable) { return; } | 578 | if (!rgblight_config.enable) { return; } |
| 673 | 579 | ||
| 674 | LED_TYPE tmp_led; | 580 | LED_TYPE tmp_led; |
| @@ -701,7 +607,7 @@ void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8 | |||
| 701 | wait_ms(1); | 607 | wait_ms(1); |
| 702 | } | 608 | } |
| 703 | 609 | ||
| 704 | void rgblight_sethsv_range(uint16_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end) { | 610 | void rgblight_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end) { |
| 705 | if (!rgblight_config.enable) { return; } | 611 | if (!rgblight_config.enable) { return; } |
| 706 | 612 | ||
| 707 | LED_TYPE tmp_led; | 613 | LED_TYPE tmp_led; |
| @@ -717,11 +623,11 @@ void rgblight_setrgb_slave(uint8_t r, uint8_t g, uint8_t b) { | |||
| 717 | rgblight_setrgb_range(r, g, b, (uint8_t) RGBLED_NUM/2, (uint8_t) RGBLED_NUM); | 623 | rgblight_setrgb_range(r, g, b, (uint8_t) RGBLED_NUM/2, (uint8_t) RGBLED_NUM); |
| 718 | } | 624 | } |
| 719 | 625 | ||
| 720 | void rgblight_sethsv_master(uint16_t hue, uint8_t sat, uint8_t val) { | 626 | void rgblight_sethsv_master(uint8_t hue, uint8_t sat, uint8_t val) { |
| 721 | rgblight_sethsv_range(hue, sat, val, 0, (uint8_t) RGBLED_NUM/2); | 627 | rgblight_sethsv_range(hue, sat, val, 0, (uint8_t) RGBLED_NUM/2); |
| 722 | } | 628 | } |
| 723 | 629 | ||
| 724 | void rgblight_sethsv_slave(uint16_t hue, uint8_t sat, uint8_t val) { | 630 | void rgblight_sethsv_slave(uint8_t hue, uint8_t sat, uint8_t val) { |
| 725 | rgblight_sethsv_range(hue, sat, val, (uint8_t) RGBLED_NUM/2, (uint8_t) RGBLED_NUM); | 631 | rgblight_sethsv_range(hue, sat, val, (uint8_t) RGBLED_NUM/2, (uint8_t) RGBLED_NUM); |
| 726 | } | 632 | } |
| 727 | 633 | ||
| @@ -982,7 +888,7 @@ void rgblight_effect_breathing(animation_status_t *anim) { | |||
| 982 | // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ | 888 | // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ |
| 983 | val = (exp(sin((anim->pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E)); | 889 | val = (exp(sin((anim->pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E)); |
| 984 | rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val); | 890 | rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val); |
| 985 | anim->pos = (anim->pos + 1) % 256; | 891 | anim->pos = (anim->pos + 1); |
| 986 | } | 892 | } |
| 987 | #endif | 893 | #endif |
| 988 | 894 | ||
| @@ -992,36 +898,32 @@ const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30}; | |||
| 992 | 898 | ||
| 993 | void rgblight_effect_rainbow_mood(animation_status_t *anim) { | 899 | void rgblight_effect_rainbow_mood(animation_status_t *anim) { |
| 994 | rgblight_sethsv_noeeprom_old(anim->current_hue, rgblight_config.sat, rgblight_config.val); | 900 | rgblight_sethsv_noeeprom_old(anim->current_hue, rgblight_config.sat, rgblight_config.val); |
| 995 | anim->current_hue = (anim->current_hue + 1) % 360; | 901 | anim->current_hue++; |
| 996 | } | 902 | } |
| 997 | #endif | 903 | #endif |
| 998 | 904 | ||
| 999 | #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL | 905 | #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL |
| 1000 | #ifndef RGBLIGHT_RAINBOW_SWIRL_RANGE | 906 | #ifndef RGBLIGHT_RAINBOW_SWIRL_RANGE |
| 1001 | #define RGBLIGHT_RAINBOW_SWIRL_RANGE 360 | 907 | #define RGBLIGHT_RAINBOW_SWIRL_RANGE 255 |
| 1002 | #endif | 908 | #endif |
| 1003 | 909 | ||
| 1004 | __attribute__ ((weak)) | 910 | __attribute__ ((weak)) |
| 1005 | const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20}; | 911 | const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20}; |
| 1006 | 912 | ||
| 1007 | void rgblight_effect_rainbow_swirl(animation_status_t *anim) { | 913 | void rgblight_effect_rainbow_swirl(animation_status_t *anim) { |
| 1008 | uint16_t hue; | 914 | uint8_t hue; |
| 1009 | uint8_t i; | 915 | uint8_t i; |
| 1010 | 916 | ||
| 1011 | for (i = 0; i < RGBLED_NUM; i++) { | 917 | for (i = 0; i < RGBLED_NUM; i++) { |
| 1012 | hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / RGBLED_NUM * i + anim->current_hue) % 360; | 918 | hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / RGBLED_NUM * i + anim->current_hue); |
| 1013 | sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); | 919 | sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); |
| 1014 | } | 920 | } |
| 1015 | rgblight_set(); | 921 | rgblight_set(); |
| 1016 | 922 | ||
| 1017 | if (anim->delta % 2) { | 923 | if (anim->delta % 2) { |
| 1018 | anim->current_hue = (anim->current_hue + 1) % 360; | 924 | anim->current_hue++; |
| 1019 | } else { | 925 | } else { |
| 1020 | if (anim->current_hue - 1 < 0) { | 926 | anim->current_hue--; |
| 1021 | anim->current_hue = 359; | ||
| 1022 | } else { | ||
| 1023 | anim->current_hue = anim->current_hue - 1; | ||
| 1024 | } | ||
| 1025 | } | 927 | } |
| 1026 | } | 928 | } |
| 1027 | #endif | 929 | #endif |
| @@ -1146,12 +1048,12 @@ void rgblight_effect_knight(animation_status_t *anim) { | |||
| 1146 | 1048 | ||
| 1147 | #ifdef RGBLIGHT_EFFECT_CHRISTMAS | 1049 | #ifdef RGBLIGHT_EFFECT_CHRISTMAS |
| 1148 | void rgblight_effect_christmas(animation_status_t *anim) { | 1050 | void rgblight_effect_christmas(animation_status_t *anim) { |
| 1149 | uint16_t hue; | 1051 | uint8_t hue; |
| 1150 | uint8_t i; | 1052 | uint8_t i; |
| 1151 | 1053 | ||
| 1152 | anim->current_offset = (anim->current_offset + 1) % 2; | 1054 | anim->current_offset = (anim->current_offset + 1) % 2; |
| 1153 | for (i = 0; i < RGBLED_NUM; i++) { | 1055 | for (i = 0; i < RGBLED_NUM; i++) { |
| 1154 | hue = 0 + ((i/RGBLIGHT_EFFECT_CHRISTMAS_STEP + anim->current_offset) % 2) * 120; | 1056 | hue = 0 + ((i/RGBLIGHT_EFFECT_CHRISTMAS_STEP + anim->current_offset) % 2) * 85; |
| 1155 | sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); | 1057 | sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); |
| 1156 | } | 1058 | } |
| 1157 | rgblight_set(); | 1059 | rgblight_set(); |
