This commit is contained in:
ReFil 2024-09-01 21:31:41 +08:00 committed by GitHub
commit 6e9e021009
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 1 deletions

View file

@ -326,7 +326,7 @@ config ZMK_RGB_UNDERGLOW_SPD_START
config ZMK_RGB_UNDERGLOW_EFF_START config ZMK_RGB_UNDERGLOW_EFF_START
int "RGB underglow start effect int value related to the effect enum list" int "RGB underglow start effect int value related to the effect enum list"
range 0 3 range 0 4
default 0 default 0
config ZMK_RGB_UNDERGLOW_ON_START config ZMK_RGB_UNDERGLOW_ON_START

View file

@ -21,6 +21,7 @@
#include <zmk/activity.h> #include <zmk/activity.h>
#include <zmk/usb.h> #include <zmk/usb.h>
#include <zmk/battery.h>
#include <zmk/event_manager.h> #include <zmk/event_manager.h>
#include <zmk/events/activity_state_changed.h> #include <zmk/events/activity_state_changed.h>
#include <zmk/events/usb_conn_state_changed.h> #include <zmk/events/usb_conn_state_changed.h>
@ -49,6 +50,7 @@ enum rgb_underglow_effect {
UNDERGLOW_EFFECT_BREATHE, UNDERGLOW_EFFECT_BREATHE,
UNDERGLOW_EFFECT_SPECTRUM, UNDERGLOW_EFFECT_SPECTRUM,
UNDERGLOW_EFFECT_SWIRL, UNDERGLOW_EFFECT_SWIRL,
UNDERGLOW_EFFECT_BATTERY,
UNDERGLOW_EFFECT_NUMBER // Used to track number of underglow effects 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; 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) { static void zmk_rgb_underglow_tick(struct k_work *work) {
switch (state.current_effect) { switch (state.current_effect) {
case UNDERGLOW_EFFECT_SOLID: case UNDERGLOW_EFFECT_SOLID:
@ -189,6 +207,9 @@ static void zmk_rgb_underglow_tick(struct k_work *work) {
case UNDERGLOW_EFFECT_SWIRL: case UNDERGLOW_EFFECT_SWIRL:
zmk_rgb_underglow_effect_swirl(); zmk_rgb_underglow_effect_swirl();
break; break;
case UNDERGLOW_EFFECT_BATTERY:
zmk_rgb_underglow_effect_battery();
break;
} }
int err = led_strip_update_rgb(led_strip, pixels, STRIP_NUM_PIXELS); int err = led_strip_update_rgb(led_strip, pixels, STRIP_NUM_PIXELS);