feat(Underglow): Momentary effect selection

Adds the ability to have an RGB effect select whilst held down and revert when release
This commit is contained in:
ReFil 2022-09-13 14:54:53 +01:00
parent 7c09eb217e
commit 93bd321460
2 changed files with 11 additions and 1 deletions

View file

@ -18,7 +18,8 @@
#define RGB_EFF_CMD 11
#define RGB_EFR_CMD 12
#define RGB_EFS_CMD 13
#define RGB_COLOR_HSB_CMD 14
#define RGB_MEFS_CMD 14
#define RGB_COLOR_HSB_CMD 15
#define RGB_TOG RGB_TOG_CMD 0
#define RGB_ON RGB_ON_CMD 0
@ -33,6 +34,8 @@
#define RGB_SPD RGB_SPD_CMD 0
#define RGB_EFF RGB_EFF_CMD 0
#define RGB_EFR RGB_EFR_CMD 0
#define RGB_EFS RGB_EFS_CMD
#define RGB_MEFS RGB_MEFS_CMD
#define RGB_COLOR_HSB_VAL(h, s, v) (((h) << 16) + ((s) << 8) + (v))
#define RGB_COLOR_HSB(h, s, v) RGB_COLOR_HSB_CMD##(RGB_COLOR_HSB_VAL(h, s, v))
#define RGB_COLOR_HSV RGB_COLOR_HSB

View file

@ -18,6 +18,8 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT)
static uint8_t old_effect;
static int behavior_rgb_underglow_init(const struct device *dev) { return 0; }
static int
@ -123,6 +125,9 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
return zmk_rgb_underglow_change_spd(-1);
case RGB_EFS_CMD:
return zmk_rgb_underglow_select_effect(binding->param2);
case RGB_MEFS_CMD:
old_effect = zmk_rgb_underglow_calc_effect(0);
return zmk_rgb_underglow_select_effect(binding->param2);
case RGB_EFF_CMD:
return zmk_rgb_underglow_cycle_effect(1);
case RGB_EFR_CMD:
@ -138,6 +143,8 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
if (binding->param1 == RGB_MEFS_CMD)
return zmk_rgb_underglow_select_effect(old_effect);
return ZMK_BEHAVIOR_OPAQUE;
}