diff --git a/app/src/applications/settings/settings_app.c b/app/src/applications/settings/settings_app.c index 161d3573..99c45e4a 100644 --- a/app/src/applications/settings/settings_app.c +++ b/app/src/applications/settings/settings_app.c @@ -10,6 +10,7 @@ #include "sensors/zsw_imu.h" #include "drivers/zsw_display_control.h" #include "managers/zsw_app_manager.h" +#include "zsw_settings.h" static void settings_app_start(lv_obj_t *root, lv_group_t *group); static void settings_app_stop(void); @@ -163,7 +164,7 @@ static void on_brightness_changed(lv_setting_value_t value, bool final) // Slider have values 0-10 hence multiply with 10 to get brightness in percent zsw_display_control_set_brightness(value.item.slider * 10); value.item.slider *= 10; - settings_save_one("settings/brightness", &value.item.slider, sizeof(value.item.slider)); + settings_save_one(ZSW_SETTINGS_BRIGHTNESS, &value.item.slider, sizeof(value.item.slider)); } static void on_display_on_changed(lv_setting_value_t value, bool final) @@ -207,12 +208,6 @@ static void on_reset_steps_changed(lv_setting_value_t value, bool final) } } -static int setting_on_commit(void) -{ - printk("Settings loaded\n"); - return 0; -} - static int settings_load_cb(const char *name, size_t len, settings_read_cb read_cb, void *cb_arg) { @@ -220,19 +215,29 @@ static int settings_load_cb(const char *name, size_t len, int rc; int32_t bri; - if (settings_name_steq(name, "brightness", &next) && !next) { + if (settings_name_steq(name, ZSW_SETTINGS_KEY_BRIGHTNESS, &next) && !next) { if (len != sizeof(bri)) { return -EINVAL; } rc = read_cb(cb_arg, &bri, sizeof(bri)); - printk("Read br: %d\n", bri); general_page_items[0].item.slider.inital_val = bri / 10; zsw_display_control_set_brightness(bri); if (rc >= 0) { return 0; } + return rc; + } if (settings_name_steq(name, ZSW_SETTINGS_KEY_VIBRATION, &next) && !next) { + if (len != sizeof(bri)) { + return -EINVAL; + } + rc = read_cb(cb_arg, &bri, sizeof(bri)); + general_page_items[0].item.slider.inital_val = bri / 10; + zsw_display_control_set_brightness(bri); + if (rc >= 0) { + return 0; + } return rc; } @@ -247,7 +252,7 @@ static int settings_app_add(void) return 0; } -SETTINGS_STATIC_HANDLER_DEFINE(my_name, "settings", NULL, - settings_load_cb, setting_on_commit, NULL); +SETTINGS_STATIC_HANDLER_DEFINE(settings_app_handler, ZSW_SETTINGS_PATH, NULL, + settings_load_cb, NULL, NULL); SYS_INIT(settings_app_add, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); diff --git a/app/src/zsw_settings.h b/app/src/zsw_settings.h new file mode 100644 index 00000000..0cb5ea34 --- /dev/null +++ b/app/src/zsw_settings.h @@ -0,0 +1,11 @@ +#pragma once + +#define ZSW_SETTINGS_NAME(name, key) (name "/" key) + +#define ZSW_SETTINGS_PATH "settings" + +#define ZSW_SETTINGS_KEY_BRIGHTNESS "bri" +#define ZSW_SETTINGS_BRIGHTNESS (ZSW_SETTINGS_PATH "/" ZSW_SETTINGS_KEY_BRIGHTNESS) + +#define ZSW_SETTINGS_KEY_VIBRATION_ON_PRESS "vib" +#define ZSW_SETTINGS_VIBRATE_ON_PRESS (ZSW_SETTINGS_PATH "/" ZSW_SETTINGS_KEY_VIBRATION)