SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
time/SensorRtcHelper.hpp
Go to the documentation of this file.
1
33#pragma once
34
35#include "../SensorBuildOpt.h"
36#if !SENSORLIB_EXCLUDE_RTC
37
40
47typedef enum {
48 RtcDrv_UNKNOWN, // Represents an unknown or unsupported RTC driver type.
49 RtcDrv_PCF85063, // Represents the PCF85063 RTC driver type.
50 RtcDrv_PCF8563, // Represents the PCF8563 RTC driver type.
52
54{
55public:
58
60
62
73 void setRtcDrvModel(SensorRTCType model);
74
75#if defined(ARDUINO)
87 bool begin(TwoWire &wire, int sda = -1, int scl = -1);
88
89#elif defined(ESP_PLATFORM)
90
91#if defined(SENSORLIB_USE_I2C_LEGACY)
103 bool begin(i2c_port_t port_num, int sda, int scl);
104
105#else
106
115 bool begin(i2c_master_bus_handle_t handle);
116
117#endif //SENSORLIB_USE_I2C_LEGACY
118
119#endif // ESP_PLATFORM
120
131
139 void setDateTime(RTC_DateTime datetime);
140
149
154 const char *getChipName();
155
156private:
165 std::unique_ptr<SensorRTC> createDriver(SensorRTCType type);
166
173 using DriverCreator = std::unique_ptr<SensorRTC> (*)();
174
180 static constexpr uint8_t driverCreatorMaxNum = RtcDrv_PCF8563 + 1;
181
188 static DriverCreator driverCreators[driverCreatorMaxNum];
189
196 SensorRTCType _drvType;
197
204 std::unique_ptr<SensorRTC> _drv;
205};
206
207#endif
bool(*)(uint8_t addr, uint8_t reg, uint8_t *buf, size_t len, bool writeReg, bool isWrite) CustomCallback
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.
const char * getChipName()
Get the name of the RTC chip.
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.
bool begin(SensorCommCustom::CustomCallback callback)
Initialize the RTC driver using a custom callback.
void setRtcDrvModel(SensorRTCType model)
Set the model of the RTC (real-time clock) driver.
SensorRTCType
Enumeration of different RTC (Real-Time Clock) driver types.
@ RtcDrv_PCF85063
@license MIT License
@license MIT License