diff --git a/app/Kconfig b/app/Kconfig index 108fcbe7096..66662b1112d 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -346,7 +346,7 @@ config ZMK_RGB_UNDERGLOW_SPD_START config ZMK_RGB_UNDERGLOW_EFF_START int "RGB underglow start effect int value related to the effect enum list" - range 0 3 + range 0 4 default 0 config ZMK_RGB_UNDERGLOW_ON_START diff --git a/app/src/rgb_underglow.c b/app/src/rgb_underglow.c index 3453fb44e0d..111e0a42278 100644 --- a/app/src/rgb_underglow.c +++ b/app/src/rgb_underglow.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -49,6 +50,7 @@ enum rgb_underglow_effect { UNDERGLOW_EFFECT_BREATHE, UNDERGLOW_EFFECT_SPECTRUM, UNDERGLOW_EFFECT_SWIRL, + UNDERGLOW_EFFECT_BATTERY, UNDERGLOW_EFFECT_NUMBER // Used to track number of underglow effects }; @@ -175,6 +177,22 @@ static void zmk_rgb_underglow_effect_swirl(void) { state.animation_step = state.animation_step % HUE_MAX; } +static void zmk_rgb_underglow_effect_battery(void) { + struct zmk_led_hsb hsb = state.color; + + // Only set lights if battery information available, otherwise set to blue + if (DT_HAS_CHOSEN(zmk_battery)) { + uint8_t soc = zmk_battery_state_of_charge(); + hsb.h = (soc * 1.2); + } else { + hsb.h = 240; + } + hsb.s = SAT_MAX; + for (int i = 0; i < STRIP_NUM_PIXELS; i++) { + pixels[i] = hsb_to_rgb(hsb_scale_min_max(hsb)); + } +} + static void zmk_rgb_underglow_tick(struct k_work *work) { switch (state.current_effect) { case UNDERGLOW_EFFECT_SOLID: @@ -189,6 +207,9 @@ static void zmk_rgb_underglow_tick(struct k_work *work) { case UNDERGLOW_EFFECT_SWIRL: zmk_rgb_underglow_effect_swirl(); break; + case UNDERGLOW_EFFECT_BATTERY: + zmk_rgb_underglow_effect_battery(); + break; } int err = led_strip_update_rgb(led_strip, pixels, STRIP_NUM_PIXELS);