diff options
| author | Michele Bini <michele.bini@gmail.com> | 2022-04-10 15:12:50 (GMT) |
|---|---|---|
| committer | Michele Bini <michele.bini@gmail.com> | 2022-04-10 15:12:50 (GMT) |
| commit | 9a9a15f00c33f79e1b5fda59cda66ee3f25441b4 (patch) | |
| tree | 20fe38bb528681b6d1ef0a613a924135166e2d80 | |
| parent | dd7e564d2ea745f5907dc6a69966da493ff50cee (diff) | |
battery stats
| -rw-r--r-- | src/displayapp/screens/WatchFaceDigital.cpp | 41 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFaceDigital.h | 5 |
2 files changed, 45 insertions, 1 deletions
diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index cf8f659..0c7c86b 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -44,6 +44,19 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, lv_label_set_text_static(batteryPlug, Symbols::plug); lv_obj_align(batteryPlug, batteryIcon, LV_ALIGN_OUT_LEFT_MID, 0, 0); + batteryPercentLabel = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color( batteryPercentLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); + lv_obj_set_style_local_text_font( batteryPercentLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &neofont1); + lv_label_set_text_static( batteryPercentLabel, battery_percent_label_text); + lv_obj_align( batteryPercentLabel, batteryIcon, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 0); + lv_label_set_align( batteryPercentLabel, LV_LABEL_ALIGN_RIGHT); + + batteryVoltageLabel = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_font( batteryVoltageLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &neofont1); + lv_obj_set_style_local_text_color( batteryVoltageLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); + lv_label_set_text_static( batteryVoltageLabel, battery_voltage_label_text); + lv_obj_align( batteryVoltageLabel, batteryPercentLabel, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 0); + bleIcon = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(bleIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x0082FC)); lv_label_set_text_static(bleIcon, Symbols::bluetooth); @@ -60,7 +73,7 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); label_temp = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_color( label_temp, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x222222)); + lv_obj_set_style_local_text_color( label_temp, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x555555)); lv_label_set_text_fmt(label_temp, "??°C"); lv_obj_align(label_temp, lv_scr_act(), LV_ALIGN_CENTER, 60, -60); @@ -120,6 +133,8 @@ WatchFaceDigital::~WatchFaceDigital() { } void WatchFaceDigital::Refresh() { + bool batteryRefreshed = false; + powerPresent = batteryController.IsPowerPresent(); if (powerPresent.IsUpdated()) { lv_label_set_text_static(batteryPlug, BatteryIcon::GetPlugIcon(powerPresent.Get())); @@ -127,6 +142,7 @@ void WatchFaceDigital::Refresh() { batteryPercentRemaining = batteryController.PercentRemaining(); if (batteryPercentRemaining.IsUpdated()) { + batteryRefreshed = true; auto batteryPercent = batteryPercentRemaining.Get(); if (batteryPercent == 100) { lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN); @@ -198,6 +214,7 @@ void WatchFaceDigital::Refresh() { uint8_t minute = time.minutes().count(); if (displayedHour != hour || displayedMinute != minute) { + refreshBatteryInfo = true; displayedHour = hour; displayedMinute = minute; bool hide_pm = true; @@ -261,4 +278,26 @@ void WatchFaceDigital::Refresh() { lv_obj_realign(stepValue); lv_obj_realign(stepIcon); } + + if (batteryRefreshed || refreshBatteryInfo) { + if (refreshBatteryInfo) { + batteryController.MeasureVoltage(); + refreshBatteryInfo = false; + } + { + auto x = batteryController.Voltage(); + battery_voltage_label_text[3] = '0' + (x%10); x /= 10; + battery_voltage_label_text[2] = '0' + (x%10); x /= 10; + battery_voltage_label_text[1] = '0' + (x%10); x /= 10; + battery_voltage_label_text[0] = '0' + (x%10); + } + lv_label_set_text_static(batteryVoltageLabel, battery_voltage_label_text); + { + uint8_t x = batteryController.PercentRemaining(); + battery_percent_label_text[2] = '0' + (x%10); x /= 10; + battery_percent_label_text[1] = '0' + (x%10); x /= 10; + battery_percent_label_text[0] = x ? '0' + (x%10): ' '; + } + lv_label_set_text_static(batteryPercentLabel, battery_percent_label_text); + } } diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index 0bf5eec..c29033b 100644 --- a/src/displayapp/screens/WatchFaceDigital.h +++ b/src/displayapp/screens/WatchFaceDigital.h @@ -48,10 +48,13 @@ namespace Pinetime { Controllers::DateTime::Months currentMonth = Pinetime::Controllers::DateTime::Months::Unknown; Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown; uint8_t currentDay = 0; + bool refreshBatteryInfo = true; char hhmm_label_text[6] = { '?', '?', ':', '?', '?', 0 }; char seconds_label_text[5] = { ':', '?', '?', '.', 0 }; char deciseconds_label_text[2] = { '?', 0 }; + char battery_percent_label_text[5] = { '?', '?', '?', '%', 0 }; + char battery_voltage_label_text[8] = { '0', '0', '0', '0', ' ', 'm', 'V', 0 }; DirtyValue<uint8_t> batteryPercentRemaining {}; DirtyValue<bool> powerPresent {}; @@ -79,6 +82,8 @@ namespace Pinetime { lv_obj_t* stepIcon; lv_obj_t* stepValue; lv_obj_t* notificationIcon; + lv_obj_t* batteryPercentLabel; + lv_obj_t* batteryVoltageLabel; Controllers::DateTime& dateTimeController; Controllers::Battery& batteryController; |
