From fd1446a3632f0ca52dd2f1b1e2db00792a0982f0 Mon Sep 17 00:00:00 2001 From: Ruffalo Lavoisier Date: Sun, 29 Sep 2024 11:36:41 +0900 Subject: [PATCH 1/9] Simplifies API usage - update getDate, getTime API --- include/osw_hal.h | 51 ++++++------- src/apps/tools/OswAppDistStats.cpp | 16 ++-- src/apps/tools/OswAppKcalStats.cpp | 6 +- src/apps/tools/OswAppStepStats.cpp | 19 +++-- src/apps/tools/OswAppTimeConfig.cpp | 31 ++++---- src/apps/watchfaces/OswAppWatchface.cpp | 27 ++++--- src/apps/watchfaces/OswAppWatchfaceBinary.cpp | 12 +-- .../watchfaces/OswAppWatchfaceDigital.cpp | 20 ++--- src/apps/watchfaces/OswAppWatchfaceDual.cpp | 6 +- .../watchfaces/OswAppWatchfaceFitness.cpp | 25 ++++--- .../OswAppWatchfaceFitnessAnalog.cpp | 22 +++--- src/apps/watchfaces/OswAppWatchfaceMix.cpp | 31 ++++---- .../watchfaces/OswAppWatchfaceMonotimer.cpp | 18 +++-- .../watchfaces/OswAppWatchfaceNumerals.cpp | 30 ++++---- src/hal/environment.cpp | 19 +++-- src/hal/time.cpp | 75 +++++++++---------- 16 files changed, 215 insertions(+), 193 deletions(-) diff --git a/include/osw_hal.h b/include/osw_hal.h index b92bccd37..0dab3e862 100644 --- a/include/osw_hal.h +++ b/include/osw_hal.h @@ -28,6 +28,21 @@ #define ERR_SD_MISSING 1 #define ERR_SD_MOUNT_FAILED 2 +typedef struct { + uint32_t hour; + uint32_t minute; + uint32_t second; + bool afterNoon; +} OSW_TIME; + +typedef struct { + uint32_t year; + uint32_t month; + uint32_t day; + uint32_t weekDay; + const char* weekDayName; +} OSW_DATE; + class OswHal { public: static OswHal* getInstance(); @@ -181,7 +196,7 @@ class OswHal { // UTC Time void setUTCTime(const time_t& epoch); time_t getUTCTime(); - void getUTCTime(uint32_t* hour, uint32_t* minute, uint32_t* second); + void getUTCTime(OSW_TIME* oswTime); // Offset getters for primary / secondary time (cached!) time_t getTimezoneOffsetPrimary(); @@ -189,43 +204,29 @@ class OswHal { // New time functions with offset time_t getTime(time_t& offset); - void getTime(time_t& offset, uint32_t* hour, uint32_t* minute, uint32_t* second, bool* afterNoon = nullptr); - void getDate(time_t& offset, uint32_t* day, uint32_t* weekDay); - void getDate(time_t& offset, uint32_t* day, uint32_t* month, uint32_t* year); - const char* getWeekday(time_t& offset, uint32_t* setWDay = nullptr); + void getTime(time_t& offset, OSW_TIME* oswTime); + void getDate(time_t& offset, OSW_DATE* oswDate, uint32_t* setWDay = nullptr); // For backward compatibility: Local time functions (= primary timezone) - inline void getLocalTime(uint32_t* hour, uint32_t* minute, uint32_t* second, bool* afterNoon = nullptr) { - this->getTime(this->timezoneOffsetPrimary, hour, minute, second, afterNoon); + inline void getLocalTime(OSW_TIME* oswTime) { + this->getTime(this->timezoneOffsetPrimary, oswTime); } inline uint32_t getLocalTime() { return this->getTime(this->timezoneOffsetPrimary); } - inline void getLocalDate(uint32_t* day, uint32_t* weekDay) { - this->getDate(this->timezoneOffsetPrimary, day, weekDay); - }; - inline void getLocalDate(uint32_t* day, uint32_t* month, uint32_t* year) { - this->getDate(this->timezoneOffsetPrimary, day, month, year); - }; - inline const char* getLocalWeekday(uint32_t* sWDay = nullptr) { - return this->getWeekday(this->timezoneOffsetPrimary, sWDay); + inline void getLocalDate(OSW_DATE* oswDate, uint32_t* sWDay = nullptr) { + this->getDate(this->timezoneOffsetPrimary, oswDate, sWDay); }; // For backward compatibility: Dual time functions (= secondary timezone) - inline void getDualTime(uint32_t* hour, uint32_t* minute, uint32_t* second, bool* afterNoon = nullptr) { - this->getTime(this->timezoneOffsetSecondary, hour, minute, second, afterNoon); + inline void getDualTime(OSW_TIME* oswTime) { + this->getTime(this->timezoneOffsetSecondary, oswTime); } inline uint32_t getDualTime() { return this->getTime(this->timezoneOffsetSecondary); } - inline void getDualDate(uint32_t* day, uint32_t* weekDay) { - this->getDate(this->timezoneOffsetSecondary, day, weekDay); - }; - inline void getDualDate(uint32_t* day, uint32_t* month, uint32_t* year) { - this->getDate(this->timezoneOffsetSecondary, day, month, year); - }; - inline const char* getDualWeekday(uint32_t* sWDay = nullptr) { - return this->getWeekday(this->timezoneOffsetSecondary, sWDay); + inline void getDualDate(OSW_DATE* oswDate, uint32_t* sWDay = nullptr) { + this->getDate(this->timezoneOffsetPrimary, oswDate, sWDay); }; bool _requestDisableBuffer = false; diff --git a/src/apps/tools/OswAppDistStats.cpp b/src/apps/tools/OswAppDistStats.cpp index f2addd5e0..3d499ce0e 100644 --- a/src/apps/tools/OswAppDistStats.cpp +++ b/src/apps/tools/OswAppDistStats.cpp @@ -15,9 +15,10 @@ void OswAppDistStats::drawChart() { uint8_t interval = 20; uint16_t goalValue = OswConfigAllKeys::distPerDay.get(); - uint32_t weekDay = 0; - uint32_t dayOfMonth = 0; - hal->getLocalDate(&dayOfMonth, &weekDay); + OSW_DATE oswDate = { 0, }; + hal->getLocalDate(&oswDate); + uint32_t weekDay = oswDate.day; + uint32_t dayOfMonth = oswDate.weekDay; for (uint8_t index = 0; index < 7; index++) { uint32_t weekDayDist = OswAppWatchfaceFitness::calculateDistance(hal->environment()->getStepsOnDay(index)); @@ -46,15 +47,14 @@ void OswAppDistStats::showStickChart() { hal->gfx()->print(LANG_DISTSTATS_TITLE); OswAppDistStats::drawChart(); - OswAppStepStats::drawInfoPanel(ui, (uint32_t)cursorPos, OswAppWatchfaceFitness::calculateDistance(hal->environment()->getStepsOnDay((uint32_t)cursorPos, true)), OswAppWatchfaceFitness::calculateDistance(hal->environment()->getStepsOnDay((uint32_t)cursorPos)), OswAppWatchfaceFitness::calculateDistance(hal->environment()->getStepsAverage()), OswAppWatchfaceFitness::calculateDistance(hal->environment()->getStepsTotalWeek()), " m"); + OswAppStepStats::drawInfoPanel(ui, cursorPos, OswAppWatchfaceFitness::calculateDistance(hal->environment()->getStepsOnDay((uint32_t)cursorPos, true)), OswAppWatchfaceFitness::calculateDistance(hal->environment()->getStepsOnDay((uint32_t)cursorPos)), OswAppWatchfaceFitness::calculateDistance(hal->environment()->getStepsAverage()), OswAppWatchfaceFitness::calculateDistance(hal->environment()->getStepsTotalWeek()), " m"); } void OswAppDistStats::setup() { OswHal* hal = OswHal::getInstance(); - uint32_t weekDay = 0; - uint32_t dayOfMonth = 0; - hal->getLocalDate(&dayOfMonth, &weekDay); - cursorPos = weekDay; + OSW_DATE oswDate = { 0, }; + hal->getLocalDate(&oswDate); + cursorPos = oswDate.weekDay; } void OswAppDistStats::loop() { OswHal* hal = OswHal::getInstance(); diff --git a/src/apps/tools/OswAppKcalStats.cpp b/src/apps/tools/OswAppKcalStats.cpp index 53889a15a..0331f44d3 100644 --- a/src/apps/tools/OswAppKcalStats.cpp +++ b/src/apps/tools/OswAppKcalStats.cpp @@ -14,9 +14,9 @@ uint32_t findCursorWeekDay(uint8_t Index) { // Show the day of the week that cursor (Dynamic weekDay--info) OswHal* hal = OswHal::getInstance(); - uint32_t d, wD = 0; - hal->getLocalDate(&d, &wD); - int cursorWeekDay = wD - (6 - Index); + OSW_DATE oswDate = { 0, }; + hal->getLocalDate(&oswDate); + int cursorWeekDay = oswDate.weekDay - (6 - Index); int findWeekDay = (cursorWeekDay >= 0) ? cursorWeekDay : (cursorWeekDay + 7); uint32_t fWD = findWeekDay; return fWD; diff --git a/src/apps/tools/OswAppStepStats.cpp b/src/apps/tools/OswAppStepStats.cpp index eee20f443..1030cc987 100644 --- a/src/apps/tools/OswAppStepStats.cpp +++ b/src/apps/tools/OswAppStepStats.cpp @@ -14,9 +14,10 @@ void OswAppStepStats::drawChart() { uint8_t interval = 20; uint16_t goalValue = OswConfigAllKeys::stepsPerDay.get(); - uint32_t weekDay = 0; - uint32_t dayOfMonth = 0; - hal->getLocalDate(&dayOfMonth, &weekDay); + OSW_DATE oswDate = { 0, }; + hal->getLocalDate(&oswDate); + uint32_t weekDay = oswDate.weekDay; + uint32_t dayOfMonth = oswDate.day; for (uint8_t index = 0; index < 7; index++) { unsigned int weekDayStep = hal->environment()->getStepsOnDay(index); @@ -43,7 +44,10 @@ void OswAppStepStats::drawInfoPanel(OswUI* ui, uint32_t pos, uint32_t lastWeekDa hal->gfx()->setTextCenterAligned(); hal->gfx()->setTextBottomAligned(); hal->gfx()->setTextCursor(DISP_W / 2, 170); - hal->gfx()->print(hal->getLocalWeekday(&pos)); + OSW_DATE oswDate = { 0, }; + hal->getLocalDate(&oswDate, &pos); + const char* weekday = oswDate.weekDayName; + hal->gfx()->print(weekday); hal->gfx()->setTextCursor(DISP_W / 2, 190); hal->gfx()->print(String(lastWeekData)); // lastweek(before 7 day) hal->gfx()->setTextCursor(DISP_W / 2, 215); @@ -69,10 +73,9 @@ void OswAppStepStats::showStickChart() { void OswAppStepStats::setup() { OswHal* hal = OswHal::getInstance(); - uint32_t weekDay = 0; - uint32_t dayOfMonth = 0; - hal->getLocalDate(&dayOfMonth, &weekDay); - cursorPos = weekDay; + OSW_DATE oswDate = { 0, }; + hal->getLocalDate(&oswDate); + cursorPos = oswDate.weekDay; } void OswAppStepStats::loop() { OswHal* hal = OswHal::getInstance(); diff --git a/src/apps/tools/OswAppTimeConfig.cpp b/src/apps/tools/OswAppTimeConfig.cpp index f5be04736..51ac0f9ca 100644 --- a/src/apps/tools/OswAppTimeConfig.cpp +++ b/src/apps/tools/OswAppTimeConfig.cpp @@ -15,14 +15,16 @@ void OswAppTimeConfig::setup() {} void OswAppTimeConfig::enterManualMode() { - uint32_t second = 0; - uint32_t minute = 0; - uint32_t hour = 0; - uint32_t day = 0; - uint32_t month = 0; - uint32_t year = 0; - OswHal::getInstance()->getLocalTime(&hour, &minute, &second); - OswHal::getInstance()->getLocalDate(&day, &month, &year); + OSW_TIME oswTime = { 0, }; + OSW_DATE oswDate = { 0, }; + OswHal::getInstance()->getLocalTime(&oswTime); + OswHal::getInstance()->getLocalDate(&oswDate); + uint32_t second = oswTime.second; + uint32_t minute = oswTime.minute; + uint32_t hour = oswTime.hour; + uint32_t day = oswDate.day; + uint32_t month = oswDate.month; + uint32_t year = oswDate.year; manualSettingTimestamp[0] = year % 10; manualSettingTimestamp[1] = month / 10; manualSettingTimestamp[2] = month % 10; @@ -196,16 +198,13 @@ void OswAppTimeConfig::loop() { hal->gfx()->setTextMiddleAligned(); hal->gfx()->setTextLeftAligned(); hal->gfx()->setTextCursor(120 - hal->gfx()->getTextOfsetColumns(4), 120); - - uint32_t second = 0; - uint32_t minute = 0; - uint32_t hour = 0; - hal->getLocalTime(&hour, &minute, &second); - hal->gfx()->printDecimal(hour, 2); + OSW_TIME oswTime = { 0, }; + hal->getLocalTime(&oswTime); + hal->gfx()->printDecimal(oswTime.hour, 2); hal->gfx()->print(":"); - hal->gfx()->printDecimal(minute, 2); + hal->gfx()->printDecimal(oswTime.minute, 2); hal->gfx()->print(":"); - hal->gfx()->printDecimal(second, 2); + hal->gfx()->printDecimal(oswTime.second, 2); } else { handleIncrementButton(); diff --git a/src/apps/watchfaces/OswAppWatchface.cpp b/src/apps/watchfaces/OswAppWatchface.cpp index 859c776d1..9e03754a9 100644 --- a/src/apps/watchfaces/OswAppWatchface.cpp +++ b/src/apps/watchfaces/OswAppWatchface.cpp @@ -28,9 +28,11 @@ const char* OswAppWatchface::getAppName() { void OswAppWatchface::drawStepHistory(OswUI* ui, uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint32_t max) { OswHal* hal = OswHal::getInstance(); OswUI::getInstance()->resetTextColors(); - uint32_t weekDay = 0; - uint32_t dayOfMonth = 0; - hal->getLocalDate(&dayOfMonth, &weekDay); + + OSW_DATE oswDate = { 0, }; + hal->getLocalDate(&oswDate); + uint32_t weekDay = oswDate.weekDay; + for (uint8_t i = 0; i < 7; i++) { uint32_t s = hal->environment()->getStepsOnDay(i); uint16_t boxHeight = ((float)(s > max ? max : s) / max) * h; @@ -64,6 +66,7 @@ void OswAppWatchface::drawStepHistory(OswUI* ui, uint8_t x, uint8_t y, uint8_t w void OswAppWatchface::drawWatch() { OswHal* hal = OswHal::getInstance(); + hal->gfx()->drawMinuteTicks(CENTER_Y, CENTER_Y, 116, 112, ui->getForegroundDimmedColor(), true); hal->gfx()->drawHourTicks(CENTER_X, CENTER_Y, 117, 107, ui->getForegroundColor(), true); @@ -91,16 +94,18 @@ void OswAppWatchface::drawWatch() { // hal->gfx()->drawArc(120, 120, 0, bat, 180, 57, 7, dimColor(COLOR_BLUE, 25)); // hal->gfx()->drawArc(120, 120, 0, bat, 180, 57, 6, COLOR_BLUE); - uint32_t second = 0; - uint32_t minute = 0; - uint32_t hour = 0; - hal->getLocalTime(&hour, &minute, &second); + OSW_TIME oswTime = { 0, }; + hal->getLocalTime(&oswTime); + uint32_t second = oswTime.second; + uint32_t minute = oswTime.minute; + uint32_t hour = oswTime.hour; if(OswConfigAllKeys::settingDisplayDualHourTick.get()) { - uint32_t dualSecond = 0; - uint32_t dualMinute = 0; - uint32_t dualHour = 0; - hal->getDualTime(&dualHour, &dualMinute, &dualSecond); + OSW_TIME oswTime = { 0, }; + hal->getDualTime(&oswTime); + uint32_t dualSecond = oswTime.second; + uint32_t dualMinute = oswTime.minute; + uint32_t dualHour = oswTime.hour; // dual-hours hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 0, 16, (int)(360.0f / 12.0f * (dualHour + dualMinute / 60.0f)), 2, ui->getBackgroundDimmedColor(), true, STRAIGHT_END); diff --git a/src/apps/watchfaces/OswAppWatchfaceBinary.cpp b/src/apps/watchfaces/OswAppWatchfaceBinary.cpp index 00d894078..1000f13f8 100644 --- a/src/apps/watchfaces/OswAppWatchfaceBinary.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceBinary.cpp @@ -14,12 +14,14 @@ #define COLOR_WHxITE rgb565(255, 255, 255) void OswAppWatchfaceBinary::drawWatch() { - uint32_t second = 0; - uint32_t minute = 0; - uint32_t hour = 0; - bool afterNoon = false; OswHal* hal = OswHal::getInstance(); - hal->getLocalTime(&hour, &minute, &second, &afterNoon); + + OSW_TIME oswTime = { 0, }; + hal->getLocalTime(&oswTime); + uint32_t second = oswTime.second; + uint32_t minute = oswTime.minute; + uint32_t hour = oswTime.hour; + bool afterNoon = oswTime.afterNoon; uint16_t width = hal->gfx()->getWidth(); uint16_t height = hal->gfx()->getHeight(); diff --git a/src/apps/watchfaces/OswAppWatchfaceDigital.cpp b/src/apps/watchfaces/OswAppWatchfaceDigital.cpp index ca74c6d41..46df0a7f5 100644 --- a/src/apps/watchfaces/OswAppWatchfaceDigital.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceDigital.cpp @@ -64,11 +64,16 @@ static void drawDate(time_t timeZone, uint8_t fontSize, uint8_t CoordY) { uint32_t dayInt = 0; uint32_t monthInt = 0; uint32_t yearInt = 0; + const char* weekday = nullptr; + OSW_DATE oswDate = { 0, }; OswHal* hal = OswHal::getInstance(); - const char* weekday = hal->getWeekday(timeZone); - hal->getDate(timeZone,&dayInt, &monthInt, &yearInt); + hal->getDate(timeZone, &oswDate); + dayInt = oswDate.day; + monthInt = oswDate.month; + yearInt = oswDate.year; + weekday = oswDate.weekDayName; // we want to output a value like "Wed, 05/02/2021" hal->gfx()->setTextSize(fontSize); @@ -101,10 +106,7 @@ void OswAppWatchfaceDigital::timeOutput(uint32_t hour, uint32_t minute, uint32_t } static void drawTime(time_t timeZone,uint8_t CoordY) { - uint32_t second = 0; - uint32_t minute = 0; - uint32_t hour = 0; - bool afterNoon = false; + OSW_TIME oswTime = { 0, }; char am[] = "AM"; char pm[] = "PM"; OswHal* hal = OswHal::getInstance(); @@ -114,11 +116,11 @@ static void drawTime(time_t timeZone,uint8_t CoordY) { hal->gfx()->setTextLeftAligned(); hal->gfx()->setTextCursor(120 - hal->gfx()->getTextOfsetColumns(OswConfigAllKeys::timeFormat.get() ? 4 : 5.5),CoordY ); - hal->getTime(timeZone,&hour, &minute, &second, &afterNoon); - OswAppWatchfaceDigital::timeOutput(hour, minute, second); + hal->getTime(timeZone, &oswTime); + OswAppWatchfaceDigital::timeOutput(oswTime.hour, oswTime.minute, oswTime.second); if (!OswConfigAllKeys::timeFormat.get()) { hal->gfx()->print(" "); - if (afterNoon) { + if (oswTime.afterNoon) { hal->gfx()->print(pm); } else { hal->gfx()->print(am); diff --git a/src/apps/watchfaces/OswAppWatchfaceDual.cpp b/src/apps/watchfaces/OswAppWatchfaceDual.cpp index 2e49d2107..d1c40fa9f 100644 --- a/src/apps/watchfaces/OswAppWatchfaceDual.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceDual.cpp @@ -32,9 +32,9 @@ void OswAppWatchfaceDual::drawProgressBar(OswUI* ui,uint8_t cx, uint8_t cy, uint void OswAppWatchfaceDual::drawAnimSec() { OswHal* hal = OswHal::getInstance(); uint8_t barWidth = 140; - uint32_t Hs, Ms, Ss = 0; - hal->getLocalTime(&Hs,&Ms,&Ss); - uint32_t onlySecond = Ss; + OSW_TIME oswTime = { 0, }; + hal->getLocalTime(&oswTime); + uint32_t onlySecond = oswTime.second; uint16_t barValue = ((float)onlySecond / 60) * barWidth; barValue = barValue < 2 ? 0 : barValue; uint8_t coordX = (DISP_W - barWidth) / 2; diff --git a/src/apps/watchfaces/OswAppWatchfaceFitness.cpp b/src/apps/watchfaces/OswAppWatchfaceFitness.cpp index d7fe46baf..56a76e7a0 100644 --- a/src/apps/watchfaces/OswAppWatchfaceFitness.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceFitness.cpp @@ -25,14 +25,15 @@ uint32_t OswAppWatchfaceFitness::calculateKcalorie(uint32_t steps) { } void dateDisplay() { - uint32_t dayInt = 0; - uint32_t monthInt = 0; - uint32_t yearInt = 0; OswHal* hal = OswHal::getInstance(); - const char* weekday = hal->getLocalWeekday(); - - hal->getLocalDate(&dayInt, &monthInt, &yearInt); + OSW_DATE oswDate = { 0, }; + hal->getLocalDate(&oswDate); + uint32_t dayInt = oswDate.day; + uint32_t monthInt = oswDate.month; + uint32_t yearInt = oswDate.year; + const char* weekday = oswDate.weekDayName; + hal->gfx()->setTextSize(2); hal->gfx()->setTextMiddleAligned(); hal->gfx()->setTextRightAligned(); @@ -62,10 +63,6 @@ void timeDisplay(uint32_t hour, uint32_t minute, uint32_t second) { } void digitalWatchDisplay() { - uint32_t second = 0; - uint32_t minute = 0; - uint32_t hour = 0; - bool afterNoon = false; char am[] = "AM"; char pm[] = "PM"; OswHal* hal = OswHal::getInstance(); @@ -74,8 +71,12 @@ void digitalWatchDisplay() { hal->gfx()->setTextMiddleAligned(); hal->gfx()->setTextLeftAligned(); hal->gfx()->setTextCursor(DISP_W / 2 - 30, DISP_W / 2); - - hal->getLocalTime(&hour, &minute, &second, &afterNoon); + OSW_TIME oswTime = { 0, }; + hal->getLocalTime(&oswTime); + uint32_t second = oswTime.second; + uint32_t minute = oswTime.minute; + uint32_t hour = oswTime.hour; + bool afterNoon = oswTime.afterNoon; timeDisplay(hour, minute, second); if (!OswConfigAllKeys::timeFormat.get()) { diff --git a/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp b/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp index 63562eff0..c0f4b8353 100644 --- a/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp @@ -111,7 +111,9 @@ void OswAppWatchfaceFitnessAnalog::drawWatchFace(OswHal* hal, uint32_t hour, uin } void OswAppWatchfaceFitnessAnalog::drawDateFace(OswHal* hal, uint32_t hour, uint32_t minute, uint32_t second, bool afterNoon) { - const char* weekday = hal->getLocalWeekday(); + OSW_DATE oswDate = { 0, }; + hal->getLocalDate(&oswDate); + const char* weekday = oswDate.weekDayName; hal->gfx()->setTextSize(2); hal->gfx()->setTextRightAligned(); @@ -119,10 +121,10 @@ void OswAppWatchfaceFitnessAnalog::drawDateFace(OswHal* hal, uint32_t hour, uint OswAppWatchfaceDigital::displayWeekDay3(weekday); // Date - uint32_t dayInt = 0; - uint32_t monthInt = 0; - uint32_t yearInt = 0; - hal->getLocalDate(&dayInt, &monthInt, &yearInt); + uint32_t dayInt = oswDate.day; + uint32_t monthInt = oswDate.month; + uint32_t yearInt = oswDate.year; + hal->gfx()->setTextSize(3); hal->gfx()->setTextLeftAligned(); hal->gfx()->setTextCursor(CENTER_X - 70, 170); @@ -207,11 +209,11 @@ void OswAppWatchfaceFitnessAnalog::onDraw() { OswHal* hal = OswHal::getInstance(); - uint32_t second = 0; - uint32_t minute = 0; - uint32_t hour = 0; - bool afterNoon; - hal->getLocalTime(&hour, &minute, &second, &afterNoon); + OSW_TIME oswTime = { 0, }; + uint32_t second = oswTime.second; + uint32_t minute = oswTime.minute; + uint32_t hour = oswTime.hour; + bool afterNoon = oswTime.afterNoon; if (this->screen == 0) { #if OSW_PLATFORM_ENVIRONMENT_ACCELEROMETER == 1 diff --git a/src/apps/watchfaces/OswAppWatchfaceMix.cpp b/src/apps/watchfaces/OswAppWatchfaceMix.cpp index 51633f877..392744b74 100644 --- a/src/apps/watchfaces/OswAppWatchfaceMix.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceMix.cpp @@ -23,11 +23,12 @@ const char* OswAppWatchfaceMix::getAppName() { void OswAppWatchfaceMix::analogWatchDisplay() { OswHal* hal = OswHal::getInstance(); - uint32_t second = 0; - uint32_t minute = 0; // Unused, but required by function signature - uint32_t hour = 0; // Unused, but required by function signature + OSW_TIME oswTime = { 0, }; + hal->getLocalTime(&oswTime); + uint32_t second = oswTime.second; + uint32_t minute = oswTime.minute; + uint32_t hour = oswTime.hour; - hal->getLocalTime(&hour, &minute, &second); hal->gfx()->drawCircle((int)(DISP_W*0.5)-OFF_SET_ANALOG_WATCH_X_COORD, 100, 50, ui->getForegroundColor()); hal->gfx()->drawHourTicks((int)(DISP_W*0.5)-OFF_SET_ANALOG_WATCH_X_COORD, 100, 45, 40, ui->getForegroundDimmedColor()); @@ -49,13 +50,14 @@ void OswAppWatchfaceMix::analogWatchDisplay() { } void OswAppWatchfaceMix::dateDisplay() { - uint32_t dayInt = 0; - uint32_t monthInt = 0; - uint32_t yearInt = 0; OswHal* hal = OswHal::getInstance(); - const char* weekday = hal->getLocalWeekday(); - hal->getLocalDate(&dayInt, &monthInt, &yearInt); + OSW_DATE oswDate = { 0, }; + hal->getLocalDate(&oswDate); + uint32_t dayInt = oswDate.day; + uint32_t monthInt = oswDate.month; + uint32_t yearInt = oswDate.year; + const char* weekday = oswDate.weekDayName; hal->gfx()->setTextSize(1); hal->gfx()->setTextMiddleAligned(); @@ -76,10 +78,6 @@ void OswAppWatchfaceMix::dateDisplay() { } void OswAppWatchfaceMix::digitalWatchDisplay() { - uint32_t second = 0; - uint32_t minute = 0; - uint32_t hour = 0; - bool afterNoon = false; char am[] = "AM"; char pm[] = "PM"; OswHal* hal = OswHal::getInstance(); @@ -89,7 +87,12 @@ void OswAppWatchfaceMix::digitalWatchDisplay() { hal->gfx()->setTextLeftAligned(); hal->gfx()->setTextCursor(DISP_W / 2 - OFF_SET_DATE_DIGITAL_WATCH_X_COORD, DISP_H / 2); - hal->getLocalTime(&hour, &minute, &second, &afterNoon); + OSW_TIME oswTime = { 0, }; + hal->getLocalTime(&oswTime); + uint32_t second = oswTime.second; + uint32_t minute = oswTime.minute; + uint32_t hour = oswTime.hour; + bool afterNoon = oswTime.afterNoon; OswAppWatchfaceDigital::timeOutput(hour, minute, second,false); if (!OswConfigAllKeys::timeFormat.get()) { hal->gfx()->setTextSize(1); diff --git a/src/apps/watchfaces/OswAppWatchfaceMonotimer.cpp b/src/apps/watchfaces/OswAppWatchfaceMonotimer.cpp index 996f6c4b2..e0c860d31 100644 --- a/src/apps/watchfaces/OswAppWatchfaceMonotimer.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceMonotimer.cpp @@ -104,16 +104,18 @@ void OswAppWatchfaceMonotimer::drawWatch() { #endif // ticks - uint32_t second = 0; - uint32_t minute = 0; - uint32_t hour = 0; - hal->getLocalTime(&hour, &minute, &second); + OSW_TIME oswTime = { 0, }; + hal->getLocalTime(&oswTime); + uint32_t second = oswTime.second; + uint32_t minute = oswTime.minute; + uint32_t hour = oswTime.hour; if (OswConfigAllKeys::settingDisplayDualHourTick.get()) { - uint32_t dualSecond = 0; - uint32_t dualMinute = 0; - uint32_t dualHour = 0; - hal->getDualTime(&dualHour, &dualMinute, &dualSecond); + OSW_TIME oswTime = { 0, }; + hal->getDualTime(&oswTime); + uint32_t dualSecond = oswTime.second; + uint32_t dualMinute = oswTime.minute; + uint32_t dualHour = oswTime.hour; hal->gfx()->drawThickTick(120, 120, 0, 105, (360.0f * (60 * dualHour + dualMinute)) / 720.0f, 1, ui->getBackgroundDimmedColor()); } diff --git a/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp b/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp index ab5d49a92..2220e547b 100644 --- a/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp @@ -33,17 +33,19 @@ void OswAppWatchfaceNumerals::drawWatch() { OswAppWatchfaceMonotimer::drawHour(); - uint32_t dayInt = 0; - uint32_t monthInt = 0; - uint32_t yearInt = 0; - hal->getLocalDate(&dayInt, &monthInt, &yearInt); + OSW_DATE oswDate = { 0, }; + hal->getLocalDate(&oswDate); + uint32_t dayInt = oswDate.day; + uint32_t monthInt = oswDate.month; + uint32_t yearInt = oswDate.year; + hal->gfx()->setTextCenterAligned(); hal->gfx()->setTextSize(1); hal->gfx()->setTextColor(ui->getDangerColor()); hal->gfx()->setTextCursor(120, 85); hal->gfx()->print(dayInt); - const char* weekday = hal->getLocalWeekday(); + const char* weekday = oswDate.weekDayName; hal->gfx()->setTextCursor(120, 70); OswAppWatchfaceDigital::displayWeekDay3(weekday); @@ -61,15 +63,17 @@ void OswAppWatchfaceNumerals::drawWatch() { #endif // ticks - uint32_t second = 0; - uint32_t minute = 0; - uint32_t hour = 0; - hal->getLocalTime(&hour, &minute, &second); + OSW_TIME oswTime = { 0, }; + hal->getLocalTime(&oswTime); + uint32_t second = oswTime.second; + uint32_t minute = oswTime.minute; + uint32_t hour = oswTime.hour; if(OswConfigAllKeys::settingDisplayDualHourTick.get()) { - uint32_t dualSecond = 0; - uint32_t dualMinute = 0; - uint32_t dualHour = 0; - hal->getDualTime(&dualHour, &dualMinute, &dualSecond); + OSW_TIME oswTime = { 0, }; + hal->getDualTime(&oswTime); + uint32_t dualSecond = oswTime.second; + uint32_t dualMinute = oswTime.minute; + uint32_t dualHour = oswTime.hour; // dual-hours hal->gfx()->drawThickTick(DISP_W / 2, DISP_H / 2, 0, 16, 360.0f / 12.0f * (dualHour + dualMinute / 60.0f), 2, ui->getBackgroundDimmedColor()); diff --git a/src/hal/environment.cpp b/src/hal/environment.cpp index b233e94cb..4d477415c 100644 --- a/src/hal/environment.cpp +++ b/src/hal/environment.cpp @@ -132,9 +132,9 @@ void OswHal::Environment::setupStepStatistics() { * @param alwaysPrintStepStatistics Set to true to print the step history to the console */ void OswHal::Environment::commitStepStatistics(const bool& alwaysPrintStepStatistics) { - uint32_t currDoM = 0; // Unused, but required by function signature - uint32_t currDoW = 0; - OswHal::getInstance()->getLocalDate(&currDoM, &currDoW); + OSW_DATE oswDate = { 0, }; + OswHal::getInstance()->getLocalDate(&oswDate); + uint32_t currDoW = oswDate.weekDay; bool changedDoW = currDoW != this->_stepsLastDoW; if(changedDoW) { Preferences prefs; @@ -196,10 +196,9 @@ void OswHal::Environment::commitStepStatistics(const bool& alwaysPrintStepStatis uint32_t OswHal::Environment::getStepsOnDay(uint8_t dayOfWeek, bool lastWeek) { this->commitStepStatistics(); - uint32_t day = 0; - uint32_t weekday = 0; - OswHal::getInstance()->getLocalDate(&day, &weekday); - + OSW_DATE oswDate = { 0, }; + OswHal::getInstance()->getLocalDate(&oswDate); + uint32_t weekday = oswDate.weekDay; if (!lastWeek and dayOfWeek == weekday) return this->getStepsToday(); else if(!lastWeek or (lastWeek and dayOfWeek == weekday)) @@ -225,9 +224,9 @@ uint32_t OswHal::Environment::getStepsTotalWeek() { #ifdef OSW_FEATURE_STATS_STEPS this->commitStepStatistics(); uint32_t sum = 0; - uint32_t currDoM = 0; // Unused, but required by function signature - uint32_t currDoW = 0; - OswHal::getInstance()->getLocalDate(&currDoM, &currDoW); + OSW_DATE oswDate = { 0, }; + OswHal::getInstance()->getLocalDate(&oswDate); + uint32_t currDoW = oswDate.weekDay; for (uint8_t i = 0; i < 7; i++) { if (i == currDoW) { sum = sum + this->getStepsToday(); diff --git a/src/hal/time.cpp b/src/hal/time.cpp index d0ce9cb71..001516329 100644 --- a/src/hal/time.cpp +++ b/src/hal/time.cpp @@ -26,37 +26,37 @@ void OswHal::updateTimeProvider() { OSW_LOG_D("No provider for Time is available!"); } -void OswHal::getUTCTime(uint32_t* hour, uint32_t* minute, uint32_t* second) { +void OswHal::getUTCTime(OSW_TIME* oswTime) { RtcDateTime d = RtcDateTime(); d.InitWithUnix32Time(this->getUTCTime()); - *hour = d.Hour(); - *minute = d.Minute(); - *second = d.Second(); + oswTime->hour = d.Hour(); + oswTime->minute = d.Minute(); + oswTime->second = d.Second(); } -void OswHal::getTime(time_t& offset, uint32_t* hour, uint32_t* minute, uint32_t* second, bool* afterNoon) { +void OswHal::getTime(time_t& offset, OSW_TIME* oswTime) { RtcDateTime d = RtcDateTime(); d.InitWithUnix32Time(this->getTime(offset)); if (!OswConfigAllKeys::timeFormat.get()) { if (d.Hour() > 12) { - *hour = d.Hour() - 12; - if (afterNoon != nullptr) *afterNoon = true; + oswTime->hour = d.Hour() - 12; + oswTime->afterNoon = true; } else if (d.Hour() == 0) { - *hour = 12; - if (afterNoon != nullptr) *afterNoon = false; + oswTime->hour = 12; + oswTime->afterNoon = false; } else if (d.Hour() == 12) { - *hour = d.Hour(); - if (afterNoon != nullptr) *afterNoon = true; + oswTime->hour = d.Hour(); + oswTime->afterNoon = true; } else { - *hour = d.Hour(); - if (afterNoon != nullptr) *afterNoon = false; + oswTime->hour = d.Hour(); + oswTime->afterNoon = false; } } else { - *hour = d.Hour(); - if (afterNoon != nullptr) *afterNoon = false; + oswTime->hour = d.Hour(); + oswTime->afterNoon = false; } - *minute = d.Minute(); - *second = d.Second(); + oswTime->minute = d.Minute(); + oswTime->second = d.Second(); } /** @@ -122,27 +122,26 @@ time_t OswHal::getTime(time_t& offset) { return this->getUTCTime() + offset; } -void OswHal::getDate(time_t& offset, uint32_t* day, uint32_t* weekDay) { - RtcDateTime d = RtcDateTime(); - d.InitWithUnix32Time(this->getTime(offset)); - *weekDay = d.DayOfWeek(); - *day = d.Day(); -} +void OswHal::getDate(time_t& offset, OSW_DATE* oswDate, uint32_t* setWDay) { + const char* dayMap[7] = { + LANG_SUNDAY + , LANG_MONDAY + , LANG_TUESDAY + , LANG_WEDNESDAY + , LANG_THURSDAY + , LANG_FRIDAY + , LANG_SATURDAY + }; -void OswHal::getDate(time_t& offset, uint32_t* day, uint32_t* month, uint32_t* year) { RtcDateTime d = RtcDateTime(); d.InitWithUnix32Time(this->getTime(offset)); - *day = d.Day(); - *month = d.Month(); - *year = d.Year(); -} - -const char* OswHal::getWeekday(time_t& offset, uint32_t* setWDay) { - uint32_t day = 0; - uint32_t wDay = 0; - this->getDate(offset, &day, &wDay); - - const char* dayMap[7] = {LANG_SUNDAY, LANG_MONDAY, LANG_TUESDAY, LANG_WEDNESDAY, LANG_THURSDAY, LANG_FRIDAY, LANG_SATURDAY}; - if (setWDay != nullptr) wDay = *setWDay; - return dayMap[wDay]; -} + oswDate->year = d.Year(); + oswDate->month = d.Month(); + oswDate->day = d.Day(); + oswDate->weekDay = d.DayOfWeek(); + if (setWDay != nullptr) { + oswDate->weekDayName = dayMap[*setWDay]; + } else { + oswDate->weekDayName = dayMap[oswDate->weekDay]; + } +} \ No newline at end of file From dc83f8deaa40ad81648ada700c2ff6de004393ea Mon Sep 17 00:00:00 2001 From: Ruffalo Lavoisier Date: Mon, 30 Sep 2024 14:38:39 +0900 Subject: [PATCH 2/9] Fix osw_hal.h struct naming --- include/osw_hal.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/osw_hal.h b/include/osw_hal.h index 0dab3e862..5c0024dbb 100644 --- a/include/osw_hal.h +++ b/include/osw_hal.h @@ -33,7 +33,7 @@ typedef struct { uint32_t minute; uint32_t second; bool afterNoon; -} OSW_TIME; +} OswTime; typedef struct { uint32_t year; @@ -41,7 +41,7 @@ typedef struct { uint32_t day; uint32_t weekDay; const char* weekDayName; -} OSW_DATE; +} OswDate; class OswHal { public: @@ -196,7 +196,7 @@ class OswHal { // UTC Time void setUTCTime(const time_t& epoch); time_t getUTCTime(); - void getUTCTime(OSW_TIME* oswTime); + void getUTCTime(OswTime* oswTime); // Offset getters for primary / secondary time (cached!) time_t getTimezoneOffsetPrimary(); @@ -204,28 +204,28 @@ class OswHal { // New time functions with offset time_t getTime(time_t& offset); - void getTime(time_t& offset, OSW_TIME* oswTime); - void getDate(time_t& offset, OSW_DATE* oswDate, uint32_t* setWDay = nullptr); + void getTime(time_t& offset, OswTime* oswTime); + void getDate(time_t& offset, OswDate* oswDate, uint32_t* setWDay = nullptr); // For backward compatibility: Local time functions (= primary timezone) - inline void getLocalTime(OSW_TIME* oswTime) { + inline void getLocalTime(OswTime* oswTime) { this->getTime(this->timezoneOffsetPrimary, oswTime); } inline uint32_t getLocalTime() { return this->getTime(this->timezoneOffsetPrimary); } - inline void getLocalDate(OSW_DATE* oswDate, uint32_t* sWDay = nullptr) { + inline void getLocalDate(OswDate* oswDate, uint32_t* sWDay = nullptr) { this->getDate(this->timezoneOffsetPrimary, oswDate, sWDay); }; // For backward compatibility: Dual time functions (= secondary timezone) - inline void getDualTime(OSW_TIME* oswTime) { + inline void getDualTime(OswTime* oswTime) { this->getTime(this->timezoneOffsetSecondary, oswTime); } inline uint32_t getDualTime() { return this->getTime(this->timezoneOffsetSecondary); } - inline void getDualDate(OSW_DATE* oswDate, uint32_t* sWDay = nullptr) { + inline void getDualDate(OswDate* oswDate, uint32_t* sWDay = nullptr) { this->getDate(this->timezoneOffsetPrimary, oswDate, sWDay); }; From d30ce2d4adbb778b2edf01ffcc0e84da11c86d62 Mon Sep 17 00:00:00 2001 From: Ruffalo Lavoisier Date: Mon, 7 Oct 2024 00:55:21 +0900 Subject: [PATCH 3/9] HAL/time: change date/time API param style - init value, method proto type, structure style --- include/osw_hal.h | 14 +++--- src/apps/tools/OswAppDistStats.cpp | 4 +- src/apps/tools/OswAppKcalStats.cpp | 2 +- src/apps/tools/OswAppStepStats.cpp | 6 +-- src/apps/tools/OswAppTimeConfig.cpp | 6 +-- src/apps/watchfaces/OswAppWatchface.cpp | 6 +-- src/apps/watchfaces/OswAppWatchfaceBinary.cpp | 2 +- .../watchfaces/OswAppWatchfaceDigital.cpp | 4 +- src/apps/watchfaces/OswAppWatchfaceDual.cpp | 2 +- .../watchfaces/OswAppWatchfaceFitness.cpp | 4 +- .../OswAppWatchfaceFitnessAnalog.cpp | 4 +- src/apps/watchfaces/OswAppWatchfaceMix.cpp | 6 +-- .../watchfaces/OswAppWatchfaceMonotimer.cpp | 4 +- .../watchfaces/OswAppWatchfaceNumerals.cpp | 6 +-- src/hal/environment.cpp | 6 +-- src/hal/time.cpp | 48 +++++++++---------- 16 files changed, 62 insertions(+), 62 deletions(-) diff --git a/include/osw_hal.h b/include/osw_hal.h index 5c0024dbb..d02fefbf0 100644 --- a/include/osw_hal.h +++ b/include/osw_hal.h @@ -196,7 +196,7 @@ class OswHal { // UTC Time void setUTCTime(const time_t& epoch); time_t getUTCTime(); - void getUTCTime(OswTime* oswTime); + void getUTCTime(OswTime& oswTime); // Offset getters for primary / secondary time (cached!) time_t getTimezoneOffsetPrimary(); @@ -204,28 +204,28 @@ class OswHal { // New time functions with offset time_t getTime(time_t& offset); - void getTime(time_t& offset, OswTime* oswTime); - void getDate(time_t& offset, OswDate* oswDate, uint32_t* setWDay = nullptr); + void getTime(time_t& offset, OswTime& oswTime); + void getDate(time_t& offset, OswDate& oswDate, uint32_t* setWDay = nullptr); // For backward compatibility: Local time functions (= primary timezone) - inline void getLocalTime(OswTime* oswTime) { + inline void getLocalTime(OswTime& oswTime) { this->getTime(this->timezoneOffsetPrimary, oswTime); } inline uint32_t getLocalTime() { return this->getTime(this->timezoneOffsetPrimary); } - inline void getLocalDate(OswDate* oswDate, uint32_t* sWDay = nullptr) { + inline void getLocalDate(OswDate& oswDate, uint32_t* sWDay = nullptr) { this->getDate(this->timezoneOffsetPrimary, oswDate, sWDay); }; // For backward compatibility: Dual time functions (= secondary timezone) - inline void getDualTime(OswTime* oswTime) { + inline void getDualTime(OswTime& oswTime) { this->getTime(this->timezoneOffsetSecondary, oswTime); } inline uint32_t getDualTime() { return this->getTime(this->timezoneOffsetSecondary); } - inline void getDualDate(OswDate* oswDate, uint32_t* sWDay = nullptr) { + inline void getDualDate(OswDate& oswDate, uint32_t* sWDay = nullptr) { this->getDate(this->timezoneOffsetPrimary, oswDate, sWDay); }; diff --git a/src/apps/tools/OswAppDistStats.cpp b/src/apps/tools/OswAppDistStats.cpp index 3d499ce0e..b3bd169a3 100644 --- a/src/apps/tools/OswAppDistStats.cpp +++ b/src/apps/tools/OswAppDistStats.cpp @@ -15,7 +15,7 @@ void OswAppDistStats::drawChart() { uint8_t interval = 20; uint16_t goalValue = OswConfigAllKeys::distPerDay.get(); - OSW_DATE oswDate = { 0, }; + OswDate oswDate = { }; hal->getLocalDate(&oswDate); uint32_t weekDay = oswDate.day; uint32_t dayOfMonth = oswDate.weekDay; @@ -52,7 +52,7 @@ void OswAppDistStats::showStickChart() { void OswAppDistStats::setup() { OswHal* hal = OswHal::getInstance(); - OSW_DATE oswDate = { 0, }; + OswDate oswDate = { }; hal->getLocalDate(&oswDate); cursorPos = oswDate.weekDay; } diff --git a/src/apps/tools/OswAppKcalStats.cpp b/src/apps/tools/OswAppKcalStats.cpp index 0331f44d3..89c894951 100644 --- a/src/apps/tools/OswAppKcalStats.cpp +++ b/src/apps/tools/OswAppKcalStats.cpp @@ -14,7 +14,7 @@ uint32_t findCursorWeekDay(uint8_t Index) { // Show the day of the week that cursor (Dynamic weekDay--info) OswHal* hal = OswHal::getInstance(); - OSW_DATE oswDate = { 0, }; + OswDate oswDate = { }; hal->getLocalDate(&oswDate); int cursorWeekDay = oswDate.weekDay - (6 - Index); int findWeekDay = (cursorWeekDay >= 0) ? cursorWeekDay : (cursorWeekDay + 7); diff --git a/src/apps/tools/OswAppStepStats.cpp b/src/apps/tools/OswAppStepStats.cpp index 1030cc987..602c7c307 100644 --- a/src/apps/tools/OswAppStepStats.cpp +++ b/src/apps/tools/OswAppStepStats.cpp @@ -14,7 +14,7 @@ void OswAppStepStats::drawChart() { uint8_t interval = 20; uint16_t goalValue = OswConfigAllKeys::stepsPerDay.get(); - OSW_DATE oswDate = { 0, }; + OswDate oswDate = { }; hal->getLocalDate(&oswDate); uint32_t weekDay = oswDate.weekDay; uint32_t dayOfMonth = oswDate.day; @@ -44,7 +44,7 @@ void OswAppStepStats::drawInfoPanel(OswUI* ui, uint32_t pos, uint32_t lastWeekDa hal->gfx()->setTextCenterAligned(); hal->gfx()->setTextBottomAligned(); hal->gfx()->setTextCursor(DISP_W / 2, 170); - OSW_DATE oswDate = { 0, }; + OswDate oswDate = { }; hal->getLocalDate(&oswDate, &pos); const char* weekday = oswDate.weekDayName; hal->gfx()->print(weekday); @@ -73,7 +73,7 @@ void OswAppStepStats::showStickChart() { void OswAppStepStats::setup() { OswHal* hal = OswHal::getInstance(); - OSW_DATE oswDate = { 0, }; + OswDate oswDate = { }; hal->getLocalDate(&oswDate); cursorPos = oswDate.weekDay; } diff --git a/src/apps/tools/OswAppTimeConfig.cpp b/src/apps/tools/OswAppTimeConfig.cpp index 51ac0f9ca..b2f492bb1 100644 --- a/src/apps/tools/OswAppTimeConfig.cpp +++ b/src/apps/tools/OswAppTimeConfig.cpp @@ -15,8 +15,8 @@ void OswAppTimeConfig::setup() {} void OswAppTimeConfig::enterManualMode() { - OSW_TIME oswTime = { 0, }; - OSW_DATE oswDate = { 0, }; + OswTime oswTime = { }; + OswDate oswDate = { }; OswHal::getInstance()->getLocalTime(&oswTime); OswHal::getInstance()->getLocalDate(&oswDate); uint32_t second = oswTime.second; @@ -198,7 +198,7 @@ void OswAppTimeConfig::loop() { hal->gfx()->setTextMiddleAligned(); hal->gfx()->setTextLeftAligned(); hal->gfx()->setTextCursor(120 - hal->gfx()->getTextOfsetColumns(4), 120); - OSW_TIME oswTime = { 0, }; + OswTime oswTime = { }; hal->getLocalTime(&oswTime); hal->gfx()->printDecimal(oswTime.hour, 2); hal->gfx()->print(":"); diff --git a/src/apps/watchfaces/OswAppWatchface.cpp b/src/apps/watchfaces/OswAppWatchface.cpp index 9e03754a9..634634e8a 100644 --- a/src/apps/watchfaces/OswAppWatchface.cpp +++ b/src/apps/watchfaces/OswAppWatchface.cpp @@ -29,7 +29,7 @@ void OswAppWatchface::drawStepHistory(OswUI* ui, uint8_t x, uint8_t y, uint8_t w OswHal* hal = OswHal::getInstance(); OswUI::getInstance()->resetTextColors(); - OSW_DATE oswDate = { 0, }; + OswDate oswDate = { }; hal->getLocalDate(&oswDate); uint32_t weekDay = oswDate.weekDay; @@ -94,14 +94,14 @@ void OswAppWatchface::drawWatch() { // hal->gfx()->drawArc(120, 120, 0, bat, 180, 57, 7, dimColor(COLOR_BLUE, 25)); // hal->gfx()->drawArc(120, 120, 0, bat, 180, 57, 6, COLOR_BLUE); - OSW_TIME oswTime = { 0, }; + OswTime oswTime = { }; hal->getLocalTime(&oswTime); uint32_t second = oswTime.second; uint32_t minute = oswTime.minute; uint32_t hour = oswTime.hour; if(OswConfigAllKeys::settingDisplayDualHourTick.get()) { - OSW_TIME oswTime = { 0, }; + OswTime oswTime = { }; hal->getDualTime(&oswTime); uint32_t dualSecond = oswTime.second; uint32_t dualMinute = oswTime.minute; diff --git a/src/apps/watchfaces/OswAppWatchfaceBinary.cpp b/src/apps/watchfaces/OswAppWatchfaceBinary.cpp index 1000f13f8..7d5d715ea 100644 --- a/src/apps/watchfaces/OswAppWatchfaceBinary.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceBinary.cpp @@ -16,7 +16,7 @@ void OswAppWatchfaceBinary::drawWatch() { OswHal* hal = OswHal::getInstance(); - OSW_TIME oswTime = { 0, }; + OswTime oswTime = { }; hal->getLocalTime(&oswTime); uint32_t second = oswTime.second; uint32_t minute = oswTime.minute; diff --git a/src/apps/watchfaces/OswAppWatchfaceDigital.cpp b/src/apps/watchfaces/OswAppWatchfaceDigital.cpp index 46df0a7f5..0e8f5cd5a 100644 --- a/src/apps/watchfaces/OswAppWatchfaceDigital.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceDigital.cpp @@ -65,7 +65,7 @@ static void drawDate(time_t timeZone, uint8_t fontSize, uint8_t CoordY) { uint32_t monthInt = 0; uint32_t yearInt = 0; const char* weekday = nullptr; - OSW_DATE oswDate = { 0, }; + OswDate oswDate = { }; OswHal* hal = OswHal::getInstance(); hal->getDate(timeZone, &oswDate); @@ -106,7 +106,7 @@ void OswAppWatchfaceDigital::timeOutput(uint32_t hour, uint32_t minute, uint32_t } static void drawTime(time_t timeZone,uint8_t CoordY) { - OSW_TIME oswTime = { 0, }; + OswTime oswTime = { }; char am[] = "AM"; char pm[] = "PM"; OswHal* hal = OswHal::getInstance(); diff --git a/src/apps/watchfaces/OswAppWatchfaceDual.cpp b/src/apps/watchfaces/OswAppWatchfaceDual.cpp index d1c40fa9f..5f169aeac 100644 --- a/src/apps/watchfaces/OswAppWatchfaceDual.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceDual.cpp @@ -32,7 +32,7 @@ void OswAppWatchfaceDual::drawProgressBar(OswUI* ui,uint8_t cx, uint8_t cy, uint void OswAppWatchfaceDual::drawAnimSec() { OswHal* hal = OswHal::getInstance(); uint8_t barWidth = 140; - OSW_TIME oswTime = { 0, }; + OswTime oswTime = { }; hal->getLocalTime(&oswTime); uint32_t onlySecond = oswTime.second; uint16_t barValue = ((float)onlySecond / 60) * barWidth; diff --git a/src/apps/watchfaces/OswAppWatchfaceFitness.cpp b/src/apps/watchfaces/OswAppWatchfaceFitness.cpp index 56a76e7a0..dbcf2f9e9 100644 --- a/src/apps/watchfaces/OswAppWatchfaceFitness.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceFitness.cpp @@ -27,7 +27,7 @@ uint32_t OswAppWatchfaceFitness::calculateKcalorie(uint32_t steps) { void dateDisplay() { OswHal* hal = OswHal::getInstance(); - OSW_DATE oswDate = { 0, }; + OswDate oswDate = { }; hal->getLocalDate(&oswDate); uint32_t dayInt = oswDate.day; uint32_t monthInt = oswDate.month; @@ -71,7 +71,7 @@ void digitalWatchDisplay() { hal->gfx()->setTextMiddleAligned(); hal->gfx()->setTextLeftAligned(); hal->gfx()->setTextCursor(DISP_W / 2 - 30, DISP_W / 2); - OSW_TIME oswTime = { 0, }; + OswTime oswTime = { }; hal->getLocalTime(&oswTime); uint32_t second = oswTime.second; uint32_t minute = oswTime.minute; diff --git a/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp b/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp index c0f4b8353..534ff1238 100644 --- a/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp @@ -111,7 +111,7 @@ void OswAppWatchfaceFitnessAnalog::drawWatchFace(OswHal* hal, uint32_t hour, uin } void OswAppWatchfaceFitnessAnalog::drawDateFace(OswHal* hal, uint32_t hour, uint32_t minute, uint32_t second, bool afterNoon) { - OSW_DATE oswDate = { 0, }; + OswDate oswDate = { }; hal->getLocalDate(&oswDate); const char* weekday = oswDate.weekDayName; @@ -209,7 +209,7 @@ void OswAppWatchfaceFitnessAnalog::onDraw() { OswHal* hal = OswHal::getInstance(); - OSW_TIME oswTime = { 0, }; + OswTime oswTime = { }; uint32_t second = oswTime.second; uint32_t minute = oswTime.minute; uint32_t hour = oswTime.hour; diff --git a/src/apps/watchfaces/OswAppWatchfaceMix.cpp b/src/apps/watchfaces/OswAppWatchfaceMix.cpp index 392744b74..652c6d699 100644 --- a/src/apps/watchfaces/OswAppWatchfaceMix.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceMix.cpp @@ -23,7 +23,7 @@ const char* OswAppWatchfaceMix::getAppName() { void OswAppWatchfaceMix::analogWatchDisplay() { OswHal* hal = OswHal::getInstance(); - OSW_TIME oswTime = { 0, }; + OswTime oswTime = { }; hal->getLocalTime(&oswTime); uint32_t second = oswTime.second; uint32_t minute = oswTime.minute; @@ -52,7 +52,7 @@ void OswAppWatchfaceMix::analogWatchDisplay() { void OswAppWatchfaceMix::dateDisplay() { OswHal* hal = OswHal::getInstance(); - OSW_DATE oswDate = { 0, }; + OswDate oswDate = { }; hal->getLocalDate(&oswDate); uint32_t dayInt = oswDate.day; uint32_t monthInt = oswDate.month; @@ -87,7 +87,7 @@ void OswAppWatchfaceMix::digitalWatchDisplay() { hal->gfx()->setTextLeftAligned(); hal->gfx()->setTextCursor(DISP_W / 2 - OFF_SET_DATE_DIGITAL_WATCH_X_COORD, DISP_H / 2); - OSW_TIME oswTime = { 0, }; + OswTime oswTime = { }; hal->getLocalTime(&oswTime); uint32_t second = oswTime.second; uint32_t minute = oswTime.minute; diff --git a/src/apps/watchfaces/OswAppWatchfaceMonotimer.cpp b/src/apps/watchfaces/OswAppWatchfaceMonotimer.cpp index e0c860d31..ce74c1735 100644 --- a/src/apps/watchfaces/OswAppWatchfaceMonotimer.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceMonotimer.cpp @@ -104,14 +104,14 @@ void OswAppWatchfaceMonotimer::drawWatch() { #endif // ticks - OSW_TIME oswTime = { 0, }; + OswTime oswTime = { }; hal->getLocalTime(&oswTime); uint32_t second = oswTime.second; uint32_t minute = oswTime.minute; uint32_t hour = oswTime.hour; if (OswConfigAllKeys::settingDisplayDualHourTick.get()) { - OSW_TIME oswTime = { 0, }; + OswTime oswTime = { }; hal->getDualTime(&oswTime); uint32_t dualSecond = oswTime.second; uint32_t dualMinute = oswTime.minute; diff --git a/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp b/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp index 2220e547b..661d7eae3 100644 --- a/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp @@ -33,7 +33,7 @@ void OswAppWatchfaceNumerals::drawWatch() { OswAppWatchfaceMonotimer::drawHour(); - OSW_DATE oswDate = { 0, }; + OswDate oswDate = { }; hal->getLocalDate(&oswDate); uint32_t dayInt = oswDate.day; uint32_t monthInt = oswDate.month; @@ -63,13 +63,13 @@ void OswAppWatchfaceNumerals::drawWatch() { #endif // ticks - OSW_TIME oswTime = { 0, }; + OswTime oswTime = { }; hal->getLocalTime(&oswTime); uint32_t second = oswTime.second; uint32_t minute = oswTime.minute; uint32_t hour = oswTime.hour; if(OswConfigAllKeys::settingDisplayDualHourTick.get()) { - OSW_TIME oswTime = { 0, }; + OswTime oswTime = { }; hal->getDualTime(&oswTime); uint32_t dualSecond = oswTime.second; uint32_t dualMinute = oswTime.minute; diff --git a/src/hal/environment.cpp b/src/hal/environment.cpp index 4d477415c..77a0a4bb0 100644 --- a/src/hal/environment.cpp +++ b/src/hal/environment.cpp @@ -132,7 +132,7 @@ void OswHal::Environment::setupStepStatistics() { * @param alwaysPrintStepStatistics Set to true to print the step history to the console */ void OswHal::Environment::commitStepStatistics(const bool& alwaysPrintStepStatistics) { - OSW_DATE oswDate = { 0, }; + OswDate oswDate = { }; OswHal::getInstance()->getLocalDate(&oswDate); uint32_t currDoW = oswDate.weekDay; bool changedDoW = currDoW != this->_stepsLastDoW; @@ -196,7 +196,7 @@ void OswHal::Environment::commitStepStatistics(const bool& alwaysPrintStepStatis uint32_t OswHal::Environment::getStepsOnDay(uint8_t dayOfWeek, bool lastWeek) { this->commitStepStatistics(); - OSW_DATE oswDate = { 0, }; + OswDate oswDate = { }; OswHal::getInstance()->getLocalDate(&oswDate); uint32_t weekday = oswDate.weekDay; if (!lastWeek and dayOfWeek == weekday) @@ -224,7 +224,7 @@ uint32_t OswHal::Environment::getStepsTotalWeek() { #ifdef OSW_FEATURE_STATS_STEPS this->commitStepStatistics(); uint32_t sum = 0; - OSW_DATE oswDate = { 0, }; + OswDate oswDate = { }; OswHal::getInstance()->getLocalDate(&oswDate); uint32_t currDoW = oswDate.weekDay; for (uint8_t i = 0; i < 7; i++) { diff --git a/src/hal/time.cpp b/src/hal/time.cpp index 001516329..231d9f3b8 100644 --- a/src/hal/time.cpp +++ b/src/hal/time.cpp @@ -26,37 +26,37 @@ void OswHal::updateTimeProvider() { OSW_LOG_D("No provider for Time is available!"); } -void OswHal::getUTCTime(OSW_TIME* oswTime) { +void OswHal::getUTCTime(OswTime& oswTime) { RtcDateTime d = RtcDateTime(); d.InitWithUnix32Time(this->getUTCTime()); - oswTime->hour = d.Hour(); - oswTime->minute = d.Minute(); - oswTime->second = d.Second(); + oswTime.hour = d.Hour(); + oswTime.minute = d.Minute(); + oswTime.second = d.Second(); } -void OswHal::getTime(time_t& offset, OSW_TIME* oswTime) { +void OswHal::getTime(time_t& offset, OswTime& oswTime) { RtcDateTime d = RtcDateTime(); d.InitWithUnix32Time(this->getTime(offset)); if (!OswConfigAllKeys::timeFormat.get()) { if (d.Hour() > 12) { - oswTime->hour = d.Hour() - 12; - oswTime->afterNoon = true; + oswTime.hour = d.Hour() - 12; + oswTime.afterNoon = true; } else if (d.Hour() == 0) { - oswTime->hour = 12; - oswTime->afterNoon = false; + oswTime.hour = 12; + oswTime.afterNoon = false; } else if (d.Hour() == 12) { - oswTime->hour = d.Hour(); - oswTime->afterNoon = true; + oswTime.hour = d.Hour(); + oswTime.afterNoon = true; } else { - oswTime->hour = d.Hour(); - oswTime->afterNoon = false; + oswTime.hour = d.Hour(); + oswTime.afterNoon = false; } } else { - oswTime->hour = d.Hour(); - oswTime->afterNoon = false; + oswTime.hour = d.Hour(); + oswTime.afterNoon = false; } - oswTime->minute = d.Minute(); - oswTime->second = d.Second(); + oswTime.minute = d.Minute(); + oswTime.second = d.Second(); } /** @@ -122,7 +122,7 @@ time_t OswHal::getTime(time_t& offset) { return this->getUTCTime() + offset; } -void OswHal::getDate(time_t& offset, OSW_DATE* oswDate, uint32_t* setWDay) { +void OswHal::getDate(time_t& offset, OswDate& oswDate, uint32_t* setWDay) { const char* dayMap[7] = { LANG_SUNDAY , LANG_MONDAY @@ -135,13 +135,13 @@ void OswHal::getDate(time_t& offset, OSW_DATE* oswDate, uint32_t* setWDay) { RtcDateTime d = RtcDateTime(); d.InitWithUnix32Time(this->getTime(offset)); - oswDate->year = d.Year(); - oswDate->month = d.Month(); - oswDate->day = d.Day(); - oswDate->weekDay = d.DayOfWeek(); + oswDate.year = d.Year(); + oswDate.month = d.Month(); + oswDate.day = d.Day(); + oswDate.weekDay = d.DayOfWeek(); if (setWDay != nullptr) { - oswDate->weekDayName = dayMap[*setWDay]; + oswDate.weekDayName = dayMap[*setWDay]; } else { - oswDate->weekDayName = dayMap[oswDate->weekDay]; + oswDate.weekDayName = dayMap[oswDate.weekDay]; } } \ No newline at end of file From 3f5698aa3129eb5cbf328ba7447a948709c9669b Mon Sep 17 00:00:00 2001 From: Ruffalo Lavoisier Date: Mon, 7 Oct 2024 01:00:10 +0900 Subject: [PATCH 4/9] Apps: remove & on args --- src/apps/tools/OswAppDistStats.cpp | 4 ++-- src/apps/tools/OswAppKcalStats.cpp | 2 +- src/apps/tools/OswAppStepStats.cpp | 6 +++--- src/apps/tools/OswAppTimeConfig.cpp | 6 +++--- src/apps/watchfaces/OswAppWatchface.cpp | 6 +++--- src/apps/watchfaces/OswAppWatchfaceBinary.cpp | 2 +- src/apps/watchfaces/OswAppWatchfaceDigital.cpp | 4 ++-- src/apps/watchfaces/OswAppWatchfaceDual.cpp | 2 +- src/apps/watchfaces/OswAppWatchfaceFitness.cpp | 4 ++-- src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp | 2 +- src/apps/watchfaces/OswAppWatchfaceMix.cpp | 6 +++--- src/apps/watchfaces/OswAppWatchfaceMonotimer.cpp | 4 ++-- src/apps/watchfaces/OswAppWatchfaceNumerals.cpp | 6 +++--- src/hal/environment.cpp | 6 +++--- 14 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/apps/tools/OswAppDistStats.cpp b/src/apps/tools/OswAppDistStats.cpp index b3bd169a3..ab4a58981 100644 --- a/src/apps/tools/OswAppDistStats.cpp +++ b/src/apps/tools/OswAppDistStats.cpp @@ -16,7 +16,7 @@ void OswAppDistStats::drawChart() { uint16_t goalValue = OswConfigAllKeys::distPerDay.get(); OswDate oswDate = { }; - hal->getLocalDate(&oswDate); + hal->getLocalDate(oswDate); uint32_t weekDay = oswDate.day; uint32_t dayOfMonth = oswDate.weekDay; @@ -53,7 +53,7 @@ void OswAppDistStats::showStickChart() { void OswAppDistStats::setup() { OswHal* hal = OswHal::getInstance(); OswDate oswDate = { }; - hal->getLocalDate(&oswDate); + hal->getLocalDate(oswDate); cursorPos = oswDate.weekDay; } void OswAppDistStats::loop() { diff --git a/src/apps/tools/OswAppKcalStats.cpp b/src/apps/tools/OswAppKcalStats.cpp index 89c894951..f4fb02ab0 100644 --- a/src/apps/tools/OswAppKcalStats.cpp +++ b/src/apps/tools/OswAppKcalStats.cpp @@ -15,7 +15,7 @@ uint32_t findCursorWeekDay(uint8_t Index) { // Show the day of the week that cursor (Dynamic weekDay--info) OswHal* hal = OswHal::getInstance(); OswDate oswDate = { }; - hal->getLocalDate(&oswDate); + hal->getLocalDate(oswDate); int cursorWeekDay = oswDate.weekDay - (6 - Index); int findWeekDay = (cursorWeekDay >= 0) ? cursorWeekDay : (cursorWeekDay + 7); uint32_t fWD = findWeekDay; diff --git a/src/apps/tools/OswAppStepStats.cpp b/src/apps/tools/OswAppStepStats.cpp index 602c7c307..69925a7f2 100644 --- a/src/apps/tools/OswAppStepStats.cpp +++ b/src/apps/tools/OswAppStepStats.cpp @@ -15,7 +15,7 @@ void OswAppStepStats::drawChart() { uint16_t goalValue = OswConfigAllKeys::stepsPerDay.get(); OswDate oswDate = { }; - hal->getLocalDate(&oswDate); + hal->getLocalDate(oswDate); uint32_t weekDay = oswDate.weekDay; uint32_t dayOfMonth = oswDate.day; @@ -45,7 +45,7 @@ void OswAppStepStats::drawInfoPanel(OswUI* ui, uint32_t pos, uint32_t lastWeekDa hal->gfx()->setTextBottomAligned(); hal->gfx()->setTextCursor(DISP_W / 2, 170); OswDate oswDate = { }; - hal->getLocalDate(&oswDate, &pos); + hal->getLocalDate(oswDate, &pos); const char* weekday = oswDate.weekDayName; hal->gfx()->print(weekday); hal->gfx()->setTextCursor(DISP_W / 2, 190); @@ -74,7 +74,7 @@ void OswAppStepStats::showStickChart() { void OswAppStepStats::setup() { OswHal* hal = OswHal::getInstance(); OswDate oswDate = { }; - hal->getLocalDate(&oswDate); + hal->getLocalDate(oswDate); cursorPos = oswDate.weekDay; } void OswAppStepStats::loop() { diff --git a/src/apps/tools/OswAppTimeConfig.cpp b/src/apps/tools/OswAppTimeConfig.cpp index b2f492bb1..cf7a89c5b 100644 --- a/src/apps/tools/OswAppTimeConfig.cpp +++ b/src/apps/tools/OswAppTimeConfig.cpp @@ -17,8 +17,8 @@ void OswAppTimeConfig::setup() {} void OswAppTimeConfig::enterManualMode() { OswTime oswTime = { }; OswDate oswDate = { }; - OswHal::getInstance()->getLocalTime(&oswTime); - OswHal::getInstance()->getLocalDate(&oswDate); + OswHal::getInstance()->getLocalTime(oswTime); + OswHal::getInstance()->getLocalDate(oswDate); uint32_t second = oswTime.second; uint32_t minute = oswTime.minute; uint32_t hour = oswTime.hour; @@ -199,7 +199,7 @@ void OswAppTimeConfig::loop() { hal->gfx()->setTextLeftAligned(); hal->gfx()->setTextCursor(120 - hal->gfx()->getTextOfsetColumns(4), 120); OswTime oswTime = { }; - hal->getLocalTime(&oswTime); + hal->getLocalTime(oswTime); hal->gfx()->printDecimal(oswTime.hour, 2); hal->gfx()->print(":"); hal->gfx()->printDecimal(oswTime.minute, 2); diff --git a/src/apps/watchfaces/OswAppWatchface.cpp b/src/apps/watchfaces/OswAppWatchface.cpp index 634634e8a..3cdf708a7 100644 --- a/src/apps/watchfaces/OswAppWatchface.cpp +++ b/src/apps/watchfaces/OswAppWatchface.cpp @@ -30,7 +30,7 @@ void OswAppWatchface::drawStepHistory(OswUI* ui, uint8_t x, uint8_t y, uint8_t w OswUI::getInstance()->resetTextColors(); OswDate oswDate = { }; - hal->getLocalDate(&oswDate); + hal->getLocalDate(oswDate); uint32_t weekDay = oswDate.weekDay; for (uint8_t i = 0; i < 7; i++) { @@ -95,14 +95,14 @@ void OswAppWatchface::drawWatch() { // hal->gfx()->drawArc(120, 120, 0, bat, 180, 57, 6, COLOR_BLUE); OswTime oswTime = { }; - hal->getLocalTime(&oswTime); + hal->getLocalTime(oswTime); uint32_t second = oswTime.second; uint32_t minute = oswTime.minute; uint32_t hour = oswTime.hour; if(OswConfigAllKeys::settingDisplayDualHourTick.get()) { OswTime oswTime = { }; - hal->getDualTime(&oswTime); + hal->getDualTime(oswTime); uint32_t dualSecond = oswTime.second; uint32_t dualMinute = oswTime.minute; uint32_t dualHour = oswTime.hour; diff --git a/src/apps/watchfaces/OswAppWatchfaceBinary.cpp b/src/apps/watchfaces/OswAppWatchfaceBinary.cpp index 7d5d715ea..cd3a1f09c 100644 --- a/src/apps/watchfaces/OswAppWatchfaceBinary.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceBinary.cpp @@ -17,7 +17,7 @@ void OswAppWatchfaceBinary::drawWatch() { OswHal* hal = OswHal::getInstance(); OswTime oswTime = { }; - hal->getLocalTime(&oswTime); + hal->getLocalTime(oswTime); uint32_t second = oswTime.second; uint32_t minute = oswTime.minute; uint32_t hour = oswTime.hour; diff --git a/src/apps/watchfaces/OswAppWatchfaceDigital.cpp b/src/apps/watchfaces/OswAppWatchfaceDigital.cpp index 0e8f5cd5a..d8dba5c3c 100644 --- a/src/apps/watchfaces/OswAppWatchfaceDigital.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceDigital.cpp @@ -68,7 +68,7 @@ static void drawDate(time_t timeZone, uint8_t fontSize, uint8_t CoordY) { OswDate oswDate = { }; OswHal* hal = OswHal::getInstance(); - hal->getDate(timeZone, &oswDate); + hal->getDate(timeZone, oswDate); dayInt = oswDate.day; monthInt = oswDate.month; @@ -116,7 +116,7 @@ static void drawTime(time_t timeZone,uint8_t CoordY) { hal->gfx()->setTextLeftAligned(); hal->gfx()->setTextCursor(120 - hal->gfx()->getTextOfsetColumns(OswConfigAllKeys::timeFormat.get() ? 4 : 5.5),CoordY ); - hal->getTime(timeZone, &oswTime); + hal->getTime(timeZone, oswTime); OswAppWatchfaceDigital::timeOutput(oswTime.hour, oswTime.minute, oswTime.second); if (!OswConfigAllKeys::timeFormat.get()) { hal->gfx()->print(" "); diff --git a/src/apps/watchfaces/OswAppWatchfaceDual.cpp b/src/apps/watchfaces/OswAppWatchfaceDual.cpp index 5f169aeac..d665c73bf 100644 --- a/src/apps/watchfaces/OswAppWatchfaceDual.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceDual.cpp @@ -33,7 +33,7 @@ void OswAppWatchfaceDual::drawAnimSec() { OswHal* hal = OswHal::getInstance(); uint8_t barWidth = 140; OswTime oswTime = { }; - hal->getLocalTime(&oswTime); + hal->getLocalTime(oswTime); uint32_t onlySecond = oswTime.second; uint16_t barValue = ((float)onlySecond / 60) * barWidth; barValue = barValue < 2 ? 0 : barValue; diff --git a/src/apps/watchfaces/OswAppWatchfaceFitness.cpp b/src/apps/watchfaces/OswAppWatchfaceFitness.cpp index dbcf2f9e9..2e0864d0c 100644 --- a/src/apps/watchfaces/OswAppWatchfaceFitness.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceFitness.cpp @@ -28,7 +28,7 @@ void dateDisplay() { OswHal* hal = OswHal::getInstance(); OswDate oswDate = { }; - hal->getLocalDate(&oswDate); + hal->getLocalDate(oswDate); uint32_t dayInt = oswDate.day; uint32_t monthInt = oswDate.month; uint32_t yearInt = oswDate.year; @@ -72,7 +72,7 @@ void digitalWatchDisplay() { hal->gfx()->setTextLeftAligned(); hal->gfx()->setTextCursor(DISP_W / 2 - 30, DISP_W / 2); OswTime oswTime = { }; - hal->getLocalTime(&oswTime); + hal->getLocalTime(oswTime); uint32_t second = oswTime.second; uint32_t minute = oswTime.minute; uint32_t hour = oswTime.hour; diff --git a/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp b/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp index 534ff1238..937eef818 100644 --- a/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp @@ -112,7 +112,7 @@ void OswAppWatchfaceFitnessAnalog::drawWatchFace(OswHal* hal, uint32_t hour, uin void OswAppWatchfaceFitnessAnalog::drawDateFace(OswHal* hal, uint32_t hour, uint32_t minute, uint32_t second, bool afterNoon) { OswDate oswDate = { }; - hal->getLocalDate(&oswDate); + hal->getLocalDate(oswDate); const char* weekday = oswDate.weekDayName; hal->gfx()->setTextSize(2); diff --git a/src/apps/watchfaces/OswAppWatchfaceMix.cpp b/src/apps/watchfaces/OswAppWatchfaceMix.cpp index 652c6d699..0442ced02 100644 --- a/src/apps/watchfaces/OswAppWatchfaceMix.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceMix.cpp @@ -24,7 +24,7 @@ const char* OswAppWatchfaceMix::getAppName() { void OswAppWatchfaceMix::analogWatchDisplay() { OswHal* hal = OswHal::getInstance(); OswTime oswTime = { }; - hal->getLocalTime(&oswTime); + hal->getLocalTime(oswTime); uint32_t second = oswTime.second; uint32_t minute = oswTime.minute; uint32_t hour = oswTime.hour; @@ -53,7 +53,7 @@ void OswAppWatchfaceMix::dateDisplay() { OswHal* hal = OswHal::getInstance(); OswDate oswDate = { }; - hal->getLocalDate(&oswDate); + hal->getLocalDate(oswDate); uint32_t dayInt = oswDate.day; uint32_t monthInt = oswDate.month; uint32_t yearInt = oswDate.year; @@ -88,7 +88,7 @@ void OswAppWatchfaceMix::digitalWatchDisplay() { hal->gfx()->setTextCursor(DISP_W / 2 - OFF_SET_DATE_DIGITAL_WATCH_X_COORD, DISP_H / 2); OswTime oswTime = { }; - hal->getLocalTime(&oswTime); + hal->getLocalTime(oswTime); uint32_t second = oswTime.second; uint32_t minute = oswTime.minute; uint32_t hour = oswTime.hour; diff --git a/src/apps/watchfaces/OswAppWatchfaceMonotimer.cpp b/src/apps/watchfaces/OswAppWatchfaceMonotimer.cpp index ce74c1735..a2ba41f1f 100644 --- a/src/apps/watchfaces/OswAppWatchfaceMonotimer.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceMonotimer.cpp @@ -105,14 +105,14 @@ void OswAppWatchfaceMonotimer::drawWatch() { // ticks OswTime oswTime = { }; - hal->getLocalTime(&oswTime); + hal->getLocalTime(oswTime); uint32_t second = oswTime.second; uint32_t minute = oswTime.minute; uint32_t hour = oswTime.hour; if (OswConfigAllKeys::settingDisplayDualHourTick.get()) { OswTime oswTime = { }; - hal->getDualTime(&oswTime); + hal->getDualTime(oswTime); uint32_t dualSecond = oswTime.second; uint32_t dualMinute = oswTime.minute; uint32_t dualHour = oswTime.hour; diff --git a/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp b/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp index 661d7eae3..14679ff5a 100644 --- a/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp @@ -34,7 +34,7 @@ void OswAppWatchfaceNumerals::drawWatch() { OswAppWatchfaceMonotimer::drawHour(); OswDate oswDate = { }; - hal->getLocalDate(&oswDate); + hal->getLocalDate(oswDate); uint32_t dayInt = oswDate.day; uint32_t monthInt = oswDate.month; uint32_t yearInt = oswDate.year; @@ -64,13 +64,13 @@ void OswAppWatchfaceNumerals::drawWatch() { // ticks OswTime oswTime = { }; - hal->getLocalTime(&oswTime); + hal->getLocalTime(oswTime); uint32_t second = oswTime.second; uint32_t minute = oswTime.minute; uint32_t hour = oswTime.hour; if(OswConfigAllKeys::settingDisplayDualHourTick.get()) { OswTime oswTime = { }; - hal->getDualTime(&oswTime); + hal->getDualTime(oswTime); uint32_t dualSecond = oswTime.second; uint32_t dualMinute = oswTime.minute; uint32_t dualHour = oswTime.hour; diff --git a/src/hal/environment.cpp b/src/hal/environment.cpp index 77a0a4bb0..97d22ec61 100644 --- a/src/hal/environment.cpp +++ b/src/hal/environment.cpp @@ -133,7 +133,7 @@ void OswHal::Environment::setupStepStatistics() { */ void OswHal::Environment::commitStepStatistics(const bool& alwaysPrintStepStatistics) { OswDate oswDate = { }; - OswHal::getInstance()->getLocalDate(&oswDate); + OswHal::getInstance()->getLocalDate(oswDate); uint32_t currDoW = oswDate.weekDay; bool changedDoW = currDoW != this->_stepsLastDoW; if(changedDoW) { @@ -197,7 +197,7 @@ void OswHal::Environment::commitStepStatistics(const bool& alwaysPrintStepStatis uint32_t OswHal::Environment::getStepsOnDay(uint8_t dayOfWeek, bool lastWeek) { this->commitStepStatistics(); OswDate oswDate = { }; - OswHal::getInstance()->getLocalDate(&oswDate); + OswHal::getInstance()->getLocalDate(oswDate); uint32_t weekday = oswDate.weekDay; if (!lastWeek and dayOfWeek == weekday) return this->getStepsToday(); @@ -225,7 +225,7 @@ uint32_t OswHal::Environment::getStepsTotalWeek() { this->commitStepStatistics(); uint32_t sum = 0; OswDate oswDate = { }; - OswHal::getInstance()->getLocalDate(&oswDate); + OswHal::getInstance()->getLocalDate(oswDate); uint32_t currDoW = oswDate.weekDay; for (uint8_t i = 0; i < 7; i++) { if (i == currDoW) { From d8fb1aaad177830259b8d2eccac6a83a35fef442 Mon Sep 17 00:00:00 2001 From: Ruffalo Lavoisier Date: Mon, 7 Oct 2024 21:13:43 +0900 Subject: [PATCH 5/9] Apps: remove unnecessary data type --- src/apps/tools/OswAppDistStats.cpp | 5 --- src/apps/tools/OswAppStepStats.cpp | 5 --- src/apps/tools/OswAppTimeConfig.cpp | 28 +++++++--------- src/apps/watchfaces/OswAppWatchface.cpp | 27 ++++++--------- src/apps/watchfaces/OswAppWatchfaceBinary.cpp | 10 ++---- .../watchfaces/OswAppWatchfaceDigital.cpp | 8 +---- .../watchfaces/OswAppWatchfaceFitness.cpp | 13 ++------ .../OswAppWatchfaceFitnessAnalog.cpp | 15 ++------- src/apps/watchfaces/OswAppWatchfaceMix.cpp | 32 +++++++----------- .../watchfaces/OswAppWatchfaceMonotimer.cpp | 14 +++----- .../watchfaces/OswAppWatchfaceNumerals.cpp | 31 +++++++---------- src/hal/environment.cpp | 33 +++++++++---------- 12 files changed, 72 insertions(+), 149 deletions(-) diff --git a/src/apps/tools/OswAppDistStats.cpp b/src/apps/tools/OswAppDistStats.cpp index ab4a58981..fede1dd1b 100644 --- a/src/apps/tools/OswAppDistStats.cpp +++ b/src/apps/tools/OswAppDistStats.cpp @@ -15,11 +15,6 @@ void OswAppDistStats::drawChart() { uint8_t interval = 20; uint16_t goalValue = OswConfigAllKeys::distPerDay.get(); - OswDate oswDate = { }; - hal->getLocalDate(oswDate); - uint32_t weekDay = oswDate.day; - uint32_t dayOfMonth = oswDate.weekDay; - for (uint8_t index = 0; index < 7; index++) { uint32_t weekDayDist = OswAppWatchfaceFitness::calculateDistance(hal->environment()->getStepsOnDay(index)); uint16_t chartStickValue = ((float)(weekDayDist > goalValue ? goalValue : weekDayDist) / goalValue) * chartStickHeight; diff --git a/src/apps/tools/OswAppStepStats.cpp b/src/apps/tools/OswAppStepStats.cpp index 69925a7f2..1d5b9aabb 100644 --- a/src/apps/tools/OswAppStepStats.cpp +++ b/src/apps/tools/OswAppStepStats.cpp @@ -14,11 +14,6 @@ void OswAppStepStats::drawChart() { uint8_t interval = 20; uint16_t goalValue = OswConfigAllKeys::stepsPerDay.get(); - OswDate oswDate = { }; - hal->getLocalDate(oswDate); - uint32_t weekDay = oswDate.weekDay; - uint32_t dayOfMonth = oswDate.day; - for (uint8_t index = 0; index < 7; index++) { unsigned int weekDayStep = hal->environment()->getStepsOnDay(index); unsigned short chartStickValue = ((float)(weekDayStep > goalValue ? goalValue : weekDayStep) / goalValue) * chartStickHeight; diff --git a/src/apps/tools/OswAppTimeConfig.cpp b/src/apps/tools/OswAppTimeConfig.cpp index cf7a89c5b..eccda97fd 100644 --- a/src/apps/tools/OswAppTimeConfig.cpp +++ b/src/apps/tools/OswAppTimeConfig.cpp @@ -19,23 +19,17 @@ void OswAppTimeConfig::enterManualMode() { OswDate oswDate = { }; OswHal::getInstance()->getLocalTime(oswTime); OswHal::getInstance()->getLocalDate(oswDate); - uint32_t second = oswTime.second; - uint32_t minute = oswTime.minute; - uint32_t hour = oswTime.hour; - uint32_t day = oswDate.day; - uint32_t month = oswDate.month; - uint32_t year = oswDate.year; - manualSettingTimestamp[0] = year % 10; - manualSettingTimestamp[1] = month / 10; - manualSettingTimestamp[2] = month % 10; - manualSettingTimestamp[3] = day / 10; - manualSettingTimestamp[4] = day % 10; - manualSettingTimestamp[5] = hour / 10; - manualSettingTimestamp[6] = hour % 10; - manualSettingTimestamp[7] = minute / 10; - manualSettingTimestamp[8] = minute % 10; - manualSettingTimestamp[9] = second / 10; - manualSettingTimestamp[10] = second % 10; + manualSettingTimestamp[0] = oswDate.year % 10; + manualSettingTimestamp[1] = oswDate.month / 10; + manualSettingTimestamp[2] = oswDate.month % 10; + manualSettingTimestamp[3] = oswDate.day / 10; + manualSettingTimestamp[4] = oswDate.day % 10; + manualSettingTimestamp[5] = oswTime.hour / 10; + manualSettingTimestamp[6] = oswTime.hour % 10; + manualSettingTimestamp[7] = oswTime.minute / 10; + manualSettingTimestamp[8] = oswTime.minute % 10; + manualSettingTimestamp[9] = oswTime.second / 10; + manualSettingTimestamp[10] = oswTime.second % 10; manualSettingScreen = true; } diff --git a/src/apps/watchfaces/OswAppWatchface.cpp b/src/apps/watchfaces/OswAppWatchface.cpp index 3cdf708a7..ba8ae4a7f 100644 --- a/src/apps/watchfaces/OswAppWatchface.cpp +++ b/src/apps/watchfaces/OswAppWatchface.cpp @@ -31,7 +31,6 @@ void OswAppWatchface::drawStepHistory(OswUI* ui, uint8_t x, uint8_t y, uint8_t w OswDate oswDate = { }; hal->getLocalDate(oswDate); - uint32_t weekDay = oswDate.weekDay; for (uint8_t i = 0; i < 7; i++) { uint32_t s = hal->environment()->getStepsOnDay(i); @@ -42,7 +41,7 @@ void OswAppWatchface::drawStepHistory(OswUI* ui, uint8_t x, uint8_t y, uint8_t w uint16_t c = (unsigned int) OswConfigAllKeys::stepsPerDay.get() <= s ? ui->getSuccessColor() : ui->getPrimaryColor(); hal->gfx()->fillFrame(x + i * w, y + (h - boxHeight), w, boxHeight, c); // bar frames - uint16_t f = weekDay == i ? ui->getForegroundColor() : ui->getForegroundDimmedColor(); + uint16_t f = oswDate.weekDay == i ? ui->getForegroundColor() : ui->getForegroundDimmedColor(); hal->gfx()->drawRFrame(x + i * w, y, w, h, 2, f); // labels @@ -96,33 +95,27 @@ void OswAppWatchface::drawWatch() { OswTime oswTime = { }; hal->getLocalTime(oswTime); - uint32_t second = oswTime.second; - uint32_t minute = oswTime.minute; - uint32_t hour = oswTime.hour; if(OswConfigAllKeys::settingDisplayDualHourTick.get()) { - OswTime oswTime = { }; - hal->getDualTime(oswTime); - uint32_t dualSecond = oswTime.second; - uint32_t dualMinute = oswTime.minute; - uint32_t dualHour = oswTime.hour; + OswTime oswDualTime = { }; + hal->getDualTime(oswDualTime); // dual-hours - hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 0, 16, (int)(360.0f / 12.0f * (dualHour + dualMinute / 60.0f)), 2, ui->getBackgroundDimmedColor(), true, STRAIGHT_END); - hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 16, 60, (int)(360.0f / 12.0f * (dualHour + dualMinute / 60.0f)), 5, ui->getBackgroundDimmedColor(), true); + hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 0, 16, (int)(360.0f / 12.0f * (oswDualTime.hour + oswDualTime.minute / 60.0f)), 2, ui->getBackgroundDimmedColor(), true, STRAIGHT_END); + hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 16, 60, (int)(360.0f / 12.0f * (oswDualTime.hour + oswDualTime.minute / 60.0f)), 5, ui->getBackgroundDimmedColor(), true); } // hours - hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 0, (int)16, (int)(360.0f / 12.0f * (hour + minute / 60.0f)), 1, ui->getForegroundColor(), true, STRAIGHT_END); - hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 16, 60, (int)(360.0f / 12.0f * (hour + minute / 60.0f)), 4, ui->getForegroundColor(), true); + hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 0, (int)16, (int)(360.0f / 12.0f * (oswTime.hour + oswTime.minute / 60.0f)), 1, ui->getForegroundColor(), true, STRAIGHT_END); + hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 16, 60, (int)(360.0f / 12.0f * (oswTime.hour + oswTime.minute / 60.0f)), 4, ui->getForegroundColor(), true); // minutes - hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 0, 16, (int)(360.0f / 60.0f * (minute + second / 60.0f)), 1, ui->getForegroundColor(), true, STRAIGHT_END); - hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 16, 105, (int)(360.0f / 60.0f * (minute + second / 60.0f)), 4, ui->getForegroundColor(), true); + hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 0, 16, (int)(360.0f / 60.0f * (oswTime.minute + oswTime.second / 60.0f)), 1, ui->getForegroundColor(), true, STRAIGHT_END); + hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 16, 105, (int)(360.0f / 60.0f * (oswTime.minute + oswTime.second / 60.0f)), 4, ui->getForegroundColor(), true); #ifndef GIF_BG // seconds hal->gfx()->fillCircleAA(CENTER_X, CENTER_Y, 3, ui->getDangerColor()); - hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, -16, 110, 180 + 360 / 60 * second, 1, ui->getDangerColor(), true); + hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, -16, 110, 180 + 360 / 60 * oswTime.second, 1, ui->getDangerColor(), true); #endif } diff --git a/src/apps/watchfaces/OswAppWatchfaceBinary.cpp b/src/apps/watchfaces/OswAppWatchfaceBinary.cpp index cd3a1f09c..02bb8a16b 100644 --- a/src/apps/watchfaces/OswAppWatchfaceBinary.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceBinary.cpp @@ -18,10 +18,6 @@ void OswAppWatchfaceBinary::drawWatch() { OswTime oswTime = { }; hal->getLocalTime(oswTime); - uint32_t second = oswTime.second; - uint32_t minute = oswTime.minute; - uint32_t hour = oswTime.hour; - bool afterNoon = oswTime.afterNoon; uint16_t width = hal->gfx()->getWidth(); uint16_t height = hal->gfx()->getHeight(); @@ -29,7 +25,7 @@ void OswAppWatchfaceBinary::drawWatch() { //hours for(uint8_t i = 0; i < 5 ; i++ ) { uint32_t b = pow(2, i); - if((hour & b) == 0) { + if((oswTime.hour & b) == 0) { hal->gfx()->drawFrame(width - (((width - 32) / 8) * i + 64) - 32, height / 2 - 16, 8, 8, ui->getWarningColor()); } else { hal->gfx()->fillFrame(width - (((width - 32) / 8) * i + 64) - 32, height / 2 - 16, 8, 8, ui->getWarningColor()); @@ -38,7 +34,7 @@ void OswAppWatchfaceBinary::drawWatch() { //minutes for(uint8_t i = 0; i < 6 ; i++ ) { uint32_t b = pow(2, i); - if((minute & b) == 0) { + if((oswTime.minute & b) == 0) { hal->gfx()->drawFrame(width - (((width - 32) / 8) * i + 64) - 32, height / 2, 8, 8, ui->getDangerColor()); } else { hal->gfx()->fillFrame(width - (((width - 32) / 8) * i + 64) - 32, height / 2, 8, 8, ui->getDangerColor()); @@ -47,7 +43,7 @@ void OswAppWatchfaceBinary::drawWatch() { //seconds for(uint8_t i = 0; i < 6 ; i++ ) { uint32_t b = pow(2, i); - if((second & b) == 0) { + if((oswTime.second & b) == 0) { hal->gfx()->drawFrame(width - (((width - 32) / 8) * i + 64) - 32, height / 2 + 16, 8, 8, ui->getInfoColor()); } else { hal->gfx()->fillFrame(width - (((width - 32) / 8) * i + 64) - 32, height / 2 + 16, 8, 8, ui->getInfoColor()); diff --git a/src/apps/watchfaces/OswAppWatchfaceDigital.cpp b/src/apps/watchfaces/OswAppWatchfaceDigital.cpp index d8dba5c3c..71f052ecf 100644 --- a/src/apps/watchfaces/OswAppWatchfaceDigital.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceDigital.cpp @@ -61,18 +61,12 @@ void OswAppWatchfaceDigital::dateOutput(uint32_t yearInt, uint32_t monthInt, uin } static void drawDate(time_t timeZone, uint8_t fontSize, uint8_t CoordY) { - uint32_t dayInt = 0; - uint32_t monthInt = 0; - uint32_t yearInt = 0; const char* weekday = nullptr; OswDate oswDate = { }; OswHal* hal = OswHal::getInstance(); hal->getDate(timeZone, oswDate); - dayInt = oswDate.day; - monthInt = oswDate.month; - yearInt = oswDate.year; weekday = oswDate.weekDayName; // we want to output a value like "Wed, 05/02/2021" @@ -91,7 +85,7 @@ static void drawDate(time_t timeZone, uint8_t fontSize, uint8_t CoordY) { // i really would want the date to be dynamic based on what's in the config, but the most efficient thing to do right // now is simply three if statements covering the 3 common conditions. - OswAppWatchfaceDigital::dateOutput(yearInt, monthInt, dayInt); + OswAppWatchfaceDigital::dateOutput(oswDate.year, oswDate.month, oswDate.day); } void OswAppWatchfaceDigital::timeOutput(uint32_t hour, uint32_t minute, uint32_t second,bool showSecond) { diff --git a/src/apps/watchfaces/OswAppWatchfaceFitness.cpp b/src/apps/watchfaces/OswAppWatchfaceFitness.cpp index 2e0864d0c..b6a1c5f24 100644 --- a/src/apps/watchfaces/OswAppWatchfaceFitness.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceFitness.cpp @@ -29,9 +29,6 @@ void dateDisplay() { OswDate oswDate = { }; hal->getLocalDate(oswDate); - uint32_t dayInt = oswDate.day; - uint32_t monthInt = oswDate.month; - uint32_t yearInt = oswDate.year; const char* weekday = oswDate.weekDayName; hal->gfx()->setTextSize(2); @@ -46,7 +43,7 @@ void dateDisplay() { hal->gfx()->setTextMiddleAligned(); hal->gfx()->setTextLeftAligned(); hal->gfx()->setTextCursor(DISP_W / 2 - 30 + hal->gfx()->getTextOfsetColumns(1), 150); - OswAppWatchfaceDigital::dateOutput(yearInt, monthInt, dayInt); + OswAppWatchfaceDigital::dateOutput(oswDate.year, oswDate.month, oswDate.day); } void timeDisplay(uint32_t hour, uint32_t minute, uint32_t second) { @@ -73,15 +70,11 @@ void digitalWatchDisplay() { hal->gfx()->setTextCursor(DISP_W / 2 - 30, DISP_W / 2); OswTime oswTime = { }; hal->getLocalTime(oswTime); - uint32_t second = oswTime.second; - uint32_t minute = oswTime.minute; - uint32_t hour = oswTime.hour; - bool afterNoon = oswTime.afterNoon; - timeDisplay(hour, minute, second); + timeDisplay(oswTime.hour, oswTime.minute, oswTime.second); if (!OswConfigAllKeys::timeFormat.get()) { hal->gfx()->setTextCursor(215, 130); - if (afterNoon) { + if (oswTime.afterNoon) { hal->gfx()->print(pm); } else { hal->gfx()->print(am); diff --git a/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp b/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp index 937eef818..34f6c9a24 100644 --- a/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp @@ -119,16 +119,11 @@ void OswAppWatchfaceFitnessAnalog::drawDateFace(OswHal* hal, uint32_t hour, uint hal->gfx()->setTextRightAligned(); hal->gfx()->setTextCursor(205, 75); OswAppWatchfaceDigital::displayWeekDay3(weekday); - - // Date - uint32_t dayInt = oswDate.day; - uint32_t monthInt = oswDate.month; - uint32_t yearInt = oswDate.year; hal->gfx()->setTextSize(3); hal->gfx()->setTextLeftAligned(); hal->gfx()->setTextCursor(CENTER_X - 70, 170); - OswAppWatchfaceDigital::dateOutput(yearInt, monthInt, dayInt); + OswAppWatchfaceDigital::dateOutput(oswDate.year, oswDate.month, oswDate.day); hal->gfx()->setTextSize(4); hal->gfx()->setTextLeftAligned(); @@ -210,19 +205,15 @@ void OswAppWatchfaceFitnessAnalog::onDraw() { OswHal* hal = OswHal::getInstance(); OswTime oswTime = { }; - uint32_t second = oswTime.second; - uint32_t minute = oswTime.minute; - uint32_t hour = oswTime.hour; - bool afterNoon = oswTime.afterNoon; if (this->screen == 0) { #if OSW_PLATFORM_ENVIRONMENT_ACCELEROMETER == 1 showFitnessTracking(hal); #endif - drawWatchFace(hal, hour, minute, second, afterNoon); + drawWatchFace(hal, oswTime.hour, oswTime.minute, oswTime.second, oswTime.afterNoon); } else if (this->screen == 1) { - drawDateFace(hal, hour, minute, second, afterNoon); + drawDateFace(hal, oswTime.hour, oswTime.minute, oswTime.second, oswTime.afterNoon); static int wait_time = 1; if (wait_time >= 0) diff --git a/src/apps/watchfaces/OswAppWatchfaceMix.cpp b/src/apps/watchfaces/OswAppWatchfaceMix.cpp index 0442ced02..affd66a70 100644 --- a/src/apps/watchfaces/OswAppWatchfaceMix.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceMix.cpp @@ -25,28 +25,25 @@ void OswAppWatchfaceMix::analogWatchDisplay() { OswHal* hal = OswHal::getInstance(); OswTime oswTime = { }; hal->getLocalTime(oswTime); - uint32_t second = oswTime.second; - uint32_t minute = oswTime.minute; - uint32_t hour = oswTime.hour; hal->gfx()->drawCircle((int)(DISP_W*0.5)-OFF_SET_ANALOG_WATCH_X_COORD, 100, 50, ui->getForegroundColor()); hal->gfx()->drawHourTicks((int)(DISP_W*0.5)-OFF_SET_ANALOG_WATCH_X_COORD, 100, 45, 40, ui->getForegroundDimmedColor()); // hour hal->gfx()->drawLine(DISP_W/2-OFF_SET_ANALOG_WATCH_X_COORD, 100, - rpx(DISP_W/3-OFF_SET_ANALOG_WATCH_X_COORD, 33 / 2, (int32_t) (hour * 30 + minute/10 * 6)), - rpy(100, 33 / 2, (int32_t)(hour * 30 + minute/10 * 6)), ui->getForegroundColor()); + rpx(DISP_W/3-OFF_SET_ANALOG_WATCH_X_COORD, 33 / 2, (int32_t) (oswTime.hour * 30 + oswTime.minute/10 * 6)), + rpy(100, 33 / 2, (int32_t)(oswTime.hour * 30 + oswTime.minute/10 * 6)), ui->getForegroundColor()); // minute hal->gfx()->drawLine(DISP_W/2-OFF_SET_ANALOG_WATCH_X_COORD, 100, - rpx(DISP_W/2-OFF_SET_ANALOG_WATCH_X_COORD, 66 / 2, (int32_t) minute * 6), - rpy(100, 66 / 2, (int32_t)(minute * 6)), ui->getSuccessColor()); + rpx(DISP_W/2-OFF_SET_ANALOG_WATCH_X_COORD, 66 / 2, (int32_t) oswTime.minute * 6), + rpy(100, 66 / 2, (int32_t)(oswTime.minute * 6)), ui->getSuccessColor()); // second hal->gfx()->drawLine(DISP_W/2-OFF_SET_ANALOG_WATCH_X_COORD, 100, - rpx(DISP_W/2-OFF_SET_ANALOG_WATCH_X_COORD, 15 / 2, s2d(second) + 180), - rpy(100, (int)(15 * 0.5f), s2d(second) + 180), ui->getDangerColor()); // short backwards + rpx(DISP_W/2-OFF_SET_ANALOG_WATCH_X_COORD, 15 / 2, s2d(oswTime.second) + 180), + rpy(100, (int)(15 * 0.5f), s2d(oswTime.second) + 180), ui->getDangerColor()); // short backwards hal->gfx()->drawLine(DISP_W/2-OFF_SET_ANALOG_WATCH_X_COORD, 100, - rpx(DISP_W/2-OFF_SET_ANALOG_WATCH_X_COORD, 90 / 2, s2d(second)), - rpy(100, (int)(90 * 0.5f), s2d(second)), ui->getDangerColor()); // long front + rpx(DISP_W/2-OFF_SET_ANALOG_WATCH_X_COORD, 90 / 2, s2d(oswTime.second)), + rpy(100, (int)(90 * 0.5f), s2d(oswTime.second)), ui->getDangerColor()); // long front } void OswAppWatchfaceMix::dateDisplay() { @@ -54,9 +51,6 @@ void OswAppWatchfaceMix::dateDisplay() { OswDate oswDate = { }; hal->getLocalDate(oswDate); - uint32_t dayInt = oswDate.day; - uint32_t monthInt = oswDate.month; - uint32_t yearInt = oswDate.year; const char* weekday = oswDate.weekDayName; hal->gfx()->setTextSize(1); @@ -74,7 +68,7 @@ void OswAppWatchfaceMix::dateDisplay() { hal->gfx()->setTextLeftAligned(); hal->gfx()->setTextCursor(DISP_W / 2 - OFF_SET_DATE_DIGITAL_WATCH_X_COORD, 90); - OswAppWatchfaceDigital::dateOutput(yearInt, monthInt, dayInt); + OswAppWatchfaceDigital::dateOutput(oswDate.year, oswDate.month, oswDate.day); } void OswAppWatchfaceMix::digitalWatchDisplay() { @@ -89,11 +83,7 @@ void OswAppWatchfaceMix::digitalWatchDisplay() { OswTime oswTime = { }; hal->getLocalTime(oswTime); - uint32_t second = oswTime.second; - uint32_t minute = oswTime.minute; - uint32_t hour = oswTime.hour; - bool afterNoon = oswTime.afterNoon; - OswAppWatchfaceDigital::timeOutput(hour, minute, second,false); + OswAppWatchfaceDigital::timeOutput(oswTime.hour, oswTime.minute, oswTime.second, false); if (!OswConfigAllKeys::timeFormat.get()) { hal->gfx()->setTextSize(1); hal->gfx()->setTextMiddleAligned(); @@ -103,7 +93,7 @@ void OswAppWatchfaceMix::digitalWatchDisplay() { hal->gfx()->setTextCursor(DISP_W / 2 - OFF_SET_DATE_DIGITAL_WATCH_X_COORD + hal->gfx()->getTextOfsetColumns(5.25f), 130); hal->gfx()->setTextSize(1); hal->gfx()->print(" "); - if (afterNoon) { + if (oswTime.afterNoon) { hal->gfx()->print(pm); } else { hal->gfx()->print(am); diff --git a/src/apps/watchfaces/OswAppWatchfaceMonotimer.cpp b/src/apps/watchfaces/OswAppWatchfaceMonotimer.cpp index a2ba41f1f..359e88f35 100644 --- a/src/apps/watchfaces/OswAppWatchfaceMonotimer.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceMonotimer.cpp @@ -106,21 +106,15 @@ void OswAppWatchfaceMonotimer::drawWatch() { // ticks OswTime oswTime = { }; hal->getLocalTime(oswTime); - uint32_t second = oswTime.second; - uint32_t minute = oswTime.minute; - uint32_t hour = oswTime.hour; if (OswConfigAllKeys::settingDisplayDualHourTick.get()) { - OswTime oswTime = { }; - hal->getDualTime(oswTime); - uint32_t dualSecond = oswTime.second; - uint32_t dualMinute = oswTime.minute; - uint32_t dualHour = oswTime.hour; + OswTime oswDualTime = { }; + hal->getDualTime(oswDualTime); - hal->gfx()->drawThickTick(120, 120, 0, 105, (360.0f * (60 * dualHour + dualMinute)) / 720.0f, 1, ui->getBackgroundDimmedColor()); + hal->gfx()->drawThickTick(120, 120, 0, 105, (360.0f * (60 * oswDualTime.hour + oswDualTime.minute)) / 720.0f, 1, ui->getBackgroundDimmedColor()); } - hal->gfx()->drawThickTick(120, 120, 0, 105, (360.0f * (60 * hour + minute)) / 720.0f, 1, ui->getForegroundColor()); + hal->gfx()->drawThickTick(120, 120, 0, 105, (360.0f * (60 * oswTime.hour + oswTime.minute)) / 720.0f, 1, ui->getForegroundColor()); hal->gfx()->fillEllipse(120, 120, 4, 4, ui->getForegroundColor()); } diff --git a/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp b/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp index 14679ff5a..b31437c1e 100644 --- a/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp @@ -35,15 +35,12 @@ void OswAppWatchfaceNumerals::drawWatch() { OswDate oswDate = { }; hal->getLocalDate(oswDate); - uint32_t dayInt = oswDate.day; - uint32_t monthInt = oswDate.month; - uint32_t yearInt = oswDate.year; hal->gfx()->setTextCenterAligned(); hal->gfx()->setTextSize(1); hal->gfx()->setTextColor(ui->getDangerColor()); hal->gfx()->setTextCursor(120, 85); - hal->gfx()->print(dayInt); + hal->gfx()->print(oswDate.day); const char* weekday = oswDate.weekDayName; hal->gfx()->setTextCursor(120, 70); @@ -65,34 +62,28 @@ void OswAppWatchfaceNumerals::drawWatch() { // ticks OswTime oswTime = { }; hal->getLocalTime(oswTime); - uint32_t second = oswTime.second; - uint32_t minute = oswTime.minute; - uint32_t hour = oswTime.hour; if(OswConfigAllKeys::settingDisplayDualHourTick.get()) { - OswTime oswTime = { }; - hal->getDualTime(oswTime); - uint32_t dualSecond = oswTime.second; - uint32_t dualMinute = oswTime.minute; - uint32_t dualHour = oswTime.hour; + OswTime oswDualTime = { }; + hal->getDualTime(oswDualTime); // dual-hours - hal->gfx()->drawThickTick(DISP_W / 2, DISP_H / 2, 0, 16, 360.0f / 12.0f * (dualHour + dualMinute / 60.0f), 2, ui->getBackgroundDimmedColor()); - hal->gfx()->drawThickTick(DISP_W / 2, DISP_H / 2, 16, 60, 360.0f / 12.0f * (dualHour + dualMinute / 60.0f), 5, ui->getBackgroundDimmedColor()); + hal->gfx()->drawThickTick(DISP_W / 2, DISP_H / 2, 0, 16, 360.0f / 12.0f * (oswDualTime.hour + oswDualTime.minute / 60.0f), 2, ui->getBackgroundDimmedColor()); + hal->gfx()->drawThickTick(DISP_W / 2, DISP_H / 2, 16, 60, 360.0f / 12.0f * (oswDualTime.hour + oswDualTime.minute / 60.0f), 5, ui->getBackgroundDimmedColor()); } // hours - hal->gfx()->drawThickTick(DISP_W / 2, DISP_H / 2, 0, 16, 360.0f / 12.0f * (hour + minute / 60.0f), 1, ui->getForegroundColor()); - hal->gfx()->drawThickTick(DISP_W / 2, DISP_H / 2, 16, 60, 360.0f / 12.0f * (hour + minute / 60.0f), 4, ui->getForegroundColor()); + hal->gfx()->drawThickTick(DISP_W / 2, DISP_H / 2, 0, 16, 360.0f / 12.0f * (oswTime.hour + oswTime.minute / 60.0f), 1, ui->getForegroundColor()); + hal->gfx()->drawThickTick(DISP_W / 2, DISP_H / 2, 16, 60, 360.0f / 12.0f * (oswTime.hour + oswTime.minute / 60.0f), 4, ui->getForegroundColor()); // minutes - hal->gfx()->drawThickTick(DISP_W / 2, DISP_H / 2, 0, 16, 360.0f / 60.0f * (minute + second / 60.0f), 1, ui->getForegroundColor()); - hal->gfx()->drawThickTick(DISP_W / 2, DISP_H / 2, 16, 80, 360.0f / 60.0f * (minute + second / 60.0f), 4, ui->getForegroundColor()); + hal->gfx()->drawThickTick(DISP_W / 2, DISP_H / 2, 0, 16, 360.0f / 60.0f * (oswTime.minute + oswTime.second / 60.0f), 1, ui->getForegroundColor()); + hal->gfx()->drawThickTick(DISP_W / 2, DISP_H / 2, 16, 80, 360.0f / 60.0f * (oswTime.minute + oswTime.second / 60.0f), 4, ui->getForegroundColor()); #ifndef GIF_BG // seconds hal->gfx()->fillCircle(DISP_W / 2, DISP_H / 2, 3, ui->getDangerColor()); - hal->gfx()->drawThickTick(DISP_W / 2, DISP_H / 2, 0, 16, 180 + ( 360.0f / 60.0f * second ), 1, ui->getDangerColor()); - hal->gfx()->drawThickTick(DISP_W / 2, DISP_H / 2, 0, 105, 360.0f / 60.0f * second, 1, ui->getDangerColor()); + hal->gfx()->drawThickTick(DISP_W / 2, DISP_H / 2, 0, 16, 180 + ( 360.0f / 60.0f * oswTime.second ), 1, ui->getDangerColor()); + hal->gfx()->drawThickTick(DISP_W / 2, DISP_H / 2, 0, 105, 360.0f / 60.0f * oswTime.second, 1, ui->getDangerColor()); #endif } diff --git a/src/hal/environment.cpp b/src/hal/environment.cpp index 97d22ec61..df06fbc68 100644 --- a/src/hal/environment.cpp +++ b/src/hal/environment.cpp @@ -134,8 +134,7 @@ void OswHal::Environment::setupStepStatistics() { void OswHal::Environment::commitStepStatistics(const bool& alwaysPrintStepStatistics) { OswDate oswDate = { }; OswHal::getInstance()->getLocalDate(oswDate); - uint32_t currDoW = oswDate.weekDay; - bool changedDoW = currDoW != this->_stepsLastDoW; + bool changedDoW = oswDate.weekDay != this->_stepsLastDoW; if(changedDoW) { Preferences prefs; bool res = prefs.begin(PREFS_STEPS, false); // Open in RW, just in case @@ -144,14 +143,14 @@ void OswHal::Environment::commitStepStatistics(const bool& alwaysPrintStepStatis this->_stepsSum += currentSteps; // Let's just hope this never rolls over... OswHal::getInstance()->environment()->resetStepCount(); if(OswConfigAllKeys::stepsHistoryClear.get()) { - if(currDoW > this->_stepsLastDoW) { - // set stepscache to 0 in ]lastDoW, currDoW[ - for(uint32_t i = currDoW; this->_stepsLastDoW + 1 < i; i--) + if(oswDate.weekDay > this->_stepsLastDoW) { + // set stepscache to 0 in ]lastDoW, oswDate.weekDay[ + for(uint32_t i = oswDate.weekDay; this->_stepsLastDoW + 1 < i; i--) this->_stepsCache[i - 1] = 0; } else { // set > last dow to 0 && set < curr dow to 0 - if(currDoW > 0) - for(uint32_t i = currDoW; 0 < i; i--) + if(oswDate.weekDay > 0) + for(uint32_t i = oswDate.weekDay; 0 < i; i--) this->_stepsCache[i - 1] = 0; for(uint32_t i = this->_stepsLastDoW + 1; i < 7; i++) this->_stepsCache[i] = 0; @@ -160,11 +159,11 @@ void OswHal::Environment::commitStepStatistics(const bool& alwaysPrintStepStatis // Check if today is the initialization day short resetDay = OswConfigAllKeys::resetDay.get(); - if ((resetDay >= 0 && resetDay < 8) && (unsigned short) resetDay == currDoW + 1) // (e.g. 1 - 7 are days, 0 is disabled) + if ((resetDay >= 0 && resetDay < 8) && (unsigned short) resetDay == oswDate.weekDay + 1) // (e.g. 1 - 7 are days, 0 is disabled) this->_stepsSum = 0; - this->_stepsLastDoW = currDoW; - OSW_LOG_D("Updated steps from DoW ", this->_stepsLastDoW, " to DoW ", currDoW); + this->_stepsLastDoW = oswDate.weekDay; + OSW_LOG_D("Updated steps from DoW ", this->_stepsLastDoW, " to DoW ", oswDate.weekDay); // write step cache + stepsum res = prefs.putBytes(PREFS_STEPS_STATS, &this->_stepsCache, sizeof(this->_stepsCache)) == sizeof(this->_stepsCache); @@ -178,14 +177,14 @@ void OswHal::Environment::commitStepStatistics(const bool& alwaysPrintStepStatis #ifndef NDEBUG if(changedDoW or alwaysPrintStepStatistics) { - String stepHistoryDbgMsg = "Current step history (day " + String(currDoW) + ", today " + String(OswHal::getInstance()->environment()->getStepsToday()) + ", sum " + String(this->_stepsSum) + ") is: {"; + String stepHistoryDbgMsg = "Current step history (day " + String(oswDate.weekDay) + ", today " + String(OswHal::getInstance()->environment()->getStepsToday()) + ", sum " + String(this->_stepsSum) + ") is: {"; for(size_t i = 0; i < 7; i++) { if(i > 0) stepHistoryDbgMsg += ", "; - if(i == currDoW) + if(i == oswDate.weekDay) stepHistoryDbgMsg += "["; stepHistoryDbgMsg += this->_stepsCache[i]; - if(i == currDoW) + if(i == oswDate.weekDay) stepHistoryDbgMsg += "]"; } stepHistoryDbgMsg += "}"; @@ -198,10 +197,9 @@ uint32_t OswHal::Environment::getStepsOnDay(uint8_t dayOfWeek, bool lastWeek) { this->commitStepStatistics(); OswDate oswDate = { }; OswHal::getInstance()->getLocalDate(oswDate); - uint32_t weekday = oswDate.weekDay; - if (!lastWeek and dayOfWeek == weekday) + if (!lastWeek and dayOfWeek == oswDate.weekDay) return this->getStepsToday(); - else if(!lastWeek or (lastWeek and dayOfWeek == weekday)) + else if(!lastWeek or (lastWeek and dayOfWeek == oswDate.weekDay)) return this->_stepsCache[dayOfWeek]; else return 0; // In that case we don't have any history left anymore - just reply with a zero... @@ -226,9 +224,8 @@ uint32_t OswHal::Environment::getStepsTotalWeek() { uint32_t sum = 0; OswDate oswDate = { }; OswHal::getInstance()->getLocalDate(oswDate); - uint32_t currDoW = oswDate.weekDay; for (uint8_t i = 0; i < 7; i++) { - if (i == currDoW) { + if (i == oswDate.weekDay) { sum = sum + this->getStepsToday(); } sum = sum + this->_stepsCache[i]; From 61519136bf5de7e27d56eca725010f98c145b2bb Mon Sep 17 00:00:00 2001 From: Ruffalo Lavoisier Date: Thu, 10 Oct 2024 18:51:26 +0900 Subject: [PATCH 6/9] HAL: replace getWeekDay method to array --- include/osw_hal.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/osw_hal.h b/include/osw_hal.h index d02fefbf0..d0d471b52 100644 --- a/include/osw_hal.h +++ b/include/osw_hal.h @@ -229,6 +229,16 @@ class OswHal { this->getDate(this->timezoneOffsetPrimary, oswDate, sWDay); }; + const std::array getWeekDay = { + LANG_SUNDAY, + LANG_MONDAY, + LANG_TUESDAY, + LANG_WEDNESDAY, + LANG_THURSDAY, + LANG_FRIDAY, + LANG_SATURDAY + }; + bool _requestDisableBuffer = false; bool _requestEnableBuffer = false; From d644e5030ac1a02f7e7c60de74edc0cec1bf3b48 Mon Sep 17 00:00:00 2001 From: Ruffalo Lavoisier Date: Tue, 15 Oct 2024 05:03:38 +0900 Subject: [PATCH 7/9] Apply getWeekDay array API --- include/osw_hal.h | 11 +++++------ src/apps/tools/OswAppStepStats.cpp | 4 ++-- src/apps/watchfaces/OswAppWatchfaceDigital.cpp | 2 +- src/apps/watchfaces/OswAppWatchfaceFitness.cpp | 3 ++- .../watchfaces/OswAppWatchfaceFitnessAnalog.cpp | 2 +- src/apps/watchfaces/OswAppWatchfaceMix.cpp | 2 +- src/apps/watchfaces/OswAppWatchfaceNumerals.cpp | 2 +- src/hal/time.cpp | 17 +---------------- 8 files changed, 14 insertions(+), 29 deletions(-) diff --git a/include/osw_hal.h b/include/osw_hal.h index d0d471b52..aa64f569f 100644 --- a/include/osw_hal.h +++ b/include/osw_hal.h @@ -40,7 +40,6 @@ typedef struct { uint32_t month; uint32_t day; uint32_t weekDay; - const char* weekDayName; } OswDate; class OswHal { @@ -205,7 +204,7 @@ class OswHal { // New time functions with offset time_t getTime(time_t& offset); void getTime(time_t& offset, OswTime& oswTime); - void getDate(time_t& offset, OswDate& oswDate, uint32_t* setWDay = nullptr); + void getDate(time_t& offset, OswDate& oswDate); // For backward compatibility: Local time functions (= primary timezone) inline void getLocalTime(OswTime& oswTime) { @@ -214,8 +213,8 @@ class OswHal { inline uint32_t getLocalTime() { return this->getTime(this->timezoneOffsetPrimary); } - inline void getLocalDate(OswDate& oswDate, uint32_t* sWDay = nullptr) { - this->getDate(this->timezoneOffsetPrimary, oswDate, sWDay); + inline void getLocalDate(OswDate& oswDate) { + this->getDate(this->timezoneOffsetPrimary, oswDate); }; // For backward compatibility: Dual time functions (= secondary timezone) @@ -225,8 +224,8 @@ class OswHal { inline uint32_t getDualTime() { return this->getTime(this->timezoneOffsetSecondary); } - inline void getDualDate(OswDate& oswDate, uint32_t* sWDay = nullptr) { - this->getDate(this->timezoneOffsetPrimary, oswDate, sWDay); + inline void getDualDate(OswDate& oswDate) { + this->getDate(this->timezoneOffsetPrimary, oswDate); }; const std::array getWeekDay = { diff --git a/src/apps/tools/OswAppStepStats.cpp b/src/apps/tools/OswAppStepStats.cpp index 1d5b9aabb..dae9cd7fb 100644 --- a/src/apps/tools/OswAppStepStats.cpp +++ b/src/apps/tools/OswAppStepStats.cpp @@ -40,8 +40,8 @@ void OswAppStepStats::drawInfoPanel(OswUI* ui, uint32_t pos, uint32_t lastWeekDa hal->gfx()->setTextBottomAligned(); hal->gfx()->setTextCursor(DISP_W / 2, 170); OswDate oswDate = { }; - hal->getLocalDate(oswDate, &pos); - const char* weekday = oswDate.weekDayName; + hal->getLocalDate(oswDate); + const char* weekday = hal->getWeekDay[oswDate.weekDay]; hal->gfx()->print(weekday); hal->gfx()->setTextCursor(DISP_W / 2, 190); hal->gfx()->print(String(lastWeekData)); // lastweek(before 7 day) diff --git a/src/apps/watchfaces/OswAppWatchfaceDigital.cpp b/src/apps/watchfaces/OswAppWatchfaceDigital.cpp index 71f052ecf..88071aa8e 100644 --- a/src/apps/watchfaces/OswAppWatchfaceDigital.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceDigital.cpp @@ -67,7 +67,7 @@ static void drawDate(time_t timeZone, uint8_t fontSize, uint8_t CoordY) { hal->getDate(timeZone, oswDate); - weekday = oswDate.weekDayName; + weekday = hal->getWeekDay[oswDate.weekDay]; // we want to output a value like "Wed, 05/02/2021" hal->gfx()->setTextSize(fontSize); diff --git a/src/apps/watchfaces/OswAppWatchfaceFitness.cpp b/src/apps/watchfaces/OswAppWatchfaceFitness.cpp index b6a1c5f24..a0915e022 100644 --- a/src/apps/watchfaces/OswAppWatchfaceFitness.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceFitness.cpp @@ -29,7 +29,8 @@ void dateDisplay() { OswDate oswDate = { }; hal->getLocalDate(oswDate); - const char* weekday = oswDate.weekDayName; + const char* weekday = hal->getWeekDay[oswDate.weekDay]; + hal->gfx()->setTextSize(2); hal->gfx()->setTextMiddleAligned(); diff --git a/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp b/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp index 34f6c9a24..eed567a6f 100644 --- a/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp @@ -113,7 +113,7 @@ void OswAppWatchfaceFitnessAnalog::drawWatchFace(OswHal* hal, uint32_t hour, uin void OswAppWatchfaceFitnessAnalog::drawDateFace(OswHal* hal, uint32_t hour, uint32_t minute, uint32_t second, bool afterNoon) { OswDate oswDate = { }; hal->getLocalDate(oswDate); - const char* weekday = oswDate.weekDayName; + const char* weekday = hal->getWeekDay[oswDate.weekDay]; hal->gfx()->setTextSize(2); hal->gfx()->setTextRightAligned(); diff --git a/src/apps/watchfaces/OswAppWatchfaceMix.cpp b/src/apps/watchfaces/OswAppWatchfaceMix.cpp index affd66a70..bfdbaebe0 100644 --- a/src/apps/watchfaces/OswAppWatchfaceMix.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceMix.cpp @@ -51,7 +51,7 @@ void OswAppWatchfaceMix::dateDisplay() { OswDate oswDate = { }; hal->getLocalDate(oswDate); - const char* weekday = oswDate.weekDayName; + const char* weekday = hal->getWeekDay[oswDate.weekDay]; hal->gfx()->setTextSize(1); hal->gfx()->setTextMiddleAligned(); diff --git a/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp b/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp index b31437c1e..f6a23951e 100644 --- a/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp @@ -42,7 +42,7 @@ void OswAppWatchfaceNumerals::drawWatch() { hal->gfx()->setTextCursor(120, 85); hal->gfx()->print(oswDate.day); - const char* weekday = oswDate.weekDayName; + const char* weekday = hal->getWeekDay[oswDate.weekDay]; hal->gfx()->setTextCursor(120, 70); OswAppWatchfaceDigital::displayWeekDay3(weekday); diff --git a/src/hal/time.cpp b/src/hal/time.cpp index 231d9f3b8..a8d3b45b0 100644 --- a/src/hal/time.cpp +++ b/src/hal/time.cpp @@ -122,26 +122,11 @@ time_t OswHal::getTime(time_t& offset) { return this->getUTCTime() + offset; } -void OswHal::getDate(time_t& offset, OswDate& oswDate, uint32_t* setWDay) { - const char* dayMap[7] = { - LANG_SUNDAY - , LANG_MONDAY - , LANG_TUESDAY - , LANG_WEDNESDAY - , LANG_THURSDAY - , LANG_FRIDAY - , LANG_SATURDAY - }; - +void OswHal::getDate(time_t& offset, OswDate& oswDate) { RtcDateTime d = RtcDateTime(); d.InitWithUnix32Time(this->getTime(offset)); oswDate.year = d.Year(); oswDate.month = d.Month(); oswDate.day = d.Day(); oswDate.weekDay = d.DayOfWeek(); - if (setWDay != nullptr) { - oswDate.weekDayName = dayMap[*setWDay]; - } else { - oswDate.weekDayName = dayMap[oswDate.weekDay]; - } } \ No newline at end of file From 586b00456d19a2eb427a852d034a8dcaf0b469ad Mon Sep 17 00:00:00 2001 From: Ruffalo Lavoisier Date: Thu, 17 Oct 2024 23:13:18 +0900 Subject: [PATCH 8/9] Add exception catch code for std array --- src/apps/tools/OswAppStepStats.cpp | 8 ++++++-- src/apps/watchfaces/OswAppWatchfaceDigital.cpp | 9 ++++++--- src/apps/watchfaces/OswAppWatchfaceFitness.cpp | 10 ++++++---- src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp | 8 ++++++-- src/apps/watchfaces/OswAppWatchfaceMix.cpp | 9 ++++++--- src/apps/watchfaces/OswAppWatchfaceNumerals.cpp | 9 ++++++--- 6 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/apps/tools/OswAppStepStats.cpp b/src/apps/tools/OswAppStepStats.cpp index dae9cd7fb..2c8b2bc93 100644 --- a/src/apps/tools/OswAppStepStats.cpp +++ b/src/apps/tools/OswAppStepStats.cpp @@ -41,8 +41,12 @@ void OswAppStepStats::drawInfoPanel(OswUI* ui, uint32_t pos, uint32_t lastWeekDa hal->gfx()->setTextCursor(DISP_W / 2, 170); OswDate oswDate = { }; hal->getLocalDate(oswDate); - const char* weekday = hal->getWeekDay[oswDate.weekDay]; - hal->gfx()->print(weekday); + try { + const char* weekday = hal->getWeekDay.at(oswDate.weekDay); + hal->gfx()->print(weekday); + } catch (const std::out_of_range& ignore) { + OSW_LOG_E("getWeekDay is out of range: ", ignore.what()); + } hal->gfx()->setTextCursor(DISP_W / 2, 190); hal->gfx()->print(String(lastWeekData)); // lastweek(before 7 day) hal->gfx()->setTextCursor(DISP_W / 2, 215); diff --git a/src/apps/watchfaces/OswAppWatchfaceDigital.cpp b/src/apps/watchfaces/OswAppWatchfaceDigital.cpp index 88071aa8e..ec1e09138 100644 --- a/src/apps/watchfaces/OswAppWatchfaceDigital.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceDigital.cpp @@ -61,13 +61,11 @@ void OswAppWatchfaceDigital::dateOutput(uint32_t yearInt, uint32_t monthInt, uin } static void drawDate(time_t timeZone, uint8_t fontSize, uint8_t CoordY) { - const char* weekday = nullptr; OswDate oswDate = { }; OswHal* hal = OswHal::getInstance(); hal->getDate(timeZone, oswDate); - weekday = hal->getWeekDay[oswDate.weekDay]; // we want to output a value like "Wed, 05/02/2021" hal->gfx()->setTextSize(fontSize); @@ -75,7 +73,12 @@ static void drawDate(time_t timeZone, uint8_t fontSize, uint8_t CoordY) { hal->gfx()->setTextLeftAligned(); hal->gfx()->setTextCursor(120 - hal->gfx()->getTextOfsetColumns(6.9f), CoordY); - OswAppWatchfaceDigital::displayWeekDay3(weekday); + try { + const char* weekday = hal->getWeekDay.at(oswDate.weekDay); + OswAppWatchfaceDigital::displayWeekDay3(weekday); + } catch (const std::out_of_range& ignore) { + OSW_LOG_E("getWeekDay is out of range: ", ignore.what()); + } // The GFX library has an alignment bug, causing single letters to "float", therefore the workaround above is used to still utilize the correct string printing. //hal->gfx()->print(weekday[0]); diff --git a/src/apps/watchfaces/OswAppWatchfaceFitness.cpp b/src/apps/watchfaces/OswAppWatchfaceFitness.cpp index a0915e022..20fafa802 100644 --- a/src/apps/watchfaces/OswAppWatchfaceFitness.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceFitness.cpp @@ -29,15 +29,17 @@ void dateDisplay() { OswDate oswDate = { }; hal->getLocalDate(oswDate); - const char* weekday = hal->getWeekDay[oswDate.weekDay]; - hal->gfx()->setTextSize(2); hal->gfx()->setTextMiddleAligned(); hal->gfx()->setTextRightAligned(); hal->gfx()->setTextCursor(205, 90); - - OswAppWatchfaceDigital::displayWeekDay3(weekday); + try { + const char* weekday = hal->getWeekDay.at(oswDate.weekDay); + OswAppWatchfaceDigital::displayWeekDay3(weekday); + } catch (const std::out_of_range& ignore) { + OSW_LOG_E("getWeekDay is out of range: ", ignore.what()); + } // Date hal->gfx()->setTextSize(2); diff --git a/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp b/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp index eed567a6f..2e3388856 100644 --- a/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp @@ -113,12 +113,16 @@ void OswAppWatchfaceFitnessAnalog::drawWatchFace(OswHal* hal, uint32_t hour, uin void OswAppWatchfaceFitnessAnalog::drawDateFace(OswHal* hal, uint32_t hour, uint32_t minute, uint32_t second, bool afterNoon) { OswDate oswDate = { }; hal->getLocalDate(oswDate); - const char* weekday = hal->getWeekDay[oswDate.weekDay]; hal->gfx()->setTextSize(2); hal->gfx()->setTextRightAligned(); hal->gfx()->setTextCursor(205, 75); - OswAppWatchfaceDigital::displayWeekDay3(weekday); + try { + const char* weekday = hal->getWeekDay.at(oswDate.weekDay); + OswAppWatchfaceDigital::displayWeekDay3(weekday); + } catch (const std::out_of_range& ignore) { + OSW_LOG_E("getWeekDay is out of range: ", ignore.what()); + } hal->gfx()->setTextSize(3); hal->gfx()->setTextLeftAligned(); diff --git a/src/apps/watchfaces/OswAppWatchfaceMix.cpp b/src/apps/watchfaces/OswAppWatchfaceMix.cpp index bfdbaebe0..55e9afea3 100644 --- a/src/apps/watchfaces/OswAppWatchfaceMix.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceMix.cpp @@ -51,14 +51,17 @@ void OswAppWatchfaceMix::dateDisplay() { OswDate oswDate = { }; hal->getLocalDate(oswDate); - const char* weekday = hal->getWeekDay[oswDate.weekDay]; hal->gfx()->setTextSize(1); hal->gfx()->setTextMiddleAligned(); hal->gfx()->setTextLeftAligned(); hal->gfx()->setTextCursor(DISP_W / 2 - OFF_SET_DATE_DIGITAL_WATCH_X_COORD, 75); - - OswAppWatchfaceDigital::displayWeekDay3(weekday); + try { + const char* weekday = hal->getWeekDay.at(oswDate.weekDay); + OswAppWatchfaceDigital::displayWeekDay3(weekday); + } catch (const std::out_of_range& ignore) { + OSW_LOG_E("getWeekDay is out of range: ", ignore.what()); + } hal->gfx()->print(", "); diff --git a/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp b/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp index f6a23951e..3d5275f9f 100644 --- a/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceNumerals.cpp @@ -41,10 +41,13 @@ void OswAppWatchfaceNumerals::drawWatch() { hal->gfx()->setTextColor(ui->getDangerColor()); hal->gfx()->setTextCursor(120, 85); hal->gfx()->print(oswDate.day); - - const char* weekday = hal->getWeekDay[oswDate.weekDay]; hal->gfx()->setTextCursor(120, 70); - OswAppWatchfaceDigital::displayWeekDay3(weekday); + try { + const char* weekday = hal->getWeekDay.at(oswDate.weekDay); + OswAppWatchfaceDigital::displayWeekDay3(weekday); + } catch (const std::out_of_range& ignore) { + OSW_LOG_E("getWeekDay is out of range: ", ignore.what()); + } #if OSW_PLATFORM_ENVIRONMENT_ACCELEROMETER == 1 uint32_t steps = hal->environment()->getStepsToday(); From e6e78ba209ff1a1fef396d40fa82c1c1e3cc95f8 Mon Sep 17 00:00:00 2001 From: Ruffalo Lavoisier Date: Fri, 18 Oct 2024 20:41:25 +0900 Subject: [PATCH 9/9] apps: fix getWeekDay arg to pos value - Gets the name of the day of the week that the cursor points to --- src/apps/tools/OswAppStepStats.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/apps/tools/OswAppStepStats.cpp b/src/apps/tools/OswAppStepStats.cpp index 2c8b2bc93..967ba053d 100644 --- a/src/apps/tools/OswAppStepStats.cpp +++ b/src/apps/tools/OswAppStepStats.cpp @@ -39,10 +39,8 @@ void OswAppStepStats::drawInfoPanel(OswUI* ui, uint32_t pos, uint32_t lastWeekDa hal->gfx()->setTextCenterAligned(); hal->gfx()->setTextBottomAligned(); hal->gfx()->setTextCursor(DISP_W / 2, 170); - OswDate oswDate = { }; - hal->getLocalDate(oswDate); try { - const char* weekday = hal->getWeekDay.at(oswDate.weekDay); + const char* weekday = hal->getWeekDay.at(pos); hal->gfx()->print(weekday); } catch (const std::out_of_range& ignore) { OSW_LOG_E("getWeekDay is out of range: ", ignore.what());