Move settings load

This commit is contained in:
Nick 2020-08-23 10:33:19 -05:00
parent 74fd4fc997
commit c5c21022a2
3 changed files with 36 additions and 18 deletions

View file

@ -55,4 +55,5 @@ target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/hog.c)
target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/rgb_underglow.c) target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/rgb_underglow.c)
target_sources(app PRIVATE src/endpoints.c) target_sources(app PRIVATE src/endpoints.c)
target_sources(app PRIVATE src/hid_listener.c) target_sources(app PRIVATE src/hid_listener.c)
target_sources(app PRIVATE src/settings.c)
target_sources(app PRIVATE src/main.c) target_sources(app PRIVATE src/main.c)

View file

@ -15,7 +15,6 @@
#include <logging/log.h> #include <logging/log.h>
#include <drivers/led_strip.h> #include <drivers/led_strip.h>
#include <device.h>
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
@ -106,6 +105,16 @@ 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++)
@ -199,6 +208,15 @@ 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)
{
zmk_rgb_underglow_off();
k_timer_stop(timer);
return;
}
k_work_submit(&underglow_work); k_work_submit(&underglow_work);
} }
@ -221,20 +239,12 @@ static int zmk_rgb_underglow_init(struct device *_arg)
animation_speed: CONFIG_ZMK_RGB_UNDERGLOW_SPD_START, animation_speed: CONFIG_ZMK_RGB_UNDERGLOW_SPD_START,
current_effect: CONFIG_ZMK_RGB_UNDERGLOW_EFF_START, current_effect: CONFIG_ZMK_RGB_UNDERGLOW_EFF_START,
animation_step: 0, animation_step: 0,
#ifdef CONFIG_ZMK_RGB_UNDERGLOW_ON_START on: IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_ON_START)
on: true
#else
on: false
#endif
}; };
settings_subsys_init();
settings_register(&rgb_conf); settings_register(&rgb_conf);
settings_load();
if (state.on) { k_timer_start(&underglow_tick, K_NO_WAIT, K_MSEC(50));
k_timer_start(&underglow_tick, K_NO_WAIT, K_MSEC(50));
}
return 0; return 0;
} }
@ -274,13 +284,7 @@ int zmk_rgb_underglow_toggle()
state.animation_step = 0; state.animation_step = 0;
k_timer_start(&underglow_tick, K_NO_WAIT, K_MSEC(50)); k_timer_start(&underglow_tick, K_NO_WAIT, K_MSEC(50));
} else { } else {
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);
k_timer_stop(&underglow_tick); k_timer_stop(&underglow_tick);
} }

13
app/src/settings.c Normal file
View file

@ -0,0 +1,13 @@
#include <device.h>
#include <init.h>
#include <kernel.h>
#include <settings/settings.h>
static int zmk_settings_init(struct device *_arg)
{
return settings_load();
}
SYS_INIT(zmk_settings_init,
APPLICATION,
CONFIG_APPLICATION_INIT_PRIORITY);