summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--quantum/rgblight.c59
-rw-r--r--quantum/rgblight.h4
2 files changed, 20 insertions, 43 deletions
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index d568a4f446..1b50764503 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;
+ }
}
diff --git a/quantum/rgblight.h b/quantum/rgblight.h
index d3e3a6cf71..d0dd6e4903 100644
--- a/quantum/rgblight.h
+++ b/quantum/rgblight.h
@@ -33,10 +33,6 @@
#define RGBLIGHT_EFFECT_KNIGHT_OFFSET 0
#endif
-#ifndef RGBLIGHT_EFFECT_DUALKNIGHT_LENGTH
-#define RGBLIGHT_EFFECT_DUALKNIGHT_LENGTH 4
-#endif
-
#ifndef RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL
#define RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL 1000
#endif