Skip to content

Commit

Permalink
Improve and simplify RGB Knight mode (qmk#1677)
Browse files Browse the repository at this point in the history
* Simplify RGB Knight mode code, and make it look closer to KITT

* Remove RGBLIGHT_EFFECT_DUALKNIGHT_LENGTH
  • Loading branch information
davidstosik authored and skullydazed committed Sep 5, 2017
1 parent 5f154f0 commit 4edfa97
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 43 deletions.
59 changes: 20 additions & 39 deletions quantum/rgblight.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}


Expand Down
4 changes: 0 additions & 4 deletions quantum/rgblight.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4edfa97

Please sign in to comment.