Skip to content

Commit

Permalink
HAL : merged and default param
Browse files Browse the repository at this point in the history
  • Loading branch information
RuffaloLavoisier committed May 8, 2022
1 parent 35ebc3f commit 5736300
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 16 deletions.
10 changes: 8 additions & 2 deletions include/osw_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,18 @@ class OswHal {
time_t getUTCTime();
void getUTCTime(uint32_t* hour, uint32_t* minute, uint32_t* second);
uint32_t getLocalTime();
void getLocalTime(uint32_t* hour, uint32_t* minute, uint32_t* second);
void getLocalTime(uint32_t* hour, uint32_t* minute, uint32_t* second, bool* afterNoon);
void getLocalTime(uint32_t* hour, uint32_t* minute, uint32_t* second, bool* afterNoon = nullptr);
void getDate(uint32_t* day, uint32_t* weekDay);
void getDate(uint32_t* day, uint32_t* month, uint32_t* year);
const char* getWeekday();

// Dual-Time
uint32_t getDualTime();
void getDualTime(uint32_t* hour, uint32_t* minute, uint32_t* second, bool* afterNoon = nullptr);
void getDualDate(uint32_t* day, uint32_t* weekDay);
void getDualDate(uint32_t* day, uint32_t* month, uint32_t* year);
const char* getDualWeekday();

bool _requestDisableBuffer = false;
bool _requestEnableBuffer = false;
Button buttons[NUM_BUTTONS] = {BUTTON_1, BUTTON_2, BUTTON_3};
Expand Down
64 changes: 50 additions & 14 deletions src/hal/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,70 +39,106 @@ void OswHal::getUTCTime(uint32_t *hour, uint32_t *minute, uint32_t *second) {
*second = d.Second();
}

void OswHal::getLocalTime(uint32_t *hour, uint32_t *minute, uint32_t *second) {
void OswHal::getLocalTime(uint32_t *hour, uint32_t *minute, uint32_t *second, bool *afterNoon) {
RtcDateTime d = RtcDateTime();
d.InitWithEpoch32Time(this->getLocalTime());
if (!OswConfigAllKeys::timeFormat.get()) {
if (d.Hour() > 12) {
*hour = d.Hour() - 12;
if (afterNoon!=nullptr) *afterNoon = true;
} else if (d.Hour() == 0) {
*hour = 12;
if (afterNoon != nullptr) *afterNoon = false;
} else if (d.Hour() == 12) {
*hour = d.Hour();
if (afterNoon != nullptr) *afterNoon = true;
} else {
*hour = d.Hour();
if (afterNoon != nullptr) *afterNoon = false;
}
} else {
*hour = d.Hour();
if (afterNoon != nullptr) *afterNoon = false;
}
*minute = d.Minute();
*second = d.Second();
}

void OswHal::getLocalTime(uint32_t *hour, uint32_t *minute, uint32_t *second, bool *afterNoon) {
void OswHal::getDate(uint32_t *day, uint32_t *weekDay) {
RtcDateTime d = RtcDateTime();
d.InitWithEpoch32Time(this->getLocalTime());
*weekDay = d.DayOfWeek();
*day = d.Day();
}

void OswHal::getDate(uint32_t *day, uint32_t *month, uint32_t *year) {
RtcDateTime d = RtcDateTime();
d.InitWithEpoch32Time(getLocalTime());
*day = d.Day();
*month = d.Month();
*year = d.Year();
}

const char *OswHal::getWeekday() {
uint32_t day = 0;
uint32_t wDay = 0;
this->getDate(&day, &wDay);

const char *dayMap[7] = {LANG_SUNDAY, LANG_MONDAY, LANG_TUESDAY, LANG_WEDNESDAY,
LANG_THURSDAY, LANG_FRIDAY, LANG_SATURDAY};
return dayMap[wDay];
}

uint32_t OswHal::getDualTime() {
return this->getUTCTime() + 3600 * OswConfigAllKeys::dualTimeZone.get() + (long)(3600 * OswConfigAllKeys::daylightOffset.get());
}

void OswHal::getDualTime(uint32_t *hour, uint32_t *minute, uint32_t *second, bool *afterNoon) {
RtcDateTime d = RtcDateTime();
d.InitWithEpoch32Time(this->getDualTime());
if (!OswConfigAllKeys::timeFormat.get()) {
if (d.Hour() > 12) {
*hour = d.Hour() - 12;
*afterNoon = true;
if (afterNoon != nullptr) *afterNoon = true;
} else if (d.Hour() == 0) {
*hour = 12;
*afterNoon = false;
if (afterNoon != nullptr) *afterNoon = false;
} else if (d.Hour() == 12) {
*hour = d.Hour();
*afterNoon = true;
if (afterNoon != nullptr) *afterNoon = true;
} else {
*hour = d.Hour();
*afterNoon = false;
if (afterNoon != nullptr) *afterNoon = false;
}
} else {
*hour = d.Hour();
*afterNoon = false;
if (afterNoon != nullptr) *afterNoon = false;
}
*minute = d.Minute();
*second = d.Second();
}

void OswHal::getDate(uint32_t *day, uint32_t *weekDay) {
void OswHal::getDualDate(uint32_t *day, uint32_t *weekDay) {
RtcDateTime d = RtcDateTime();
d.InitWithEpoch32Time(this->getLocalTime());
d.InitWithEpoch32Time(this->getDualTime());
*weekDay = d.DayOfWeek();
*day = d.Day();
}

void OswHal::getDate(uint32_t *day, uint32_t *month, uint32_t *year) {
void OswHal::getDualDate(uint32_t *day, uint32_t *month, uint32_t *year) {
RtcDateTime d = RtcDateTime();
d.InitWithEpoch32Time(getLocalTime());
d.InitWithEpoch32Time(getDualTime());
*day = d.Day();
*month = d.Month();
*year = d.Year();
}

const char *OswHal::getWeekday() {
const char *OswHal::getDualWeekday() {
uint32_t day = 0;
uint32_t wDay = 0;
this->getDate(&day, &wDay);
this->getDualDate(&day, &wDay);

const char *dayMap[7] = {LANG_SUNDAY, LANG_MONDAY, LANG_TUESDAY, LANG_WEDNESDAY,
LANG_THURSDAY, LANG_FRIDAY, LANG_SATURDAY};
LANG_THURSDAY, LANG_FRIDAY, LANG_SATURDAY};
return dayMap[wDay];
}

0 comments on commit 5736300

Please sign in to comment.