dirtyvalue: Move to src/utility
This commit is contained in:
parent
47931f41d5
commit
616aa91b4c
|
@ -9,41 +9,6 @@ namespace Pinetime {
|
||||||
class DisplayApp;
|
class DisplayApp;
|
||||||
|
|
||||||
namespace Screens {
|
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 {
|
class Screen {
|
||||||
private:
|
private:
|
||||||
virtual void Refresh() {
|
virtual void Refresh() {
|
||||||
|
|
|
@ -9,7 +9,8 @@
|
||||||
#include "components/battery/BatteryController.h"
|
#include "components/battery/BatteryController.h"
|
||||||
#include "components/ble/BleController.h"
|
#include "components/ble/BleController.h"
|
||||||
#include "components/ble/NotificationManager.h"
|
#include "components/ble/NotificationManager.h"
|
||||||
#include <displayapp/screens/BatteryIcon.h>
|
#include "displayapp/screens/BatteryIcon.h"
|
||||||
|
#include "utility/DirtyValue.h"
|
||||||
|
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
namespace Controllers {
|
namespace Controllers {
|
||||||
|
@ -37,13 +38,13 @@ namespace Pinetime {
|
||||||
private:
|
private:
|
||||||
uint8_t sHour, sMinute, sSecond;
|
uint8_t sHour, sMinute, sSecond;
|
||||||
|
|
||||||
DirtyValue<uint8_t> batteryPercentRemaining {0};
|
Utility::DirtyValue<uint8_t> batteryPercentRemaining {0};
|
||||||
DirtyValue<bool> isCharging {};
|
Utility::DirtyValue<bool> isCharging {};
|
||||||
DirtyValue<bool> bleState {};
|
Utility::DirtyValue<bool> bleState {};
|
||||||
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime;
|
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime;
|
||||||
DirtyValue<bool> notificationState {false};
|
Utility::DirtyValue<bool> notificationState {false};
|
||||||
using days = std::chrono::duration<int32_t, std::ratio<86400>>; // TODO: days is standard in c++20
|
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;
|
||||||
lv_obj_t* hour_body_trace;
|
lv_obj_t* hour_body_trace;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "displayapp/screens/Screen.h"
|
#include "displayapp/screens/Screen.h"
|
||||||
#include "components/datetime/DateTimeController.h"
|
#include "components/datetime/DateTimeController.h"
|
||||||
#include "components/ble/BleController.h"
|
#include "components/ble/BleController.h"
|
||||||
|
#include "utility/DirtyValue.h"
|
||||||
|
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
namespace Controllers {
|
namespace Controllers {
|
||||||
|
@ -47,16 +48,16 @@ namespace Pinetime {
|
||||||
Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
|
Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
|
||||||
uint8_t currentDay = 0;
|
uint8_t currentDay = 0;
|
||||||
|
|
||||||
DirtyValue<uint8_t> batteryPercentRemaining {};
|
Utility::DirtyValue<uint8_t> batteryPercentRemaining {};
|
||||||
DirtyValue<bool> powerPresent {};
|
Utility::DirtyValue<bool> powerPresent {};
|
||||||
DirtyValue<bool> bleState {};
|
Utility::DirtyValue<bool> bleState {};
|
||||||
DirtyValue<bool> bleRadioEnabled {};
|
Utility::DirtyValue<bool> bleRadioEnabled {};
|
||||||
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
|
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
|
||||||
DirtyValue<bool> motionSensorOk {};
|
Utility::DirtyValue<bool> motionSensorOk {};
|
||||||
DirtyValue<uint32_t> stepCount {};
|
Utility::DirtyValue<uint32_t> stepCount {};
|
||||||
DirtyValue<uint8_t> heartbeat {};
|
Utility::DirtyValue<uint8_t> heartbeat {};
|
||||||
DirtyValue<bool> heartbeatRunning {};
|
Utility::DirtyValue<bool> heartbeatRunning {};
|
||||||
DirtyValue<bool> notificationState {};
|
Utility::DirtyValue<bool> notificationState {};
|
||||||
|
|
||||||
lv_point_t line_icons_points[3] {{0, 5}, {117, 5}, {122, 0}};
|
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}};
|
lv_point_t line_day_of_week_number_points[4] {{0, 0}, {100, 0}, {95, 95}, {0, 95}};
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "components/datetime/DateTimeController.h"
|
#include "components/datetime/DateTimeController.h"
|
||||||
#include "components/ble/BleController.h"
|
#include "components/ble/BleController.h"
|
||||||
#include "displayapp/widgets/StatusIcons.h"
|
#include "displayapp/widgets/StatusIcons.h"
|
||||||
|
#include "utility/DirtyValue.h"
|
||||||
|
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
namespace Controllers {
|
namespace Controllers {
|
||||||
|
@ -44,16 +45,16 @@ namespace Pinetime {
|
||||||
Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
|
Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
|
||||||
uint8_t currentDay = 0;
|
uint8_t currentDay = 0;
|
||||||
|
|
||||||
DirtyValue<uint8_t> batteryPercentRemaining {};
|
Utility::DirtyValue<uint8_t> batteryPercentRemaining {};
|
||||||
DirtyValue<bool> powerPresent {};
|
Utility::DirtyValue<bool> powerPresent {};
|
||||||
DirtyValue<bool> bleState {};
|
Utility::DirtyValue<bool> bleState {};
|
||||||
DirtyValue<bool> bleRadioEnabled {};
|
Utility::DirtyValue<bool> bleRadioEnabled {};
|
||||||
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
|
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
|
||||||
DirtyValue<bool> motionSensorOk {};
|
Utility::DirtyValue<bool> motionSensorOk {};
|
||||||
DirtyValue<uint32_t> stepCount {};
|
Utility::DirtyValue<uint32_t> stepCount {};
|
||||||
DirtyValue<uint8_t> heartbeat {};
|
Utility::DirtyValue<uint8_t> heartbeat {};
|
||||||
DirtyValue<bool> heartbeatRunning {};
|
Utility::DirtyValue<bool> heartbeatRunning {};
|
||||||
DirtyValue<bool> notificationState {};
|
Utility::DirtyValue<bool> notificationState {};
|
||||||
|
|
||||||
lv_obj_t* label_time;
|
lv_obj_t* label_time;
|
||||||
lv_obj_t* label_time_ampm;
|
lv_obj_t* label_time_ampm;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "displayapp/screens/Screen.h"
|
#include "displayapp/screens/Screen.h"
|
||||||
#include "components/datetime/DateTimeController.h"
|
#include "components/datetime/DateTimeController.h"
|
||||||
|
#include "utility/DirtyValue.h"
|
||||||
|
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
namespace Controllers {
|
namespace Controllers {
|
||||||
|
@ -51,14 +52,14 @@ namespace Pinetime {
|
||||||
uint32_t savedTick = 0;
|
uint32_t savedTick = 0;
|
||||||
uint8_t chargingBatteryPercent = 101; // not a mistake ;)
|
uint8_t chargingBatteryPercent = 101; // not a mistake ;)
|
||||||
|
|
||||||
DirtyValue<uint8_t> batteryPercentRemaining {};
|
Utility::DirtyValue<uint8_t> batteryPercentRemaining {};
|
||||||
DirtyValue<bool> isCharging {};
|
Utility::DirtyValue<bool> isCharging {};
|
||||||
DirtyValue<bool> bleState {};
|
Utility::DirtyValue<bool> bleState {};
|
||||||
DirtyValue<bool> bleRadioEnabled {};
|
Utility::DirtyValue<bool> bleRadioEnabled {};
|
||||||
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
|
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
|
||||||
DirtyValue<bool> motionSensorOk {};
|
Utility::DirtyValue<bool> motionSensorOk {};
|
||||||
DirtyValue<uint32_t> stepCount {};
|
Utility::DirtyValue<uint32_t> stepCount {};
|
||||||
DirtyValue<bool> notificationState {};
|
Utility::DirtyValue<bool> notificationState {};
|
||||||
|
|
||||||
// Lines making up the side cover
|
// Lines making up the side cover
|
||||||
lv_obj_t* lineBattery;
|
lv_obj_t* lineBattery;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "displayapp/Colors.h"
|
#include "displayapp/Colors.h"
|
||||||
#include "components/datetime/DateTimeController.h"
|
#include "components/datetime/DateTimeController.h"
|
||||||
#include "components/ble/BleController.h"
|
#include "components/ble/BleController.h"
|
||||||
|
#include "utility/DirtyValue.h"
|
||||||
|
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
namespace Controllers {
|
namespace Controllers {
|
||||||
|
@ -50,14 +51,14 @@ namespace Pinetime {
|
||||||
uint8_t currentDay = 0;
|
uint8_t currentDay = 0;
|
||||||
uint32_t savedTick = 0;
|
uint32_t savedTick = 0;
|
||||||
|
|
||||||
DirtyValue<uint8_t> batteryPercentRemaining {};
|
Utility::DirtyValue<uint8_t> batteryPercentRemaining {};
|
||||||
DirtyValue<bool> isCharging {};
|
Utility::DirtyValue<bool> isCharging {};
|
||||||
DirtyValue<bool> bleState {};
|
Utility::DirtyValue<bool> bleState {};
|
||||||
DirtyValue<bool> bleRadioEnabled {};
|
Utility::DirtyValue<bool> bleRadioEnabled {};
|
||||||
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
|
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
|
||||||
DirtyValue<bool> motionSensorOk {};
|
Utility::DirtyValue<bool> motionSensorOk {};
|
||||||
DirtyValue<uint32_t> stepCount {};
|
Utility::DirtyValue<uint32_t> stepCount {};
|
||||||
DirtyValue<bool> notificationState {};
|
Utility::DirtyValue<bool> notificationState {};
|
||||||
|
|
||||||
static Pinetime::Controllers::Settings::Colors GetNext(Controllers::Settings::Colors color);
|
static Pinetime::Controllers::Settings::Colors GetNext(Controllers::Settings::Colors color);
|
||||||
static Pinetime::Controllers::Settings::Colors GetPrevious(Controllers::Settings::Colors color);
|
static Pinetime::Controllers::Settings::Colors GetPrevious(Controllers::Settings::Colors color);
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "displayapp/screens/Screen.h"
|
#include "displayapp/screens/Screen.h"
|
||||||
#include "components/datetime/DateTimeController.h"
|
#include "components/datetime/DateTimeController.h"
|
||||||
|
#include "utility/DirtyValue.h"
|
||||||
|
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
namespace Controllers {
|
namespace Controllers {
|
||||||
|
@ -43,16 +44,16 @@ namespace Pinetime {
|
||||||
Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
|
Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
|
||||||
uint8_t currentDay = 0;
|
uint8_t currentDay = 0;
|
||||||
|
|
||||||
DirtyValue<int> batteryPercentRemaining {};
|
Utility::DirtyValue<int> batteryPercentRemaining {};
|
||||||
DirtyValue<bool> powerPresent {};
|
Utility::DirtyValue<bool> powerPresent {};
|
||||||
DirtyValue<bool> bleState {};
|
Utility::DirtyValue<bool> bleState {};
|
||||||
DirtyValue<bool> bleRadioEnabled {};
|
Utility::DirtyValue<bool> bleRadioEnabled {};
|
||||||
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
|
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
|
||||||
DirtyValue<bool> motionSensorOk {};
|
Utility::DirtyValue<bool> motionSensorOk {};
|
||||||
DirtyValue<uint32_t> stepCount {};
|
Utility::DirtyValue<uint32_t> stepCount {};
|
||||||
DirtyValue<uint8_t> heartbeat {};
|
Utility::DirtyValue<uint8_t> heartbeat {};
|
||||||
DirtyValue<bool> heartbeatRunning {};
|
Utility::DirtyValue<bool> heartbeatRunning {};
|
||||||
DirtyValue<bool> notificationState {};
|
Utility::DirtyValue<bool> notificationState {};
|
||||||
|
|
||||||
lv_obj_t* label_time;
|
lv_obj_t* label_time;
|
||||||
lv_obj_t* label_date;
|
lv_obj_t* label_date;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "components/battery/BatteryController.h"
|
#include "components/battery/BatteryController.h"
|
||||||
#include "components/ble/BleController.h"
|
#include "components/ble/BleController.h"
|
||||||
#include "displayapp/screens/BatteryIcon.h"
|
#include "displayapp/screens/BatteryIcon.h"
|
||||||
|
#include "utility/DirtyValue.h"
|
||||||
|
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
namespace Applications {
|
namespace Applications {
|
||||||
|
@ -27,10 +28,10 @@ namespace Pinetime {
|
||||||
const Pinetime::Controllers::Battery& batteryController;
|
const Pinetime::Controllers::Battery& batteryController;
|
||||||
const Controllers::Ble& bleController;
|
const Controllers::Ble& bleController;
|
||||||
|
|
||||||
Screens::DirtyValue<uint8_t> batteryPercentRemaining {};
|
Utility::DirtyValue<uint8_t> batteryPercentRemaining {};
|
||||||
Screens::DirtyValue<bool> powerPresent {};
|
Utility::DirtyValue<bool> powerPresent {};
|
||||||
Screens::DirtyValue<bool> bleState {};
|
Utility::DirtyValue<bool> bleState {};
|
||||||
Screens::DirtyValue<bool> bleRadioEnabled {};
|
Utility::DirtyValue<bool> bleRadioEnabled {};
|
||||||
|
|
||||||
lv_obj_t* bleIcon;
|
lv_obj_t* bleIcon;
|
||||||
lv_obj_t* batteryPlug;
|
lv_obj_t* batteryPlug;
|
||||||
|
|
39
src/utility/DirtyValue.h
Normal file
39
src/utility/DirtyValue.h
Normal file
|
@ -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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue