|
|
@ -105,14 +105,6 @@ static struct led_rgb hsb_to_rgb(struct led_hsb hsb) { |
|
|
|
return rgb; |
|
|
|
return rgb; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void zmk_rgb_underglow_off() { |
|
|
|
|
|
|
|
for (int i = 0; i < STRIP_NUM_PIXELS; i++) { |
|
|
|
|
|
|
|
pixels[i] = (struct led_rgb){r : 0, g : 0, b : 0}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
led_strip_update_rgb(led_strip, pixels, STRIP_NUM_PIXELS); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void zmk_rgb_underglow_effect_solid() { |
|
|
|
static void zmk_rgb_underglow_effect_solid() { |
|
|
|
for (int i = 0; i < STRIP_NUM_PIXELS; i++) { |
|
|
|
for (int i = 0; i < STRIP_NUM_PIXELS; i++) { |
|
|
|
int hue = state.hue; |
|
|
|
int hue = state.hue; |
|
|
@ -196,10 +188,6 @@ K_WORK_DEFINE(underglow_work, zmk_rgb_underglow_tick); |
|
|
|
|
|
|
|
|
|
|
|
static void zmk_rgb_underglow_tick_handler(struct k_timer *timer) { |
|
|
|
static void zmk_rgb_underglow_tick_handler(struct k_timer *timer) { |
|
|
|
if (!state.on) { |
|
|
|
if (!state.on) { |
|
|
|
zmk_rgb_underglow_off(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
k_timer_stop(timer); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -292,60 +280,83 @@ int zmk_rgb_underglow_save_state() { |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int zmk_rgb_underglow_cycle_effect(int direction) { |
|
|
|
int zmk_rgb_underglow_get_state(bool *on_off) { |
|
|
|
if (!led_strip) |
|
|
|
if (!led_strip) |
|
|
|
return -ENODEV; |
|
|
|
return -ENODEV; |
|
|
|
|
|
|
|
|
|
|
|
if (state.current_effect == 0 && direction < 0) { |
|
|
|
*on_off = state.on; |
|
|
|
state.current_effect = UNDERGLOW_EFFECT_NUMBER - 1; |
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
state.current_effect += direction; |
|
|
|
int zmk_rgb_underglow_on() { |
|
|
|
|
|
|
|
if (!led_strip) |
|
|
|
|
|
|
|
return -ENODEV; |
|
|
|
|
|
|
|
|
|
|
|
if (state.current_effect >= UNDERGLOW_EFFECT_NUMBER) { |
|
|
|
#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_EXT_POWER) |
|
|
|
state.current_effect = 0; |
|
|
|
if (ext_power != NULL) { |
|
|
|
|
|
|
|
int rc = ext_power_enable(ext_power); |
|
|
|
|
|
|
|
if (rc != 0) { |
|
|
|
|
|
|
|
LOG_ERR("Unable to enable EXT_POWER: %d", rc); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state.on = true; |
|
|
|
state.animation_step = 0; |
|
|
|
state.animation_step = 0; |
|
|
|
|
|
|
|
k_timer_start(&underglow_tick, K_NO_WAIT, K_MSEC(50)); |
|
|
|
|
|
|
|
|
|
|
|
return zmk_rgb_underglow_save_state(); |
|
|
|
return zmk_rgb_underglow_save_state(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int zmk_rgb_underglow_toggle() { |
|
|
|
int zmk_rgb_underglow_off() { |
|
|
|
if (!led_strip) |
|
|
|
if (!led_strip) |
|
|
|
return -ENODEV; |
|
|
|
return -ENODEV; |
|
|
|
|
|
|
|
|
|
|
|
state.on = !state.on; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_EXT_POWER) |
|
|
|
#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_EXT_POWER) |
|
|
|
if (ext_power != NULL) { |
|
|
|
if (ext_power != NULL) { |
|
|
|
int rc; |
|
|
|
int rc = ext_power_disable(ext_power); |
|
|
|
|
|
|
|
|
|
|
|
if (state.on) { |
|
|
|
|
|
|
|
rc = ext_power_enable(ext_power); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
rc = ext_power_disable(ext_power); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (rc != 0) { |
|
|
|
if (rc != 0) { |
|
|
|
LOG_ERR("Unable to toggle EXT_POWER: %d", rc); |
|
|
|
LOG_ERR("Unable to disable EXT_POWER: %d", rc); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
if (state.on) { |
|
|
|
for (int i = 0; i < STRIP_NUM_PIXELS; i++) { |
|
|
|
state.animation_step = 0; |
|
|
|
pixels[i] = (struct led_rgb){r : 0, g : 0, b : 0}; |
|
|
|
k_timer_start(&underglow_tick, K_NO_WAIT, K_MSEC(50)); |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
zmk_rgb_underglow_off(); |
|
|
|
led_strip_update_rgb(led_strip, pixels, STRIP_NUM_PIXELS); |
|
|
|
|
|
|
|
|
|
|
|
k_timer_stop(&underglow_tick); |
|
|
|
k_timer_stop(&underglow_tick); |
|
|
|
|
|
|
|
state.on = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return zmk_rgb_underglow_save_state(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int zmk_rgb_underglow_cycle_effect(int direction) { |
|
|
|
|
|
|
|
if (!led_strip) |
|
|
|
|
|
|
|
return -ENODEV; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (state.current_effect == 0 && direction < 0) { |
|
|
|
|
|
|
|
state.current_effect = UNDERGLOW_EFFECT_NUMBER - 1; |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state.current_effect += direction; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (state.current_effect >= UNDERGLOW_EFFECT_NUMBER) { |
|
|
|
|
|
|
|
state.current_effect = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state.animation_step = 0; |
|
|
|
|
|
|
|
|
|
|
|
return zmk_rgb_underglow_save_state(); |
|
|
|
return zmk_rgb_underglow_save_state(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int zmk_rgb_underglow_toggle() { |
|
|
|
|
|
|
|
return state.on ? zmk_rgb_underglow_off() : zmk_rgb_underglow_on(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int zmk_rgb_underglow_set_hsb(uint16_t hue, uint8_t saturation, uint8_t brightness) { |
|
|
|
int zmk_rgb_underglow_set_hsb(uint16_t hue, uint8_t saturation, uint8_t brightness) { |
|
|
|
if (hue > 360 || saturation > 100 || brightness > 100) { |
|
|
|
if (hue > 360 || saturation > 100 || brightness > 100) { |
|
|
|
return -ENOTSUP; |
|
|
|
return -ENOTSUP; |
|
|
|