From 616aa91b4c373dd49e60ac8b6b5c942ebc5804c9 Mon Sep 17 00:00:00 2001 From: Finlay Davidson Date: Thu, 16 Mar 2023 22:08:51 +0100 Subject: [PATCH] dirtyvalue: Move to src/utility --- src/displayapp/screens/Screen.h | 35 ----------------- src/displayapp/screens/WatchFaceAnalog.h | 15 +++---- .../screens/WatchFaceCasioStyleG7710.h | 21 +++++----- src/displayapp/screens/WatchFaceDigital.h | 21 +++++----- src/displayapp/screens/WatchFaceInfineat.h | 17 ++++---- .../screens/WatchFacePineTimeStyle.h | 17 ++++---- src/displayapp/screens/WatchFaceTerminal.h | 21 +++++----- src/displayapp/widgets/StatusIcons.h | 9 +++-- src/utility/DirtyValue.h | 39 +++++++++++++++++++ 9 files changed, 103 insertions(+), 92 deletions(-) create mode 100644 src/utility/DirtyValue.h diff --git a/src/displayapp/screens/Screen.h b/src/displayapp/screens/Screen.h index 09bd6131..9f6e0ede 100644 --- a/src/displayapp/screens/Screen.h +++ b/src/displayapp/screens/Screen.h @@ -9,41 +9,6 @@ namespace Pinetime { class DisplayApp; namespace Screens { - - template - class DirtyValue { - public: - DirtyValue() = default; // Use NSDMI - - explicit DirtyValue(T const& v) : value {v} { - } // Use MIL and const-lvalue-ref - - bool IsUpdated() { - if (this->isUpdated) { - this->isUpdated = false; - return true; - } - return false; - } - - T const& Get() { - this->isUpdated = false; - return value; - } // never expose a non-const lvalue-ref - - DirtyValue& operator=(const T& other) { - if (this->value != other) { - this->value = other; - this->isUpdated = true; - } - return *this; - } - - private: - T value {}; // NSDMI - default initialise type - bool isUpdated {true}; // NSDMI - use brace initialisation - }; - class Screen { private: virtual void Refresh() { diff --git a/src/displayapp/screens/WatchFaceAnalog.h b/src/displayapp/screens/WatchFaceAnalog.h index b32293da..501de115 100644 --- a/src/displayapp/screens/WatchFaceAnalog.h +++ b/src/displayapp/screens/WatchFaceAnalog.h @@ -9,7 +9,8 @@ #include "components/battery/BatteryController.h" #include "components/ble/BleController.h" #include "components/ble/NotificationManager.h" -#include +#include "displayapp/screens/BatteryIcon.h" +#include "utility/DirtyValue.h" namespace Pinetime { namespace Controllers { @@ -37,13 +38,13 @@ namespace Pinetime { private: uint8_t sHour, sMinute, sSecond; - DirtyValue batteryPercentRemaining {0}; - DirtyValue isCharging {}; - DirtyValue bleState {}; - DirtyValue> currentDateTime; - DirtyValue notificationState {false}; + Utility::DirtyValue batteryPercentRemaining {0}; + Utility::DirtyValue isCharging {}; + Utility::DirtyValue bleState {}; + Utility::DirtyValue> currentDateTime; + Utility::DirtyValue notificationState {false}; using days = std::chrono::duration>; // TODO: days is standard in c++20 - DirtyValue> currentDate; + Utility::DirtyValue> currentDate; lv_obj_t* hour_body; lv_obj_t* hour_body_trace; diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.h b/src/displayapp/screens/WatchFaceCasioStyleG7710.h index 0445c9f2..4d4d8f2f 100644 --- a/src/displayapp/screens/WatchFaceCasioStyleG7710.h +++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.h @@ -8,6 +8,7 @@ #include "displayapp/screens/Screen.h" #include "components/datetime/DateTimeController.h" #include "components/ble/BleController.h" +#include "utility/DirtyValue.h" namespace Pinetime { namespace Controllers { @@ -47,16 +48,16 @@ namespace Pinetime { Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown; uint8_t currentDay = 0; - DirtyValue batteryPercentRemaining {}; - DirtyValue powerPresent {}; - DirtyValue bleState {}; - DirtyValue bleRadioEnabled {}; - DirtyValue> currentDateTime {}; - DirtyValue motionSensorOk {}; - DirtyValue stepCount {}; - DirtyValue heartbeat {}; - DirtyValue heartbeatRunning {}; - DirtyValue notificationState {}; + Utility::DirtyValue batteryPercentRemaining {}; + Utility::DirtyValue powerPresent {}; + Utility::DirtyValue bleState {}; + Utility::DirtyValue bleRadioEnabled {}; + Utility::DirtyValue> currentDateTime {}; + Utility::DirtyValue motionSensorOk {}; + Utility::DirtyValue stepCount {}; + Utility::DirtyValue heartbeat {}; + Utility::DirtyValue heartbeatRunning {}; + Utility::DirtyValue notificationState {}; lv_point_t line_icons_points[3] {{0, 5}, {117, 5}, {122, 0}}; lv_point_t line_day_of_week_number_points[4] {{0, 0}, {100, 0}, {95, 95}, {0, 95}}; diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index 0931f007..a51c24e4 100644 --- a/src/displayapp/screens/WatchFaceDigital.h +++ b/src/displayapp/screens/WatchFaceDigital.h @@ -8,6 +8,7 @@ #include "components/datetime/DateTimeController.h" #include "components/ble/BleController.h" #include "displayapp/widgets/StatusIcons.h" +#include "utility/DirtyValue.h" namespace Pinetime { namespace Controllers { @@ -44,16 +45,16 @@ namespace Pinetime { Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown; uint8_t currentDay = 0; - DirtyValue batteryPercentRemaining {}; - DirtyValue powerPresent {}; - DirtyValue bleState {}; - DirtyValue bleRadioEnabled {}; - DirtyValue> currentDateTime {}; - DirtyValue motionSensorOk {}; - DirtyValue stepCount {}; - DirtyValue heartbeat {}; - DirtyValue heartbeatRunning {}; - DirtyValue notificationState {}; + Utility::DirtyValue batteryPercentRemaining {}; + Utility::DirtyValue powerPresent {}; + Utility::DirtyValue bleState {}; + Utility::DirtyValue bleRadioEnabled {}; + Utility::DirtyValue> currentDateTime {}; + Utility::DirtyValue motionSensorOk {}; + Utility::DirtyValue stepCount {}; + Utility::DirtyValue heartbeat {}; + Utility::DirtyValue heartbeatRunning {}; + Utility::DirtyValue notificationState {}; lv_obj_t* label_time; lv_obj_t* label_time_ampm; diff --git a/src/displayapp/screens/WatchFaceInfineat.h b/src/displayapp/screens/WatchFaceInfineat.h index 26973efe..ef908ffc 100644 --- a/src/displayapp/screens/WatchFaceInfineat.h +++ b/src/displayapp/screens/WatchFaceInfineat.h @@ -6,6 +6,7 @@ #include #include "displayapp/screens/Screen.h" #include "components/datetime/DateTimeController.h" +#include "utility/DirtyValue.h" namespace Pinetime { namespace Controllers { @@ -51,14 +52,14 @@ namespace Pinetime { uint32_t savedTick = 0; uint8_t chargingBatteryPercent = 101; // not a mistake ;) - DirtyValue batteryPercentRemaining {}; - DirtyValue isCharging {}; - DirtyValue bleState {}; - DirtyValue bleRadioEnabled {}; - DirtyValue> currentDateTime {}; - DirtyValue motionSensorOk {}; - DirtyValue stepCount {}; - DirtyValue notificationState {}; + Utility::DirtyValue batteryPercentRemaining {}; + Utility::DirtyValue isCharging {}; + Utility::DirtyValue bleState {}; + Utility::DirtyValue bleRadioEnabled {}; + Utility::DirtyValue> currentDateTime {}; + Utility::DirtyValue motionSensorOk {}; + Utility::DirtyValue stepCount {}; + Utility::DirtyValue notificationState {}; // Lines making up the side cover lv_obj_t* lineBattery; diff --git a/src/displayapp/screens/WatchFacePineTimeStyle.h b/src/displayapp/screens/WatchFacePineTimeStyle.h index bccb224a..6ac0cd28 100644 --- a/src/displayapp/screens/WatchFacePineTimeStyle.h +++ b/src/displayapp/screens/WatchFacePineTimeStyle.h @@ -9,6 +9,7 @@ #include "displayapp/Colors.h" #include "components/datetime/DateTimeController.h" #include "components/ble/BleController.h" +#include "utility/DirtyValue.h" namespace Pinetime { namespace Controllers { @@ -50,14 +51,14 @@ namespace Pinetime { uint8_t currentDay = 0; uint32_t savedTick = 0; - DirtyValue batteryPercentRemaining {}; - DirtyValue isCharging {}; - DirtyValue bleState {}; - DirtyValue bleRadioEnabled {}; - DirtyValue> currentDateTime {}; - DirtyValue motionSensorOk {}; - DirtyValue stepCount {}; - DirtyValue notificationState {}; + Utility::DirtyValue batteryPercentRemaining {}; + Utility::DirtyValue isCharging {}; + Utility::DirtyValue bleState {}; + Utility::DirtyValue bleRadioEnabled {}; + Utility::DirtyValue> currentDateTime {}; + Utility::DirtyValue motionSensorOk {}; + Utility::DirtyValue stepCount {}; + Utility::DirtyValue notificationState {}; static Pinetime::Controllers::Settings::Colors GetNext(Controllers::Settings::Colors color); static Pinetime::Controllers::Settings::Colors GetPrevious(Controllers::Settings::Colors color); diff --git a/src/displayapp/screens/WatchFaceTerminal.h b/src/displayapp/screens/WatchFaceTerminal.h index 67156a50..75e3434e 100644 --- a/src/displayapp/screens/WatchFaceTerminal.h +++ b/src/displayapp/screens/WatchFaceTerminal.h @@ -6,6 +6,7 @@ #include #include "displayapp/screens/Screen.h" #include "components/datetime/DateTimeController.h" +#include "utility/DirtyValue.h" namespace Pinetime { namespace Controllers { @@ -43,16 +44,16 @@ namespace Pinetime { Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown; uint8_t currentDay = 0; - DirtyValue batteryPercentRemaining {}; - DirtyValue powerPresent {}; - DirtyValue bleState {}; - DirtyValue bleRadioEnabled {}; - DirtyValue> currentDateTime {}; - DirtyValue motionSensorOk {}; - DirtyValue stepCount {}; - DirtyValue heartbeat {}; - DirtyValue heartbeatRunning {}; - DirtyValue notificationState {}; + Utility::DirtyValue batteryPercentRemaining {}; + Utility::DirtyValue powerPresent {}; + Utility::DirtyValue bleState {}; + Utility::DirtyValue bleRadioEnabled {}; + Utility::DirtyValue> currentDateTime {}; + Utility::DirtyValue motionSensorOk {}; + Utility::DirtyValue stepCount {}; + Utility::DirtyValue heartbeat {}; + Utility::DirtyValue heartbeatRunning {}; + Utility::DirtyValue notificationState {}; lv_obj_t* label_time; lv_obj_t* label_date; diff --git a/src/displayapp/widgets/StatusIcons.h b/src/displayapp/widgets/StatusIcons.h index 27e8b86a..9e21d3ad 100644 --- a/src/displayapp/widgets/StatusIcons.h +++ b/src/displayapp/widgets/StatusIcons.h @@ -6,6 +6,7 @@ #include "components/battery/BatteryController.h" #include "components/ble/BleController.h" #include "displayapp/screens/BatteryIcon.h" +#include "utility/DirtyValue.h" namespace Pinetime { namespace Applications { @@ -27,10 +28,10 @@ namespace Pinetime { const Pinetime::Controllers::Battery& batteryController; const Controllers::Ble& bleController; - Screens::DirtyValue batteryPercentRemaining {}; - Screens::DirtyValue powerPresent {}; - Screens::DirtyValue bleState {}; - Screens::DirtyValue bleRadioEnabled {}; + Utility::DirtyValue batteryPercentRemaining {}; + Utility::DirtyValue powerPresent {}; + Utility::DirtyValue bleState {}; + Utility::DirtyValue bleRadioEnabled {}; lv_obj_t* bleIcon; lv_obj_t* batteryPlug; diff --git a/src/utility/DirtyValue.h b/src/utility/DirtyValue.h new file mode 100644 index 00000000..8d5147aa --- /dev/null +++ b/src/utility/DirtyValue.h @@ -0,0 +1,39 @@ +#pragma once + +namespace Pinetime { + namespace Utility { + template + class DirtyValue { + public: + DirtyValue() = default; // Use NSDMI + + explicit DirtyValue(T const& v) : value {v} { + } // Use MIL and const-lvalue-ref + + bool IsUpdated() { + if (this->isUpdated) { + this->isUpdated = false; + return true; + } + return false; + } + + T const& Get() { + this->isUpdated = false; + return value; + } // never expose a non-const lvalue-ref + + DirtyValue& operator=(const T& other) { + if (this->value != other) { + this->value = other; + this->isUpdated = true; + } + return *this; + } + + private: + T value {}; // NSDMI - default initialise type + bool isUpdated {true}; // NSDMI - use brace initialisation + }; + } +}