MCP79410RK
Public Member Functions | Static Public Member Functions | Data Fields
MCP79410Time Class Reference

Container to hold a time value similar to how it's stored on the MCP79410, and also convert to other useful formats. More...

#include <MCP79410RK.h>

Public Member Functions

 MCP79410Time ()
 Constructor, clears object with clear() More...
 
virtual ~MCP79410Time ()
 Destructor.
 
 MCP79410Time (const MCP79410Time &other)
 Construct a time object from another time object.
 
MCP79410Timeoperator= (const MCP79410Time &other)
 Copy another time object into this object.
 
void clear ()
 Clear all of the fields. More...
 
void fromUnixTime (time_t unixTime)
 Fill in the fields of this object from a Unix time value (seconds past January 1, 1970) at GMT. More...
 
time_t toUnixTime () const
 Convert this object to a Unix time value (seconds past January 1, 1970) at GMT. More...
 
int getYear () const
 Gets the year: 2000 <= year < 2099.
 
void setYear (int value)
 Sets the year. More...
 
int getMonth () const
 Gets the month 1 <= month <= 12, 1 = January, 2 = February, ..., 12 = December.
 
void setMonth (int value)
 Sets the month. More...
 
int getDayOfMonth () const
 Gets the day of the month, 1 <= dayOfMonth <= 31 (smaller for some months, of course)
 
void setDayOfMonth (int value)
 Sets the day of the month. More...
 
int getDayOfWeek () const
 Get the day of week: 0 = Sunday, 1 = Monday, 2 = Tuesday, ..., 6 = Saturday.
 
void setDayOfWeek (int value)
 Sets the dayOfWeek value. More...
 
int getHour () const
 Gets the hour in 24-hour format (0 <= hour <= 23) More...
 
void setHour (int value)
 Sets the hour in 24-hour format (0 <= hour <= 23) More...
 
int getMinute () const
 Gets the minute (0 <= minute < 60)
 
void setMinute (int value)
 Sets the minute. More...
 
int getSecond () const
 Gets the second value (0 <= second < 60)
 
void setSecond (int value)
 Sets the second. More...
 
void setAlarmSecond (int second)
 Set the time values for an alarm when second equals alarm. More...
 
void setAlarmMinute (int minute)
 Set the time values for an alarm when minute equals alarm. More...
 
void setAlarmHour (int hour)
 Set the time values for an alarm when hour equals alarm. More...
 
void setAlarmDayOfWeek (int dayOfWeek)
 Set the time values for an alarm when day of week equals alarm. More...
 
void setAlarmDayOfMonth (int dayOfMonth)
 Set the time values for an alarm when day of month equals alarm. More...
 
void setAlarmTime (time_t unixTime)
 Set the time alarm for a specific time. More...
 
String toStringRaw () const
 Make a reasable representation of this object. More...
 

Static Public Member Functions

static int bcdToInt (uint8_t value)
 Utility function to convert a BCD value to an integer. More...
 
static uint8_t intToBcd (int value)
 Utility function to convert a integer to a BCD value. More...
 

Data Fields

const uint8_t ALARM_SECOND = 0
 ALMxMSK value stored in ALMxWKDAY. This is set automatically when using setAlarmSecond().
 
const uint8_t ALARM_MINUTE = 1
 ALMxMSK value stored in ALMxWKDAY. This is set automatically when using setAlarmMinute().
 
const uint8_t ALARM_HOUR = 2
 ALMxMSK value stored in ALMxWKDAY. This is set automatically when using setAlarmHour().
 
const uint8_t ALARM_DAY_OF_WEEK = 3
 ALMxMSK value stored in ALMxWKDAY. This is set automatically when using setAlarmDayOfWeek().
 
const uint8_t ALARM_DAY_OF_MONTH = 4
 ALMxMSK value stored in ALMxWKDAY. This is set automatically when using setAlarmDayOfMonth().
 
const uint8_t ALARM_MONTH_DAY_DOW_HMS = 7
 ALMxMSK value stored in ALMxWKDAY. This is set automatically when using setAlarmTime(). More...
 
uint8_t rawYear
 MCP79410 raw year value, BCD 0 <= year <= 99. Not used for alarms.
 
uint8_t rawMonth
 MCP79410 raw month value, BCD 1 <= month <= 12. Also contains leap year bit when reading the time.
 
uint8_t rawDayOfMonth
 MCP79410 raw day of month value, BCD 1 <= dayOfMonth <= 31.
 
uint8_t rawDayOfWeek
 MCP79410 raw day of week value, BCD 1 <= dayOfWeek <= 7. More...
 
uint8_t rawHour
 MCP79410 raw hour of day, BCD 0 <= hour <= 23. Or can be 12 hour mode with AM/PM flag. More...
 
