From cb2131ec2cc26a55131192e86287dd6f5fe3e472 Mon Sep 17 00:00:00 2001 From: Diego Miguel Date: Sun, 3 Apr 2022 17:20:25 +0200 Subject: Implement charging battery animation --- src/displayapp/screens/WatchFaceInfineat.cpp | 19 +++++++++++++++---- src/displayapp/screens/WatchFaceInfineat.h | 4 +++- 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'src/displayapp/screens') diff --git a/src/displayapp/screens/WatchFaceInfineat.cpp b/src/displayapp/screens/WatchFaceInfineat.cpp index b9b13a09..c5c18d0d 100644 --- a/src/displayapp/screens/WatchFaceInfineat.cpp +++ b/src/displayapp/screens/WatchFaceInfineat.cpp @@ -145,7 +145,7 @@ WatchFaceInfineat::WatchFaceInfineat(DisplayApp* app, lv_style_set_line_width(&lineBatteryStyle, LV_STATE_DEFAULT, 24); lv_style_set_line_color(&lineBatteryStyle, LV_STATE_DEFAULT, lv_color_hex(infineatColors.orange[settingsController.GetInfineatColorIndex()*nLines + 4])); - lv_style_set_line_opa(&lineBatteryStyle, LV_STATE_DEFAULT, LV_OPA_80); + lv_style_set_line_opa(&lineBatteryStyle, LV_STATE_DEFAULT, 190); lv_obj_add_style(lineBattery, LV_LINE_PART_MAIN, &lineBatteryStyle); lineBatteryPoints[0] = {27, 105}; lineBatteryPoints[1] = {27, 106}; @@ -484,9 +484,20 @@ void WatchFaceInfineat::Refresh() { } batteryPercentRemaining = batteryController.PercentRemaining(); - if (batteryPercentRemaining.IsUpdated()) { - auto batteryPercent = batteryPercentRemaining.Get(); - SetBatteryLevel(batteryPercent); + isCharging = batteryController.IsCharging(); + // We store if battery and charging are updated before calling Get(), + // since Get() sets isUpdated to false. + bool isBatteryUpdated = batteryPercentRemaining.IsUpdated(); + bool isChargingUpdated = isCharging.IsUpdated(); + if (isCharging.Get()) { // Charging battery animation + chargingBatteryPercent += 1; + if (chargingBatteryPercent > 100) { + chargingBatteryPercent = batteryPercentRemaining.Get(); + } + SetBatteryLevel(chargingBatteryPercent); + } else if (isChargingUpdated || isBatteryUpdated) { + chargingBatteryPercent = batteryPercentRemaining.Get(); + SetBatteryLevel(chargingBatteryPercent); } bleState = bleController.IsConnected(); diff --git a/src/displayapp/screens/WatchFaceInfineat.h b/src/displayapp/screens/WatchFaceInfineat.h index 42d2d16d..54e3cb74 100644 --- a/src/displayapp/screens/WatchFaceInfineat.h +++ b/src/displayapp/screens/WatchFaceInfineat.h @@ -46,9 +46,11 @@ namespace Pinetime { Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown; uint8_t currentDay = 0; uint32_t savedTick = 0; + uint8_t chargingBatteryPercent = 101; // not a mistake ;) + DirtyValue batteryPercentRemaining {}; - DirtyValue powerPresent {}; + DirtyValue isCharging {}; DirtyValue bleState {}; DirtyValue bleRadioEnabled {}; DirtyValue> currentDateTime {}; -- cgit v1.2.3