Skip to content

Commit 616aa91

Browse files
FintasticManRiksu9000
authored andcommitted
dirtyvalue: Move to src/utility
1 parent 47931f4 commit 616aa91

9 files changed

+103
-92
lines changed

src/displayapp/screens/Screen.h

-35
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,6 @@ namespace Pinetime {
99
class DisplayApp;
1010

1111
namespace Screens {
12-
13-
template <class T>
14-
class DirtyValue {
15-
public:
16-
DirtyValue() = default; // Use NSDMI
17-
18-
explicit DirtyValue(T const& v) : value {v} {
19-
} // Use MIL and const-lvalue-ref
20-
21-
bool IsUpdated() {
22-
if (this->isUpdated) {
23-
this->isUpdated = false;
24-
return true;
25-
}
26-
return false;
27-
}
28-
29-
T const& Get() {
30-
this->isUpdated = false;
31-
return value;
32-
} // never expose a non-const lvalue-ref
33-
34-
DirtyValue& operator=(const T& other) {
35-
if (this->value != other) {
36-
this->value = other;
37-
this->isUpdated = true;
38-
}
39-
return *this;
40-
}
41-
42-
private:
43-
T value {}; // NSDMI - default initialise type
44-
bool isUpdated {true}; // NSDMI - use brace initialisation
45-
};
46-
4712
class Screen {
4813
private:
4914
virtual void Refresh() {

src/displayapp/screens/WatchFaceAnalog.h

+8-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
#include "components/battery/BatteryController.h"
1010
#include "components/ble/BleController.h"
1111
#include "components/ble/NotificationManager.h"
12-
#include <displayapp/screens/BatteryIcon.h>
12+
#include "displayapp/screens/BatteryIcon.h"
13+
#include "utility/DirtyValue.h"
1314

1415
namespace Pinetime {
1516
namespace Controllers {
@@ -37,13 +38,13 @@ namespace Pinetime {
3738
private:
3839
uint8_t sHour, sMinute, sSecond;
3940

40-
DirtyValue<uint8_t> batteryPercentRemaining {0};
41-
DirtyValue<bool> isCharging {};
42-
DirtyValue<bool> bleState {};
43-
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime;
44-
DirtyValue<bool> notificationState {false};
41+
Utility::DirtyValue<uint8_t> batteryPercentRemaining {0};
42+
Utility::DirtyValue<bool> isCharging {};
43+
Utility::DirtyValue<bool> bleState {};
44+
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime;
45+
Utility::DirtyValue<bool> notificationState {false};
4546
using days = std::chrono::duration<int32_t, std::ratio<86400>>; // TODO: days is standard in c++20
46-
DirtyValue<std::chrono::time_point<std::chrono::system_clock, days>> currentDate;
47+
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, days>> currentDate;
4748

4849
lv_obj_t* hour_body;
4950
lv_obj_t* hour_body_trace;

src/displayapp/screens/WatchFaceCasioStyleG7710.h

+11-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "displayapp/screens/Screen.h"
99
#include "components/datetime/DateTimeController.h"
1010
#include "components/ble/BleController.h"
11+
#include "utility/DirtyValue.h"
1112

1213
namespace Pinetime {
1314
namespace Controllers {
@@ -47,16 +48,16 @@ namespace Pinetime {
4748
Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
4849
uint8_t currentDay = 0;
4950

50-
DirtyValue<uint8_t> batteryPercentRemaining {};
51-
DirtyValue<bool> powerPresent {};
52-
DirtyValue<bool> bleState {};
53-
DirtyValue<bool> bleRadioEnabled {};
54-
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
55-
DirtyValue<bool> motionSensorOk {};
56-
DirtyValue<uint32_t> stepCount {};
57-
DirtyValue<uint8_t> heartbeat {};
58-
DirtyValue<bool> heartbeatRunning {};
59-
DirtyValue<bool> notificationState {};
51+
Utility::DirtyValue<uint8_t> batteryPercentRemaining {};
52+
Utility::DirtyValue<bool> powerPresent {};
53+
Utility::DirtyValue<bool> bleState {};
54+
Utility::DirtyValue<bool> bleRadioEnabled {};
55+
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
56+
Utility::DirtyValue<bool> motionSensorOk {};
57+
Utility::DirtyValue<uint32_t> stepCount {};
58+
Utility::DirtyValue<uint8_t> heartbeat {};
59+
Utility::DirtyValue<bool> heartbeatRunning {};
60+
Utility::DirtyValue<bool> notificationState {};
6061

6162
lv_point_t line_icons_points[3] {{0, 5}, {117, 5}, {122, 0}};
6263
lv_point_t line_day_of_week_number_points[4] {{0, 0}, {100, 0}, {95, 95}, {0, 95}};

src/displayapp/screens/WatchFaceDigital.h

+11-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "components/datetime/DateTimeController.h"
99
#include "components/ble/BleController.h"
1010
#include "displayapp/widgets/StatusIcons.h"
11+
#include "utility/DirtyValue.h"
1112

1213
namespace Pinetime {
1314
namespace Controllers {
@@ -44,16 +45,16 @@ namespace Pinetime {
4445
Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
4546
uint8_t currentDay = 0;
4647

47-
DirtyValue<uint8_t> batteryPercentRemaining {};
48-
DirtyValue<bool> powerPresent {};
49-
DirtyValue<bool> bleState {};
50-
DirtyValue<bool> bleRadioEnabled {};
51-
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
52-
DirtyValue<bool> motionSensorOk {};
53-
DirtyValue<uint32_t> stepCount {};
54-
DirtyValue<uint8_t> heartbeat {};
55-
DirtyValue<bool> heartbeatRunning {};
56-
DirtyValue<bool> notificationState {};
48+
Utility::DirtyValue<uint8_t> batteryPercentRemaining {};
49+
Utility::DirtyValue<bool> powerPresent {};
50+
Utility::DirtyValue<bool> bleState {};
51+
Utility::DirtyValue<bool> bleRadioEnabled {};
52+
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
53+
Utility::DirtyValue<bool> motionSensorOk {};
54+
Utility::DirtyValue<uint32_t> stepCount {};
55+
Utility::DirtyValue<uint8_t> heartbeat {};
56+
Utility::DirtyValue<bool> heartbeatRunning {};
57+
Utility::DirtyValue<bool> notificationState {};
5758

5859
lv_obj_t* label_time;
5960
lv_obj_t* label_time_ampm;

src/displayapp/screens/WatchFaceInfineat.h

+9-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <memory>
77
#include "displayapp/screens/Screen.h"
88
#include "components/datetime/DateTimeController.h"
9+
#include "utility/DirtyValue.h"
910

1011
namespace Pinetime {
1112
namespace Controllers {
@@ -51,14 +52,14 @@ namespace Pinetime {
5152
uint32_t savedTick = 0;
5253
uint8_t chargingBatteryPercent = 101; // not a mistake ;)
5354

54-
DirtyValue<uint8_t> batteryPercentRemaining {};
55-
DirtyValue<bool> isCharging {};
56-
DirtyValue<bool> bleState {};
57-
DirtyValue<bool> bleRadioEnabled {};
58-
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
59-
DirtyValue<bool> motionSensorOk {};
60-
DirtyValue<uint32_t> stepCount {};
61-
DirtyValue<bool> notificationState {};
55+
Utility::DirtyValue<uint8_t> batteryPercentRemaining {};
56+
Utility::DirtyValue<bool> isCharging {};
57+
Utility::DirtyValue<bool> bleState {};
58+
Utility::DirtyValue<bool> bleRadioEnabled {};
59+
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
60+
Utility::DirtyValue<bool> motionSensorOk {};
61+
Utility::DirtyValue<uint32_t> stepCount {};
62+
Utility::DirtyValue<bool> notificationState {};
6263

6364
// Lines making up the side cover
6465
lv_obj_t* lineBattery;

src/displayapp/screens/WatchFacePineTimeStyle.h

+9-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "displayapp/Colors.h"
1010
#include "components/datetime/DateTimeController.h"
1111
#include "components/ble/BleController.h"
12+
#include "utility/DirtyValue.h"
1213

1314
namespace Pinetime {
1415
namespace Controllers {
@@ -50,14 +51,14 @@ namespace Pinetime {
5051
uint8_t currentDay = 0;
5152
uint32_t savedTick = 0;
5253

53-
DirtyValue<uint8_t> batteryPercentRemaining {};
54-
DirtyValue<bool> isCharging {};
55-
DirtyValue<bool> bleState {};
56-
DirtyValue<bool> bleRadioEnabled {};
57-
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
58-
DirtyValue<bool> motionSensorOk {};
59-
DirtyValue<uint32_t> stepCount {};
60-
DirtyValue<bool> notificationState {};
54+
Utility::DirtyValue<uint8_t> batteryPercentRemaining {};
55+
Utility::DirtyValue<bool> isCharging {};
56+
Utility::DirtyValue<bool> bleState {};
57+
Utility::DirtyValue<bool> bleRadioEnabled {};
58+
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
59+
Utility::DirtyValue<bool> motionSensorOk {};
60+
Utility::DirtyValue<uint32_t> stepCount {};
61+
Utility::DirtyValue<bool> notificationState {};
6162

6263
static Pinetime::Controllers::Settings::Colors GetNext(Controllers::Settings::Colors color);
6364
static Pinetime::Controllers::Settings::Colors GetPrevious(Controllers::Settings::Colors color);

src/displayapp/screens/WatchFaceTerminal.h

+11-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <memory>
77
#include "displayapp/screens/Screen.h"
88
#include "components/datetime/DateTimeController.h"
9+
#include "utility/DirtyValue.h"
910

1011
namespace Pinetime {
1112
namespace Controllers {
@@ -43,16 +44,16 @@ namespace Pinetime {
4344
Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
4445
uint8_t currentDay = 0;
4546

46-
DirtyValue<int> batteryPercentRemaining {};
47-
DirtyValue<bool> powerPresent {};
48-
DirtyValue<bool> bleState {};
49-
DirtyValue<bool> bleRadioEnabled {};
50-
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
51-
DirtyValue<bool> motionSensorOk {};
52-
DirtyValue<uint32_t> stepCount {};
53-
DirtyValue<uint8_t> heartbeat {};
54-
DirtyValue<bool> heartbeatRunning {};
55-
DirtyValue<bool> notificationState {};
47+
Utility::DirtyValue<int> batteryPercentRemaining {};
48+
Utility::DirtyValue<bool> powerPresent {};
49+
Utility::DirtyValue<bool> bleState {};
50+
Utility::DirtyValue<bool> bleRadioEnabled {};
51+
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
52+
Utility::DirtyValue<bool> motionSensorOk {};
53+
Utility::DirtyValue<uint32_t> stepCount {};
54+
Utility::DirtyValue<uint8_t> heartbeat {};
55+
Utility::DirtyValue<bool> heartbeatRunning {};
56+
Utility::DirtyValue<bool> notificationState {};
5657

5758
lv_obj_t* label_time;
5859
lv_obj_t* label_date;

src/displayapp/widgets/StatusIcons.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "components/battery/BatteryController.h"
77
#include "components/ble/BleController.h"
88
#include "displayapp/screens/BatteryIcon.h"
9+
#include "utility/DirtyValue.h"
910

1011
namespace Pinetime {
1112
namespace Applications {
@@ -27,10 +28,10 @@ namespace Pinetime {
2728
const Pinetime::Controllers::Battery& batteryController;
2829
const Controllers::Ble& bleController;
2930

30-
Screens::DirtyValue<uint8_t> batteryPercentRemaining {};
31-
Screens::DirtyValue<bool> powerPresent {};
32-
Screens::DirtyValue<bool> bleState {};
33-
Screens::DirtyValue<bool> bleRadioEnabled {};
31+
Utility::DirtyValue<uint8_t> batteryPercentRemaining {};
32+
Utility::DirtyValue<bool> powerPresent {};
33+
Utility::DirtyValue<bool> bleState {};
34+
Utility::DirtyValue<bool> bleRadioEnabled {};
3435

3536
lv_obj_t* bleIcon;
3637
lv_obj_t* batteryPlug;

src/utility/DirtyValue.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
namespace Pinetime {
4+
namespace Utility {
5+
template <class T>
6+
class DirtyValue {
7+
public:
8+
DirtyValue() = default; // Use NSDMI
9+
10+
explicit DirtyValue(T const& v) : value {v} {
11+
} // Use MIL and const-lvalue-ref
12+
13+
bool IsUpdated() {
14+
if (this->isUpdated) {
15+
this->isUpdated = false;
16+
return true;
17+
}
18+
return false;
19+
}
20+
21+
T const& Get() {
22+
this->isUpdated = false;
23+
return value;
24+
} // never expose a non-const lvalue-ref
25+
26+
DirtyValue& operator=(const T& other) {
27+
if (this->value != other) {
28+
this->value = other;
29+
this->isUpdated = true;
30+
}
31+
return *this;
32+
}
33+
34+
private:
35+
T value {}; // NSDMI - default initialise type
36+
bool isUpdated {true}; // NSDMI - use brace initialisation
37+
};
38+
}
39+
}

0 commit comments

Comments
 (0)