CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
cdc::hal::Esp32Rtc Class Reference
Inheritance diagram for cdc::hal::Esp32Rtc:
cdc::hal::IRtc cdc::core::IService

Public Member Functions

 Esp32Rtc ()=default
bool init () override
 Initializes RTC service and timezone context.
bool start () override
void stop () override
core::ServiceState getState () const override
const char * getName () const override
void getTime (struct tm *timeinfo) const override
 Reads current local time into tm.
void getTimeStr (char *buf, size_t bufLen) const override
 Formats current time as HH:MM.
void getDateStr (char *buf, size_t bufLen) const override
 Formats current date as YYYY-MM-DD.
void setTime (int hour, int minute, int second) override
 Sets RTC time while preserving current date.
void setDate (int year, int month, int day) override
 Sets RTC date while preserving current time.
void setTimestamp (time_t timestamp) override
 Sets RTC from UNIX timestamp.
time_t getTimestamp () const override
 Returns current UNIX timestamp.
bool isTimeSet () const override
void markTimeSet () override
void setTimezoneOffset (int8_t hours) override
 Sets timezone offset and persists it.
int8_t getTimezoneOffset () const override
Public Member Functions inherited from cdc::hal::IRtc
virtual ~IRtc ()=default
Public Member Functions inherited from cdc::core::IService
virtual ~IService ()=default

Detailed Description

Definition at line 32 of file Rtc.cpp.

Constructor & Destructor Documentation

◆ Esp32Rtc()

cdc::hal::Esp32Rtc::Esp32Rtc ( )
default

Member Function Documentation

◆ getDateStr()

void cdc::hal::Esp32Rtc::getDateStr ( char * buf,
size_t bufLen ) const
overridevirtual

Formats current date as YYYY-MM-DD.

Parameters
bufOutput character buffer.
bufLenSize of output buffer.
Returns
void

Implements cdc::hal::IRtc.

Definition at line 144 of file Rtc.cpp.

References getTime().

◆ getName()

const char * cdc::hal::Esp32Rtc::getName ( ) const
inlineoverridevirtual

Get service name (for logging/debugging)

Implements cdc::core::IService.

Definition at line 41 of file Rtc.cpp.

◆ getState()

core::ServiceState cdc::hal::Esp32Rtc::getState ( ) const
inlineoverridevirtual

Get current service state

Implements cdc::core::IService.

Definition at line 40 of file Rtc.cpp.

◆ getTime()

void cdc::hal::Esp32Rtc::getTime ( struct tm * timeinfo) const
overridevirtual

Reads current local time into tm.

Parameters
timeinfoOutput time structure.
Returns
void

Implements cdc::hal::IRtc.

Definition at line 118 of file Rtc.cpp.

Referenced by getDateStr(), getTimeStr(), setDate(), and setTime().

◆ getTimestamp()

time_t cdc::hal::Esp32Rtc::getTimestamp ( ) const
overridevirtual

Returns current UNIX timestamp.

Returns
Current UNIX timestamp.

Implements cdc::hal::IRtc.

Definition at line 232 of file Rtc.cpp.

◆ getTimeStr()

void cdc::hal::Esp32Rtc::getTimeStr ( char * buf,
size_t bufLen ) const
overridevirtual

Formats current time as HH:MM.

Parameters
bufOutput character buffer.
bufLenSize of output buffer.
Returns
void

Implements cdc::hal::IRtc.

Definition at line 131 of file Rtc.cpp.

References getTime().

◆ getTimezoneOffset()

int8_t cdc::hal::Esp32Rtc::getTimezoneOffset ( ) const
inlineoverridevirtual

Get timezone offset in hours

Implements cdc::hal::IRtc.

Definition at line 54 of file Rtc.cpp.

◆ init()

bool cdc::hal::Esp32Rtc::init ( )
overridevirtual

Initializes RTC service and timezone context.

Returns
true if initialization succeeded.

Implements cdc::core::IService.

Definition at line 69 of file Rtc.cpp.

References cdc::core::INITIALIZED, LOG_I, LOG_W, cdc::core::STARTED, TAG, and cdc::core::UNINITIALIZED.

◆ isTimeSet()

bool cdc::hal::Esp32Rtc::isTimeSet ( ) const
inlineoverridevirtual

Check if time has been set (year >= 2024)

Implements cdc::hal::IRtc.

Definition at line 51 of file Rtc.cpp.

◆ markTimeSet()

void cdc::hal::Esp32Rtc::markTimeSet ( )
inlineoverridevirtual

Mark time as set (e.g. after NTP sync)

Implements cdc::hal::IRtc.

Definition at line 52 of file Rtc.cpp.

◆ setDate()

void cdc::hal::Esp32Rtc::setDate ( int year,
int month,
int day )
overridevirtual

Sets RTC date while preserving current time.

Parameters
yearYear value.
monthMonth value.
dayDay value.
Returns
void

Implements cdc::hal::IRtc.

Definition at line 193 of file Rtc.cpp.

References getTime(), LOG_I, and TAG.

◆ setTime()

void cdc::hal::Esp32Rtc::setTime ( int hour,
int minute,
int second )
overridevirtual

Sets RTC time while preserving current date.

Parameters
hourHour value.
minuteMinute value.
secondSecond value.
Returns
void

Implements cdc::hal::IRtc.

Definition at line 158 of file Rtc.cpp.

References getTime(), LOG_I, LOG_W, and TAG.

◆ setTimestamp()

void cdc::hal::Esp32Rtc::setTimestamp ( time_t timestamp)
overridevirtual

Sets RTC from UNIX timestamp.

Parameters
timestampUNIX timestamp.
Returns
void

Implements cdc::hal::IRtc.

Definition at line 215 of file Rtc.cpp.

References LOG_I, and TAG.

◆ setTimezoneOffset()

void cdc::hal::Esp32Rtc::setTimezoneOffset ( int8_t hours)
overridevirtual

Sets timezone offset and persists it.

Parameters
hoursTimezone offset from UTC.
Returns
void

Implements cdc::hal::IRtc.

Definition at line 243 of file Rtc.cpp.

References LOG_I, LOG_W, cdc::hal::NVS_KEY_TZ, cdc::hal::NVS_NAMESPACE, and TAG.

◆ start()

bool cdc::hal::Esp32Rtc::start ( )
inlineoverridevirtual

Start the service (can be called after init or stop)

Returns
true on success

Implements cdc::core::IService.

Definition at line 38 of file Rtc.cpp.

References cdc::core::STARTED.

◆ stop()

void cdc::hal::Esp32Rtc::stop ( )
inlineoverridevirtual

Stop the service (reversible, can start again)

Implements cdc::core::IService.

Definition at line 39 of file Rtc.cpp.

References cdc::core::STOPPED.


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