ArduinoLibs
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
RTC Class Reference

Base class for realtime clock handlers. More...

#include <RTC.h>

Inheritance diagram for RTC:
DS1307RTC DS3231RTC DS3232RTC

Public Types

enum  DayOfWeek {
  Monday = 1, Tuesday, Wednesday, Thursday,
  Friday, Saturday, Sunday
}
 Day of the week corresponding to a date. More...
 

Public Member Functions

 RTC ()
 Constructs a new realtime clock handler. More...
 
virtual bool hasUpdates ()
 Returns true if the realtime clock has updated since the last call to this function. More...
 
virtual void readTime (RTCTime *value)
 Reads the current time from the realtime clock into value. More...
 
virtual void readDate (RTCDate *value)
 Reads the current date from the realtime clock into value. More...
 
virtual void writeTime (const RTCTime *value)
 Updates the time in the realtime clock to match value. More...
 
virtual void writeDate (const RTCDate *value)
 Updates the date in the realtime clock to match value. More...
 
virtual void readAlarm (uint8_t alarmNum, RTCAlarm *value)
 Reads the details of the alarm with index alarmNum into value. More...
 
virtual void writeAlarm (uint8_t alarmNum, const RTCAlarm *value)
 Updates the details of the alarm with index alarmNum from value. More...
 
virtual int byteCount () const
 Returns the number of bytes of non-volatile memory that can be used for storage of arbitrary settings, excluding storage used by alarms. More...
 
virtual uint8_t readByte (uint8_t offset)
 Reads the byte at offset within the realtime clock's non-volatile memory. More...
 
virtual void writeByte (uint8_t offset, uint8_t value)
 Writes value to offset within the realtime clock's non-volatile memory. More...
 
virtual int readTemperature ()
 Reads the value of the temperature sensor and returns the temperature in quarters of a degree celcius. More...
 

Static Public Member Functions

static void adjustDays (RTCDate *date, uint8_t flags)
 Adjusts date up or down one day according to flags. More...
 
static void adjustMonths (RTCDate *date, uint8_t flags)
 Adjusts date up or down one month according to flags. More...
 
static void adjustYears (RTCDate *date, uint8_t flags)
 Adjusts date up or down one year according to flags. More...
 
static DayOfWeek dayOfWeek (const RTCDate *date)
 Returns the day of the week corresponding to date. More...
 

Static Public Attributes

static const uint8_t ALARM_COUNT = 4
 Number of alarms that are supported by RTC::readAlarm() and RTC::writeAlarm().
 
static const int NO_TEMPERATURE = 32767
 Value that is returned from readTemperature() if the realtime clock chip cannot determine the temperature.
 
static const uint8_t INCREMENT = 0x0000
 Increment the day, month, or year in a call to adjustDays(), adjustMonths(), or adjustYears().
 
static const uint8_t DECREMENT = 0x0001
 Decrement the day, month, or year in a call to adjustDays(), adjustMonths(), or adjustYears().
 
static const uint8_t WRAP = 0x0002
 Wrap around to the beginning of the current month/year rather than advance to the next one.
 

Detailed Description

Base class for realtime clock handlers.

This class simplifies the process of reading and writing the time and date information in a realtime clock chip. The class also provides support for reading and writing information about alarms and other clock settings.

It is intended that the application will instantiate a subclass of this class to handle the specific realtime clock chip in the system. The default implementation in RTC simulates a clock based on the value of millis(), with alarms and clock settings stored in main memory.

Because the common DS1307 and DS3232 realtime clock chips use a 2-digit year, this class is also limited to dates between 2000 and 2099 inclusive.

See Also
RTCTime, RTCDate, RTCAlarm, DS1307RTC, DS3232RTC

Definition at line 52 of file RTC.h.

Member Enumeration Documentation

Day of the week corresponding to a date.

See Also
dayOfWeek()

Definition at line 58 of file RTC.h.

Constructor & Destructor Documentation

RTC::RTC ( )

Constructs a new realtime clock handler.

See Also
hasUpdates()

Definition at line 105 of file RTC.cpp.

Member Function Documentation

void RTC::adjustDays ( RTCDate date,
uint8_t  flags 
)
static

Adjusts date up or down one day according to flags.

See Also
adjustMonths(), adjustYears()

Definition at line 313 of file RTC.cpp.

void RTC::adjustMonths ( RTCDate date,
uint8_t  flags 
)
static

