|
|
@ -52,9 +52,7 @@ struct led_rgb pixels[STRIP_NUM_PIXELS]; |
|
|
|
struct rgb_underglow_state state; |
|
|
|
struct rgb_underglow_state state; |
|
|
|
|
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_SETTINGS) |
|
|
|
#if IS_ENABLED(CONFIG_SETTINGS) |
|
|
|
static int rgb_settings_set(const char *name, size_t len, |
|
|
|
static int rgb_settings_set(const char *name, size_t len, settings_read_cb read_cb, void *cb_arg) { |
|
|
|
settings_read_cb read_cb, void *cb_arg) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const char *next; |
|
|
|
const char *next; |
|
|
|
int rc; |
|
|
|
int rc; |
|
|
|
|
|
|
|
|
|
|
@ -74,14 +72,10 @@ static int rgb_settings_set(const char *name, size_t len, |
|
|
|
return -ENOENT; |
|
|
|
return -ENOENT; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
struct settings_handler rgb_conf = { |
|
|
|
struct settings_handler rgb_conf = {.name = "rgb/underglow", .h_set = rgb_settings_set}; |
|
|
|
.name = "rgb/underglow", |
|
|
|
|
|
|
|
.h_set = rgb_settings_set |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
static struct led_rgb hsb_to_rgb(struct led_hsb hsb) |
|
|
|
static struct led_rgb hsb_to_rgb(struct led_hsb hsb) { |
|
|
|
{ |
|
|
|
|
|
|
|
double r, g, b; |
|
|
|
double r, g, b; |
|
|
|
|
|
|
|
|
|
|
|
u8_t i = hsb.h / 60; |
|
|
|
u8_t i = hsb.h / 60; |
|
|
@ -130,20 +124,16 @@ static struct led_rgb hsb_to_rgb(struct led_hsb hsb) |
|
|
|
return rgb; |
|
|
|
return rgb; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void zmk_rgb_underglow_off() |
|
|
|
static void zmk_rgb_underglow_off() { |
|
|
|
{ |
|
|
|
for (int i = 0; i < STRIP_NUM_PIXELS; i++) { |
|
|
|
for (int i=0; i<STRIP_NUM_PIXELS; i++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
pixels[i] = (struct led_rgb){r : 0, g : 0, b : 0}; |
|
|
|
pixels[i] = (struct led_rgb){r : 0, g : 0, b : 0}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
led_strip_update_rgb(led_strip, pixels, STRIP_NUM_PIXELS); |
|
|
|
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; |
|
|
|
int sat = state.saturation; |
|
|
|
int sat = state.saturation; |
|
|
|
int brt = state.brightness; |
|
|
|
int brt = state.brightness; |
|
|
@ -223,10 +213,8 @@ static void zmk_rgb_underglow_tick(struct k_work *work) { |
|
|
|
|
|
|
|
|
|
|
|
K_WORK_DEFINE(underglow_work, zmk_rgb_underglow_tick); |
|
|
|
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(); |
|
|
|
zmk_rgb_underglow_off(); |
|
|
|
|
|
|
|
|
|
|
|
k_timer_stop(timer); |
|
|
|
k_timer_stop(timer); |
|
|
@ -267,8 +255,7 @@ static int zmk_rgb_underglow_init(struct device *_arg) { |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int zmk_rgb_underglow_save_state() |
|
|
|
int zmk_rgb_underglow_save_state() { |
|
|
|
{ |
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_SETTINGS) |
|
|
|
#if IS_ENABLED(CONFIG_SETTINGS) |
|
|
|
return settings_save_one("rgb/underglow/state", &state, sizeof(state)); |
|
|
|
return settings_save_one("rgb/underglow/state", &state, sizeof(state)); |
|
|
|
#else |
|
|
|
#else |
|
|
@ -276,9 +263,9 @@ int zmk_rgb_underglow_save_state() |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int zmk_rgb_underglow_cycle_effect(int direction) |
|
|
|
int zmk_rgb_underglow_cycle_effect(int direction) { |
|
|
|
{ |
|
|
|
if (!led_strip) |
|
|
|
if (!led_strip) return -ENODEV; |
|
|
|
return -ENODEV; |
|
|
|
|
|
|
|
|
|
|
|
if (state.current_effect == 0 && direction < 0) { |
|
|
|
if (state.current_effect == 0 && direction < 0) { |
|
|
|
state.current_effect = UNDERGLOW_EFFECT_NUMBER - 1; |
|
|
|
state.current_effect = UNDERGLOW_EFFECT_NUMBER - 1; |
|
|
|