uint8_t rawMinute
 MCP79410 raw minute, BCD 0 <= minute <= 59.
 
uint8_t rawSecond
 MCP79410 raw second, BCD 0 <= second <= 59. Sometimes contains the oscillator running flag in the high bit.
 
uint8_t alarmMode = 0
 Alarm mode ALARM_SECOND, ALARM_MINUTE, ... More...
 

Detailed Description

Container to hold a time value similar to how it's stored on the MCP79410, and also convert to other useful formats.

Constructor & Destructor Documentation

◆ MCP79410Time()

MCP79410Time::MCP79410Time ( )

Constructor, clears object with clear()

This object allocates no heap memory. It should only have 8 bytes of storge for an object instance.

Member Function Documentation

◆ bcdToInt()

int MCP79410Time::bcdToInt ( uint8_t  value)
static

Utility function to convert a BCD value to an integer.

The MAX79410 stores data in BCD, for example 27 is stored as 0x27 = 39 (decimal). It can only represent values from 0 - 99 of course.

◆ clear()

void MCP79410Time::clear ( )

Clear all of the fields.

Most fields are set to 0 unless invalid. month and dayOfMonth are set to 1.

◆ fromUnixTime()

void MCP79410Time::fromUnixTime ( time_t  unixTime)

Fill in the fields of this object from a Unix time value (seconds past January 1, 1970) at GMT.

You can set this from the value returned by Time.now(), for example.

◆ getHour()

int MCP79410Time::getHour ( ) const

Gets the hour in 24-hour format (0 <= hour <= 23)

Note that the RTC may have a 12-hour + AM/PM format configured, but this method always returns 24-hour.

◆ intToBcd()

uint8_t MCP79410Time::intToBcd ( int  value)
static

Utility function to convert a integer to a BCD value.

The MAX79410 stores data in BCD, for example 27 is stored as 0x27 = 39 (decimal). It can only represent values from 0 - 99 of course.

◆ setAlarmDayOfMonth()

void MCP79410Time::setAlarmDayOfMonth ( int  dayOfMonth)

Set the time values for an alarm when day of month equals alarm.

Parameters
dayOfMonthThe day of month value to trigger the alarm at 1 = first of the month

This is typically used to alarm every month when the day of month equals the specified value. Note that this will only alarm on transition into an equal condition; it has no concept of a missed day of month alarm. Also, if you clear the interrupt you won't get interrupted again in the same d as it only triggers on transition into an equal condition.

You typically use it like this to wake up once a month, on the 15th of the month at midnight UTC:

bool bResult = rtc.setAlarm(t);

Note: the time is at UTC, not taking into account daylight saving time, so it will actually trigger before midnight on the previous day in the United States (and other negative from UTC timezones)!

◆ setAlarmDayOfWeek()

void MCP79410Time::setAlarmDayOfWeek ( int  dayOfWeek)

Set the time values for an alarm when day of week equals alarm.

Parameters
dayOfWeekThe day of week value to trigger the alarm at (0 - 6). Sunday = 0, Monday = 1, ..., Saturday = 6.

This is typically used to alarm every week when the day of week equals the specified value. Note that this will only alarm on transition into an equal condition; it has no concept of a missed day of week alarm. Also, if you clear the interrupt you won't get interrupted again in the same d as it only triggers on transition into an equal condition.

You typically use it like this to wake up once a week, Sunday at midnight UTC:

bool bResult = rtc.setAlarm(t);

Note: the time is at UTC, not taking into account daylight saving time, so it will actually trigger before midnight on the previous day in the United States (and other negative from UTC timezones)!

◆ setAlarmHour()

void MCP79410Time::setAlarmHour ( int  hour)

Set the time values for an alarm when hour equals alarm.

Parameters
hourThe hour value to trigger the alarm at

This is typically used to alarm every hour when the hour equals the specified value. Note that this will only alarm on transition into an equal condition; it has no concept of a missed hour alarm. Also, if you clear the interrupt you won't get interrupted again in the same hour as it only triggers on transition into an equal condition.

You typically use it like this to wake up once a day at midnight

bool bResult = rtc.setAlarm(t);

Note: the hour is at UTC, not taking into account daylight saving time, so keep that in mind.

◆ setAlarmMinute()

void MCP79410Time::setAlarmMinute ( int  minute)

Set the time values for an alarm when minute equals alarm.

Parameters
minuteThe minute value to trigger the alarm at

This is typically used to alarm every hour when the minute equals the specified value. Note that this will only alarm on transition into an equal condition; it has no concept of a missed minute alarm. Also, if you clear the interrupt you won't get interrupted again in the same minute as it only triggers on transition into an equal condition.

