|
SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
|
#include <SensorRTC.h>
Public Member Functions | |
| virtual bool | begin (SensorCommCustom::CustomCallback callback)=0 |
| Initialize the RTC device using a custom callback. | |
| virtual void | setDateTime (RTC_DateTime datetime)=0 |
| Set the date and time of the RTC using an RTC_DateTime object. | |
| virtual RTC_DateTime | getDateTime ()=0 |
| Get the current date and time from the RTC. | |
| virtual const char * | getChipName ()=0 |
| Get the name of the RTC chip. | |
| virtual void | reset () |
| Reset the RTC. | |
| void | getDateTime (struct tm *info) |
| Retrieve the current date and time from the RTC (Real-Time Clock) and populate a struct tm object. | |
| void | setDateTime (uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) |
| Set the date and time of the RTC using individual values. | |
| const char * | strftime (DateTimeFormat style=DT_FMT_YMD_HMS_WEEK) |
| Format the current date and time according to the specified style. | |
| time_t | hwClockRead (const timezone *tz=NULL) |
| Read the time from the RTC (Real-Time Clock) and write it to the system clock. | |
| int | hwClockWrite () |
| Write the current system time to the RTC clock chip. | |
| uint32_t | getDayOfWeek (uint32_t day, uint32_t month, uint32_t year) |
| Calculate the day of the week for a given date using Zeller's congruence. | |
| uint8_t | getNextMonth (uint8_t curMonth) |
| Get the next month based on the current month. | |
| uint16_t | getNextYear (uint16_t curYear) |
| Get the next year based on the current year. | |
| uint32_t | getLeapYear (uint32_t year) |
| Determine whether a given year is a leap year. | |
| uint8_t | getDaysInMonth (uint8_t month, uint16_t year) |
| Get the number of days in a given month of a specific year, considering leap years. | |
| void | convertUtcToTimezone (int &year, int &month, int &day, int &hour, int &minute, int &second, int timezoneOffsetSeconds) |
| Convert UTC time represented by individual values to the time in the specified timezone. | |
| void | convertUtcToTimezone (struct tm &utcTime, int timezoneOffsetSeconds) |
| Overloaded function to convert UTC time represented by a struct tm object to the time in the specified timezone. | |
Static Public Member Functions | |
| static uint8_t | BCD2DEC (uint8_t val) |
| Convert a Binary Coded Decimal (BCD) number to a decimal number. | |
| static uint8_t | DEC2BCD (uint8_t val) |
| Convert a decimal number to a Binary Coded Decimal (BCD) number. | |
Definition at line 214 of file SensorRTC.h.
|
inlinestatic |
Convert a Binary Coded Decimal (BCD) number to a decimal number.
| val | A uint8_t value representing a BCD number. |
Definition at line 657 of file SensorRTC.h.
Referenced by SensorPCF85063::getAlarm(), SensorPCF8563::getAlarm(), SensorPCF85063::getDateTime(), and SensorPCF8563::getDateTime().
|
pure virtual |
Initialize the RTC device using a custom callback.
This function allows for a custom way of initializing the RTC device. It takes a custom callback function as a parameter. The callback can be used to perform custom communication or configuration operations during the initialization process.
| callback | A pointer to the custom callback function. The callback should follow the signature defined in SensorCommCustom::CustomCallback. |
true if the initialization is successful, false otherwise. Implemented in SensorPCF85063, SensorPCF8563, and SensorRtcHelper.
|
inline |
Convert UTC time represented by individual values to the time in the specified timezone.
| year | The year of the UTC time. |
| month | The month of the UTC time (1 - 12). |
| day | The day of the UTC time. |
| hour | The hour of the UTC time (0 - 23). |
| minute | The minute of the UTC time (0 - 59). |
| second | The second of the UTC time (0 - 59). |
| timezoneOffsetSeconds | The offset of the target timezone from UTC (in seconds). |
Definition at line 601 of file SensorRTC.h.
References getDaysInMonth(), and SENSORLIB_LOG_E.
Referenced by convertUtcToTimezone(), and loop().
|
inline |
Overloaded function to convert UTC time represented by a struct tm object to the time in the specified timezone.
| utcTime | A reference to the struct tm object representing UTC time. |
| timezoneOffsetSeconds | The offset of the target timezone from UTC (in seconds). |
Definition at line 633 of file SensorRTC.h.
References convertUtcToTimezone().
|
inlinestatic |
Convert a decimal number to a Binary Coded Decimal (BCD) number.
| val | A uint8_t value representing a decimal number. |
Definition at line 667 of file SensorRTC.h.
Referenced by SensorPCF8563::setAlarm(), SensorPCF85063::setAlarm(), SensorPCF85063::setDateTime(), and SensorPCF8563::setDateTime().
|
pure virtual |
Get the name of the RTC chip.
This is a pure virtual function that derived classes must implement. It returns a pointer to a null - terminated string representing the name of the RTC chip.
Implemented in SensorRtcHelper, SensorPCF85063, and SensorPCF8563.
|
pure virtual |
Get the current date and time from the RTC.
This is a pure virtual function that derived classes must implement. It retrieves the current date and time from the RTC and returns them as an RTC_DateTime object.
Implemented in SensorRtcHelper, SensorPCF85063, SensorPCF8563, SensorPCF85063, SensorPCF8563, and SensorRtcHelper.
Referenced by getDateTime(), hwClockRead(), and strftime().
|
inline |
Retrieve the current date and time from the RTC (Real-Time Clock) and populate a struct tm object.
This function fetches the current date and time information from the RTC device. It then fills the provided struct tm object with the corresponding values. The struct tm object is a standard C structure used to represent date and time components, such as year, month, day, hour, minute, and second.
| info | A pointer to a struct tm object where the retrieved date and time information will be stored. This pointer must not be a null pointer |
struct tm object is the number of years since 1900. The month value ranges from 0 (January) to 11 (December). The day value represents the day of the month, starting from 1. The hour value ranges from 0 to 23, the minute and second values range from 0 to 59. Definition at line 335 of file SensorRTC.h.
References getDateTime(), and RTC_DateTime::toUnixTime().
|
inline |
Calculate the day of the week for a given date using Zeller's congruence.
| day | The day of the month (1 - 31). |
| month | The month of the year (1 - 12). |
| year | The year. |
Definition at line 483 of file SensorRTC.h.
Referenced by SensorPCF85063::setDateTime(), and SensorPCF8563::setDateTime().
|
inline |
Get the number of days in a given month of a specific year, considering leap years.
| month | The month (1 - 12). |
| year | The year. |
Definition at line 552 of file SensorRTC.h.
References getLeapYear().
Referenced by convertUtcToTimezone(), SensorPCF8563::setAlarm(), SensorPCF85063::setAlarm(), testAlarmDay(), and testAlarmHour().
|
inline |
Determine whether a given year is a leap year.
| year | The year to check. |
Definition at line 536 of file SensorRTC.h.
Referenced by getDaysInMonth().
|
inline |
Get the next month based on the current month.
| curMonth | The current month (1 - 12). |
Definition at line 514 of file SensorRTC.h.
|
inline |
Get the next year based on the current year.
| curYear | The current year. |
Definition at line 525 of file SensorRTC.h.
|
inline |
Read the time from the RTC (Real-Time Clock) and write it to the system clock.
This function retrieves the current date and time from the RTC chip, converts it to a Unix timestamp, and then sets this timestamp as the system time on systems that support it (e.g., BSD systems).
| tz | A pointer to a timezone structure specifying timezone information. In modern systems, this parameter is usually ignored and can be set to NULL. The default value of this parameter is NULL. |
Definition at line 427 of file SensorRTC.h.
References getDateTime(), SENSORLIB_LOG_E, timestamp, and RTC_DateTime::toUnixTime().
|
inline |
Write the current system time to the RTC clock chip.
Definition at line 456 of file SensorRTC.h.
References SENSORLIB_LOG_E, and setDateTime().
|
inlinevirtual |
Reset the RTC.
This function is available depending on the chip.
Reimplemented in SensorPCF85063, and SensorPCF8563.
Definition at line 316 of file SensorRTC.h.
|
pure virtual |
Set the date and time of the RTC using an RTC_DateTime object.
This is a pure virtual function that derived classes must implement. It allows setting the RTC's date and time using a single RTC_DateTime object.
| datetime | An RTC_DateTime object containing the date and time information to set on the RTC. |
Implemented in SensorRtcHelper, SensorPCF85063, SensorPCF8563, SensorPCF85063, SensorPCF8563, and SensorRtcHelper.
Referenced by hwClockWrite(), and setDateTime().
|
inline |
Set the date and time of the RTC using individual values.
| year | The year to set on the RTC. It's usually a 16 - bit unsigned integer. |
| month | The month to set on the RTC, ranging from 1 (January) to 12 (December). |
| day | The day of the month to set on the RTC, ranging from 1 to 31, depending on the month and leap year. |
| hour | The hour to set on the RTC, ranging from 0 to 23. |
| minute | The minute to set on the RTC, ranging from 0 to 59. |
| second | The second to set on the RTC, ranging from 0 to 59. |
Definition at line 351 of file SensorRTC.h.
References setDateTime().
|
inline |
Format the current date and time according to the specified style.
This function retrieves the current date and time from the RTC (Real-Time Clock) using the getDateTime() function. Then, it formats the date and time into a string based on the provided style. The result is stored in a static buffer and a pointer to this buffer is returned.
| style | The format style for the date and time string. It should be one of the values defined in the DateTimeFormat enumeration. The default value is DT_FMT_YMD_HMS_WEEK, which represents the format "Year-Month-Day/Hour:Minute:Second - Weekday". |
Definition at line 372 of file SensorRTC.h.
References DT_FMT_DMY, DT_FMT_HM, DT_FMT_HMS, DT_FMT_MDY, DT_FMT_YMD, DT_FMT_YMD_HMS, DT_FMT_YMD_HMS_WEEK, and getDateTime().
Referenced by printDateTime().