Skip to content

Commit

Permalink
Add option for relative battery scale and set limit for battery arc
Browse files Browse the repository at this point in the history
  • Loading branch information
Kampi committed Aug 5, 2024
1 parent 7094253 commit 4bc9f09
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 10 deletions.
9 changes: 2 additions & 7 deletions app/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ CONFIG_ZBUS=y
CONFIG_ZBUS_RUNTIME_OBSERVERS=y
CONFIG_ZBUS_CHANNEL_NAME=y
CONFIG_ZBUS_OBSERVER_NAME=y
CONFIG_ZBUS_CHANNELS_SYS_INIT_PRIORITY=1

# Choose one or many of below
CONFIG_WATCHFACE_ANALOG=n
Expand All @@ -191,10 +192,6 @@ CONFIG_INPUT_MODIFIED_CST816S=y
CONFIG_BMI270_PLUS=y
CONFIG_BMI270_PLUS_TRIGGER_GLOBAL_THREAD=y

# Uncomment for BME688 IAQ using Bosch BSEC
#CONFIG_BME680=n
#CONFIG_EXTERNAL_USE_BOSCH_BSEC=y

CONFIG_RESET_ON_FATAL_ERROR=y

CONFIG_DEBUG_COREDUMP=y
Expand All @@ -203,6 +200,4 @@ CONFIG_RETENTION_MUTEX_FORCE_DISABLE=y
CONFIG_RETAINED_MEM_MUTEX_FORCE_DISABLE=y
CONFIG_RETENTION_BUFFER_SIZE=256

CONFIG_ZBUS_CHANNELS_SYS_INIT_PRIORITY=1

CONFIG_CJSON_LIB=y
CONFIG_CJSON_LIB=y
34 changes: 34 additions & 0 deletions app/src/applications/settings/settings_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static void on_close_settings(void);
static void on_brightness_changed(lv_setting_value_t value, bool final);
static void on_display_on_changed(lv_setting_value_t value, bool final);
static void on_display_vib_press_changed(lv_setting_value_t value, bool final);
static void on_relative_battery_press_changed(lv_setting_value_t value, bool final);
static void on_aoa_enable_changed(lv_setting_value_t value, bool final);
static void on_aoa_interval_changed(lv_setting_value_t value, bool final);
static void on_pairing_enable_changed(lv_setting_value_t value, bool final);
Expand Down Expand Up @@ -62,6 +63,11 @@ static setting_app_t settings_app = {
.ble_aoa_enabled = false,
.ble_aoa_tx_interval = 100,
.watchface = {
#if DEBUG
.relative_battery = false,
#else
.relative_battery = true,
#endif
.animations_on = false,
.watchface_index = 0,
.smooth_second_hand = false
Expand Down Expand Up @@ -232,6 +238,17 @@ static lv_settings_item_t ui_page_items[] = {
}
}
},
{
.type = LV_SETTINGS_TYPE_SWITCH,
.icon = LV_SYMBOL_BATTERY_3,
.change_callback = on_relative_battery_press_changed,
.item = {
.sw = {
.name = "Battery percent",
.inital_val = &settings_app.watchface.relative_battery,
}
}
},
};

static lv_settings_page_t settings_menu[] = {
Expand Down Expand Up @@ -302,6 +319,12 @@ static void on_display_vib_press_changed(lv_setting_value_t value, bool final)
sizeof(settings_app.vibration_on_click));
}

static void on_relative_battery_press_changed(lv_setting_value_t value, bool final)
{
settings_app.watchface.relative_battery = value.item.sw;
settings_save_one(ZSW_SETTINGS_WATCHFACE, &settings_app.watchface, sizeof(settings_app.watchface));
}