You typically use it like this to wake up every hour on he half hour:

bool bResult = rtc.setAlarm(t);

◆ setAlarmSecond()

void MCP79410Time::setAlarmSecond ( int  second)

Set the time values for an alarm when second equals alarm.

Parameters
secondThe second value to trigger the alarm at

This is typically used to alarm every minute when the second equals the specified value. Note that this will only alarm on transition into an equal condition; it has no concept of a missed second alarm.

You typically use it like this:

t.setAlarmSecond(secondsValue);
bool bResult = rtc.setAlarm(t);

In the more common case of "seconds from now" you don't need to use the MCP79410Time object and can just call rtc.setAlarm(secondsFromNow).

◆ setAlarmTime()

void MCP79410Time::setAlarmTime ( time_t  unixTime)

Set the time alarm for a specific time.

Parameters
unixTimeThe time to set the alarm for.

Note that only the second, minute, hour, dayOfWeek, dayOfMonth, and month are tested. You can't set a time alarm for more than a year in advance. Also, the time is at UTC.

◆ setDayOfMonth()

void MCP79410Time::setDayOfMonth ( int  value)

Sets the day of the month.

Parameters
value1 <= value <= 31 (smaller for some months, of course)

Setting the day, month, or year manually does not reset dayOfWeek; it will be inaccurate when setting the date this way!

◆ setDayOfWeek()

void MCP79410Time::setDayOfWeek ( int  value)

Sets the dayOfWeek value.

Parameters
value0 = Sunday, 1 = Monday, 2 = Tuesday, ..., 6 = Saturday

Note: The rawDayOfWeek value is 1 to 7, the value returned by this function is 0 - 6!

◆ setHour()

void MCP79410Time::setHour ( int  value)

Sets the hour in 24-hour format (0 <= hour <= 23)

Parameters
valueHour in 24-hour format (0 <= value <= 23)

◆ setMinute()

void MCP79410Time::setMinute ( int  value)

Sets the minute.

Parameters
valueThe minute: 0 <= value < 60

◆ setMonth()

void MCP79410Time::setMonth ( int  value)

Sets the month.

Parameters
value1 <= value <= 12, 1 = January, 2 = February, ..., 12 = December

Setting the day, month, or year manually does not reset dayOfWeek; it will be inaccurate when setting the date this way!

◆ setSecond()

void MCP79410Time::setSecond ( int  value)

Sets the second.

Parameters
valueThe second: 0 <= value < 60

◆ setYear()

void MCP79410Time::setYear ( int  value)

Sets the year.

Parameters
value2000 <= value <= 2099

Actually, the value is stored modulo 100, so it really doesn't matter what century you pass.

Setting the day, month, or year manually does not reset dayOfWeek; it will be inaccurate when setting the date this way!

◆ toStringRaw()

String MCP79410Time::toStringRaw ( ) const

Make a reasable representation of this object.

If you pass the string to variable arguments (Log.info, sprintf, etc.) make sure you use toStringRaw().c_str() to make sure the object is converted to a c-string (null terminated).

◆ toUnixTime()

time_t MCP79410Time::toUnixTime ( ) const

Convert this object to a Unix time value (seconds past January 1, 1970) at GMT.

The rawDayOfWeek field is ignored.

Field Documentation

◆ ALARM_MONTH_DAY_DOW_HMS

const uint8_t MCP79410Time::ALARM_MONTH_DAY_DOW_HMS = 7

ALMxMSK value stored in ALMxWKDAY. This is set automatically when using setAlarmTime().

Note that this checks only month, day, day of week, hour, minute, and second. It does not check year. However since it oddly checks day of week, you can schedule more than a year out, though things get tricky with leap years. Best to just assume you can only schedule out one year.

◆ alarmMode

uint8_t MCP79410Time::alarmMode = 0

Alarm mode ALARM_SECOND, ALARM_MINUTE, ...

Note that these values are 0-7 and are shifted when storing in the ALxMSK value in the ALMxWKDAY register.

◆ rawDayOfWeek

uint8_t MCP79410Time::rawDayOfWeek

MCP79410 raw day of week value, BCD 1 <= dayOfWeek <= 7.

The RTC does not enforce a day of week convention but this library does. 1 = Sunday, 7 = Saturday. This is because of how it's set based on the Unix mktime/gmtime functions. However, mktime is zero based, so be careful of that.

◆ rawHour

uint8_t MCP79410Time::rawHour

MCP79410 raw hour of day, BCD 0 <= hour <= 23. Or can be 12 hour mode with AM/PM flag.

When setting from cloud time 24-hour time is always used, but the conversion functions can deal with 12-hour.


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