forked from mirror/qmk_firmware
Add generic handling to cycle LED/RGB Matrix flags (#24649)
This commit is contained in:
@@ -72,6 +72,13 @@ uint8_t g_rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS] = {{0}};
|
||||
last_hit_t g_last_hit_tracker;
|
||||
#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
|
||||
|
||||
#ifndef RGB_MATRIX_FLAG_STEPS
|
||||
# define RGB_MATRIX_FLAG_STEPS \
|
||||
{ LED_FLAG_ALL, LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER, LED_FLAG_UNDERGLOW, LED_FLAG_NONE }
|
||||
#endif
|
||||
static const uint8_t rgb_matrix_flag_steps[] = RGB_MATRIX_FLAG_STEPS;
|
||||
#define RGB_MATRIX_FLAG_STEPS_COUNT ARRAY_SIZE(rgb_matrix_flag_steps)
|
||||
|
||||
// internals
|
||||
static bool suspend_state = false;
|
||||
static uint8_t rgb_last_enable = UINT8_MAX;
|
||||
@@ -747,6 +754,50 @@ void rgb_matrix_set_flags_noeeprom(led_flags_t flags) {
|
||||
rgb_matrix_set_flags_eeprom_helper(flags, false);
|
||||
}
|
||||
|
||||
void rgb_matrix_flags_step_helper(bool write_to_eeprom) {
|
||||
led_flags_t flags = rgb_matrix_get_flags();
|
||||
|
||||
uint8_t next = 0;
|
||||
for (uint8_t i = 0; i < RGB_MATRIX_FLAG_STEPS_COUNT; i++) {
|
||||
if (rgb_matrix_flag_steps[i] == flags) {
|
||||
next = i == RGB_MATRIX_FLAG_STEPS_COUNT - 1 ? 0 : i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
rgb_matrix_set_flags_eeprom_helper(rgb_matrix_flag_steps[next], write_to_eeprom);
|
||||
}
|
||||
|
||||
void rgb_matrix_flags_step_noeeprom(void) {
|
||||
rgb_matrix_flags_step_helper(false);
|
||||
}
|
||||
|
||||
void rgb_matrix_flags_step(void) {
|
||||
rgb_matrix_flags_step_helper(true);
|
||||
}
|
||||
|
||||
void rgb_matrix_flags_step_reverse_helper(bool write_to_eeprom) {
|
||||
led_flags_t flags = rgb_matrix_get_flags();
|
||||
|
||||
uint8_t next = 0;
|
||||
for (uint8_t i = 0; i < RGB_MATRIX_FLAG_STEPS_COUNT; i++) {
|
||||
if (rgb_matrix_flag_steps[i] == flags) {
|
||||
next = i == 0 ? RGB_MATRIX_FLAG_STEPS_COUNT - 1 : i - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
rgb_matrix_set_flags_eeprom_helper(rgb_matrix_flag_steps[next], write_to_eeprom);
|
||||
}
|
||||
|
||||
void rgb_matrix_flags_step_reverse_noeeprom(void) {
|
||||
rgb_matrix_flags_step_reverse_helper(false);
|
||||
}
|
||||
|
||||
void rgb_matrix_flags_step_reverse(void) {
|
||||
rgb_matrix_flags_step_reverse_helper(true);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------
|
||||
// RGB Matrix naming
|
||||
#undef RGB_MATRIX_EFFECT
|
||||
|
||||
@@ -218,6 +218,10 @@ void rgb_matrix_decrease_speed_noeeprom(void);
|
||||
led_flags_t rgb_matrix_get_flags(void);
|
||||
void rgb_matrix_set_flags(led_flags_t flags);
|
||||
void rgb_matrix_set_flags_noeeprom(led_flags_t flags);
|
||||
void rgb_matrix_flags_step_noeeprom(void);
|
||||
void rgb_matrix_flags_step(void);
|
||||
void rgb_matrix_flags_step_reverse_noeeprom(void);
|
||||
void rgb_matrix_flags_step_reverse(void);
|
||||
void rgb_matrix_update_pwm_buffers(void);
|
||||
|
||||
#ifdef RGB_MATRIX_MODE_NAME_ENABLE
|
||||
|
||||
Reference in New Issue
Block a user