static void on_aoa_enable_changed(lv_setting_value_t value, bool final)
{
settings_app.ble_aoa_enabled = value.item.sw;
Expand Down Expand Up @@ -434,6 +457,17 @@ static int settings_load_cb(const char *name, size_t len,
}
return rc;
}
if (settings_name_steq(name, ZSW_SETTINGS_WATCHFACE, &next) && !next) {
if (len != sizeof(settings_app.watchface)) {
return -EINVAL;
}

rc = read_cb(cb_arg, &settings_app.watchface, sizeof(settings_app.watchface));
if (rc >= 0) {
return 0;
}
return rc;
}
if (settings_name_steq(name, ZSW_SETTINGS_KEY_DISPLAY_ALWAYS_ON, &next) && !next) {
if (len != sizeof(settings_app.display_always_on)) {
return -EINVAL;
Expand Down
6 changes: 5 additions & 1 deletion app/src/applications/settings/settings_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,18 @@ void lv_settings_create(lv_obj_t *root, lv_settings_page_t *pages, uint8_t num_p

// Draw menu screen
_menu = lv_menu_create(root);
lv_menu_set_mode_root_back_btn(_menu, LV_MENU_ROOT_BACK_BTN_ENABLED);
lv_obj_add_event_cb(_menu, close_button_pressed, LV_EVENT_CLICKED, _menu);
lv_obj_set_size(_menu, LV_PCT(100), LV_PCT(90));
lv_obj_set_pos(_menu, 0, 0);
lv_obj_set_style_pad_top(_menu, 25, LV_PART_MAIN);
lv_obj_set_style_pad_left(_menu, 20, LV_PART_MAIN);
lv_obj_set_style_bg_opa(_menu, LV_OPA_TRANSP, LV_PART_MAIN);

// Disable the back button
lv_menu_set_mode_root_back_btn(_menu, LV_MENU_ROOT_BACK_BTN_DISABLED);
lv_obj_t *header = lv_menu_get_main_header(_menu);
lv_obj_set_size(header, 0, 0);

// Main page
_mainPage = lv_menu_page_create(_menu, NULL);

Expand Down
21 changes: 19 additions & 2 deletions app/src/ui/watchfaces/0_digital/zsw_watchface_digital_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,14 @@ static int last_second = -1;
static int last_date = -1;
static int last_day_of_week = -1;

static bool use_relative_battery = false;

static watchface_app_evt_listener ui_evt_cb;

static void watchface_show(lv_obj_t *parent, watchface_app_evt_listener evt_cb, zsw_settings_watchface_t *settings)
{
use_relative_battery = settings->relative_battery;

ui_evt_cb = evt_cb;
lv_obj_clear_flag(parent, LV_OBJ_FLAG_SCROLLABLE);
root_page = lv_obj_create(parent);
Expand Down Expand Up @@ -312,6 +316,13 @@ static void watchface_show(lv_obj_t *parent, watchface_app_evt_listener evt_cb,
LV_OBJ_FLAG_SCROLL_CHAIN | LV_OBJ_FLAG_CLICKABLE);
lv_obj_set_style_arc_width(ui_battery_arc, 3, LV_PART_MAIN | LV_STATE_DEFAULT);

if (use_relative_battery) {
lv_arc_set_range(ui_battery_arc, 0, 100);
} else {

lv_arc_set_range(ui_battery_arc, 3500, 4200);
}

lv_obj_set_style_arc_color(ui_battery_arc, lv_color_hex(0xFFB140), LV_PART_INDICATOR | LV_STATE_DEFAULT);
lv_obj_set_style_arc_opa(ui_battery_arc, 255, LV_PART_INDICATOR | LV_STATE_DEFAULT);
lv_obj_set_style_arc_width(ui_battery_arc, 3, LV_PART_INDICATOR | LV_STATE_DEFAULT);
Expand Down Expand Up @@ -484,8 +495,14 @@ static void watchface_set_battery_percent(int32_t percent, int32_t battery)
if (!root_page) {
return;
}
lv_arc_set_value(ui_battery_arc, percent);
lv_label_set_text_fmt(ui_battery_percent_label, "%d", battery);

if (use_relative_battery) {
lv_arc_set_value(ui_battery_arc, percent);
lv_label_set_text_fmt(ui_battery_percent_label, "%d%%", percent);
} else {
lv_arc_set_value(ui_battery_arc, battery);
lv_label_set_text_fmt(ui_battery_percent_label, "%d", battery);
}
}

static void watchface_set_hrm(int32_t bpm, int32_t oxygen)
Expand Down
1 change: 1 addition & 0 deletions app/src/zsw_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ typedef struct {
bool animations_on;
uint8_t watchface_index;
bool smooth_second_hand;
bool relative_battery;
} zsw_settings_watchface_t;
#define ZSW_SETTINGS_KEY_WATCHFACE "watchface"
#define ZSW_SETTINGS_WATCHFACE (ZSW_SETTINGS_PATH "/" ZSW_SETTINGS_KEY_WATCHFACE)

0 comments on commit 4bc9f09

Please sign in to comment.