Adjusts date up or down one month according to flags.

See Also
adjustDays(), adjustYears()

Definition at line 343 of file RTC.cpp.

void RTC::adjustYears ( RTCDate date,
uint8_t  flags 
)
static

Adjusts date up or down one year according to flags.

See Also
adjustDays(), adjustMonths()

Definition at line 370 of file RTC.cpp.

int RTC::byteCount ( ) const
virtual

Returns the number of bytes of non-volatile memory that can be used for storage of arbitrary settings, excluding storage used by alarms.

See Also
readByte(), writeByte()

Reimplemented in DS1307RTC, and DS3232RTC.

Definition at line 235 of file RTC.cpp.

RTC::DayOfWeek RTC::dayOfWeek ( const RTCDate date)
static

Returns the day of the week corresponding to date.

This function is only guaranteed to produce meaningful values for years between 2000 and 2099.

Definition at line 399 of file RTC.cpp.

bool RTC::hasUpdates ( )
virtual

Returns true if the realtime clock has updated since the last call to this function.

The default implementation returns true, indicating that an update is always available to be read.

Reimplemented in DS3231RTC, DS1307RTC, and DS3232RTC.

Definition at line 134 of file RTC.cpp.

void RTC::readAlarm ( uint8_t  alarmNum,
RTCAlarm value 
)
virtual

Reads the details of the alarm with index alarmNum into value.

The alarmNum parameter must be between 0 and ALARM_COUNT - 1.

Alarm details are stored at the end of the realtime clock's non-volatile memory.

See Also
writeAlarm(), alarmCount()

Reimplemented in DS3231RTC, DS1307RTC, and DS3232RTC.

Definition at line 209 of file RTC.cpp.

uint8_t RTC::readByte ( uint8_t  offset)
virtual

Reads the byte at offset within the realtime clock's non-volatile memory.

The offset parameter must be between 0 and byteCount() - 1.

See Also
writeByte(), byteCount()

Reimplemented in DS1307RTC, and DS3232RTC.

Definition at line 247 of file RTC.cpp.

void RTC::readDate ( RTCDate value)
virtual

Reads the current date from the realtime clock into value.

The time should be read first with readTime() as the default implementation only advances the date when the time is read and it crosses midnight.

See Also
writeDate(), readTime()

Reimplemented in DS3231RTC, DS1307RTC, and DS3232RTC.

Definition at line 169 of file RTC.cpp.

int RTC::readTemperature ( )
virtual

Reads the value of the temperature sensor and returns the temperature in quarters of a degree celcius.

Returns the value NO_TEMPERATURE if the realtime clock chip cannot determine the temperature.

Reimplemented in DS3231RTC, and DS3232RTC.

Definition at line 288 of file RTC.cpp.

void RTC::readTime ( RTCTime value)
virtual

Reads the current time from the realtime clock into value.

See Also
writeTime(), readDate()

Reimplemented in DS3231RTC, DS1307RTC, and DS3232RTC.

Definition at line 144 of file RTC.cpp.

void RTC::writeAlarm ( uint8_t  alarmNum,
const RTCAlarm value 
)
virtual

Updates the details of the alarm with index alarmNum from value.

The alarmNum parameter must be between 0 and ALARM_COUNT - 1.

Alarm details are stored at the end of the realtime clock's non-volatile memory.

See Also
readAlarm(), alarmCount()

Reimplemented in DS3231RTC, DS1307RTC, and DS3232RTC.

Definition at line 224 of file RTC.cpp.

void RTC::writeByte ( uint8_t  offset,
uint8_t  value 
)
virtual

Writes value to offset within the realtime clock's non-volatile memory.

The offset parameter must be between 0 and byteCount() - 1.

See Also
readByte(), byteCount()

Reimplemented in DS1307RTC, and DS3232RTC.

Definition at line 262 of file RTC.cpp.

void RTC::writeDate ( const RTCDate value)
virtual

Updates the date in the realtime clock to match value.

See Also
readDate(), writeTime()

Reimplemented in DS3231RTC, DS1307RTC, and DS3232RTC.

Definition at line 194 of file RTC.cpp.

void RTC::writeTime ( const RTCTime value)
virtual

Updates the time in the realtime clock to match value.

See Also
readTime(), writeDate()

Reimplemented in DS3231RTC, DS1307RTC, and DS3232RTC.

Definition at line 179 of file RTC.cpp.


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