Browse Source

fix(underglow): Handle cycling effects on splits.

* Convert relative effect cycling to absolute effect selection.
xmkb
Peter Johanson 3 years ago committed by Pete Johanson
parent
commit
d486304f79
  1. 3
      app/include/dt-bindings/zmk/rgb.h
  2. 2
      app/include/zmk/rgb_underglow.h
  3. 12
      app/src/behaviors/behavior_rgb_underglow.c
  4. 16
      app/src/rgb_underglow.c

3
app/include/dt-bindings/zmk/rgb.h

@ -17,7 +17,8 @@
#define RGB_SPD_CMD 10 #define RGB_SPD_CMD 10
#define RGB_EFF_CMD 11 #define RGB_EFF_CMD 11
#define RGB_EFR_CMD 12 #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_TOG RGB_TOG_CMD 0
#define RGB_ON RGB_ON_CMD 0 #define RGB_ON RGB_ON_CMD 0

2
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_on();
int zmk_rgb_underglow_off(); int zmk_rgb_underglow_off();
int zmk_rgb_underglow_cycle_effect(int direction); 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_hue(int direction);
struct zmk_led_hsb zmk_rgb_underglow_calc_sat(int direction); struct zmk_led_hsb zmk_rgb_underglow_calc_sat(int direction);
struct zmk_led_hsb zmk_rgb_underglow_calc_brt(int direction); struct zmk_led_hsb zmk_rgb_underglow_calc_brt(int direction);

12
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); binding->param2 = RGB_COLOR_HSB_VAL(color.h, color.s, color.b);
break; 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: default:
return 0; return 0;
} }
@ -111,6 +121,8 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
return zmk_rgb_underglow_change_spd(1); return zmk_rgb_underglow_change_spd(1);
case RGB_SPD_CMD: case RGB_SPD_CMD:
return zmk_rgb_underglow_change_spd(-1); return zmk_rgb_underglow_change_spd(-1);
case RGB_EFS_CMD:
return zmk_rgb_underglow_select_effect(binding->param2);
case RGB_EFF_CMD: case RGB_EFF_CMD:
return zmk_rgb_underglow_cycle_effect(1); return zmk_rgb_underglow_cycle_effect(1);
case RGB_EFR_CMD: case RGB_EFR_CMD:

16
app/src/rgb_underglow.c

@ -332,18 +332,28 @@ int zmk_rgb_underglow_off() {
return zmk_rgb_underglow_save_state(); 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) if (!led_strip)
return -ENODEV; return -ENODEV;
state.current_effect += UNDERGLOW_EFFECT_NUMBER + direction; if (effect < 0 || effect >= UNDERGLOW_EFFECT_NUMBER) {
state.current_effect %= UNDERGLOW_EFFECT_NUMBER; return -EINVAL;
}
state.current_effect = effect;
state.animation_step = 0; state.animation_step = 0;
return zmk_rgb_underglow_save_state(); 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() { int zmk_rgb_underglow_toggle() {
return state.on ? zmk_rgb_underglow_off() : zmk_rgb_underglow_on(); return state.on ? zmk_rgb_underglow_off() : zmk_rgb_underglow_on();
} }

Loading…
Cancel
Save