diff --git a/app/include/dt-bindings/zmk/rgb.h b/app/include/dt-bindings/zmk/rgb.h index 95aa5029..c1a80082 100644 --- a/app/include/dt-bindings/zmk/rgb.h +++ b/app/include/dt-bindings/zmk/rgb.h @@ -17,7 +17,8 @@ #define RGB_SPD_CMD 10 #define RGB_EFF_CMD 11 #define RGB_EFR_CMD 12 -#define RGB_COLOR_HSB_CMD 13 +#define RGB_EFS_CMD 13 +#define RGB_COLOR_HSB_CMD 14 #define RGB_TOG RGB_TOG_CMD 0 #define RGB_ON RGB_ON_CMD 0 diff --git a/app/include/zmk/rgb_underglow.h b/app/include/zmk/rgb_underglow.h index 4d452a6f..797f0b19 100644 --- a/app/include/zmk/rgb_underglow.h +++ b/app/include/zmk/rgb_underglow.h @@ -17,6 +17,8 @@ int zmk_rgb_underglow_get_state(bool *state); int zmk_rgb_underglow_on(); int zmk_rgb_underglow_off(); int zmk_rgb_underglow_cycle_effect(int direction); +int zmk_rgb_underglow_calc_effect(int direction); +int zmk_rgb_underglow_select_effect(int effect); struct zmk_led_hsb zmk_rgb_underglow_calc_hue(int direction); struct zmk_led_hsb zmk_rgb_underglow_calc_sat(int direction); struct zmk_led_hsb zmk_rgb_underglow_calc_brt(int direction); diff --git a/app/src/behaviors/behavior_rgb_underglow.c b/app/src/behaviors/behavior_rgb_underglow.c index 33af6556..96f69048 100644 --- a/app/src/behaviors/behavior_rgb_underglow.c +++ b/app/src/behaviors/behavior_rgb_underglow.c @@ -77,6 +77,16 @@ on_keymap_binding_convert_central_state_dependent_params(struct zmk_behavior_bin binding->param2 = RGB_COLOR_HSB_VAL(color.h, color.s, color.b); break; } + case RGB_EFR_CMD: { + binding->param1 = RGB_EFS_CMD; + binding->param2 = zmk_rgb_underglow_calc_effect(-1); + break; + } + case RGB_EFF_CMD: { + binding->param1 = RGB_EFS_CMD; + binding->param2 = zmk_rgb_underglow_calc_effect(1); + break; + } default: return 0; } @@ -111,6 +121,8 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding, return zmk_rgb_underglow_change_spd(1); case RGB_SPD_CMD: return zmk_rgb_underglow_change_spd(-1); + case RGB_EFS_CMD: + return zmk_rgb_underglow_select_effect(binding->param2); case RGB_EFF_CMD: return zmk_rgb_underglow_cycle_effect(1); case RGB_EFR_CMD: diff --git a/app/src/rgb_underglow.c b/app/src/rgb_underglow.c index 40d99c7d..427552fa 100644 --- a/app/src/rgb_underglow.c +++ b/app/src/rgb_underglow.c @@ -332,18 +332,28 @@ int zmk_rgb_underglow_off() { return zmk_rgb_underglow_save_state(); } -int zmk_rgb_underglow_cycle_effect(int direction) { +int zmk_rgb_underglow_calc_effect(int direction) { + return (state.current_effect + UNDERGLOW_EFFECT_NUMBER + direction) % UNDERGLOW_EFFECT_NUMBER; +} + +int zmk_rgb_underglow_select_effect(int effect) { if (!led_strip) return -ENODEV; - state.current_effect += UNDERGLOW_EFFECT_NUMBER + direction; - state.current_effect %= UNDERGLOW_EFFECT_NUMBER; + if (effect < 0 || effect >= UNDERGLOW_EFFECT_NUMBER) { + return -EINVAL; + } + state.current_effect = effect; state.animation_step = 0; return zmk_rgb_underglow_save_state(); } +int zmk_rgb_underglow_cycle_effect(int direction) { + return zmk_rgb_underglow_select_effect(zmk_rgb_underglow_calc_effect(direction)); +} + int zmk_rgb_underglow_toggle() { return state.on ? zmk_rgb_underglow_off() : zmk_rgb_underglow_on(); }