Skip to content

Commit

Permalink
feat(Underglow): Battery state of charge effect
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFil committed Mar 21, 2024
1 parent 931a36f commit a82b84d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,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
Expand Down
21 changes: 21 additions & 0 deletions app/src/rgb_underglow.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <zmk/activity.h>
#include <zmk/usb.h>
#include <zmk/battery.h>
#include <zmk/event_manager.h>
#include <zmk/events/activity_state_changed.h>
#include <zmk/events/usb_conn_state_changed.h>
Expand Down Expand Up @@ -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
};

Expand Down Expand Up @@ -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() {
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:
Expand All @@ -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);
Expand Down

0 comments on commit a82b84d

Please sign in to comment.