Skip to content

Commit

Permalink
Make rgb repeathold a little more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
plodah committed Nov 2, 2024
1 parent 05bd9e0 commit 75db9d8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 57 deletions.
44 changes: 3 additions & 41 deletions users/plodah/functions/process_record_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,53 +96,15 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
#endif // PLODAH_KNOB_ENHANCEMENTS_ENABLE

#if defined(PLODAH_REPEATHOLD_RGB) && defined(RGB_MATRIX_ENABLE)
case RGB_VAD:
rgb_vad_pressed = record->event.pressed;
if (record->event.pressed) {
repeathold_rgb_timer = timer_read();
}
return true;
case RGB_VAI:
rgb_vai_pressed = record->event.pressed;
if (record->event.pressed) {
repeathold_rgb_timer = timer_read();
}
return true;
case RGB_HUD:
rgb_hud_pressed = record->event.pressed;
if (record->event.pressed) {
repeathold_rgb_timer = timer_read();
}
return true;
case RGB_HUI:
rgb_hui_pressed = record->event.pressed;
if (record->event.pressed) {
repeathold_rgb_timer = timer_read();
}
return true;
case RGB_SAD:
rgb_sad_pressed = record->event.pressed;
if (record->event.pressed) {
repeathold_rgb_timer = timer_read();
}
return true;
case RGB_SAI:
rgb_sai_pressed = record->event.pressed;
if (record->event.pressed) {
repeathold_rgb_timer = timer_read();
}
return true;
case RGB_VAD:
case RGB_VAI:
case RGB_SPD:
rgb_spd_pressed = record->event.pressed;
if (record->event.pressed) {
repeathold_rgb_timer = timer_read();
}
return true;
case RGB_SPI:
rgb_spi_pressed = record->event.pressed;
if (record->event.pressed) {
repeathold_rgb_timer = timer_read();
}
repeathold_rgb_start(keycode & 0xff, record->event.pressed);
return true;
#endif // defined(PLODAH_REPEATHOLD_RGB) && defined(RGB_MATRIX_ENABLE)
}
Expand Down
70 changes: 54 additions & 16 deletions users/plodah/functions/repeathold_rgb.c
Original file line number Diff line number Diff line change
@@ -1,39 +1,77 @@
#pragma once

bool rgb_vad_pressed = false;
bool rgb_vai_pressed = false;
bool rgb_hud_pressed = false;
bool rgb_hui_pressed = false;
bool rgb_sad_pressed = false;
bool rgb_sai_pressed = false;
bool rgb_spd_pressed = false;
bool rgb_spi_pressed = false;
#include <stdbool.h>
int8_t rgb_va_state = -1;
int8_t rgb_hu_state = -1;
int8_t rgb_sa_state = -1;
int8_t rgb_sp_state = -1;
uint16_t repeathold_rgb_timer;

/*
"0x7823": {"group": "rgb", "key": "RGB_HUI"},
"0x7824": {"group": "rgb", "key": "RGB_HUD"},
"0x7825": {"group": "rgb", "key": "RGB_SAI"},
"0x7826": {"group": "rgb", "key": "RGB_SAD"},
"0x7827": {"group": "rgb", "key": "RGB_VAI"},
"0x7828": {"group": "rgb", "key": "RGB_VAD"},
"0x7829": {"group": "rgb", "key": "RGB_SPI"},
"0x782A": {"group": "rgb", "key": "RGB_SPD"},
*/

void repeathold_rgb_start(int8_t keycode, bool pressed) {
switch(keycode){
case RGB_HUI & 0xff:
case RGB_HUD & 0xff:
if(pressed){rgb_hu_state = keycode & 0x1;}
else{rgb_hu_state = -1;}
break;

case RGB_SAI & 0xff:
case RGB_SAD & 0xff:
if(pressed){rgb_sa_state = keycode & 0x1;}
else{rgb_sa_state = -1;}
break;

case RGB_VAI & 0xff:
case RGB_VAD & 0xff:
if(pressed){rgb_va_state = keycode & 0x1;}
else{rgb_va_state = -1;}
break;

case RGB_SPI & 0xff:
case RGB_SPD & 0xff:
if(pressed){rgb_sp_state = keycode & 0x1;}
else{rgb_sp_state = -1;}
break;

}
repeathold_rgb_timer = timer_read();
}

void repeathold_rgb_check(void){
if(timer_elapsed(repeathold_rgb_timer) > PLODAH_REPEATHOLD_RATE){
if(rgb_vai_pressed){
if(rgb_va_state == 1){
rgb_matrix_increase_val();
}
if(rgb_vad_pressed){
if(rgb_va_state == 0){
rgb_matrix_decrease_val();
}
if(rgb_sai_pressed){
if(rgb_sa_state == 1){
rgb_matrix_increase_sat();
}
if(rgb_sad_pressed){
if(rgb_sa_state == 0){
rgb_matrix_decrease_sat();
}
if(rgb_hui_pressed){
if(rgb_hu_state == 1){
rgb_matrix_increase_hue();
}
if(rgb_hud_pressed){
if(rgb_hu_state == 0){
rgb_matrix_decrease_hue();
}
if(rgb_spi_pressed){
if(rgb_sp_state == 1){
rgb_matrix_increase_speed();
}
if(rgb_spd_pressed){
if(rgb_sp_state == 0){
rgb_matrix_decrease_speed();
}
repeathold_rgb_timer = timer_read();
Expand Down

0 comments on commit 75db9d8

Please sign in to comment.