Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkra committed Oct 22, 2023
1 parent b283d75 commit 50a2df1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
27 changes: 16 additions & 11 deletions app/src/applications/settings/settings_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -207,32 +208,36 @@ 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)
{
const char *next;
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;
}

Expand All @@ -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);
11 changes: 11 additions & 0 deletions app/src/zsw_settings.h
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 50a2df1

Please sign in to comment.