diff options
author | Peter Johanson <peter@peterjohanson.com> | 2021-11-09 05:04:54 +0000 |
---|---|---|
committer | Pete Johanson <peter@peterjohanson.com> | 2022-01-31 23:03:34 -0500 |
commit | d486304f7987e6cfd5ab9a77f3e077087759a258 (patch) | |
tree | 8cf2f97596750d5ec48182068dd7d5a0a07ac9c0 /app | |
parent | 0febaa142a2baca1be293aca339bdc6920500c01 (diff) |
fix(underglow): Handle cycling effects on splits.
* Convert relative effect cycling to absolute effect selection.
Diffstat (limited to 'app')
-rw-r--r-- | app/include/dt-bindings/zmk/rgb.h | 3 | ||||
-rw-r--r-- | app/include/zmk/rgb_underglow.h | 2 | ||||
-rw-r--r-- | app/src/behaviors/behavior_rgb_underglow.c | 12 | ||||
-rw-r--r-- | app/src/rgb_underglow.c | 16 |
4 files changed, 29 insertions, 4 deletions
diff --git a/app/include/dt-bindings/zmk/rgb.h b/app/include/dt-bindings/zmk/rgb.h index 95aa502..c1a8008 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 4d452a6..797f0b1 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 33af655..96f6904 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 40d99c7..427552f 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(); } |