Improve and simplify RGB Knight mode (#1677)

* Simplify RGB Knight mode code, and make it look closer to KITT

* Remove RGBLIGHT_EFFECT_DUALKNIGHT_LENGTH
This commit is contained in:
David Stosik 2017-09-06 06:19:08 +09:00 committed by skullydazed
parent 5f154f0a00
commit 4edfa97e03
2 changed files with 20 additions and 43 deletions

View File

@ -539,54 +539,35 @@ void rgblight_effect_snake(uint8_t interval) {
} }
} }
void rgblight_effect_knight(uint8_t interval) { void rgblight_effect_knight(uint8_t interval) {
static int8_t pos = 0;
static uint16_t last_timer = 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])) { if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval])) {
return; return;
} }
last_timer = timer_read(); last_timer = timer_read();
for (i = 0; i < RGBLED_NUM; i++) {
preled[i].r = 0; static int8_t low_bound = 0;
preled[i].g = 0; static int8_t high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1;
preled[i].b = 0; static int8_t increment = 1;
for (j = 0; j < RGBLIGHT_EFFECT_KNIGHT_LENGTH; j++) { uint8_t i, cur;
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]);
}
}
}
for (i = 0; i < RGBLED_NUM; i++) { for (i = 0; i < RGBLED_NUM; i++) {
cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % RGBLED_NUM; cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % RGBLED_NUM;
led[i].r = preled[cur].r;
led[i].g = preled[cur].g; if (i >= low_bound && i <= high_bound) {
led[i].b = preled[cur].b; sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[cur]);
} else {
led[cur].r = 0;
led[cur].g = 0;
led[cur].b = 0;
}
} }
rgblight_set(); rgblight_set();
if (increment == 1) {
if (pos - 1 < 0 - RGBLIGHT_EFFECT_KNIGHT_LENGTH) { low_bound += increment;
pos = 0 - RGBLIGHT_EFFECT_KNIGHT_LENGTH; high_bound += increment;
increment = -1;
} else { if (high_bound <= 0 || low_bound >= RGBLED_NUM - 1) {
pos -= 1; increment = -increment;
}
} else {
if (pos + 1 > RGBLED_NUM + RGBLIGHT_EFFECT_KNIGHT_LENGTH) {
pos = RGBLED_NUM + RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1;
increment = 1;
} else {
pos += 1;
}
} }
} }

View File

@ -33,10 +33,6 @@
#define RGBLIGHT_EFFECT_KNIGHT_OFFSET 0 #define RGBLIGHT_EFFECT_KNIGHT_OFFSET 0
#endif #endif
#ifndef RGBLIGHT_EFFECT_DUALKNIGHT_LENGTH
#define RGBLIGHT_EFFECT_DUALKNIGHT_LENGTH 4
#endif
#ifndef RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL #ifndef RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL
#define RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL 1000 #define RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL 1000
#endif #endif