Make Clock Persistant.
This commit is contained in:
@@ -5,6 +5,10 @@
|
||||
|
||||
using namespace Pinetime::Controllers;
|
||||
|
||||
void DateTime::SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t) {
|
||||
this->currentDateTime = t;
|
||||
}
|
||||
|
||||
void DateTime::SetTime(
|
||||
uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute, uint8_t second, uint32_t systickCounter) {
|
||||
std::tm tm = {
|
||||
@@ -67,11 +71,12 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
|
||||
// Notify new day to SystemTask
|
||||
if (hour == 0 and not isMidnightAlreadyNotified) {
|
||||
isMidnightAlreadyNotified = true;
|
||||
if(systemTask != nullptr)
|
||||
if (systemTask != nullptr)
|
||||
systemTask->PushMessage(System::Messages::OnNewDay);
|
||||
} else if (hour != 0) {
|
||||
isMidnightAlreadyNotified = false;
|
||||
}
|
||||
BackUpTime = currentDateTime;
|
||||
}
|
||||
|
||||
const char* DateTime::MonthShortToString() {
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <chrono>
|
||||
extern std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> BackUpTime;
|
||||
|
||||
namespace Pinetime {
|
||||
namespace System {
|
||||
@@ -74,6 +75,7 @@ namespace Pinetime {
|
||||
}
|
||||
|
||||
void Register(System::SystemTask* systemTask);
|
||||
void SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t);
|
||||
|
||||
private:
|
||||
uint16_t year = 0;
|
||||
|
11
src/main.cpp
11
src/main.cpp
@@ -124,7 +124,6 @@ Pinetime::Controllers::FS fs {spiNorFlash};
|
||||
Pinetime::Controllers::Settings settingsController {fs};
|
||||
Pinetime::Controllers::MotorController motorController {settingsController};
|
||||
|
||||
|
||||
Pinetime::Applications::DisplayApp displayApp(lcd,
|
||||
lvgl,
|
||||
touchPanel,
|
||||
@@ -161,6 +160,9 @@ Pinetime::System::SystemTask systemTask(spi,
|
||||
heartRateApp,
|
||||
fs);
|
||||
|
||||
uint32_t MAGIC_RAM __attribute__((section(".noinit")));
|
||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> BackUpTime __attribute__((section(".noinit")));
|
||||
|
||||
void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
|
||||
if (pin == pinTouchIrq) {
|
||||
systemTask.OnTouchEvent();
|
||||
@@ -321,6 +323,13 @@ int main(void) {
|
||||
// retrieve version stored by bootloader
|
||||
Pinetime::BootloaderVersion::SetVersion(NRF_TIMER2->CC[0]);
|
||||
|
||||
// Check Magic Ram and reset lost variables
|
||||
if (MAGIC_RAM == 0xDEADBEEF) {
|
||||
dateTimeController.SetCurrentTime(BackUpTime);
|
||||
} else {
|
||||
MAGIC_RAM = 0xDEADBEEF;
|
||||
}
|
||||
|
||||
lvgl.Init();
|
||||
|
||||
systemTask.Start();
|
||||
|
Reference in New Issue
Block a user