Open-Smartwatch / open-smartwatch-os

The Open-Smartwatch Operating System.
https://open-smartwatch.github.io
GNU General Public License v3.0
998 stars 163 forks source link

Simplifies API usage #405

Closed RuffaloLavoisier closed 3 weeks ago

RuffaloLavoisier commented 1 month ago

Update getDate, getTime API with #403

How to use

OswTime oswTime = {  };
hal->getLocalTime(oswTime);

Each element can be referred to as a sub-element. It returns data for a time or date and can be used by selecting the necessary elements.

Summary

internal getUTCTime API

void getUTCTime(uint32_t* hour, uint32_t* minute, uint32_t* second);

to

void getUTCTime(OswTime& oswTime); // New API

internal getTime API

void getTime(time_t& offset, uint32_t* hour, uint32_t* minute, uint32_t* second, bool* afterNoon = nullptr);

to

void getTime(time_t& offset, OswTime& oswTime); // New API

merge internal getDate API

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

to

void getDate(time_t& offset, OswDate& oswDate); // New API

update getLocalTime API

inline void getLocalTime(uint32_t* hour, uint32_t* minute, uint32_t* second, bool* afterNoon = nullptr) {
    this->getTime(this->timezoneOffsetPrimary, hour, minute, second, afterNoon);
}

to

inline void getLocalTime(OswTime& oswTime) {
    this->getTime(this->timezoneOffsetPrimary, oswTime);
}

merge getLocalDate API

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

to

inline void getLocalDate(OswDate& oswDate) {
    this->getDate(this->timezoneOffsetPrimary, oswDate);
};

update getDualTime API

inline void getDualTime(uint32_t* hour, uint32_t* minute, uint32_t* second, bool* afterNoon = nullptr) {
    this->getTime(this->timezoneOffsetSecondary, hour, minute, second, afterNoon);
}

to

inline void getDualTime(OswTime& oswTime) {
    this->getTime(this->timezoneOffsetSecondary, oswTime);
}

merge getDualDate API

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

to

inline void getDualDate(OswDate& oswDate) {
    this->getDate(this->timezoneOffsetPrimary, oswDate);
};

update getWeekDay API

const char* weekDay = OswHal::getInstance()->getWeekDay.at(day);
RuffaloLavoisier commented 1 month ago

Emulator is working !

simonmicro commented 1 month ago

Some thoughts of mine:

simonmicro commented 1 month ago

Hey, the changes to the code itself look fine - but, as expected, LUA is still not compatible with the deprecation attribute. I would recommend you to revert that commit for now and move it into #366, as that PR also aims to fix that.

RuffaloLavoisier commented 1 month ago

@simonmicro Ready to merge.