diff --git a/src/Components/DateTime/DateTimeController.cpp b/src/Components/DateTime/DateTimeController.cpp index 5cfa08eb..30d9c13f 100644 --- a/src/Components/DateTime/DateTimeController.cpp +++ b/src/Components/DateTime/DateTimeController.cpp @@ -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(currentDateTime); auto time = date::make_time(currentDateTime-dp); diff --git a/src/Components/DateTime/DateTimeController.h b/src/Components/DateTime/DateTimeController.h index 1e65bd11..d6020745 100644 --- a/src/Components/DateTime/DateTimeController.h +++ b/src/Components/DateTime/DateTimeController.h @@ -21,6 +21,7 @@ namespace Pinetime { uint8_t Seconds() const { return second; } std::chrono::time_point 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 currentDateTime; - + std::chrono::seconds uptime {0}; }; } } \ No newline at end of file diff --git a/src/DisplayApp/Screens/ScreenList.cpp b/src/DisplayApp/Screens/ScreenList.cpp index 93a91212..a1701688 100644 --- a/src/DisplayApp/Screens/ScreenList.cpp +++ b/src/DisplayApp/Screens/ScreenList.cpp @@ -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);