From 751ffab497f0722fa2e117915fea47a0e1f4a900 Mon Sep 17 00:00:00 2001 From: Niall Cooling Date: Fri, 12 Feb 2021 17:13:02 +0000 Subject: refactored class DirtyValue --- src/displayapp/screens/Clock.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/displayapp/screens/Clock.h') diff --git a/src/displayapp/screens/Clock.h b/src/displayapp/screens/Clock.h index 3a4c67a3..18d70532 100644 --- a/src/displayapp/screens/Clock.h +++ b/src/displayapp/screens/Clock.h @@ -21,11 +21,10 @@ namespace Pinetime { template class DirtyValue { public: - explicit DirtyValue(T v) { value = v; } - explicit DirtyValue(T& v) { value = v; } + DirtyValue() = default; // Use NSDMI + explicit DirtyValue(T const& v):value{v}{} // Use MIL and const-lvalue-ref bool IsUpdated() const { return isUpdated; } - T& Get() { this->isUpdated = false; return value; } - + 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; @@ -34,9 +33,10 @@ namespace Pinetime { return *this; } private: - T value; - bool isUpdated = true; + T value{}; // NSDMI - default initialise type + bool isUpdated{true}; // NSDMI - use brace initilisation }; + class Clock : public Screen { public: Clock(DisplayApp* app, @@ -64,13 +64,13 @@ namespace Pinetime { Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown; uint8_t currentDay = 0; - DirtyValue batteryPercentRemaining {0}; - DirtyValue bleState {false}; - DirtyValue> currentDateTime; - DirtyValue stepCount {0}; - DirtyValue heartbeat {0}; - DirtyValue heartbeatRunning {false}; - DirtyValue notificationState {false}; + DirtyValue batteryPercentRemaining {}; + DirtyValue bleState {}; + DirtyValue> currentDateTime{}; + DirtyValue stepCount {}; + DirtyValue heartbeat {}; + DirtyValue heartbeatRunning {}; + DirtyValue notificationState {}; lv_obj_t* label_time; lv_obj_t* label_date; -- cgit v1.2.3-70-g09d2 From d34a5101584bfca81a1f00ca57e32d55b50d55e5 Mon Sep 17 00:00:00 2001 From: Niall Cooling Date: Wed, 3 Mar 2021 17:07:05 +0000 Subject: Moved private statics into unnamed namespace in cpp file to reduce coupling and uncessar in header --- src/displayapp/screens/Clock.cpp | 73 +++++++++++++++++++++------------------- src/displayapp/screens/Clock.h | 5 --- 2 files changed, 39 insertions(+), 39 deletions(-) (limited to 'src/displayapp/screens/Clock.h') diff --git a/src/displayapp/screens/Clock.cpp b/src/displayapp/screens/Clock.cpp index 4b280adb..eb0e37be 100644 --- a/src/displayapp/screens/Clock.cpp +++ b/src/displayapp/screens/Clock.cpp @@ -15,6 +15,45 @@ using namespace Pinetime::Applications::Screens; +namespace { + +char const *DaysString[] = { + "", + "MONDAY", + "TUESDAY", + "WEDNESDAY", + "THURSDAY", + "FRIDAY", + "SATURDAY", + "SUNDAY" +}; + +char const *MonthsString[] = { + "", + "JAN", + "FEB", + "MAR", + "APR", + "MAY", + "JUN", + "JUL", + "AUG", + "SEP", + "OCT", + "NOV", + "DEC" +}; + +const char *MonthToString(Pinetime::Controllers::DateTime::Months month) { + return MonthsString[static_cast(month)]; +} + +const char *DayOfWeekToString(Pinetime::Controllers::DateTime::Days dayOfWeek) { + return DaysString[static_cast(dayOfWeek)]; +} + +} + static void event_handler(lv_obj_t * obj, lv_event_t event) { Clock* screen = static_cast(obj->user_data); screen->OnObjectEvent(obj, event); @@ -200,40 +239,6 @@ bool Clock::Refresh() { return running; } -const char *Clock::MonthToString(Pinetime::Controllers::DateTime::Months month) { - return Clock::MonthsString[static_cast(month)]; -} - -const char *Clock::DayOfWeekToString(Pinetime::Controllers::DateTime::Days dayOfWeek) { - return Clock::DaysString[static_cast(dayOfWeek)]; -} - -char const *Clock::DaysString[] = { - "", - "MONDAY", - "TUESDAY", - "WEDNESDAY", - "THURSDAY", - "FRIDAY", - "SATURDAY", - "SUNDAY" -}; - -char const *Clock::MonthsString[] = { - "", - "JAN", - "FEB", - "MAR", - "APR", - "MAY", - "JUN", - "JUL", - "AUG", - "SEP", - "OCT", - "NOV", - "DEC" -}; void Clock::OnObjectEvent(lv_obj_t *obj, lv_event_t event) { if(obj == backgroundLabel) { diff --git a/src/displayapp/screens/Clock.h b/src/displayapp/screens/Clock.h index 18d70532..5e9cfeaa 100644 --- a/src/displayapp/screens/Clock.h +++ b/src/displayapp/screens/Clock.h @@ -52,11 +52,6 @@ namespace Pinetime { void OnObjectEvent(lv_obj_t *pObj, lv_event_t i); private: - static const char* MonthToString(Pinetime::Controllers::DateTime::Months month); - static const char* DayOfWeekToString(Pinetime::Controllers::DateTime::Days dayOfWeek); - static char const *DaysString[]; - static char const *MonthsString[]; - char displayedChar[5]; uint16_t currentYear = 1970; -- cgit v1.2.3-70-g09d2