diff options
author | David Stosik <davidstosik@users.noreply.github.com> | 2017-09-06 06:19:08 +0900 |
---|---|---|
committer | skullydazed <skullydazed@users.noreply.github.com> | 2017-09-05 14:19:08 -0700 |
commit | 4edfa97e031c3c1884d54d6f0310c99a9d6abd82 (patch) | |
tree | 7f63fa87e63c7c2b6a153fa38aa3a41d27b2aeac /quantum/rgblight.c | |
parent | 5f154f0a00391546666ce1e3276f4299731d4be4 (diff) | |
download | qmk_firmware-4edfa97e031c3c1884d54d6f0310c99a9d6abd82.tar.gz |
Improve and simplify RGB Knight mode (#1677)
* Simplify RGB Knight mode code, and make it look closer to KITT
* Remove RGBLIGHT_EFFECT_DUALKNIGHT_LENGTH
Diffstat (limited to 'quantum/rgblight.c')
-rw-r--r-- | quantum/rgblight.c | 59 |
1 files changed, 20 insertions, 39 deletions
diff --git a/quantum/rgblight.c b/quantum/rgblight.c index d568a4f44..1b5076450 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -539,55 +539,36 @@ void rgblight_effect_snake(uint8_t interval) { } } void rgblight_effect_knight(uint8_t interval) { - static int8_t pos = 0; static uint16_t last_timer = 0; - uint8_t i, j, cur; - int8_t k; - LED_TYPE preled[RGBLED_NUM]; - static int8_t increment = -1; if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval])) { return; } last_timer = timer_read(); - for (i = 0; i < RGBLED_NUM; i++) { - preled[i].r = 0; - preled[i].g = 0; - preled[i].b = 0; - for (j = 0; j < RGBLIGHT_EFFECT_KNIGHT_LENGTH; j++) { - k = pos + j * increment; - if (k < 0) { - k = 0; - } - if (k >= RGBLED_NUM) { - k = RGBLED_NUM - 1; - } - if (i == k) { - sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&preled[i]); - } - } - } + + static int8_t low_bound = 0; + static int8_t high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1; + static int8_t increment = 1; + uint8_t i, cur; + for (i = 0; i < RGBLED_NUM; i++) { cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % RGBLED_NUM; - led[i].r = preled[cur].r; - led[i].g = preled[cur].g; - led[i].b = preled[cur].b; - } - rgblight_set(); - if (increment == 1) { - if (pos - 1 < 0 - RGBLIGHT_EFFECT_KNIGHT_LENGTH) { - pos = 0 - RGBLIGHT_EFFECT_KNIGHT_LENGTH; - increment = -1; - } else { - pos -= 1; - } - } else { - if (pos + 1 > RGBLED_NUM + RGBLIGHT_EFFECT_KNIGHT_LENGTH) { - pos = RGBLED_NUM + RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1; - increment = 1; + + if (i >= low_bound && i <= high_bound) { + sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[cur]); } else { - pos += 1; + led[cur].r = 0; + led[cur].g = 0; + led[cur].b = 0; } } + rgblight_set(); + + low_bound += increment; + high_bound += increment; + + if (high_bound <= 0 || low_bound >= RGBLED_NUM - 1) { + increment = -increment; + } } |