@@ -146,6 +146,16 @@ void DisplayApp::Refresh() {
146
146
state = States::Running;
147
147
break ;
148
148
case Messages::UpdateDateTime:
149
+ currentDateTime = {};
150
+ currentDateTime += date::years ( dateTimeController.Year ()-1970 );
151
+ currentDateTime += date::days ( dateTimeController.Day () - 1 );
152
+ currentDateTime += date::months ( (int )dateTimeController.Month () - 1 );
153
+
154
+ currentDateTime += std::chrono::hours (dateTimeController.Hours ());
155
+ currentDateTime += std::chrono::minutes (dateTimeController.Minutes ());
156
+ currentDateTime += std::chrono::seconds (dateTimeController.Seconds ());
157
+
158
+ currentDateTime -= std::chrono::hours (3 ); // TODO WHYYYY?
149
159
break ;
150
160
case Messages::UpdateBleConnection:
151
161
bleConnectionUpdated = true ;
@@ -163,6 +173,15 @@ void DisplayApp::Refresh() {
163
173
164
174
void DisplayApp::RunningState () {
165
175
uint32_t systick_counter = nrf_rtc_counter_get (portNRF_RTC_REG);
176
+ uint32_t systickDelta = 0 ;
177
+ if (systick_counter < previousSystickCounter) {
178
+ systickDelta = 0xffffff - previousSystickCounter;
179
+ systickDelta += systick_counter + 1 ;
180
+ } else {
181
+ systickDelta = systick_counter - previousSystickCounter;
182
+ }
183
+
184
+ previousSystickCounter = systick_counter;
166
185
167
186
if (batteryLevelUpdated) {
168
187
char batteryChar[11 ];
@@ -181,19 +200,8 @@ void DisplayApp::RunningState() {
181
200
gfx->DrawString (10 , 0 , color, " BLE" , &smallFont, false );
182
201
}
183
202
184
- auto raw = systick_counter / 1000 ;
185
- auto currentDeltaSeconds = raw - deltaSeconds;
186
-
187
- std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds> currentDateTime;
188
- currentDateTime += date::years ( dateTimeController.Year ()-1970 );
189
- currentDateTime += date::days ( dateTimeController.Day () - 1 );
190
- currentDateTime += date::months ( (int )dateTimeController.Month () - 1 );
191
-
192
- currentDateTime += std::chrono::hours (dateTimeController.Hours ());
193
- currentDateTime += std::chrono::minutes (dateTimeController.Minutes ());
194
- currentDateTime += std::chrono::seconds (dateTimeController.Seconds () + currentDeltaSeconds);
195
-
196
- currentDateTime -= std::chrono::hours (3 ); // TODO WHYYYY?
203
+ // TODO date/time management should be done in module DateTimeController
204
+ currentDateTime += std::chrono::milliseconds (systickDelta);
197
205
198
206
auto dp = date::floor <date::days>(currentDateTime);
199
207
auto time = date::make_time (currentDateTime-dp);
0 commit comments