diff options
| author | Finlay Davidson <finlay.davidson@coderclass.nl> | 2023-03-16 22:08:51 +0100 |
|---|---|---|
| committer | Riku Isokoski <riksu9000@gmail.com> | 2023-03-27 22:12:32 +0000 |
| commit | 616aa91b4c373dd49e60ac8b6b5c942ebc5804c9 (patch) | |
| tree | 954967ccc7fba99ff38d62ae605b3d4afe2a467f | |
| parent | 47931f41d579371c9c78ae7061317bf28848db2f (diff) | |
dirtyvalue: Move to src/utility
| -rw-r--r-- | src/displayapp/screens/Screen.h | 35 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFaceAnalog.h | 15 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFaceCasioStyleG7710.h | 21 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFaceDigital.h | 21 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFaceInfineat.h | 17 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFacePineTimeStyle.h | 17 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFaceTerminal.h | 21 | ||||
| -rw-r--r-- | src/displayapp/widgets/StatusIcons.h | 9 | ||||
| -rw-r--r-- | src/utility/DirtyValue.h | 39 |
9 files changed, 103 insertions, 92 deletions
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 T> - 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 <displayapp/screens/BatteryIcon.h> +#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<uint8_t> batteryPercentRemaining {0}; - DirtyValue<bool> isCharging {}; - DirtyValue<bool> bleState {}; - DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime; - DirtyValue<bool> notificationState {false}; + Utility::DirtyValue<uint8_t> batteryPercentRemaining {0}; + Utility::DirtyValue<bool> isCharging {}; + Utility::DirtyValue<bool> bleState {}; + Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime; + Utility::DirtyValue<bool> notificationState {false}; using days = std::chrono::duration<int32_t, std::ratio<86400>>; // TODO: days is standard in c++20 - DirtyValue<std::chrono::time_point<std::chrono::system_clock, days>> currentDate; + Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, days>> 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<uint8_t> batteryPercentRemaining {}; - DirtyValue<bool> powerPresent {}; - DirtyValue<bool> bleState {}; - DirtyValue<bool> bleRadioEnabled {}; - DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {}; - DirtyValue<bool> motionSensorOk {}; - DirtyValue<uint32_t> stepCount {}; - DirtyValue<uint8_t> heartbeat {}; - DirtyValue<bool> heartbeatRunning {}; - DirtyValue<bool> notificationState {}; + Utility::DirtyValue<uint8_t> batteryPercentRemaining {}; + Utility::DirtyValue<bool> powerPresent {}; + Utility::DirtyValue<bool> bleState {}; + Utility::DirtyValue<bool> bleRadioEnabled {}; + Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {}; + Utility::DirtyValue<bool> motionSensorOk {}; + Utility::DirtyValue<uint32_t> stepCount {}; + Utility::DirtyValue<uint8_t> heartbeat {}; + Utility::DirtyValue<bool> heartbeatRunning {}; + Utility::DirtyValue<bool> 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<uint8_t> batteryPercentRemaining {}; - DirtyValue<bool> powerPresent {}; - DirtyValue<bool> bleState {}; - DirtyValue<bool> bleRadioEnabled {}; - DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {}; - DirtyValue<bool> motionSensorOk {}; - DirtyValue<uint32_t> stepCount {}; - DirtyValue<uint8_t> heartbeat {}; - DirtyValue<bool> heartbeatRunning {}; - DirtyValue<bool> notificationState {}; + Utility::DirtyValue<uint8_t> batteryPercentRemaining {}; + Utility::DirtyValue<bool> powerPresent {}; + Utility::DirtyValue<bool> bleState {}; + Utility::DirtyValue<bool> bleRadioEnabled {}; + Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {}; + Utility::DirtyValue<bool> motionSensorOk {}; + Utility::DirtyValue<uint32_t> stepCount {}; + Utility::DirtyValue<uint8_t> heartbeat {}; + Utility::DirtyValue<bool> heartbeatRunning {}; + Utility::DirtyValue<bool> 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 <memory> #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<uint8_t> batteryPercentRemaining {}; - DirtyValue<bool> isCharging {}; - DirtyValue<bool> bleState {}; - DirtyValue<bool> bleRadioEnabled {}; - DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {}; - DirtyValue<bool> motionSensorOk {}; - DirtyValue<uint32_t> stepCount {}; - DirtyValue<bool> notificationState {}; + Utility::DirtyValue<uint8_t> batteryPercentRemaining {}; + Utility::DirtyValue<bool> isCharging {}; + Utility::DirtyValue<bool> bleState {}; + Utility::DirtyValue<bool> bleRadioEnabled {}; + Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {}; + Utility::DirtyValue<bool> motionSensorOk {}; + Utility::DirtyValue<uint32_t> stepCount {}; + Utility::DirtyValue<bool> 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<uint8_t> batteryPercentRemaining {}; - DirtyValue<bool> isCharging {}; - DirtyValue<bool> bleState {}; - DirtyValue<bool> bleRadioEnabled {}; - DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {}; - DirtyValue<bool> motionSensorOk {}; - DirtyValue<uint32_t> stepCount {}; - DirtyValue<bool> notificationState {}; + Utility::DirtyValue<uint8_t> batteryPercentRemaining {}; + Utility::DirtyValue<bool> isCharging {}; + Utility::DirtyValue<bool> bleState {}; + Utility::DirtyValue<bool> bleRadioEnabled {}; + Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {}; + Utility::DirtyValue<bool> motionSensorOk {}; + Utility::DirtyValue<uint32_t> stepCount {}; + Utility::DirtyValue<bool> 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 <memory> #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<int> batteryPercentRemaining {}; - DirtyValue<bool> powerPresent {}; - DirtyValue<bool> bleState {}; - DirtyValue<bool> bleRadioEnabled {}; - DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {}; - DirtyValue<bool> motionSensorOk {}; - DirtyValue<uint32_t> stepCount {}; - DirtyValue<uint8_t> heartbeat {}; - DirtyValue<bool> heartbeatRunning {}; - DirtyValue<bool> notificationState {}; + Utility::DirtyValue<int> batteryPercentRemaining {}; + Utility::DirtyValue<bool> powerPresent {}; + Utility::DirtyValue<bool> bleState {}; + Utility::DirtyValue<bool> bleRadioEnabled {}; + Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {}; + Utility::DirtyValue<bool> motionSensorOk {}; + Utility::DirtyValue<uint32_t> stepCount {}; + Utility::DirtyValue<uint8_t> heartbeat {}; + Utility::DirtyValue<bool> heartbeatRunning {}; + Utility::DirtyValue<bool> 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<uint8_t> batteryPercentRemaining {}; - Screens::DirtyValue<bool> powerPresent {}; - Screens::DirtyValue<bool> bleState {}; - Screens::DirtyValue<bool> bleRadioEnabled {}; + Utility::DirtyValue<uint8_t> batteryPercentRemaining {}; + Utility::DirtyValue<bool> powerPresent {}; + Utility::DirtyValue<bool> bleState {}; + Utility::DirtyValue<bool> 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 T> + 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 + }; + } +} |
