From 5736300527fe92f129b8f4d6a1874166be1fb22d Mon Sep 17 00:00:00 2001 From: Ruffalo-sunghwan Date: Sun, 8 May 2022 19:58:32 +0900 Subject: [PATCH] HAL : merged and default param --- include/osw_hal.h | 10 ++++++-- src/hal/time.cpp | 64 ++++++++++++++++++++++++++++++++++++----------- 2 files changed, 58 insertions(+), 16 deletions(-) diff --git a/include/osw_hal.h b/include/osw_hal.h index 98630045f..e5fa33920 100644 --- a/include/osw_hal.h +++ b/include/osw_hal.h @@ -151,12 +151,18 @@ class OswHal { time_t getUTCTime(); void getUTCTime(uint32_t* hour, uint32_t* minute, uint32_t* second); uint32_t getLocalTime(); - void getLocalTime(uint32_t* hour, uint32_t* minute, uint32_t* second); - void getLocalTime(uint32_t* hour, uint32_t* minute, uint32_t* second, bool* afterNoon); + void getLocalTime(uint32_t* hour, uint32_t* minute, uint32_t* second, bool* afterNoon = nullptr); void getDate(uint32_t* day, uint32_t* weekDay); void getDate(uint32_t* day, uint32_t* month, uint32_t* year); const char* getWeekday(); + // Dual-Time + uint32_t getDualTime(); + void getDualTime(uint32_t* hour, uint32_t* minute, uint32_t* second, bool* afterNoon = nullptr); + void getDualDate(uint32_t* day, uint32_t* weekDay); + void getDualDate(uint32_t* day, uint32_t* month, uint32_t* year); + const char* getDualWeekday(); + bool _requestDisableBuffer = false; bool _requestEnableBuffer = false; Button buttons[NUM_BUTTONS] = {BUTTON_1, BUTTON_2, BUTTON_3}; diff --git a/src/hal/time.cpp b/src/hal/time.cpp index f1d16fd8e..1e742d8c9 100644 --- a/src/hal/time.cpp +++ b/src/hal/time.cpp @@ -39,70 +39,106 @@ void OswHal::getUTCTime(uint32_t *hour, uint32_t *minute, uint32_t *second) { *second = d.Second(); } -void OswHal::getLocalTime(uint32_t *hour, uint32_t *minute, uint32_t *second) { +void OswHal::getLocalTime(uint32_t *hour, uint32_t *minute, uint32_t *second, bool *afterNoon) { RtcDateTime d = RtcDateTime(); d.InitWithEpoch32Time(this->getLocalTime()); if (!OswConfigAllKeys::timeFormat.get()) { if (d.Hour() > 12) { *hour = d.Hour() - 12; + if (afterNoon!=nullptr) *afterNoon = true; } else if (d.Hour() == 0) { *hour = 12; + if (afterNoon != nullptr) *afterNoon = false; + } else if (d.Hour() == 12) { + *hour = d.Hour(); + if (afterNoon != nullptr) *afterNoon = true; } else { *hour = d.Hour(); + if (afterNoon != nullptr) *afterNoon = false; } } else { *hour = d.Hour(); + if (afterNoon != nullptr) *afterNoon = false; } *minute = d.Minute(); *second = d.Second(); } -void OswHal::getLocalTime(uint32_t *hour, uint32_t *minute, uint32_t *second, bool *afterNoon) { +void OswHal::getDate(uint32_t *day, uint32_t *weekDay) { RtcDateTime d = RtcDateTime(); d.InitWithEpoch32Time(this->getLocalTime()); + *weekDay = d.DayOfWeek(); + *day = d.Day(); +} + +void OswHal::getDate(uint32_t *day, uint32_t *month, uint32_t *year) { + RtcDateTime d = RtcDateTime(); + d.InitWithEpoch32Time(getLocalTime()); + *day = d.Day(); + *month = d.Month(); + *year = d.Year(); +} + +const char *OswHal::getWeekday() { + uint32_t day = 0; + uint32_t wDay = 0; + this->getDate(&day, &wDay); + + const char *dayMap[7] = {LANG_SUNDAY, LANG_MONDAY, LANG_TUESDAY, LANG_WEDNESDAY, + LANG_THURSDAY, LANG_FRIDAY, LANG_SATURDAY}; + return dayMap[wDay]; +} + +uint32_t OswHal::getDualTime() { + return this->getUTCTime() + 3600 * OswConfigAllKeys::dualTimeZone.get() + (long)(3600 * OswConfigAllKeys::daylightOffset.get()); +} + +void OswHal::getDualTime(uint32_t *hour, uint32_t *minute, uint32_t *second, bool *afterNoon) { + RtcDateTime d = RtcDateTime(); + d.InitWithEpoch32Time(this->getDualTime()); if (!OswConfigAllKeys::timeFormat.get()) { if (d.Hour() > 12) { *hour = d.Hour() - 12; - *afterNoon = true; + if (afterNoon != nullptr) *afterNoon = true; } else if (d.Hour() == 0) { *hour = 12; - *afterNoon = false; + if (afterNoon != nullptr) *afterNoon = false; } else if (d.Hour() == 12) { *hour = d.Hour(); - *afterNoon = true; + if (afterNoon != nullptr) *afterNoon = true; } else { *hour = d.Hour(); - *afterNoon = false; + if (afterNoon != nullptr) *afterNoon = false; } } else { *hour = d.Hour(); - *afterNoon = false; + if (afterNoon != nullptr) *afterNoon = false; } *minute = d.Minute(); *second = d.Second(); } -void OswHal::getDate(uint32_t *day, uint32_t *weekDay) { +void OswHal::getDualDate(uint32_t *day, uint32_t *weekDay) { RtcDateTime d = RtcDateTime(); - d.InitWithEpoch32Time(this->getLocalTime()); + d.InitWithEpoch32Time(this->getDualTime()); *weekDay = d.DayOfWeek(); *day = d.Day(); } -void OswHal::getDate(uint32_t *day, uint32_t *month, uint32_t *year) { +void OswHal::getDualDate(uint32_t *day, uint32_t *month, uint32_t *year) { RtcDateTime d = RtcDateTime(); - d.InitWithEpoch32Time(getLocalTime()); + d.InitWithEpoch32Time(getDualTime()); *day = d.Day(); *month = d.Month(); *year = d.Year(); } -const char *OswHal::getWeekday() { +const char *OswHal::getDualWeekday() { uint32_t day = 0; uint32_t wDay = 0; - this->getDate(&day, &wDay); + this->getDualDate(&day, &wDay); const char *dayMap[7] = {LANG_SUNDAY, LANG_MONDAY, LANG_TUESDAY, LANG_WEDNESDAY, - LANG_THURSDAY, LANG_FRIDAY, LANG_SATURDAY}; + LANG_THURSDAY, LANG_FRIDAY, LANG_SATURDAY}; return dayMap[wDay]; } \ No newline at end of file