diff --git a/src/DisplayApp/DisplayApp.cpp b/src/DisplayApp/DisplayApp.cpp index 99c606d3..8bfb8b03 100644 --- a/src/DisplayApp/DisplayApp.cpp +++ b/src/DisplayApp/DisplayApp.cpp @@ -146,6 +146,16 @@ void DisplayApp::Refresh() { state = States::Running; break; case Messages::UpdateDateTime: + currentDateTime = {}; + currentDateTime += date::years( dateTimeController.Year()-1970); + currentDateTime += date::days( dateTimeController.Day() - 1); + currentDateTime += date::months( (int)dateTimeController.Month() - 1); + + currentDateTime += std::chrono::hours(dateTimeController.Hours()); + currentDateTime += std::chrono::minutes (dateTimeController.Minutes()); + currentDateTime += std::chrono::seconds (dateTimeController.Seconds()); + + currentDateTime -= std::chrono::hours(3); // TODO WHYYYY? break; case Messages::UpdateBleConnection: bleConnectionUpdated = true; @@ -163,6 +173,15 @@ void DisplayApp::Refresh() { void DisplayApp::RunningState() { uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG); + uint32_t systickDelta = 0; + if(systick_counter < previousSystickCounter) { + systickDelta = 0xffffff - previousSystickCounter; + systickDelta += systick_counter + 1; + } else { + systickDelta = systick_counter - previousSystickCounter; + } + + previousSystickCounter = systick_counter; if (batteryLevelUpdated) { char batteryChar[11]; @@ -181,19 +200,8 @@ void DisplayApp::RunningState() { gfx->DrawString(10, 0, color, "BLE", &smallFont, false); } - auto raw = systick_counter / 1000; - auto currentDeltaSeconds = raw - deltaSeconds; - - std::chrono::time_point currentDateTime; - currentDateTime += date::years( dateTimeController.Year()-1970); - currentDateTime += date::days( dateTimeController.Day() - 1); - currentDateTime += date::months( (int)dateTimeController.Month() - 1); - - currentDateTime += std::chrono::hours(dateTimeController.Hours()); - currentDateTime += std::chrono::minutes (dateTimeController.Minutes()); - currentDateTime += std::chrono::seconds(dateTimeController.Seconds() + currentDeltaSeconds); - - currentDateTime -= std::chrono::hours(3); // TODO WHYYYY? + // TODO date/time management should be done in module DateTimeController + currentDateTime += std::chrono::milliseconds(systickDelta); auto dp = date::floor(currentDateTime); auto time = date::make_time(currentDateTime-dp); diff --git a/src/DisplayApp/DisplayApp.h b/src/DisplayApp/DisplayApp.h index 1e9e2e89..7e717ff8 100644 --- a/src/DisplayApp/DisplayApp.h +++ b/src/DisplayApp/DisplayApp.h @@ -65,6 +65,8 @@ namespace Pinetime { Pinetime::Drivers::Cst816S touchPanel; void OnTouchEvent(); + uint32_t previousSystickCounter = 0; + std::chrono::time_point currentDateTime; }; } } diff --git a/src/FreeRTOSConfig.h b/src/FreeRTOSConfig.h index b4aea161..ecc631bb 100644 --- a/src/FreeRTOSConfig.h +++ b/src/FreeRTOSConfig.h @@ -58,7 +58,7 @@ #define configUSE_PREEMPTION 1 #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 #define configUSE_TICKLESS_IDLE 1 -#define configUSE_TICKLESS_IDLE_SIMPLE_DEBUG 1 /* See into vPortSuppressTicksAndSleep source code for explanation */ +#define configUSE_TICKLESS_IDLE_SIMPLE_DEBUG 0 /* See into vPortSuppressTicksAndSleep source code for explanation */ #define configCPU_CLOCK_HZ ( SystemCoreClock ) #define configTICK_RATE_HZ 1024 #define configMAX_PRIORITIES ( 3 )