diff options
| author | JF002 <JF002@users.noreply.github.com> | 2020-01-11 16:16:52 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-11 16:16:52 (GMT) |
| commit | 9baf00bbfeac1dbc3188687e91073e3adffc887e (patch) | |
| tree | d6bd678423115256c30437dd85762ca9fd86bb60 /src/DisplayApp/DisplayApp.cpp | |
| parent | 04c7b1429f3d5c947c051f405846bd1fa72f2bf8 (diff) | |
| parent | 8253c099d9178c275f0d0d4ea7766f54afd0b38d (diff) | |
Merge pull request #11 from JF002/date-library
Date/Time management
Diffstat (limited to 'src/DisplayApp/DisplayApp.cpp')
| -rw-r--r-- | src/DisplayApp/DisplayApp.cpp | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/src/DisplayApp/DisplayApp.cpp b/src/DisplayApp/DisplayApp.cpp index 2a26f18..99c606d 100644 --- a/src/DisplayApp/DisplayApp.cpp +++ b/src/DisplayApp/DisplayApp.cpp @@ -9,6 +9,9 @@ #include <queue.h> #include <Components/DateTime/DateTimeController.h> #include <drivers/Cst816s.h> +#include <chrono> +#include <string> +#include <date/date.h> using namespace Pinetime::Applications; @@ -102,6 +105,11 @@ void DisplayApp::InitHw() { gfx->DrawString(10, 0, 0x0000, "BLE", &smallFont, false); gfx->DrawString(20, 180, 0xffff, "", &smallFont, false); + currentChar[0] = 0; + currentChar[1] = 0; + currentChar[2] = 0; + currentChar[3] = 0; + touchPanel.Init(); } @@ -138,11 +146,6 @@ void DisplayApp::Refresh() { state = States::Running; break; case Messages::UpdateDateTime: - deltaSeconds = nrf_rtc_counter_get(portNRF_RTC_REG) / 1000; - this->seconds = dateTimeController.Seconds(); - this->minutes = dateTimeController.Minutes(); - this->hours = dateTimeController.Hours(); - dateUpdated = true; break; case Messages::UpdateBleConnection: bleConnectionUpdated = true; @@ -181,18 +184,35 @@ void DisplayApp::RunningState() { auto raw = systick_counter / 1000; auto currentDeltaSeconds = raw - deltaSeconds; - auto deltaMinutes = (currentDeltaSeconds / 60); - auto currentMinutes = minutes + deltaMinutes; + std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds> 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? + + auto dp = date::floor<date::days>(currentDateTime); + auto time = date::make_time(currentDateTime-dp); + auto ymd = date::year_month_day(dp); - auto deltaHours = currentMinutes / 60; - currentMinutes -= (deltaHours * 60); - auto currentHours = hours + deltaHours; + auto year = (int)ymd.year(); + auto month = (unsigned)ymd.month(); + auto day = (unsigned)ymd.day(); + auto weekday = date::weekday(ymd); + + auto hh = time.hours().count(); + auto mm = time.minutes().count(); + auto ss = time.seconds().count(); char minutesChar[3]; - sprintf(minutesChar, "%02d", currentMinutes); + sprintf(minutesChar, "%02d", mm); char hoursChar[3]; - sprintf(hoursChar, "%02d", currentHours); + sprintf(hoursChar, "%02d", hh); uint8_t x = 7; if (hoursChar[0] != currentChar[0]) { @@ -218,16 +238,13 @@ void DisplayApp::RunningState() { currentChar[3] = minutesChar[1]; } - if (dateUpdated) { - auto year = dateTimeController.Year(); - auto month = dateTimeController.Month(); - auto day = dateTimeController.Day(); - auto dayOfWeek = dateTimeController.DayOfWeek(); - + if (ymd != currentYmd) { + gfx->FillRectangle(0,180, 240, 15, 0x0000); char dateStr[22]; - sprintf(dateStr, "%s %d %s %d", DayOfWeekToString(dayOfWeek), day, MonthToString(month), year); + sprintf(dateStr, "%s %d %s %d", DayOfWeekToString(Pinetime::Controllers::DateTime::Days(weekday.iso_encoding())), day, MonthToString((Pinetime::Controllers::DateTime::Months )month), year); gfx->DrawString(10, 180, 0xffff, dateStr, &smallFont, false); - dateUpdated = false; + + currentYmd = ymd; } } |
