underglow-layer: keep RGB asleep on battery update
This commit is contained in:
parent
01f8f363f8
commit
28a1c4697e
4 changed files with 23 additions and 17 deletions
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
struct zmk_underglow_color_changed {
|
struct zmk_underglow_color_changed {
|
||||||
uint32_t layers;
|
uint32_t layers;
|
||||||
|
bool wakeup;
|
||||||
};
|
};
|
||||||
|
|
||||||
ZMK_EVENT_DECLARE(zmk_underglow_color_changed);
|
ZMK_EVENT_DECLARE(zmk_underglow_color_changed);
|
||||||
|
|
|
||||||
|
|
@ -59,8 +59,8 @@ ZMK_LISTENER(behavior_underglow_battery, underglow_battery_listener);
|
||||||
ZMK_SUBSCRIPTION(behavior_underglow_battery, zmk_battery_state_changed);
|
ZMK_SUBSCRIPTION(behavior_underglow_battery, zmk_battery_state_changed);
|
||||||
|
|
||||||
static int underglow_battery_listener(const zmk_event_t *eh) {
|
static int underglow_battery_listener(const zmk_event_t *eh) {
|
||||||
raise_zmk_underglow_color_changed(
|
raise_zmk_underglow_color_changed((struct zmk_underglow_color_changed){
|
||||||
(struct zmk_underglow_color_changed){.layers = underglow_battery_data.layers});
|
.layers = underglow_battery_data.layers, .wakeup = false});
|
||||||
|
|
||||||
return ZMK_EV_EVENT_BUBBLE;
|
return ZMK_EV_EVENT_BUBBLE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,8 @@ static struct underglow_indicators_data underglow_indicators_data = {.indicators
|
||||||
static int underglow_indicators_listener(const zmk_event_t *eh) {
|
static int underglow_indicators_listener(const zmk_event_t *eh) {
|
||||||
const struct zmk_hid_indicators_changed *ev = as_zmk_hid_indicators_changed(eh);
|
const struct zmk_hid_indicators_changed *ev = as_zmk_hid_indicators_changed(eh);
|
||||||
underglow_indicators_data.indicators = ev->indicators;
|
underglow_indicators_data.indicators = ev->indicators;
|
||||||
raise_zmk_underglow_color_changed(
|
raise_zmk_underglow_color_changed((struct zmk_underglow_color_changed){
|
||||||
(struct zmk_underglow_color_changed){.layers = underglow_indicators_data.layers});
|
.layers = underglow_indicators_data.layers, .wakeup = true});
|
||||||
|
|
||||||
return ZMK_EV_EVENT_BUBBLE;
|
return ZMK_EV_EVENT_BUBBLE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||||
|
|
||||||
#if DT_HAS_COMPAT_STATUS_OKAY(zmk_underglow_layer) && IS_ENABLED(CONFIG_EXPERIMENTAL_RGB_LAYER)
|
#if DT_HAS_COMPAT_STATUS_OKAY(zmk_underglow_layer) && IS_ENABLED(CONFIG_EXPERIMENTAL_RGB_LAYER)
|
||||||
#define UNDERGLOW_LAYER_ENABLED 1
|
#define UNDERGLOW_LAYER_ENABLED 1
|
||||||
static void zmk_rgb_underglow_set_layer(uint8_t layer);
|
static void zmk_rgb_underglow_set_layer(uint8_t layer, bool wakeup);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define HUE_MAX 360
|
#define HUE_MAX 360
|
||||||
|
|
@ -518,7 +518,7 @@ static int rgb_settings_set(const char *name, size_t len, settings_read_cb read_
|
||||||
}
|
}
|
||||||
#if IS_ENABLED(UNDERGLOW_LAYER_ENABLED)
|
#if IS_ENABLED(UNDERGLOW_LAYER_ENABLED)
|
||||||
if (state.layer_enabled) {
|
if (state.layer_enabled) {
|
||||||
zmk_rgb_underglow_set_layer(rgb_underglow_top_layer());
|
zmk_rgb_underglow_set_layer(rgb_underglow_top_layer(), true);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -573,7 +573,7 @@ static int zmk_rgb_underglow_init(void) {
|
||||||
}
|
}
|
||||||
#if IS_ENABLED(UNDERGLOW_LAYER_ENABLED)
|
#if IS_ENABLED(UNDERGLOW_LAYER_ENABLED)
|
||||||
if (state.layer_enabled) {
|
if (state.layer_enabled) {
|
||||||
zmk_rgb_underglow_set_layer(rgb_underglow_top_layer());
|
zmk_rgb_underglow_set_layer(rgb_underglow_top_layer(), true);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -721,7 +721,7 @@ static struct led_rgb hex_to_rgb(uint8_t r, uint8_t g, uint8_t b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int zmk_rgb_underglow_apply_rgbmap(const struct zmk_behavior_binding *bindings,
|
static int zmk_rgb_underglow_apply_rgbmap(const struct zmk_behavior_binding *bindings,
|
||||||
size_t rgbmap_len) {
|
size_t rgbmap_len, uint8_t layer) {
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
for (int i = 0; i < STRIP_NUM_PIXELS; i++) {
|
for (int i = 0; i < STRIP_NUM_PIXELS; i++) {
|
||||||
uint8_t midx = rgb_pixel_lookup(i);
|
uint8_t midx = rgb_pixel_lookup(i);
|
||||||
|
|
@ -739,8 +739,8 @@ static int zmk_rgb_underglow_apply_rgbmap(const struct zmk_behavior_binding *bin
|
||||||
if (api->binding_pressed == NULL) {
|
if (api->binding_pressed == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
struct zmk_behavior_binding_event event = {.position = midx,
|
struct zmk_behavior_binding_event event = {
|
||||||
.timestamp = k_uptime_get()};
|
.position = midx, .layer = layer, .timestamp = k_uptime_get()};
|
||||||
|
|
||||||
int color = api->binding_pressed((struct zmk_behavior_binding *)&bindings[midx], event);
|
int color = api->binding_pressed((struct zmk_behavior_binding *)&bindings[midx], event);
|
||||||
|
|
||||||
|
|
@ -756,15 +756,20 @@ static int zmk_rgb_underglow_apply_rgbmap(const struct zmk_behavior_binding *bin
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void zmk_rgb_underglow_set_layer(uint8_t layer) {
|
static void zmk_rgb_underglow_set_layer(uint8_t layer, bool wakeup) {
|
||||||
LOG_DBG("state.layer: %d state.on: %d", state.layer_enabled, state.on);
|
LOG_DBG("state.layer: %d state.on: %d", state.layer_enabled, state.on);
|
||||||
if (!state.layer_enabled)
|
if (!state.layer_enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const struct zmk_behavior_binding *rgbmap = rgb_underglow_get_bindings(layer);
|
const struct zmk_behavior_binding *rgbmap = rgb_underglow_get_bindings(layer);
|
||||||
if (rgbmap != NULL && zmk_rgb_underglow_apply_rgbmap(rgbmap, ZMK_KEYMAP_LEN)) {
|
if (rgbmap != NULL && zmk_rgb_underglow_apply_rgbmap(rgbmap, ZMK_KEYMAP_LEN, layer)) {
|
||||||
if (!state.on)
|
if (!state.on) {
|
||||||
|
if (!wakeup) {
|
||||||
|
LOG_DBG("rgb off and no wakeup, abort refresh");
|
||||||
|
return;
|
||||||
|
}
|
||||||
zmk_rgb_underglow_transient_on();
|
zmk_rgb_underglow_transient_on();
|
||||||
|
}
|
||||||
k_timer_stop(&underglow_tick);
|
k_timer_stop(&underglow_tick);
|
||||||
state.animation_step = 0;
|
state.animation_step = 0;
|
||||||
int fade_delay = zmk_rgbmap_fade_delay(layer);
|
int fade_delay = zmk_rgbmap_fade_delay(layer);
|
||||||
|
|
@ -930,7 +935,7 @@ static int rgb_underglow_auto_state(bool target_wake_state) {
|
||||||
if (sleep_state.is_awake) {
|
if (sleep_state.is_awake) {
|
||||||
#if IS_ENABLED(UNDERGLOW_LAYER_ENABLED)
|
#if IS_ENABLED(UNDERGLOW_LAYER_ENABLED)
|
||||||
if (state.layer_enabled) {
|
if (state.layer_enabled) {
|
||||||
zmk_rgb_underglow_set_layer(rgb_underglow_top_layer());
|
zmk_rgb_underglow_set_layer(rgb_underglow_top_layer(), true);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -963,15 +968,15 @@ static int rgb_underglow_event_listener(const zmk_event_t *eh) {
|
||||||
#endif
|
#endif
|
||||||
uint8_t layer = rgb_underglow_top_layer();
|
uint8_t layer = rgb_underglow_top_layer();
|
||||||
LOG_DBG("top layer: %d", layer);
|
LOG_DBG("top layer: %d", layer);
|
||||||
zmk_rgb_underglow_set_layer(layer);
|
zmk_rgb_underglow_set_layer(layer, true);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (as_zmk_underglow_color_changed(eh)) {
|
if (as_zmk_underglow_color_changed(eh)) {
|
||||||
const struct zmk_underglow_color_changed *ev = as_zmk_underglow_color_changed(eh);
|
const struct zmk_underglow_color_changed *ev = as_zmk_underglow_color_changed(eh);
|
||||||
LOG_DBG("refresh layer %d", ev->layers);
|
|
||||||
uint8_t layer = rgb_underglow_top_layer();
|
uint8_t layer = rgb_underglow_top_layer();
|
||||||
|
LOG_DBG("refresh layers %d, current: %d, wakeup: %d", ev->layers, layer, ev->wakeup);
|
||||||
if ((ev->layers & (BIT(layer))) == BIT(layer)) {
|
if ((ev->layers & (BIT(layer))) == BIT(layer)) {
|
||||||
zmk_rgb_underglow_set_layer(rgb_underglow_top_layer());
|
zmk_rgb_underglow_set_layer(rgb_underglow_top_layer(), ev->wakeup);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue