From d0df278b0be2aae0493d901569a094dba221ce99 Mon Sep 17 00:00:00 2001 From: hassless <85612141+hassless@users.noreply.github.com> Date: Wed, 9 Jun 2021 13:47:22 +0200 Subject: [PATCH 1/9] Update BatteryIcon.cpp Improvement to the mapping of battery percentage to the battery icon to be displayed. --- src/displayapp/screens/BatteryIcon.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/displayapp/screens/BatteryIcon.cpp b/src/displayapp/screens/BatteryIcon.cpp index 6b54a305..ff8a1381 100644 --- a/src/displayapp/screens/BatteryIcon.cpp +++ b/src/displayapp/screens/BatteryIcon.cpp @@ -4,13 +4,13 @@ using namespace Pinetime::Applications::Screens; const char* BatteryIcon::GetBatteryIcon(int batteryPercent) { - if (batteryPercent > 90) + if (batteryPercent > 87) return Symbols::batteryFull; - if (batteryPercent > 75) + if (batteryPercent > 62) return Symbols::batteryThreeQuarter; - if (batteryPercent > 50) + if (batteryPercent > 37) return Symbols::batteryHalf; - if (batteryPercent > 25) + if (batteryPercent > 12) return Symbols::batteryOneQuarter; return Symbols::batteryEmpty; } From 7efe2b7c51e1d21305154edad6ddf1b608784451 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Mon, 12 Jul 2021 23:07:05 +0300 Subject: [PATCH 2/9] Fix misconfigured ADC and remove now unnecessary filtering --- src/components/battery/BatteryController.cpp | 14 ++------ src/components/battery/BatteryController.h | 38 +------------------- 2 files changed, 4 insertions(+), 48 deletions(-) diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp index 76ad8cb3..41b4c483 100644 --- a/src/components/battery/BatteryController.cpp +++ b/src/components/battery/BatteryController.cpp @@ -26,7 +26,6 @@ void Battery::Update() { return; } // Non blocking read - samples = 0; isReading = true; SaadcInit(); @@ -45,7 +44,7 @@ void Battery::SaadcInit() { .resistor_n = NRF_SAADC_RESISTOR_DISABLED, .gain = NRF_SAADC_GAIN1_5, .reference = NRF_SAADC_REFERENCE_INTERNAL, - .acq_time = NRF_SAADC_ACQTIME_3US, + .acq_time = NRF_SAADC_ACQTIME_40US, .mode = NRF_SAADC_MODE_SINGLE_ENDED, .burst = NRF_SAADC_BURST_ENABLED, .pin_p = batteryVoltageAdcInput, @@ -75,14 +74,7 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) { percentRemaining = std::max(percentRemaining, 0); percentRemaining = std::min(percentRemaining, 100); - percentRemainingBuffer.insert(percentRemaining); - - samples++; - if (samples > percentRemainingSamples) { - nrfx_saadc_uninit(); - isReading = false; - } else { - nrfx_saadc_sample(); - } + nrfx_saadc_uninit(); + isReading = false; } } diff --git a/src/components/battery/BatteryController.h b/src/components/battery/BatteryController.h index 26e24938..84d488ed 100644 --- a/src/components/battery/BatteryController.h +++ b/src/components/battery/BatteryController.h @@ -7,38 +7,6 @@ namespace Pinetime { namespace Controllers { - /** A simple circular buffer that can be used to average - out the sensor values. The total capacity of the CircBuffer - is given as the template parameter N. - */ - template class CircBuffer { - public: - CircBuffer() : arr {}, sz {}, cap {N}, head {} { - } - /** - insert member function overwrites the next data to the current - HEAD and moves the HEAD to the newly inserted value. - */ - void insert(const int num) { - head %= cap; - arr[head++] = num; - if (sz != cap) { - sz++; - } - } - - int GetAverage() const { - int sum = std::accumulate(arr.begin(), arr.end(), 0); - return (sum / sz); - } - - private: - std::array arr; /**< internal array used to store the values*/ - uint8_t sz; /**< The current size of the array.*/ - uint8_t cap; /**< Total capacity of the CircBuffer.*/ - uint8_t head; /**< The current head of the CircBuffer*/ - }; - class Battery { public: Battery(); @@ -47,7 +15,7 @@ namespace Pinetime { void Update(); int PercentRemaining() const { - return percentRemainingBuffer.GetAverage(); + return percentRemaining; } uint16_t Voltage() const { @@ -65,9 +33,6 @@ namespace Pinetime { static Battery* instance; nrf_saadc_value_t saadc_value; - static constexpr uint8_t percentRemainingSamples = 5; - CircBuffer percentRemainingBuffer {}; - static constexpr uint32_t chargingPin = 12; static constexpr uint32_t powerPresentPin = 19; static constexpr nrf_saadc_input_t batteryVoltageAdcInput = NRF_SAADC_INPUT_AIN7; @@ -83,7 +48,6 @@ namespace Pinetime { static void adcCallbackStatic(nrfx_saadc_evt_t const* event); bool isReading = false; - uint8_t samples = 0; }; } } From 514481ef7f9c71ad816b31d979c6ab39ce9380dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Sun, 25 Jul 2021 19:55:21 +0200 Subject: [PATCH 3/9] Tile event handler : read the event data only if the event is a "value changed event". LVGL sends many other event and some of them do not set the event data (global static variable) to a valid address, which may cause an invalid read. I noticed that when porting this class on RISC-V platform (BL602). --- src/displayapp/screens/Tile.cpp | 18 ++++++++++-------- src/displayapp/screens/Tile.h | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/displayapp/screens/Tile.cpp b/src/displayapp/screens/Tile.cpp index 3eb127cc..d5d6cb80 100644 --- a/src/displayapp/screens/Tile.cpp +++ b/src/displayapp/screens/Tile.cpp @@ -6,15 +6,17 @@ using namespace Pinetime::Applications::Screens; namespace { static void lv_update_task(struct _lv_task_t* task) { - auto user_data = static_cast(task->user_data); + auto* user_data = static_cast(task->user_data); user_data->UpdateScreen(); } static void event_handler(lv_obj_t* obj, lv_event_t event) { + if (event != LV_EVENT_VALUE_CHANGED) return; + Tile* screen = static_cast(obj->user_data); - uint32_t* eventDataPtr = (uint32_t*) lv_event_get_data(); + auto* eventDataPtr = (uint32_t*) lv_event_get_data(); uint32_t eventData = *eventDataPtr; - screen->OnObjectEvent(obj, event, eventData); + screen->OnValueChangedEvent(obj, eventData); } } @@ -124,9 +126,9 @@ bool Tile::Refresh() { return running; } -void Tile::OnObjectEvent(lv_obj_t* obj, lv_event_t event, uint32_t buttonId) { - if (event == LV_EVENT_VALUE_CHANGED) { - app->StartApp(apps[buttonId], DisplayApp::FullRefreshDirections::Up); - running = false; - } +void Tile::OnValueChangedEvent(lv_obj_t* obj, uint32_t buttonId) { + if(obj != btnm1) return; + + app->StartApp(apps[buttonId], DisplayApp::FullRefreshDirections::Up); + running = false; } diff --git a/src/displayapp/screens/Tile.h b/src/displayapp/screens/Tile.h index 4ebd81cd..765a8def 100644 --- a/src/displayapp/screens/Tile.h +++ b/src/displayapp/screens/Tile.h @@ -32,7 +32,7 @@ namespace Pinetime { bool Refresh() override; void UpdateScreen(); - void OnObjectEvent(lv_obj_t* obj, lv_event_t event, uint32_t buttonId); + void OnValueChangedEvent(lv_obj_t* obj, uint32_t buttonId); private: Pinetime::Controllers::Battery& batteryController; From 79ee65bfd53d31dd282dbbb7952296cc6f1212eb Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Tue, 27 Jul 2021 22:41:48 +0300 Subject: [PATCH 4/9] Increase ADC precision --- src/components/battery/BatteryController.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp index 54b9ffd9..e334eeac 100644 --- a/src/components/battery/BatteryController.cpp +++ b/src/components/battery/BatteryController.cpp @@ -39,7 +39,7 @@ void Battery::SaadcInit() { nrf_saadc_channel_config_t adcChannelConfig = {.resistor_p = NRF_SAADC_RESISTOR_DISABLED, .resistor_n = NRF_SAADC_RESISTOR_DISABLED, - .gain = NRF_SAADC_GAIN1_5, + .gain = NRF_SAADC_GAIN1_4, .reference = NRF_SAADC_REFERENCE_INTERNAL, .acq_time = NRF_SAADC_ACQTIME_40US, .mode = NRF_SAADC_MODE_SINGLE_ENDED, @@ -59,11 +59,11 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) { APP_ERROR_CHECK(nrfx_saadc_buffer_convert(&saadc_value, 1)); // A hardware voltage divider divides the battery voltage by 2 - // ADC gain is 1/5 - // thus adc_voltage = battery_voltage / 2 * gain = battery_voltage / 10 + // ADC gain is 1/4 + // thus adc_voltage = battery_voltage / 2 * gain = battery_voltage / 8 // reference_voltage is 0.6V // p_event->data.done.p_buffer[0] = (adc_voltage / reference_voltage) * 1024 - voltage = p_event->data.done.p_buffer[0] * 6000 / 1024; + voltage = p_event->data.done.p_buffer[0] * (0.6 * 8 * 1000) / 1024; if (voltage > battery_max) { percentRemaining = 100; From 09aaa5871071857dbcd955ce8ea8e33e95960678 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Sun, 1 Aug 2021 16:19:09 +0300 Subject: [PATCH 5/9] Remove floating point calculation --- src/components/battery/BatteryController.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp index e334eeac..f8a64ecd 100644 --- a/src/components/battery/BatteryController.cpp +++ b/src/components/battery/BatteryController.cpp @@ -61,9 +61,9 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) { // A hardware voltage divider divides the battery voltage by 2 // ADC gain is 1/4 // thus adc_voltage = battery_voltage / 2 * gain = battery_voltage / 8 - // reference_voltage is 0.6V + // reference_voltage is 600mV // p_event->data.done.p_buffer[0] = (adc_voltage / reference_voltage) * 1024 - voltage = p_event->data.done.p_buffer[0] * (0.6 * 8 * 1000) / 1024; + voltage = p_event->data.done.p_buffer[0] * (8 * 600) / 1024; if (voltage > battery_max) { percentRemaining = 100; From d35a54c060700e537d3e39723b7ee9b1d71b36d8 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Mon, 9 Aug 2021 21:49:35 +0300 Subject: [PATCH 6/9] Try to fix bootloop --- src/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index ffbba5e7..a18c3942 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include #include #include +#include // nimble #define min // workaround: nimble's min/max macros conflict with libstdc++ @@ -300,6 +301,14 @@ int main(void) { nrf_drv_clock_init(); + // Unblock i2c? + nrf_gpio_cfg_output(pinTwiScl); + for (uint8_t i = 0; i < 16; i++) { + nrf_gpio_pin_toggle(pinTwiScl); + nrf_delay_us(5); + } + nrf_gpio_cfg_default(pinTwiScl); + debounceTimer = xTimerCreate("debounceTimer", 200, pdFALSE, (void*) 0, DebounceTimerCallback); debounceChargeTimer = xTimerCreate("debounceTimerCharge", 200, pdFALSE, (void*) 0, DebounceTimerChargeCallback); From ff81a72533e479388d49334d0ec3e0635b6e7f40 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Mon, 9 Aug 2021 22:07:06 +0300 Subject: [PATCH 7/9] Better pin configuration --- src/main.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index a18c3942..39d8906c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -302,7 +302,12 @@ int main(void) { nrf_drv_clock_init(); // Unblock i2c? - nrf_gpio_cfg_output(pinTwiScl); + nrf_gpio_cfg(pinTwiScl, + NRF_GPIO_PIN_DIR_OUTPUT, + NRF_GPIO_PIN_INPUT_DISCONNECT, + NRF_GPIO_PIN_NOPULL, + NRF_GPIO_PIN_S0D1, + NRF_GPIO_PIN_NOSENSE); for (uint8_t i = 0; i < 16; i++) { nrf_gpio_pin_toggle(pinTwiScl); nrf_delay_us(5); From 5eb56d9a06652cb10358ecba051bbfe8ec2957a7 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Mon, 9 Aug 2021 22:11:35 +0300 Subject: [PATCH 8/9] Set pin before loop --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cpp b/src/main.cpp index 39d8906c..d301be67 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -308,6 +308,7 @@ int main(void) { NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0D1, NRF_GPIO_PIN_NOSENSE); + nrf_gpio_pin_set(pinTwiScl); for (uint8_t i = 0; i < 16; i++) { nrf_gpio_pin_toggle(pinTwiScl); nrf_delay_us(5); From c086520c9796322043d9617e6cff5c554529d640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Sat, 24 Jul 2021 13:01:11 +0200 Subject: [PATCH 9/9] Code cleaning in Clock, WatchFaceAnalog, WatchFaceDigital and PineTimeStyle, inspired by PR #232 by nscooling. --- .../datetime/DateTimeController.cpp | 20 +++---- src/displayapp/screens/Clock.cpp | 20 +------ src/displayapp/screens/Clock.h | 7 --- src/displayapp/screens/PineTimeStyle.cpp | 60 +++++-------------- src/displayapp/screens/PineTimeStyle.h | 5 -- src/displayapp/screens/WatchFaceAnalog.cpp | 52 +++++++--------- src/displayapp/screens/WatchFaceAnalog.h | 2 - src/displayapp/screens/WatchFaceDigital.cpp | 45 ++++---------- src/displayapp/screens/WatchFaceDigital.h | 5 +- 9 files changed, 60 insertions(+), 156 deletions(-) diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp index 28a70abc..d6aa83c8 100644 --- a/src/components/datetime/DateTimeController.cpp +++ b/src/components/datetime/DateTimeController.cpp @@ -55,9 +55,9 @@ void DateTime::UpdateTime(uint32_t systickCounter) { auto time = date::make_time(currentDateTime - dp); auto yearMonthDay = date::year_month_day(dp); - year = (int) yearMonthDay.year(); - month = static_cast((unsigned) yearMonthDay.month()); - day = (unsigned) yearMonthDay.day(); + year = static_cast(yearMonthDay.year()); + month = static_cast(static_cast(yearMonthDay.month())); + day = static_cast(yearMonthDay.day()); dayOfWeek = static_cast(date::weekday(yearMonthDay).iso_encoding()); hour = time.hours().count(); @@ -75,31 +75,31 @@ void DateTime::UpdateTime(uint32_t systickCounter) { } const char* DateTime::MonthShortToString() { - return DateTime::MonthsString[(uint8_t) month]; + return DateTime::MonthsString[static_cast(month)]; } const char* DateTime::MonthShortToStringLow() { - return DateTime::MonthsStringLow[(uint8_t) month]; + return DateTime::MonthsStringLow[static_cast(month)]; } const char* DateTime::MonthsToStringLow() { - return DateTime::MonthsLow[(uint8_t) month]; + return DateTime::MonthsLow[static_cast(month)]; } const char* DateTime::DayOfWeekToString() { - return DateTime::DaysString[(uint8_t) dayOfWeek]; + return DateTime::DaysString[static_cast(dayOfWeek)]; } const char* DateTime::DayOfWeekShortToString() { - return DateTime::DaysStringShort[(uint8_t) dayOfWeek]; + return DateTime::DaysStringShort[static_cast(dayOfWeek)]; } const char* DateTime::DayOfWeekToStringLow() { - return DateTime::DaysStringLow[(uint8_t) dayOfWeek]; + return DateTime::DaysStringLow[static_cast(dayOfWeek)]; } const char* DateTime::DayOfWeekShortToStringLow() { - return DateTime::DaysStringShortLow[(uint8_t) dayOfWeek]; + return DateTime::DaysStringShortLow[static_cast(dayOfWeek)]; } void DateTime::Register(Pinetime::System::SystemTask* systemTask) { diff --git a/src/displayapp/screens/Clock.cpp b/src/displayapp/screens/Clock.cpp index e0684976..86afee0c 100644 --- a/src/displayapp/screens/Clock.cpp +++ b/src/displayapp/screens/Clock.cpp @@ -2,11 +2,6 @@ #include #include -#include -#include "BatteryIcon.h" -#include "BleIcon.h" -#include "NotificationIcon.h" -#include "Symbols.h" #include "components/battery/BatteryController.h" #include "components/motion/MotionController.h" #include "components/ble/BleController.h" @@ -88,17 +83,4 @@ std::unique_ptr Clock::PineTimeStyleScreen() { notificatioManager, settingsController, motionController); -} - -/* -// Examples for more watch faces -std::unique_ptr Clock::WatchFaceMinimalScreen() { - return std::make_unique(app, dateTimeController, batteryController, bleController, notificatioManager, -settingsController); -} - -std::unique_ptr Clock::WatchFaceCustomScreen() { - return std::make_unique(app, dateTimeController, batteryController, bleController, notificatioManager, -settingsController); -} -*/ \ No newline at end of file +} \ No newline at end of file diff --git a/src/displayapp/screens/Clock.h b/src/displayapp/screens/Clock.h index a48feea1..7968cced 100644 --- a/src/displayapp/screens/Clock.h +++ b/src/displayapp/screens/Clock.h @@ -9,9 +9,6 @@ #include "components/datetime/DateTimeController.h" namespace Pinetime { - namespace Drivers { - class BMA421; - } namespace Controllers { class Settings; class Battery; @@ -51,10 +48,6 @@ namespace Pinetime { std::unique_ptr WatchFaceDigitalScreen(); std::unique_ptr WatchFaceAnalogScreen(); std::unique_ptr PineTimeStyleScreen(); - - // Examples for more watch faces - // std::unique_ptr WatchFaceMinimalScreen(); - // std::unique_ptr WatchFaceCustomScreen(); }; } } diff --git a/src/displayapp/screens/PineTimeStyle.cpp b/src/displayapp/screens/PineTimeStyle.cpp index 0efb4dc3..98fd976c 100644 --- a/src/displayapp/screens/PineTimeStyle.cpp +++ b/src/displayapp/screens/PineTimeStyle.cpp @@ -51,7 +51,6 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app, notificatioManager {notificatioManager}, settingsController {settingsController}, motionController {motionController} { - /* This sets the watchface number to return to after leaving the menu */ settingsController.SetClockFace(2); @@ -62,7 +61,6 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app, displayedChar[4] = 0; /* Create a 200px wide background rectangle */ - timebar = lv_obj_create(lv_scr_act(), nullptr); lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); lv_obj_set_style_local_radius(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0); @@ -70,7 +68,6 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app, lv_obj_align(timebar, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 5, 0); /* Display the time */ - timeDD1 = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &open_sans_light); lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x008080)); @@ -90,7 +87,6 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app, lv_obj_align(timeAMPM, timebar, LV_ALIGN_IN_BOTTOM_LEFT, 2, -20); /* Create a 40px wide bar down the right side of the screen */ - sidebar = lv_obj_create(lv_scr_act(), nullptr); lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x008080)); lv_obj_set_style_local_radius(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0); @@ -98,7 +94,6 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app, lv_obj_align(sidebar, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0); /* Display icons */ - batteryIcon = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); lv_label_set_text(batteryIcon, Symbols::batteryFull); @@ -117,7 +112,6 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app, lv_obj_align(notificationIcon, sidebar, LV_ALIGN_IN_TOP_MID, 0, 40); /* Calendar icon */ - calendarOuter = lv_obj_create(lv_scr_act(), nullptr); lv_obj_set_style_local_bg_color(calendarOuter, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); lv_obj_set_style_local_radius(calendarOuter, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0); @@ -155,7 +149,6 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app, lv_obj_align(calendarCrossBar2, calendarBar2, LV_ALIGN_IN_BOTTOM_MID, 0, 0); /* Display date */ - dateDayOfWeek = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(dateDayOfWeek, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); lv_label_set_text(dateDayOfWeek, "THU"); @@ -223,26 +216,17 @@ bool PineTimeStyle::Refresh() { bleState = bleController.IsConnected(); if (bleState.IsUpdated()) { - if (bleState.Get() == true) { - lv_label_set_text(bleIcon, BleIcon::GetIcon(true)); - lv_obj_realign(bleIcon); - } else { - lv_label_set_text(bleIcon, BleIcon::GetIcon(false)); - } + lv_label_set_text(bleIcon, BleIcon::GetIcon(bleState.Get())); + lv_obj_realign(bleIcon); } notificationState = notificatioManager.AreNewNotificationsAvailable(); if (notificationState.IsUpdated()) { - if (notificationState.Get() == true) { - lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(true)); - lv_obj_realign(notificationIcon); - } else { - lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(false)); - } + lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(notificationState.Get())); + lv_obj_realign(notificationIcon); } currentDateTime = dateTimeController.CurrentDateTime(); - if (currentDateTime.IsUpdated()) { auto newDateTime = currentDateTime.Get(); @@ -250,9 +234,9 @@ bool PineTimeStyle::Refresh() { auto time = date::make_time(newDateTime - dp); auto yearMonthDay = date::year_month_day(dp); - auto year = (int) yearMonthDay.year(); - auto month = static_cast((unsigned) yearMonthDay.month()); - auto day = (unsigned) yearMonthDay.day(); + auto year = static_cast(yearMonthDay.year()); + auto month = static_cast(static_cast(yearMonthDay.month())); + auto day = static_cast(yearMonthDay.day()); auto dayOfWeek = static_cast(date::weekday(yearMonthDay).iso_encoding()); int hour = time.hours().count(); @@ -263,9 +247,8 @@ bool PineTimeStyle::Refresh() { char hoursChar[3]; char ampmChar[5]; - if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) { - sprintf(hoursChar, "%02d", hour); + sprintf(hoursChar, "%02d", hour); } else { if (hour == 0 && hour != 12) { hour = 12; @@ -282,41 +265,26 @@ bool PineTimeStyle::Refresh() { sprintf(hoursChar, "%02d", hour); } - if (hoursChar[0] != displayedChar[0] || hoursChar[1] != displayedChar[1] || minutesChar[0] != displayedChar[2] || + if (hoursChar[0] != displayedChar[0] or hoursChar[1] != displayedChar[1] or minutesChar[0] != displayedChar[2] or minutesChar[1] != displayedChar[3]) { displayedChar[0] = hoursChar[0]; displayedChar[1] = hoursChar[1]; displayedChar[2] = minutesChar[0]; displayedChar[3] = minutesChar[1]; - char hourStr[3]; - char minStr[3]; - if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { lv_label_set_text(timeAMPM, ampmChar); } - /* Display the time as 2 pairs of digits */ - sprintf(hourStr, "%c%c", hoursChar[0], hoursChar[1]); - lv_label_set_text(timeDD1, hourStr); - - sprintf(minStr, "%c%c", minutesChar[0], minutesChar[1]); - lv_label_set_text(timeDD2, minStr); + lv_label_set_text_fmt(timeDD1, "%s", hoursChar); + lv_label_set_text_fmt(timeDD2, "%s", minutesChar); } if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { - char dayOfWeekStr[4]; - char dayStr[3]; - char monthStr[4]; - - sprintf(dayOfWeekStr, "%s", dateTimeController.DayOfWeekShortToString()); - sprintf(dayStr, "%d", day); - sprintf(monthStr, "%s", dateTimeController.MonthShortToString()); - - lv_label_set_text(dateDayOfWeek, dayOfWeekStr); - lv_label_set_text(dateDay, dayStr); + lv_label_set_text_fmt(dateDayOfWeek, "%s", dateTimeController.DayOfWeekShortToString()); + lv_label_set_text_fmt(dateDay, "%d", day); lv_obj_realign(dateDay); - lv_label_set_text(dateMonth, monthStr); + lv_label_set_text_fmt(dateMonth, "%s", dateTimeController.MonthShortToString()); currentYear = year; currentMonth = month; diff --git a/src/displayapp/screens/PineTimeStyle.h b/src/displayapp/screens/PineTimeStyle.h index 3b4ded1e..f4cd28e4 100644 --- a/src/displayapp/screens/PineTimeStyle.h +++ b/src/displayapp/screens/PineTimeStyle.h @@ -32,8 +32,6 @@ namespace Pinetime { bool Refresh() override; - void OnObjectEvent(lv_obj_t* pObj, lv_event_t i); - private: char displayedChar[5]; @@ -67,9 +65,6 @@ namespace Pinetime { lv_obj_t* calendarBar2; lv_obj_t* calendarCrossBar1; lv_obj_t* calendarCrossBar2; - lv_obj_t* heartbeatIcon; - lv_obj_t* heartbeatValue; - lv_obj_t* heartbeatBpm; lv_obj_t* notificationIcon; lv_obj_t* stepGauge; lv_color_t needle_colors[1]; diff --git a/src/displayapp/screens/WatchFaceAnalog.cpp b/src/displayapp/screens/WatchFaceAnalog.cpp index f1889379..621929b8 100644 --- a/src/displayapp/screens/WatchFaceAnalog.cpp +++ b/src/displayapp/screens/WatchFaceAnalog.cpp @@ -10,38 +10,37 @@ LV_IMG_DECLARE(bg_clock); using namespace Pinetime::Applications::Screens; namespace { - -constexpr auto HOUR_LENGTH = 70; -constexpr auto MINUTE_LENGTH = 90; -constexpr auto SECOND_LENGTH = 110; +constexpr int16_t HourLength = 70; +constexpr int16_t MinuteLength = 90; +constexpr int16_t SecondLength = 110; // sin(90) = 1 so the value of _lv_trigo_sin(90) is the scaling factor const auto LV_TRIG_SCALE = _lv_trigo_sin(90); -int16_t cosine(int16_t angle) { +int16_t Cosine(int16_t angle) { return _lv_trigo_sin(angle + 90); } -int16_t sine(int16_t angle) { +int16_t Sine(int16_t angle) { return _lv_trigo_sin(angle); } -int16_t coordinate_x_relocate(int16_t x) { +int16_t CoordinateXRelocate(int16_t x) { return (x + LV_HOR_RES / 2); } -int16_t coordinate_y_relocate(int16_t y) { +int16_t CoordinateYRelocate(int16_t y) { return std::abs(y - LV_HOR_RES / 2); } -lv_point_t coordinate_relocate(int16_t radius, int16_t angle) { +lv_point_t CoordinateRelocate(int16_t radius, int16_t angle) { return lv_point_t{ - .x = coordinate_x_relocate(radius * static_cast(sine(angle)) / LV_TRIG_SCALE), - .y = coordinate_y_relocate(radius * static_cast(cosine(angle)) / LV_TRIG_SCALE) + .x = CoordinateXRelocate(radius * static_cast(Sine(angle)) / LV_TRIG_SCALE), + .y = CoordinateYRelocate(radius * static_cast(Cosine(angle)) / LV_TRIG_SCALE) }; } -} // namespace +} WatchFaceAnalog::WatchFaceAnalog(Pinetime::Applications::DisplayApp* app, Controllers::DateTime& dateTimeController, @@ -123,7 +122,6 @@ WatchFaceAnalog::WatchFaceAnalog(Pinetime::Applications::DisplayApp* app, } WatchFaceAnalog::~WatchFaceAnalog() { - lv_style_reset(&hour_line_style); lv_style_reset(&hour_line_style_trace); lv_style_reset(&minute_line_style); @@ -134,18 +132,17 @@ WatchFaceAnalog::~WatchFaceAnalog() { } void WatchFaceAnalog::UpdateClock() { - hour = dateTimeController.Hours(); minute = dateTimeController.Minutes(); second = dateTimeController.Seconds(); if (sMinute != minute) { auto const angle = minute * 6; - minute_point[0] = coordinate_relocate(30, angle); - minute_point[1] = coordinate_relocate(MINUTE_LENGTH, angle); + minute_point[0] = CoordinateRelocate(30, angle); + minute_point[1] = CoordinateRelocate(MinuteLength, angle); - minute_point_trace[0] = coordinate_relocate(5, angle); - minute_point_trace[1] = coordinate_relocate(31, angle); + minute_point_trace[0] = CoordinateRelocate(5, angle); + minute_point_trace[1] = CoordinateRelocate(31, angle); lv_line_set_points(minute_body, minute_point, 2); lv_line_set_points(minute_body_trace, minute_point_trace, 2); @@ -156,11 +153,11 @@ void WatchFaceAnalog::UpdateClock() { sMinute = minute; auto const angle = (hour * 30 + minute / 2); - hour_point[0] = coordinate_relocate(30, angle); - hour_point[1] = coordinate_relocate(HOUR_LENGTH, angle); + hour_point[0] = CoordinateRelocate(30, angle); + hour_point[1] = CoordinateRelocate(HourLength, angle); - hour_point_trace[0] = coordinate_relocate(5, angle); - hour_point_trace[1] = coordinate_relocate(31, angle); + hour_point_trace[0] = CoordinateRelocate(5, angle); + hour_point_trace[1] = CoordinateRelocate(31, angle); lv_line_set_points(hour_body, hour_point, 2); lv_line_set_points(hour_body_trace, hour_point_trace, 2); @@ -170,8 +167,8 @@ void WatchFaceAnalog::UpdateClock() { sSecond = second; auto const angle = second * 6; - second_point[0] = coordinate_relocate(-20, angle); - second_point[1] = coordinate_relocate(SECOND_LENGTH, angle); + second_point[0] = CoordinateRelocate(-20, angle); + second_point[1] = CoordinateRelocate(SecondLength, angle); lv_line_set_points(second_body, second_point, 2); } } @@ -186,16 +183,12 @@ bool WatchFaceAnalog::Refresh() { notificationState = notificationManager.AreNewNotificationsAvailable(); if (notificationState.IsUpdated()) { - if (notificationState.Get() == true) - lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(true)); - else - lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(false)); + lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(notificationState.Get())); } currentDateTime = dateTimeController.CurrentDateTime(); if (currentDateTime.IsUpdated()) { - month = dateTimeController.Month(); day = dateTimeController.Day(); dayOfWeek = dateTimeController.DayOfWeek(); @@ -203,7 +196,6 @@ bool WatchFaceAnalog::Refresh() { UpdateClock(); if ((month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { - lv_label_set_text_fmt(label_date_day, "%s\n%02i", dateTimeController.DayOfWeekShortToString(), day); currentMonth = month; diff --git a/src/displayapp/screens/WatchFaceAnalog.h b/src/displayapp/screens/WatchFaceAnalog.h index ac7f0ac5..5d8c6a24 100644 --- a/src/displayapp/screens/WatchFaceAnalog.h +++ b/src/displayapp/screens/WatchFaceAnalog.h @@ -58,14 +58,12 @@ namespace Pinetime { lv_obj_t* minute_body_trace; lv_obj_t* second_body; - // ## lv_point_t hour_point[2]; lv_point_t hour_point_trace[2]; lv_point_t minute_point[2]; lv_point_t minute_point_trace[2]; lv_point_t second_point[2]; - // ## lv_style_t hour_line_style; lv_style_t hour_line_style_trace; lv_style_t minute_line_style; diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index f1285eaf..7a240f1f 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -12,9 +12,6 @@ #include "components/ble/NotificationManager.h" #include "components/heartrate/HeartRateController.h" #include "components/motion/MotionController.h" -#include "components/settings/Settings.h" -#include "../DisplayApp.h" - using namespace Pinetime::Applications::Screens; WatchFaceDigital::WatchFaceDigital(DisplayApp* app, @@ -36,12 +33,6 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, motionController {motionController} { settingsController.SetClockFace(0); - displayedChar[0] = 0; - displayedChar[1] = 0; - displayedChar[2] = 0; - displayedChar[3] = 0; - displayedChar[4] = 0; - batteryIcon = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text(batteryIcon, Symbols::batteryFull); lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, -5, 2); @@ -56,7 +47,7 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, lv_label_set_text(bleIcon, Symbols::bluetooth); lv_obj_align(bleIcon, batteryPlug, LV_ALIGN_OUT_LEFT_MID, -5, 0); - notificationIcon = lv_label_create(lv_scr_act(), NULL); + notificationIcon = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FF00)); lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(false)); lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 10, 0); @@ -111,17 +102,13 @@ bool WatchFaceDigital::Refresh() { if (batteryPercentRemaining.IsUpdated()) { auto batteryPercent = batteryPercentRemaining.Get(); lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent)); - auto isCharging = batteryController.IsCharging() || batteryController.IsPowerPresent(); + auto isCharging = batteryController.IsCharging() or batteryController.IsPowerPresent(); lv_label_set_text(batteryPlug, BatteryIcon::GetPlugIcon(isCharging)); } bleState = bleController.IsConnected(); if (bleState.IsUpdated()) { - if (bleState.Get() == true) { - lv_label_set_text(bleIcon, BleIcon::GetIcon(true)); - } else { - lv_label_set_text(bleIcon, BleIcon::GetIcon(false)); - } + lv_label_set_text(bleIcon, BleIcon::GetIcon(bleState.Get())); } lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, -5, 5); lv_obj_align(batteryPlug, batteryIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0); @@ -129,10 +116,7 @@ bool WatchFaceDigital::Refresh() { notificationState = notificatioManager.AreNewNotificationsAvailable(); if (notificationState.IsUpdated()) { - if (notificationState.Get() == true) - lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(true)); - else - lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(false)); + lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(notificationState.Get())); } currentDateTime = dateTimeController.CurrentDateTime(); @@ -144,9 +128,9 @@ bool WatchFaceDigital::Refresh() { auto time = date::make_time(newDateTime - dp); auto yearMonthDay = date::year_month_day(dp); - auto year = (int) yearMonthDay.year(); - auto month = static_cast((unsigned) yearMonthDay.month()); - auto day = (unsigned) yearMonthDay.day(); + auto year = static_cast(yearMonthDay.year()); + auto month = static_cast(static_cast(yearMonthDay.month())); + auto day = static_cast(yearMonthDay.day()); auto dayOfWeek = static_cast(date::weekday(yearMonthDay).iso_encoding()); int hour = time.hours().count(); @@ -175,15 +159,13 @@ bool WatchFaceDigital::Refresh() { sprintf(hoursChar, "%02d", hour); } - if (hoursChar[0] != displayedChar[0] || hoursChar[1] != displayedChar[1] || minutesChar[0] != displayedChar[2] || - minutesChar[1] != displayedChar[3]) { + if ((hoursChar[0] != displayedChar[0]) or (hoursChar[1] != displayedChar[1]) or (minutesChar[0] != displayedChar[2]) or + (minutesChar[1] != displayedChar[3])) { displayedChar[0] = hoursChar[0]; displayedChar[1] = hoursChar[1]; displayedChar[2] = minutesChar[0]; displayedChar[3] = minutesChar[1]; - char timeStr[6]; - if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { lv_label_set_text(label_time_ampm, ampmChar); if (hoursChar[0] == '0') { @@ -191,8 +173,7 @@ bool WatchFaceDigital::Refresh() { } } - sprintf(timeStr, "%c%c:%c%c", hoursChar[0], hoursChar[1], minutesChar[0], minutesChar[1]); - lv_label_set_text(label_time, timeStr); + lv_label_set_text_fmt(label_time, "%s:%s", hoursChar, minutesChar); if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, 0); @@ -202,13 +183,11 @@ bool WatchFaceDigital::Refresh() { } if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { - char dateStr[22]; if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) { - sprintf(dateStr, "%s %d %s %d", dateTimeController.DayOfWeekShortToString(), day, dateTimeController.MonthShortToString(), year); + lv_label_set_text_fmt(label_date, "%s %d %s %d", dateTimeController.DayOfWeekShortToString(), day, dateTimeController.MonthShortToString(), year); } else { - sprintf(dateStr, "%s %s %d %d", dateTimeController.DayOfWeekShortToString(), dateTimeController.MonthShortToString(), day, year); + lv_label_set_text_fmt(label_date, "%s %s %d %d", dateTimeController.DayOfWeekShortToString(), dateTimeController.MonthShortToString(), day, year); } - lv_label_set_text(label_date, dateStr); lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60); currentYear = year; diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index 76c8d3dc..6a6e1ac6 100644 --- a/src/displayapp/screens/WatchFaceDigital.h +++ b/src/displayapp/screens/WatchFaceDigital.h @@ -35,10 +35,8 @@ namespace Pinetime { bool Refresh() override; - void OnObjectEvent(lv_obj_t* pObj, lv_event_t i); - private: - char displayedChar[5]; + char displayedChar[5] {}; uint16_t currentYear = 1970; Pinetime::Controllers::DateTime::Months currentMonth = Pinetime::Controllers::DateTime::Months::Unknown; @@ -63,7 +61,6 @@ namespace Pinetime { lv_obj_t* batteryPlug; lv_obj_t* heartbeatIcon; lv_obj_t* heartbeatValue; - lv_obj_t* heartbeatBpm; lv_obj_t* stepIcon; lv_obj_t* stepValue; lv_obj_t* notificationIcon;