From 93bd321460cf124bb7d4732606294a9184c60ca3 Mon Sep 17 00:00:00 2001 From: ReFil <31960031+ReFil@users.noreply.github.com> Date: Tue, 13 Sep 2022 14:54:53 +0100 Subject: [PATCH 1/3] feat(Underglow): Momentary effect selection Adds the ability to have an RGB effect select whilst held down and revert when release --- app/include/dt-bindings/zmk/rgb.h | 5 ++++- app/src/behaviors/behavior_rgb_underglow.c | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/include/dt-bindings/zmk/rgb.h b/app/include/dt-bindings/zmk/rgb.h index c1a80082..f9ea5f21 100644 --- a/app/include/dt-bindings/zmk/rgb.h +++ b/app/include/dt-bindings/zmk/rgb.h @@ -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 \ No newline at end of file diff --git a/app/src/behaviors/behavior_rgb_underglow.c b/app/src/behaviors/behavior_rgb_underglow.c index a16ee591..774962e0 100644 --- a/app/src/behaviors/behavior_rgb_underglow.c +++ b/app/src/behaviors/behavior_rgb_underglow.c @@ -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; } From b02bcefb8863a023afaed012d5f9700db86a6942 Mon Sep 17 00:00:00 2001 From: ReFil <31960031+ReFil@users.noreply.github.com> Date: Wed, 18 Oct 2023 10:12:38 +0100 Subject: [PATCH 2/3] feat(docs): Document RGB momentary effect selection --- docs/docs/behaviors/underglow.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/docs/behaviors/underglow.md b/docs/docs/behaviors/underglow.md index 490789a7..c3f1d8f9 100644 --- a/docs/docs/behaviors/underglow.md +++ b/docs/docs/behaviors/underglow.md @@ -35,13 +35,15 @@ Here is a table describing the action for each define: | `RGB_SPD` | Decreases the speed of the RGB feature effect's animation | | `RGB_EFF` | Cycles the RGB feature's effect forwards | | `RGB_EFR` | Cycles the RGB feature's effect reverse | +| `RGB_EFS` | Selects a specific RGB effect | +| `RGB_MEFS` | Selects a specific RGB effect whilst held down and reverts when released | | `RGB_COLOR_HSB` | Sets a specific [HSB (HSV)](https://en.wikipedia.org/wiki/HSL_and_HSV) value for the underglow | ## Behavior Binding - Reference: `&rgb_ug` - Parameter #1: The RGB action define, e.g. `RGB_TOG` or `RGB_BRI` -- Parameter #2: Only applies to `RGB_COLOR_HSB` and is the HSB representation of the color to set (see below for an example) +- Parameter #2: Applies to `RGB_EFS` and `RGB_MEFS` (the effect to select) as well as `RGB_COLOR_HSB` (the HSB representation of the color to set). See below for examples. :::note[HSB Values] @@ -61,6 +63,18 @@ They will also override the start values set by [`CONFIG_ZMK_RGB_*_START` settin However the settings will only be saved after [`CONFIG_ZMK_SETTINGS_SAVE_DEBOUNCE`](../config/system.md#general) milliseconds in order to reduce potential wear on the flash memory. ::: +:::note Effect Selection + +When using the `RGB_EFS` or `RGB_MEFS` definitions you must also include a number as an argument in the keymap corresponding to the effect you want to select e.g. `RGB_EFS 0` + +::: + +:::warning + +If the `RGB_MEFS` key is held down for longer than [`CONFIG_ZMK_SETTINGS_SAVE_DEBOUNCE`](../config/system.md#general) milliseconds and the board is reset prior to releasing the key, the temporary effect will have been saved to flash memory and will be the one selected after resetting/power cycling. + +::: + ## Examples 1. Toggle underglow on/off @@ -75,6 +89,12 @@ However the settings will only be saved after [`CONFIG_ZMK_SETTINGS_SAVE_DEBOUNC &rgb_ug RGB_COLOR_HSB(128,100,100) ``` +1. Select a specific RGB effect (Swirl) + + ```dts + &rgb_ug RGB_EFS 3 + ``` + ## Split Keyboards RGB underglow behaviors are global: This means that when triggered, they affect both the central and peripheral side of split keyboards. From d1b98ea809508663a61c722ced50b02e29286aeb Mon Sep 17 00:00:00 2001 From: ReFil <31960031+ReFil@users.noreply.github.com> Date: Thu, 19 Oct 2023 09:42:42 +0100 Subject: [PATCH 3/3] feat(docs): Document and define different RGB effects Co-Authored-By: Cem Aksoylar --- app/include/dt-bindings/zmk/rgb.h | 7 ++++++- docs/docs/behaviors/underglow.md | 11 +++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/include/dt-bindings/zmk/rgb.h b/app/include/dt-bindings/zmk/rgb.h index f9ea5f21..2c1ed34e 100644 --- a/app/include/dt-bindings/zmk/rgb.h +++ b/app/include/dt-bindings/zmk/rgb.h @@ -38,4 +38,9 @@ #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 \ No newline at end of file +#define RGB_COLOR_HSV RGB_COLOR_HSB + +#define RGB_EFF_SOLID 0 +#define RGB_EFF_BREATHE 1 +#define RGB_EFF_SPECTRUM 2 +#define RGB_EFF_SWIRL 3 \ No newline at end of file diff --git a/docs/docs/behaviors/underglow.md b/docs/docs/behaviors/underglow.md index c3f1d8f9..a733eddd 100644 --- a/docs/docs/behaviors/underglow.md +++ b/docs/docs/behaviors/underglow.md @@ -65,7 +65,14 @@ However the settings will only be saved after [`CONFIG_ZMK_SETTINGS_SAVE_DEBOUNC :::note Effect Selection -When using the `RGB_EFS` or `RGB_MEFS` definitions you must also include a number as an argument in the keymap corresponding to the effect you want to select e.g. `RGB_EFS 0` +When using the `RGB_EFS` or `RGB_MEFS` definitions you must also include a parameter corresponding to the effect you want to select, e.g. `&rgb_ug RGB_EFS RGB_EFF_SOLID`. There are currently 4 RGB effects, defined in [`dt-bindings/zmk/rgb.h`](https://github.com/zmkfirmware/zmk/blob/main/app/include/dt-bindings/zmk/rgb.h): + +| Value | Effect | +| ------------------ | ----------------------------------------- | +| `RGB_EFF_SOLID` | Solid color (set by HSB) | +| `RGB_EFF_BREATHE` | Breathe a solid color | +| `RGB_EFF_SPECTRUM` | Cycle all LEDs through the color spectrum | +| `RGB_EFF_SWIRL` | Swirl a rainbow around the LEDs | ::: @@ -92,7 +99,7 @@ If the `RGB_MEFS` key is held down for longer than [`CONFIG_ZMK_SETTINGS_SAVE_DE 1. Select a specific RGB effect (Swirl) ```dts - &rgb_ug RGB_EFS 3 + &rgb_ug RGB_EFS RGB_EFF_SWIRL ``` ## Split Keyboards