SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
SensorRtcHelper Class Reference

#include <SensorRtcHelper.hpp>

Inheritance diagram for SensorRtcHelper:
[legend]

Public Member Functions

 SensorRtcHelper ()
 
 ~SensorRtcHelper ()
 
void setRtcDrvModel (SensorRTCType model)
 Set the model of the RTC (real-time clock) driver.
 
bool begin (SensorCommCustom::CustomCallback callback)
 Initialize the RTC driver using a custom callback.
 
void setDateTime (RTC_DateTime datetime)
 Set the date and time on the RTC device.
 
RTC_DateTime getDateTime ()
 Get the current date and time from the RTC device.
 
const char * getChipName ()
 Get the name of the RTC chip.
 
virtual void setDateTime (RTC_DateTime datetime)=0
 Set the date and time of the RTC using an RTC_DateTime 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.
 
virtual RTC_DateTime getDateTime ()=0
 Get the current date and time from 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.
 
- Public Member Functions inherited from SensorRTC
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.
 

Additional Inherited Members

- Static Public Member Functions inherited from SensorRTC
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.
 

Detailed Description

Definition at line 53 of file time/SensorRtcHelper.hpp.

Constructor & Destructor Documentation

◆ SensorRtcHelper()

SensorRtcHelper::SensorRtcHelper ( )

Definition at line 49 of file SensorRtcHelper.cpp.

◆ ~SensorRtcHelper()

SensorRtcHelper::~SensorRtcHelper ( )

Definition at line 54 of file SensorRtcHelper.cpp.

Member Function Documentation

◆ begin()

bool SensorRtcHelper::begin ( SensorCommCustom::CustomCallback  callback)
virtual

Initialize the RTC driver using a custom callback.

This method allows the user to initialize the RTC driver using a custom callback function. The callback can be used to perform custom communication or configuration operations.

Parameters
callbackA pointer to the custom callback function.
Returns
true if the initialization is successful, false otherwise.

Implements SensorRTC.

Definition at line 127 of file SensorRtcHelper.cpp.

References i, RtcDrv_PCF85063, and RtcDrv_UNKNOWN.

Referenced by setup().

◆ getChipName()

const char * SensorRtcHelper::getChipName ( )
virtual

Get the name of the RTC chip.

Returns
A pointer to a constant character array containing the name of the RTC chip.

Implements SensorRTC.

Definition at line 154 of file SensorRtcHelper.cpp.

Referenced by setup().

◆ getDateTime() [1/3]

RTC_DateTime SensorRtcHelper::getDateTime ( )
virtual

Get the current date and time from the RTC device.

This method retrieves the current date and time from the RTC device and returns it as an RTC_DateTime object.

Returns
An RTC_DateTime object representing the current date and time.

Implements SensorRTC.

Definition at line 149 of file SensorRtcHelper.cpp.

Referenced by loop().

◆ getDateTime() [2/3]

virtual RTC_DateTime SensorRTC::getDateTime ( )
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.

Returns
An RTC_DateTime object representing the current date and time of the RTC.

Implements SensorRTC.

◆ getDateTime() [3/3]

void SensorRTC::getDateTime ( struct tm *  info)
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.

Parameters
infoA pointer to a struct tm object where the retrieved date and time information will be stored. This pointer must not be a null pointer
Note
The year value in the 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.

◆ setDateTime() [1/3]

void SensorRtcHelper::setDateTime ( RTC_DateTime  datetime)
virtual

Set the date and time on the RTC device.

This method sets the specified date and time on the RTC device.

Parameters
datetimeAn RTC_DateTime object containing the date and time to set.

Implements SensorRTC.

Definition at line 144 of file SensorRtcHelper.cpp.

Referenced by loop(), and setup().

◆ setDateTime() [2/3]

virtual void SensorRTC::setDateTime ( RTC_DateTime  datetime)
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.

Parameters
datetimeAn RTC_DateTime object containing the date and time information to set on the RTC.

Implements SensorRTC.

◆ setDateTime() [3/3]

void SensorRTC::setDateTime ( uint16_t  year,
uint8_t  month,
uint8_t  day,
uint8_t  hour,
uint8_t  minute,
uint8_t  second 
)
inline

Set the date and time of the RTC using individual values.

Parameters
yearThe year to set on the RTC. It's usually a 16 - bit unsigned integer.
monthThe month to set on the RTC, ranging from 1 (January) to 12 (December).
dayThe day of the month to set on the RTC, ranging from 1 to 31, depending on the month and leap year.
hourThe hour to set on the RTC, ranging from 0 to 23.
minuteThe minute to set on the RTC, ranging from 0 to 59.
secondThe second to set on the RTC, ranging from 0 to 59.

Definition at line 351 of file SensorRTC.h.

◆ setRtcDrvModel()

void SensorRtcHelper::setRtcDrvModel ( SensorRTCType  model)

Set the model of the RTC (real-time clock) driver.

This method is used to specify the type of RTC driver model that the system should use. If not set, the chip type is automatically determined by register information by default.

Parameters
modelAn enumeration value of the SensorRTCType type, indicating a specific RTC driver model. Possible values ​​include RtcDrv_UNKNOWN (unknown model), RtcDrv_PCF85063 (PCF85063 model), RtcDrv_PCF8563 (PCF8563 model), etc.

Definition at line 59 of file SensorRtcHelper.cpp.


The documentation for this class was generated from the following files: