From 7d9b92bef4922e53616e941e12e060efbc56856c Mon Sep 17 00:00:00 2001 From: Daniel Kampert Date: Sun, 4 Aug 2024 15:28:39 +0200 Subject: [PATCH] Add option for relative battery scale and set limit for battery arc --- app/prj.conf | 9 ++---- app/src/applications/settings/settings_app.c | 30 +++++++++++++++++++ app/src/applications/settings/settings_ui.c | 6 +++- .../0_digital/zsw_watchface_digital_ui.c | 21 +++++++++++-- app/src/zsw_settings.h | 1 + 5 files changed, 57 insertions(+), 10 deletions(-) diff --git a/app/prj.conf b/app/prj.conf index 47a4ed9b..08977af3 100644 --- a/app/prj.conf +++ b/app/prj.conf @@ -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 @@ -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 @@ -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 \ No newline at end of file diff --git a/app/src/applications/settings/settings_app.c b/app/src/applications/settings/settings_app.c index 0e59695d..3cd5a822 100644 --- a/app/src/applications/settings/settings_app.c +++ b/app/src/applications/settings/settings_app.c @@ -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); @@ -62,6 +63,7 @@ static setting_app_t settings_app = { .ble_aoa_enabled = false, .ble_aoa_tx_interval = 100, .watchface = { + .relative_battery = false, .animations_on = false, .watchface_index = 0, .smooth_second_hand = false @@ -232,6 +234,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[] = { @@ -302,6 +315,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; @@ -434,6 +453,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; diff --git a/app/src/applications/settings/settings_ui.c b/app/src/applications/settings/settings_ui.c index d0a51c8b..e9e69354 100644 --- a/app/src/applications/settings/settings_ui.c +++ b/app/src/applications/settings/settings_ui.c @@ -176,7 +176,6 @@ 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); @@ -184,6 +183,11 @@ void lv_settings_create(lv_obj_t *root, lv_settings_page_t *pages, uint8_t num_p 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); diff --git a/app/src/ui/watchfaces/0_digital/zsw_watchface_digital_ui.c b/app/src/ui/watchfaces/0_digital/zsw_watchface_digital_ui.c index 98f852bb..b64d408d 100644 --- a/app/src/ui/watchfaces/0_digital/zsw_watchface_digital_ui.c +++ b/app/src/ui/watchfaces/0_digital/zsw_watchface_digital_ui.c @@ -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); @@ -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); @@ -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) diff --git a/app/src/zsw_settings.h b/app/src/zsw_settings.h index 842dfaff..95cf339d 100644 --- a/app/src/zsw_settings.h +++ b/app/src/zsw_settings.h @@ -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) \ No newline at end of file