feat(underglow): battery state of charge (SoC) animation
This change adds an underglow effect that visualizes the state of charge if a battery is available. If no battery is install, blue will be sent to the LEDs. Otherwise the SoC is used to calculate a color with a green and red portion (green = full, red = empty).
This commit is contained in:
parent
2a9ab828b5
commit
22f87d34de
1 changed files with 24 additions and 0 deletions
|
@ -12,6 +12,8 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <bluetooth/services/bas.h>
|
||||||
|
|
||||||
#include <logging/log.h>
|
#include <logging/log.h>
|
||||||
|
|
||||||
#include <drivers/led_strip.h>
|
#include <drivers/led_strip.h>
|
||||||
|
@ -33,6 +35,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_SOC,
|
||||||
UNDERGLOW_EFFECT_NUMBER // Used to track number of underglow effects
|
UNDERGLOW_EFFECT_NUMBER // Used to track number of underglow effects
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -148,6 +151,24 @@ static void zmk_rgb_underglow_effect_swirl() {
|
||||||
state.animation_step = state.animation_step % HUE_MAX;
|
state.animation_step = state.animation_step % HUE_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void zmk_rgb_underglow_battery_soc() {
|
||||||
|
double r = 0.0f, g = 0.0f, b = 0.0f;
|
||||||
|
|
||||||
|
if (device_get_binding("BATTERY") == NULL) {
|
||||||
|
b = 1.0f;
|
||||||
|
} else {
|
||||||
|
uint8_t soc = bt_bas_get_battery_level();
|
||||||
|
|
||||||
|
g = soc / 100.0;
|
||||||
|
r = (100 - soc) / 100.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct led_rgb rgb = {r : r * 255, g : g * 255, b : b * 255};
|
||||||
|
for (int i = 0; i < STRIP_NUM_PIXELS; i++) {
|
||||||
|
pixels[i] = rgb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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:
|
||||||
|
@ -162,6 +183,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_SOC:
|
||||||
|
zmk_rgb_underglow_battery_soc();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
led_strip_update_rgb(led_strip, pixels, STRIP_NUM_PIXELS);
|
led_strip_update_rgb(led_strip, pixels, STRIP_NUM_PIXELS);
|
||||||
|
|
Loading…
Add table
Reference in a new issue