Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double knight rider for split keyboards #3524

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion quantum/rgblight.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
rgblight_timer_disable();
#endif
} else if ((rgblight_config.mode >= 2 && rgblight_config.mode <= 24) ||
rgblight_config.mode == 35 || rgblight_config.mode == 36) {
rgblight_config.mode == 35 || rgblight_config.mode == 36 ||
(rgblight_config.mode >= 37 && rgblight_config.mode <= 39)) {
// MODE 2-5, breathing
// MODE 6-8, rainbow mood
// MODE 9-14, rainbow swirl
Expand All @@ -256,6 +257,7 @@ void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
// MODE 24, xmas
// MODE 35 RGB test
// MODE 36, alterating
// MODE 37-39, double knight rider

#ifdef RGBLIGHT_ANIMATIONS
rgblight_timer_enable();
Expand Down Expand Up @@ -594,6 +596,9 @@ void rgblight_task(void) {
rgblight_effect_rgbtest();
} else if (rgblight_config.mode == 36){
rgblight_effect_alternating();
}else if (rgblight_config.mode >= 37 && rgblight_config.mode <= 39){
// mode = 37 to 39, double knight mode
rgblight_effect_doubleknight(rgblight_config.mode - 37);
}
}
}
Expand Down Expand Up @@ -796,4 +801,35 @@ void rgblight_effect_alternating(void){
pos = (pos + 1) % 2;
}

void rgblight_effect_doubleknight(uint8_t interval) {
static uint16_t last_timer = 0;
static int8_t increment = 1;
static uint8_t offset = 0;
static int8_t middle = RGBLED_NUM/2;

if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval])) {
return;
}
last_timer = timer_read();

//turn on led if it is 'offset' away from the beginning or end of strip
for(int i = 0; i<RGBLED_NUM; i++){
if(i == offset || i == offset-increment || offset == (RGBLED_NUM - 1 - i) ||
offset == (RGBLED_NUM - 1 - i + increment)){
rgblight_sethsv_at(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, i);
}else{
rgblight_sethsv_at(rgblight_config.hue, rgblight_config.sat, 0, i);
}
}

rgblight_set();

offset+=increment;

//reverse direction if offset is at the edge
if(offset == 0 || offset == (middle-1)){
increment*=-1;;
}
}

#endif /* RGBLIGHT_ANIMATIONS */
3 changes: 2 additions & 1 deletion quantum/rgblight.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define RGBLIGHT_H

#ifdef RGBLIGHT_ANIMATIONS
#define RGBLIGHT_MODES 36
#define RGBLIGHT_MODES 39
#else
#define RGBLIGHT_MODES 1
#endif
Expand Down Expand Up @@ -167,5 +167,6 @@ void rgblight_effect_knight(uint8_t interval);
void rgblight_effect_christmas(void);
void rgblight_effect_rgbtest(void);
void rgblight_effect_alternating(void);
void rgblight_effect_doubleknight(uint8_t interval);

#endif