ArduinoLibs
|
00001 /* 00002 * Copyright (C) 2012 Southern Storm Software, Pty Ltd. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00019 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00020 * DEALINGS IN THE SOFTWARE. 00021 */ 00022 00023 #ifndef RTC_h 00024 #define RTC_h 00025 00026 #include <inttypes.h> 00027 00028 struct RTCTime 00029 { 00030 uint8_t hour; 00031 uint8_t minute; 00032 uint8_t second; 00033 }; 00034 00035 struct RTCDate 00036 { 00037 unsigned int year; 00038 uint8_t month; 00039 uint8_t day; 00040 }; 00041 00042 struct RTCAlarm 00043 { 00044 uint8_t hour; 00045 uint8_t minute; 00046 uint8_t flags; 00047 }; 00048 00049 class RTC 00050 { 00051 public: 00052 RTC(); 00053 ~RTC(); 00054 00055 enum DayOfWeek 00056 { 00057 Monday = 1, 00058 Tuesday, 00059 Wednesday, 00060 Thursday, 00061 Friday, 00062 Saturday, 00063 Sunday, 00064 }; 00065 00066 virtual bool hasUpdates(); 00067 00068 virtual void readTime(RTCTime *value); 00069 virtual void readDate(RTCDate *value); 00070 00071 virtual void writeTime(const RTCTime *value); 00072 virtual void writeDate(const RTCDate *value); 00073 00074 static const uint8_t ALARM_COUNT = 4; 00075 00076 virtual void readAlarm(uint8_t alarmNum, RTCAlarm *value); 00077 virtual void writeAlarm(uint8_t alarmNum, const RTCAlarm *value); 00078 00079 virtual int byteCount() const; 00080 virtual uint8_t readByte(uint8_t offset); 00081 virtual void writeByte(uint8_t offset, uint8_t value); 00082 00083 static const int NO_TEMPERATURE = 32767; 00084 00085 virtual int readTemperature(); 00086 00087 // Flags for adjustDays(), adjustMonths(), and adjustYears(). 00088 static const uint8_t INCREMENT = 0x0000; 00089 static const uint8_t DECREMENT = 0x0001; 00090 static const uint8_t WRAP = 0x0002; 00091 00092 static void adjustDays(RTCDate *date, uint8_t flags); 00093 static void adjustMonths(RTCDate *date, uint8_t flags); 00094 static void adjustYears(RTCDate *date, uint8_t flags); 00095 00096 static DayOfWeek dayOfWeek(const RTCDate *date); 00097 00098 private: 00099 unsigned long midnight; 00100 RTCDate date; 00101 RTCAlarm alarms[ALARM_COUNT]; 00102 uint8_t *nvram; 00103 }; 00104 00105 #endif