1
0
Fork 0

Add uptime counter in DateTimeController and display it in SystemInfo screen.

This commit is contained in:
JF 2020-06-07 20:04:43 +02:00
parent baafb96f30
commit e22c0609b5
3 changed files with 18 additions and 3 deletions

View file

@ -47,7 +47,8 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
previousSystickCounter = 0xffffff - (rest - systickCounter);
}
currentDateTime += std::chrono::seconds (correctedDelta);
currentDateTime += std::chrono::seconds(correctedDelta);
uptime += std::chrono::seconds(correctedDelta);
auto dp = date::floor<date::days>(currentDateTime);
auto time = date::make_time(currentDateTime-dp);

View file

@ -21,6 +21,7 @@ namespace Pinetime {
uint8_t Seconds() const { return second; }
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> CurrentDateTime() const { return currentDateTime; }
std::chrono::seconds Uptime() const { return uptime; }
private:
uint16_t year = 0;
Months month = Months::Unknown;
@ -32,7 +33,7 @@ namespace Pinetime {
uint32_t previousSystickCounter = 0;
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> currentDateTime;
std::chrono::seconds uptime {0};
};
}
}

View file

@ -43,19 +43,32 @@ ScreenList::ScreenList(Pinetime::Applications::DisplayApp *app, Pinetime::Contro
}
}();
// uptime
static constexpr uint32_t secondsInADay = 60*60*24;
static constexpr uint32_t secondsInAnHour = 60*60;
static constexpr uint32_t secondsInAMinute = 60;
uint32_t uptimeSeconds = dateTimeController.Uptime().count();
uint32_t uptimeDays = (uptimeSeconds / secondsInADay);
uptimeSeconds = uptimeSeconds % secondsInADay;
uint32_t uptimeHours = uptimeSeconds / secondsInAnHour;
uptimeSeconds = uptimeSeconds % secondsInAnHour;
uint32_t uptimeMinutes = uptimeSeconds / secondsInAMinute;
uptimeSeconds = uptimeSeconds % secondsInAMinute;
// TODO handle more than 100 days of uptime
sprintf(t1, "Pinetime\n"
"Version:%d.%d.%d\n"
"Build: xx/xx/xxxx\n"
"Time: %02d:%02d:%02d\n"
"date: %02d/%02d/%04d\n"
"Uptime: xd xxhxx:xx\n"
"Uptime: %02lud %02lu:%02lu:%02lu\n"
"Battery: %d%%\n"
"Backlight: %d/3\n"
"Last reset: %s\n"
"BLE MAC: \n AA:BB:CC:DD:EE:FF", Version::Major(), Version::Minor(), Version::Patch(),
dateTimeController.Hours(), dateTimeController.Minutes(), dateTimeController.Seconds(),
dateTimeController.Day(), dateTimeController.Month(), dateTimeController.Year(),
uptimeDays, uptimeHours, uptimeMinutes, uptimeSeconds,
batteryPercent, brightness, resetReason);
screens.emplace_back(t1);