Skip to content

Commit

Permalink
HAL/time: change date/time API param style
Browse files Browse the repository at this point in the history
- init value, method proto type, structure style
  • Loading branch information
RuffaloLavoisier committed Oct 6, 2024
1 parent dc83f8d commit d30ce2d
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 62 deletions.
14 changes: 7 additions & 7 deletions include/osw_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,36 +196,36 @@ 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();
time_t getTimezoneOffsetSecondary();

// 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);
};

Expand Down
4 changes: 2 additions & 2 deletions src/apps/tools/OswAppDistStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/apps/tools/OswAppKcalStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/apps/tools/OswAppStepStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/apps/tools/OswAppTimeConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(":");
Expand Down
6 changes: 3 additions & 3 deletions src/apps/watchfaces/OswAppWatchface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/apps/watchfaces/OswAppWatchfaceBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/apps/watchfaces/OswAppWatchfaceDigital.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/apps/watchfaces/OswAppWatchfaceDual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/apps/watchfaces/OswAppWatchfaceFitness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/apps/watchfaces/OswAppWatchfaceMix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/apps/watchfaces/OswAppWatchfaceMonotimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/apps/watchfaces/OswAppWatchfaceNumerals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/hal/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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++) {
Expand Down
48 changes: 24 additions & 24 deletions src/hal/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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
Expand All @@ -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];
}
}

0 comments on commit d30ce2d

Please sign in to comment.