mirror of
https://github.com/taigrr/arduinolibs
synced 2025-01-18 04:33:12 -08:00
Update docs
This commit is contained in:
@@ -2,29 +2,37 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
||||
<title>ArduinoLibs: RTC.cpp Source File</title>
|
||||
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript" src="jquery.js"></script>
|
||||
<script type="text/javascript" src="dynsections.js"></script>
|
||||
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript" src="search/search.js"></script>
|
||||
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() { searchBox.OnSelectItem(0); });
|
||||
</script>
|
||||
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
||||
</head>
|
||||
<body onload='searchBox.OnSelectItem(0);'>
|
||||
<!-- Generated by Doxygen 1.7.4 -->
|
||||
<script type="text/javascript"><!--
|
||||
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||||
--></script>
|
||||
<div id="top">
|
||||
<body>
|
||||
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
||||
<div id="titlearea">
|
||||
<table cellspacing="0" cellpadding="0">
|
||||
<tbody>
|
||||
<tr style="height: 56px;">
|
||||
<td style="padding-left: 0.5em;">
|
||||
<div id="projectname">ArduinoLibs</div>
|
||||
<div id="projectname">ArduinoLibs
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- end header part -->
|
||||
<!-- Generated by Doxygen 1.8.1.2 -->
|
||||
<script type="text/javascript">
|
||||
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||||
</script>
|
||||
<div id="navrow1" class="tabs">
|
||||
<ul class="tablist">
|
||||
<li><a href="index.html"><span>Main Page</span></a></li>
|
||||
@@ -32,7 +40,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Classes</span></a></li>
|
||||
<li class="current"><a href="files.html"><span>Files</span></a></li>
|
||||
<li id="searchli">
|
||||
<li>
|
||||
<div id="MSearchBox" class="MSearchBoxInactive">
|
||||
<span class="left">
|
||||
<img id="MSearchSelect" src="search/mag_sel.png"
|
||||
@@ -55,274 +63,12 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||||
<li><a href="files.html"><span>File List</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="header">
|
||||
<div class="headertitle">
|
||||
<div class="title">RTC.cpp</div> </div>
|
||||
</div>
|
||||
<div class="contents">
|
||||
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
|
||||
<a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 2012 Southern Storm Software, Pty Ltd.</span>
|
||||
<a name="l00003"></a>00003 <span class="comment"> *</span>
|
||||
<a name="l00004"></a>00004 <span class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a</span>
|
||||
<a name="l00005"></a>00005 <span class="comment"> * copy of this software and associated documentation files (the "Software"),</span>
|
||||
<a name="l00006"></a>00006 <span class="comment"> * to deal in the Software without restriction, including without limitation</span>
|
||||
<a name="l00007"></a>00007 <span class="comment"> * the rights to use, copy, modify, merge, publish, distribute, sublicense,</span>
|
||||
<a name="l00008"></a>00008 <span class="comment"> * and/or sell copies of the Software, and to permit persons to whom the</span>
|
||||
<a name="l00009"></a>00009 <span class="comment"> * Software is furnished to do so, subject to the following conditions:</span>
|
||||
<a name="l00010"></a>00010 <span class="comment"> *</span>
|
||||
<a name="l00011"></a>00011 <span class="comment"> * The above copyright notice and this permission notice shall be included</span>
|
||||
<a name="l00012"></a>00012 <span class="comment"> * in all copies or substantial portions of the Software.</span>
|
||||
<a name="l00013"></a>00013 <span class="comment"> *</span>
|
||||
<a name="l00014"></a>00014 <span class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS</span>
|
||||
<a name="l00015"></a>00015 <span class="comment"> * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
|
||||
<a name="l00016"></a>00016 <span class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
|
||||
<a name="l00017"></a>00017 <span class="comment"> * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
|
||||
<a name="l00018"></a>00018 <span class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING</span>
|
||||
<a name="l00019"></a>00019 <span class="comment"> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER</span>
|
||||
<a name="l00020"></a>00020 <span class="comment"> * DEALINGS IN THE SOFTWARE.</span>
|
||||
<a name="l00021"></a>00021 <span class="comment"> */</span>
|
||||
<a name="l00022"></a>00022
|
||||
<a name="l00023"></a>00023 <span class="preprocessor">#include "RTC.h"</span>
|
||||
<a name="l00024"></a>00024 <span class="preprocessor">#if defined(ARDUINO) && ARDUINO >= 100</span>
|
||||
<a name="l00025"></a>00025 <span class="preprocessor"></span><span class="preprocessor">#include <Arduino.h></span>
|
||||
<a name="l00026"></a>00026 <span class="preprocessor">#else</span>
|
||||
<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#include <WProgram.h></span>
|
||||
<a name="l00028"></a>00028 <span class="preprocessor">#endif</span>
|
||||
<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <stdlib.h></span>
|
||||
<a name="l00030"></a>00030 <span class="preprocessor">#include <string.h></span>
|
||||
<a name="l00031"></a>00031
|
||||
<a name="l00058"></a>00058 <span class="preprocessor">#define DEFAULT_BYTE_COUNT 43 // Default simulates DS1307 NVRAM size.</span>
|
||||
<a name="l00059"></a>00059 <span class="preprocessor"></span>
|
||||
<a name="l00060"></a>00060 <span class="preprocessor">#define MILLIS_PER_DAY 86400000UL</span>
|
||||
<a name="l00061"></a>00061 <span class="preprocessor"></span><span class="preprocessor">#define MILLIS_PER_SECOND 1000UL</span>
|
||||
<a name="l00062"></a>00062 <span class="preprocessor"></span><span class="preprocessor">#define MILLIS_PER_MINUTE 60000UL</span>
|
||||
<a name="l00063"></a>00063 <span class="preprocessor"></span><span class="preprocessor">#define MILLIS_PER_HOUR 3600000UL</span>
|
||||
<a name="l00064"></a>00064 <span class="preprocessor"></span>
|
||||
<a name="l00065"></a>00065 <span class="keyword">static</span> uint8_t monthLengths[] = {
|
||||
<a name="l00066"></a>00066 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
|
||||
<a name="l00067"></a>00067 };
|
||||
<a name="l00068"></a>00068
|
||||
<a name="l00069"></a>00069 <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> monthOffsets[] = {
|
||||
<a name="l00070"></a>00070 0,
|
||||
<a name="l00071"></a>00071 31,
|
||||
<a name="l00072"></a>00072 31 + 28,
|
||||
<a name="l00073"></a>00073 31 + 28 + 31,
|
||||
<a name="l00074"></a>00074 31 + 28 + 31 + 30,
|
||||
<a name="l00075"></a>00075 31 + 28 + 31 + 30 + 31,
|
||||
<a name="l00076"></a>00076 31 + 28 + 31 + 30 + 31 + 30,
|
||||
<a name="l00077"></a>00077 31 + 28 + 31 + 30 + 31 + 30 + 31,
|
||||
<a name="l00078"></a>00078 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31,
|
||||
<a name="l00079"></a>00079 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30,
|
||||
<a name="l00080"></a>00080 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,
|
||||
<a name="l00081"></a>00081 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30
|
||||
<a name="l00082"></a>00082 };
|
||||
<a name="l00083"></a>00083
|
||||
<a name="l00084"></a>00084 <span class="keyword">inline</span> <span class="keywordtype">bool</span> isLeapYear(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> year)
|
||||
<a name="l00085"></a>00085 {
|
||||
<a name="l00086"></a>00086 <span class="keywordflow">if</span> ((year % 100) == 0)
|
||||
<a name="l00087"></a>00087 <span class="keywordflow">return</span> (year % 400) == 0;
|
||||
<a name="l00088"></a>00088 <span class="keywordflow">else</span>
|
||||
<a name="l00089"></a>00089 <span class="keywordflow">return</span> (year % 4) == 0;
|
||||
<a name="l00090"></a>00090 }
|
||||
<a name="l00091"></a>00091
|
||||
<a name="l00092"></a>00092 <span class="keyword">inline</span> uint8_t monthLength(<span class="keyword">const</span> <a class="code" href="structRTCDate.html" title="Stores date information from a realtime clock chip.">RTCDate</a> *date)
|
||||
<a name="l00093"></a>00093 {
|
||||
<a name="l00094"></a>00094 <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> != 2 || !isLeapYear(date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a>))
|
||||
<a name="l00095"></a>00095 <span class="keywordflow">return</span> monthLengths[date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> - 1];
|
||||
<a name="l00096"></a>00096 <span class="keywordflow">else</span>
|
||||
<a name="l00097"></a>00097 <span class="keywordflow">return</span> 29;
|
||||
<a name="l00098"></a>00098 }
|
||||
<a name="l00099"></a>00099
|
||||
<a name="l00105"></a><a class="code" href="classRTC.html#ada31c5120d18d2dd2863b3d440308da2">00105</a> <a class="code" href="classRTC.html#ada31c5120d18d2dd2863b3d440308da2" title="Constructs a new realtime clock handler.">RTC::RTC</a>()
|
||||
<a name="l00106"></a>00106 : midnight(millis() - 9 * MILLIS_PER_HOUR) <span class="comment">// Simulated clock starts at 9am</span>
|
||||
<a name="l00107"></a>00107 , nvram(0)
|
||||
<a name="l00108"></a>00108 {
|
||||
<a name="l00109"></a>00109 <span class="comment">// Start the simulated date at 1 Jan, 2000.</span>
|
||||
<a name="l00110"></a>00110 date.<a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> = 1;
|
||||
<a name="l00111"></a>00111 date.<a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> = 1;
|
||||
<a name="l00112"></a>00112 date.<a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> = 2000;
|
||||
<a name="l00113"></a>00113
|
||||
<a name="l00114"></a>00114 <span class="comment">// Set all simulated alarms to 6am by default.</span>
|
||||
<a name="l00115"></a>00115 <span class="keywordflow">for</span> (uint8_t index = 0; index < <a class="code" href="classRTC.html#aee5ae8f600ee5296e65635c0d836fca3" title="Number of alarms that are supported by RTC::readAlarm() and RTC::writeAlarm().">ALARM_COUNT</a>; ++index) {
|
||||
<a name="l00116"></a>00116 alarms[index].<a class="code" href="structRTCAlarm.html#a75bdc42acd3ab3ad495680c6b6a34692" title="Hour of the day for the alarm (0-23).">hour</a> = 6;
|
||||
<a name="l00117"></a>00117 alarms[index].<a class="code" href="structRTCAlarm.html#ad9a75ceb4b4b3474baa66dd5466e62fe" title="Minute of the hour for the alarm (0-59).">minute</a> = 0;
|
||||
<a name="l00118"></a>00118 alarms[index].<a class="code" href="structRTCAlarm.html#a0f2ef7363cb60a26642d5295b77ca19e" title="Additional flags for the alarm.">flags</a> = 0;
|
||||
<a name="l00119"></a>00119 }
|
||||
<a name="l00120"></a>00120 }
|
||||
<a name="l00121"></a>00121
|
||||
<a name="l00122"></a>00122 RTC::~RTC()
|
||||
<a name="l00123"></a>00123 {
|
||||
<a name="l00124"></a>00124 <span class="keywordflow">if</span> (nvram)
|
||||
<a name="l00125"></a>00125 free(nvram);
|
||||
<a name="l00126"></a>00126 }
|
||||
<a name="l00127"></a>00127
|
||||
<a name="l00134"></a><a class="code" href="classRTC.html#a3690761f29654a2c9e676fcbfa32dd30">00134</a> <span class="keywordtype">bool</span> <a class="code" href="classRTC.html#a3690761f29654a2c9e676fcbfa32dd30" title="Returns true if the realtime clock has updated since the last call to this function.">RTC::hasUpdates</a>()
|
||||
<a name="l00135"></a>00135 {
|
||||
<a name="l00136"></a>00136 <span class="keywordflow">return</span> <span class="keyword">true</span>;
|
||||
<a name="l00137"></a>00137 }
|
||||
<a name="l00138"></a>00138
|
||||
<a name="l00144"></a><a class="code" href="classRTC.html#aaf0a5c1f32f210a49718d148620b5bec">00144</a> <span class="keywordtype">void</span> <a class="code" href="classRTC.html#aaf0a5c1f32f210a49718d148620b5bec" title="Reads the current time from the realtime clock into value.">RTC::readTime</a>(<a class="code" href="structRTCTime.html" title="Stores time information from a realtime clock chip.">RTCTime</a> *value)
|
||||
<a name="l00145"></a>00145 {
|
||||
<a name="l00146"></a>00146 <span class="comment">// Determine the number of seconds since the last midnight event.</span>
|
||||
<a name="l00147"></a>00147 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> sinceMidnight = millis() - midnight;
|
||||
<a name="l00148"></a>00148 <span class="keywordflow">if</span> (sinceMidnight >= MILLIS_PER_DAY) {
|
||||
<a name="l00149"></a>00149 <span class="comment">// We have overflowed into the next day. Readjust midnight.</span>
|
||||
<a name="l00150"></a>00150 midnight += MILLIS_PER_DAY;
|
||||
<a name="l00151"></a>00151 sinceMidnight -= MILLIS_PER_DAY;
|
||||
<a name="l00152"></a>00152
|
||||
<a name="l00153"></a>00153 <span class="comment">// Increment the simulated date.</span>
|
||||
<a name="l00154"></a>00154 <a class="code" href="classRTC.html#adc29d7c43efc5a192d21965da5c3ee1d" title="Adjusts date up or down one day according to flags.">adjustDays</a>(&date, <a class="code" href="classRTC.html#aacbe3ebbf893685950b05327c11d5c37" title="Increment the day, month, or year in a call to adjustDays(), adjustMonths(), or adjustYears().">INCREMENT</a>);
|
||||
<a name="l00155"></a>00155 }
|
||||
<a name="l00156"></a>00156 value-><a class="code" href="structRTCTime.html#a87b7c02e535d808dcba04c77e34abb91" title="Second within the minute (0-59)">second</a> = (uint8_t)(((sinceMidnight / MILLIS_PER_SECOND) % 60));
|
||||
<a name="l00157"></a>00157 value-><a class="code" href="structRTCTime.html#acf2161ca037080dc4b767e636ad8db84" title="Minute within the hour (0-59)">minute</a> = (uint8_t)(((sinceMidnight / MILLIS_PER_MINUTE) % 60));
|
||||
<a name="l00158"></a>00158 value-><a class="code" href="structRTCTime.html#a98ba717092ef856dd2b773ba02fcb1a4" title="Hour of the day (0-23)">hour</a> = (uint8_t)(sinceMidnight / MILLIS_PER_HOUR);
|
||||
<a name="l00159"></a>00159 }
|
||||
<a name="l00160"></a>00160
|
||||
<a name="l00169"></a><a class="code" href="classRTC.html#aa1e21bf42ebd4456919744ae0f4f631e">00169</a> <span class="keywordtype">void</span> <a class="code" href="classRTC.html#aa1e21bf42ebd4456919744ae0f4f631e" title="Reads the current date from the realtime clock into value.">RTC::readDate</a>(<a class="code" href="structRTCDate.html" title="Stores date information from a realtime clock chip.">RTCDate</a> *value)
|
||||
<a name="l00170"></a>00170 {
|
||||
<a name="l00171"></a>00171 *value = date;
|
||||
<a name="l00172"></a>00172 }
|
||||
<a name="l00173"></a>00173
|
||||
<a name="l00179"></a><a class="code" href="classRTC.html#a102e2ec15bf0273d8f7e9ce4b6dcc96e">00179</a> <span class="keywordtype">void</span> <a class="code" href="classRTC.html#a102e2ec15bf0273d8f7e9ce4b6dcc96e" title="Updates the time in the realtime clock to match value.">RTC::writeTime</a>(<span class="keyword">const</span> <a class="code" href="structRTCTime.html" title="Stores time information from a realtime clock chip.">RTCTime</a> *value)
|
||||
<a name="l00180"></a>00180 {
|
||||
<a name="l00181"></a>00181 <span class="comment">// Adjust the position of the last simulated midnight event.</span>
|
||||
<a name="l00182"></a>00182 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> sinceMidnight =
|
||||
<a name="l00183"></a>00183 value-><a class="code" href="structRTCTime.html#a87b7c02e535d808dcba04c77e34abb91" title="Second within the minute (0-59)">second</a> * MILLIS_PER_SECOND +
|
||||
<a name="l00184"></a>00184 value-><a class="code" href="structRTCTime.html#acf2161ca037080dc4b767e636ad8db84" title="Minute within the hour (0-59)">minute</a> * MILLIS_PER_MINUTE +
|
||||
<a name="l00185"></a>00185 value-><a class="code" href="structRTCTime.html#a98ba717092ef856dd2b773ba02fcb1a4" title="Hour of the day (0-23)">hour</a> * MILLIS_PER_HOUR;
|
||||
<a name="l00186"></a>00186 midnight = millis() - sinceMidnight;
|
||||
<a name="l00187"></a>00187 }
|
||||
<a name="l00188"></a>00188
|
||||
<a name="l00194"></a><a class="code" href="classRTC.html#ae667600d05c8e7b06a93574dd068a4d7">00194</a> <span class="keywordtype">void</span> <a class="code" href="classRTC.html#ae667600d05c8e7b06a93574dd068a4d7" title="Updates the date in the realtime clock to match value.">RTC::writeDate</a>(<span class="keyword">const</span> <a class="code" href="structRTCDate.html" title="Stores date information from a realtime clock chip.">RTCDate</a> *value)
|
||||
<a name="l00195"></a>00195 {
|
||||
<a name="l00196"></a>00196 date = *value;
|
||||
<a name="l00197"></a>00197 }
|
||||
<a name="l00198"></a>00198
|
||||
<a name="l00209"></a><a class="code" href="classRTC.html#ade282d7a60147c3f0269f1fcd59c8d66">00209</a> <span class="keywordtype">void</span> <a class="code" href="classRTC.html#ade282d7a60147c3f0269f1fcd59c8d66" title="Reads the details of the alarm with index alarmNum into value.">RTC::readAlarm</a>(uint8_t alarmNum, <a class="code" href="structRTCAlarm.html" title="Stores alarm information from a realtime clock chip.">RTCAlarm</a> *value)
|
||||
<a name="l00210"></a>00210 {
|
||||
<a name="l00211"></a>00211 *value = alarms[alarmNum];
|
||||
<a name="l00212"></a>00212 }
|
||||
<a name="l00213"></a>00213
|
||||
<a name="l00224"></a><a class="code" href="classRTC.html#a0e96c91efd9e7a6340effdae3eadf17e">00224</a> <span class="keywordtype">void</span> <a class="code" href="classRTC.html#a0e96c91efd9e7a6340effdae3eadf17e" title="Updates the details of the alarm with index alarmNum from value.">RTC::writeAlarm</a>(uint8_t alarmNum, <span class="keyword">const</span> <a class="code" href="structRTCAlarm.html" title="Stores alarm information from a realtime clock chip.">RTCAlarm</a> *value)
|
||||
<a name="l00225"></a>00225 {
|
||||
<a name="l00226"></a>00226 alarms[alarmNum] = *value;
|
||||
<a name="l00227"></a>00227 }
|
||||
<a name="l00228"></a>00228
|
||||
<a name="l00235"></a><a class="code" href="classRTC.html#acfdebfb449710e44e11f9a3675e14fd8">00235</a> <span class="keywordtype">int</span> <a class="code" href="classRTC.html#acfdebfb449710e44e11f9a3675e14fd8" title="Returns the number of bytes of non-volatile memory that can be used for storage of arbitrary settings...">RTC::byteCount</a>()<span class="keyword"> const</span>
|
||||
<a name="l00236"></a>00236 <span class="keyword"></span>{
|
||||
<a name="l00237"></a>00237 <span class="keywordflow">return</span> DEFAULT_BYTE_COUNT;
|
||||
<a name="l00238"></a>00238 }
|
||||
<a name="l00239"></a>00239
|
||||
<a name="l00247"></a><a class="code" href="classRTC.html#a0f47b10b436e3f9d36e04ec907579431">00247</a> uint8_t <a class="code" href="classRTC.html#a0f47b10b436e3f9d36e04ec907579431" title="Reads the byte at offset within the realtime clock's non-volatile memory.">RTC::readByte</a>(uint8_t offset)
|
||||
<a name="l00248"></a>00248 {
|
||||
<a name="l00249"></a>00249 <span class="keywordflow">if</span> (nvram)
|
||||
<a name="l00250"></a>00250 <span class="keywordflow">return</span> nvram[offset];
|
||||
<a name="l00251"></a>00251 <span class="keywordflow">else</span>
|
||||
<a name="l00252"></a>00252 <span class="keywordflow">return</span> 0;
|
||||
<a name="l00253"></a>00253 }
|
||||
<a name="l00254"></a>00254
|
||||
<a name="l00262"></a><a class="code" href="classRTC.html#a1cab6397ec04b1e2b3feea5b3cd1f749">00262</a> <span class="keywordtype">void</span> <a class="code" href="classRTC.html#a1cab6397ec04b1e2b3feea5b3cd1f749" title="Writes value to offset within the realtime clock's non-volatile memory.">RTC::writeByte</a>(uint8_t offset, uint8_t value)
|
||||
<a name="l00263"></a>00263 {
|
||||
<a name="l00264"></a>00264 <span class="keywordflow">if</span> (nvram) {
|
||||
<a name="l00265"></a>00265 nvram[offset] = value;
|
||||
<a name="l00266"></a>00266 } <span class="keywordflow">else</span> {
|
||||
<a name="l00267"></a>00267 nvram = (uint8_t *)malloc(DEFAULT_BYTE_COUNT);
|
||||
<a name="l00268"></a>00268 <span class="keywordflow">if</span> (nvram) {
|
||||
<a name="l00269"></a>00269 memset(nvram, 0, DEFAULT_BYTE_COUNT);
|
||||
<a name="l00270"></a>00270 nvram[offset] = value;
|
||||
<a name="l00271"></a>00271 }
|
||||
<a name="l00272"></a>00272 }
|
||||
<a name="l00273"></a>00273 }
|
||||
<a name="l00274"></a>00274
|
||||
<a name="l00288"></a><a class="code" href="classRTC.html#aeca3c8387332e8cabfd09c1806276e5a">00288</a> <span class="keywordtype">int</span> <a class="code" href="classRTC.html#aeca3c8387332e8cabfd09c1806276e5a" title="Reads the value of the temperature sensor and returns the temperature in quarters of a degree celcius...">RTC::readTemperature</a>()
|
||||
<a name="l00289"></a>00289 {
|
||||
<a name="l00290"></a>00290 <span class="keywordflow">return</span> <a class="code" href="classRTC.html#a9ed5480b362a83f1f45c4d3bcf7c3bf8" title="Value that is returned from readTemperature() if the realtime clock chip cannot determine the tempera...">NO_TEMPERATURE</a>;
|
||||
<a name="l00291"></a>00291 }
|
||||
<a name="l00292"></a>00292
|
||||
<a name="l00313"></a><a class="code" href="classRTC.html#adc29d7c43efc5a192d21965da5c3ee1d">00313</a> <span class="keywordtype">void</span> <a class="code" href="classRTC.html#adc29d7c43efc5a192d21965da5c3ee1d" title="Adjusts date up or down one day according to flags.">RTC::adjustDays</a>(<a class="code" href="structRTCDate.html" title="Stores date information from a realtime clock chip.">RTCDate</a> *date, uint8_t flags)
|
||||
<a name="l00314"></a>00314 {
|
||||
<a name="l00315"></a>00315 <span class="keywordflow">if</span> (flags & <a class="code" href="classRTC.html#a05b1bd1479afc80682abdd4f3e58dc6f" title="Decrement the day, month, or year in a call to adjustDays(), adjustMonths(), or adjustYears().">DECREMENT</a>) {
|
||||
<a name="l00316"></a>00316 --(date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a>);
|
||||
<a name="l00317"></a>00317 <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> == 0) {
|
||||
<a name="l00318"></a>00318 <span class="keywordflow">if</span> (!(flags & <a class="code" href="classRTC.html#a02ace2d775063be9a99035851c9274eb" title="Wrap around to the beginning of the current month/year rather than advance to the next one...">WRAP</a>)) {
|
||||
<a name="l00319"></a>00319 --(date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a>);
|
||||
<a name="l00320"></a>00320 <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> == 0)
|
||||
<a name="l00321"></a>00321 date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> = 12;
|
||||
<a name="l00322"></a>00322 }
|
||||
<a name="l00323"></a>00323 date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> = monthLength(date);
|
||||
<a name="l00324"></a>00324 }
|
||||
<a name="l00325"></a>00325 } <span class="keywordflow">else</span> {
|
||||
<a name="l00326"></a>00326 ++(date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a>);
|
||||
<a name="l00327"></a>00327 <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> > monthLength(date)) {
|
||||
<a name="l00328"></a>00328 <span class="keywordflow">if</span> (!(flags & <a class="code" href="classRTC.html#a02ace2d775063be9a99035851c9274eb" title="Wrap around to the beginning of the current month/year rather than advance to the next one...">WRAP</a>)) {
|
||||
<a name="l00329"></a>00329 ++(date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a>);
|
||||
<a name="l00330"></a>00330 <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> == 13)
|
||||
<a name="l00331"></a>00331 date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> = 1;
|
||||
<a name="l00332"></a>00332 }
|
||||
<a name="l00333"></a>00333 date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> = 1;
|
||||
<a name="l00334"></a>00334 }
|
||||
<a name="l00335"></a>00335 }
|
||||
<a name="l00336"></a>00336 }
|
||||
<a name="l00337"></a>00337
|
||||
<a name="l00343"></a><a class="code" href="classRTC.html#aeca597e6e37a05716e664242f9cfc5f4">00343</a> <span class="keywordtype">void</span> <a class="code" href="classRTC.html#aeca597e6e37a05716e664242f9cfc5f4" title="Adjusts date up or down one month according to flags.">RTC::adjustMonths</a>(<a class="code" href="structRTCDate.html" title="Stores date information from a realtime clock chip.">RTCDate</a> *date, uint8_t flags)
|
||||
<a name="l00344"></a>00344 {
|
||||
<a name="l00345"></a>00345 <span class="keywordflow">if</span> (flags & <a class="code" href="classRTC.html#a05b1bd1479afc80682abdd4f3e58dc6f" title="Decrement the day, month, or year in a call to adjustDays(), adjustMonths(), or adjustYears().">DECREMENT</a>) {
|
||||
<a name="l00346"></a>00346 --(date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a>);
|
||||
<a name="l00347"></a>00347 <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> == 0) {
|
||||
<a name="l00348"></a>00348 date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> = 12;
|
||||
<a name="l00349"></a>00349 <span class="keywordflow">if</span> (!(flags & <a class="code" href="classRTC.html#a02ace2d775063be9a99035851c9274eb" title="Wrap around to the beginning of the current month/year rather than advance to the next one...">WRAP</a>) && date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> > 2000)
|
||||
<a name="l00350"></a>00350 --(date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a>);
|
||||
<a name="l00351"></a>00351 }
|
||||
<a name="l00352"></a>00352 } <span class="keywordflow">else</span> {
|
||||
<a name="l00353"></a>00353 ++(date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a>);
|
||||
<a name="l00354"></a>00354 <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> == 13) {
|
||||
<a name="l00355"></a>00355 date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> = 1;
|
||||
<a name="l00356"></a>00356 <span class="keywordflow">if</span> (!(flags & <a class="code" href="classRTC.html#a02ace2d775063be9a99035851c9274eb" title="Wrap around to the beginning of the current month/year rather than advance to the next one...">WRAP</a>) && date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> < 2099)
|
||||
<a name="l00357"></a>00357 ++(date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a>);
|
||||
<a name="l00358"></a>00358 }
|
||||
<a name="l00359"></a>00359 }
|
||||
<a name="l00360"></a>00360 uint8_t len = monthLength(date);
|
||||
<a name="l00361"></a>00361 <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> > len)
|
||||
<a name="l00362"></a>00362 date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> = len;
|
||||
<a name="l00363"></a>00363 }
|
||||
<a name="l00364"></a>00364
|
||||
<a name="l00370"></a><a class="code" href="classRTC.html#a31d10cb2f7cac8839bd4be2d858b802d">00370</a> <span class="keywordtype">void</span> <a class="code" href="classRTC.html#a31d10cb2f7cac8839bd4be2d858b802d" title="Adjusts date up or down one year according to flags.">RTC::adjustYears</a>(<a class="code" href="structRTCDate.html" title="Stores date information from a realtime clock chip.">RTCDate</a> *date, uint8_t flags)
|
||||
<a name="l00371"></a>00371 {
|
||||
<a name="l00372"></a>00372 <span class="keywordflow">if</span> (flags & <a class="code" href="classRTC.html#a05b1bd1479afc80682abdd4f3e58dc6f" title="Decrement the day, month, or year in a call to adjustDays(), adjustMonths(), or adjustYears().">DECREMENT</a>) {
|
||||
<a name="l00373"></a>00373 --(date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a>);
|
||||
<a name="l00374"></a>00374 <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> < 2000)
|
||||
<a name="l00375"></a>00375 date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> = 2000;
|
||||
<a name="l00376"></a>00376 } <span class="keywordflow">else</span> {
|
||||
<a name="l00377"></a>00377 ++(date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a>);
|
||||
<a name="l00378"></a>00378 <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> > 2099)
|
||||
<a name="l00379"></a>00379 date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> = 2099;
|
||||
<a name="l00380"></a>00380 }
|
||||
<a name="l00381"></a>00381 uint8_t len = monthLength(date);
|
||||
<a name="l00382"></a>00382 <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> > len)
|
||||
<a name="l00383"></a>00383 date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> = len;
|
||||
<a name="l00384"></a>00384 }
|
||||
<a name="l00385"></a>00385
|
||||
<a name="l00399"></a><a class="code" href="classRTC.html#a525a9c1dad89613708f47a683eb316aa">00399</a> <a class="code" href="classRTC.html#ab2ca0cbee608ec32d3d6e04d40298f11" title="Day of the week corresponding to a date.">RTC::DayOfWeek</a> <a class="code" href="classRTC.html#a525a9c1dad89613708f47a683eb316aa" title="Returns the day of the week corresponding to date.">RTC::dayOfWeek</a>(<span class="keyword">const</span> <a class="code" href="structRTCDate.html" title="Stores date information from a realtime clock chip.">RTCDate</a> *date)
|
||||
<a name="l00400"></a>00400 {
|
||||
<a name="l00401"></a>00401 <span class="comment">// The +4 here adjusts for Jan 1, 2000 being a Saturday.</span>
|
||||
<a name="l00402"></a>00402 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> daynum = date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> + 4;
|
||||
<a name="l00403"></a>00403 daynum += monthOffsets[date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> - 1];
|
||||
<a name="l00404"></a>00404 <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> > 2 && isLeapYear(date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a>))
|
||||
<a name="l00405"></a>00405 ++daynum;
|
||||
<a name="l00406"></a>00406 daynum += 365UL * (date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> - 2000);
|
||||
<a name="l00407"></a>00407 <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> > 2000)
|
||||
<a name="l00408"></a>00408 daynum += ((date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> - 2001) / 4) + 1;
|
||||
<a name="l00409"></a>00409 <span class="keywordflow">return</span> (<a class="code" href="classRTC.html#ab2ca0cbee608ec32d3d6e04d40298f11" title="Day of the week corresponding to a date.">DayOfWeek</a>)((daynum % 7) + 1);
|
||||
<a name="l00410"></a>00410 }
|
||||
<a name="l00411"></a>00411
|
||||
</pre></div></div>
|
||||
</div>
|
||||
<!-- window showing the filter options -->
|
||||
<div id="MSearchSelectWindow"
|
||||
onmouseover="return searchBox.OnSearchSelectShow()"
|
||||
onmouseout="return searchBox.OnSearchSelectHide()"
|
||||
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
||||
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerator</a></div>
|
||||
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark"> </span>Pages</a></div>
|
||||
|
||||
<!-- iframe showing the search results (closed by default) -->
|
||||
<div id="MSearchResultsWindow">
|
||||
@@ -331,8 +77,277 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||||
</iframe>
|
||||
</div>
|
||||
|
||||
<hr class="footer"/><address class="footer"><small>Generated on Mon Jun 18 2012 11:02:52 for ArduinoLibs by 
|
||||
<a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
||||
<div id="nav-path" class="navpath">
|
||||
<ul>
|
||||
<li class="navelem"><a class="el" href="dir_bc0718b08fb2015b8e59c47b2805f60c.html">libraries</a></li><li class="navelem"><a class="el" href="dir_f34881fcf60f680b800190d5274dfaea.html">RTC</a></li> </ul>
|
||||
</div>
|
||||
</div><!-- top -->
|
||||
<div class="header">
|
||||
<div class="headertitle">
|
||||
<div class="title">RTC.cpp</div> </div>
|
||||
</div><!--header-->
|
||||
<div class="contents">
|
||||
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="comment">/*</span></div>
|
||||
<div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="comment"> * Copyright (C) 2012 Southern Storm Software, Pty Ltd.</span></div>
|
||||
<div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="comment"> *</span></div>
|
||||
<div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a</span></div>
|
||||
<div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="comment"> * copy of this software and associated documentation files (the "Software"),</span></div>
|
||||
<div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="comment"> * to deal in the Software without restriction, including without limitation</span></div>
|
||||
<div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="comment"> * the rights to use, copy, modify, merge, publish, distribute, sublicense,</span></div>
|
||||
<div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="comment"> * and/or sell copies of the Software, and to permit persons to whom the</span></div>
|
||||
<div class="line"><a name="l00009"></a><span class="lineno"> 9</span> <span class="comment"> * Software is furnished to do so, subject to the following conditions:</span></div>
|
||||
<div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="comment"> *</span></div>
|
||||
<div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="comment"> * The above copyright notice and this permission notice shall be included</span></div>
|
||||
<div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="comment"> * in all copies or substantial portions of the Software.</span></div>
|
||||
<div class="line"><a name="l00013"></a><span class="lineno"> 13</span> <span class="comment"> *</span></div>
|
||||
<div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS</span></div>
|
||||
<div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="comment"> * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span></div>
|
||||
<div class="line"><a name="l00016"></a><span class="lineno"> 16</span> <span class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span></div>
|
||||
<div class="line"><a name="l00017"></a><span class="lineno"> 17</span> <span class="comment"> * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span></div>
|
||||
<div class="line"><a name="l00018"></a><span class="lineno"> 18</span> <span class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING</span></div>
|
||||
<div class="line"><a name="l00019"></a><span class="lineno"> 19</span> <span class="comment"> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER</span></div>
|
||||
<div class="line"><a name="l00020"></a><span class="lineno"> 20</span> <span class="comment"> * DEALINGS IN THE SOFTWARE.</span></div>
|
||||
<div class="line"><a name="l00021"></a><span class="lineno"> 21</span> <span class="comment"> */</span></div>
|
||||
<div class="line"><a name="l00022"></a><span class="lineno"> 22</span> </div>
|
||||
<div class="line"><a name="l00023"></a><span class="lineno"> 23</span> <span class="preprocessor">#include "RTC.h"</span></div>
|
||||
<div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <span class="preprocessor">#if defined(ARDUINO) && ARDUINO >= 100</span></div>
|
||||
<div class="line"><a name="l00025"></a><span class="lineno"> 25</span> <span class="preprocessor"></span><span class="preprocessor">#include <Arduino.h></span></div>
|
||||
<div class="line"><a name="l00026"></a><span class="lineno"> 26</span> <span class="preprocessor">#else</span></div>
|
||||
<div class="line"><a name="l00027"></a><span class="lineno"> 27</span> <span class="preprocessor"></span><span class="preprocessor">#include <WProgram.h></span></div>
|
||||
<div class="line"><a name="l00028"></a><span class="lineno"> 28</span> <span class="preprocessor">#endif</span></div>
|
||||
<div class="line"><a name="l00029"></a><span class="lineno"> 29</span> <span class="preprocessor"></span><span class="preprocessor">#include <stdlib.h></span></div>
|
||||
<div class="line"><a name="l00030"></a><span class="lineno"> 30</span> <span class="preprocessor">#include <string.h></span></div>
|
||||
<div class="line"><a name="l00031"></a><span class="lineno"> 31</span> </div>
|
||||
<div class="line"><a name="l00058"></a><span class="lineno"> 58</span> <span class="preprocessor">#define DEFAULT_BYTE_COUNT 43 // Default simulates DS1307 NVRAM size.</span></div>
|
||||
<div class="line"><a name="l00059"></a><span class="lineno"> 59</span> <span class="preprocessor"></span></div>
|
||||
<div class="line"><a name="l00060"></a><span class="lineno"> 60</span> <span class="preprocessor">#define MILLIS_PER_DAY 86400000UL</span></div>
|
||||
<div class="line"><a name="l00061"></a><span class="lineno"> 61</span> <span class="preprocessor"></span><span class="preprocessor">#define MILLIS_PER_SECOND 1000UL</span></div>
|
||||
<div class="line"><a name="l00062"></a><span class="lineno"> 62</span> <span class="preprocessor"></span><span class="preprocessor">#define MILLIS_PER_MINUTE 60000UL</span></div>
|
||||
<div class="line"><a name="l00063"></a><span class="lineno"> 63</span> <span class="preprocessor"></span><span class="preprocessor">#define MILLIS_PER_HOUR 3600000UL</span></div>
|
||||
<div class="line"><a name="l00064"></a><span class="lineno"> 64</span> <span class="preprocessor"></span></div>
|
||||
<div class="line"><a name="l00065"></a><span class="lineno"> 65</span> <span class="keyword">static</span> uint8_t monthLengths[] = {</div>
|
||||
<div class="line"><a name="l00066"></a><span class="lineno"> 66</span>  31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31</div>
|
||||
<div class="line"><a name="l00067"></a><span class="lineno"> 67</span> };</div>
|
||||
<div class="line"><a name="l00068"></a><span class="lineno"> 68</span> </div>
|
||||
<div class="line"><a name="l00069"></a><span class="lineno"> 69</span> <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> monthOffsets[] = {</div>
|
||||
<div class="line"><a name="l00070"></a><span class="lineno"> 70</span>  0,</div>
|
||||
<div class="line"><a name="l00071"></a><span class="lineno"> 71</span>  31,</div>
|
||||
<div class="line"><a name="l00072"></a><span class="lineno"> 72</span>  31 + 28,</div>
|
||||
<div class="line"><a name="l00073"></a><span class="lineno"> 73</span>  31 + 28 + 31,</div>
|
||||
<div class="line"><a name="l00074"></a><span class="lineno"> 74</span>  31 + 28 + 31 + 30,</div>
|
||||
<div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  31 + 28 + 31 + 30 + 31,</div>
|
||||
<div class="line"><a name="l00076"></a><span class="lineno"> 76</span>  31 + 28 + 31 + 30 + 31 + 30,</div>
|
||||
<div class="line"><a name="l00077"></a><span class="lineno"> 77</span>  31 + 28 + 31 + 30 + 31 + 30 + 31,</div>
|
||||
<div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  31 + 28 + 31 + 30 + 31 + 30 + 31 + 31,</div>
|
||||
<div class="line"><a name="l00079"></a><span class="lineno"> 79</span>  31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30,</div>
|
||||
<div class="line"><a name="l00080"></a><span class="lineno"> 80</span>  31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,</div>
|
||||
<div class="line"><a name="l00081"></a><span class="lineno"> 81</span>  31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30</div>
|
||||
<div class="line"><a name="l00082"></a><span class="lineno"> 82</span> };</div>
|
||||
<div class="line"><a name="l00083"></a><span class="lineno"> 83</span> </div>
|
||||
<div class="line"><a name="l00084"></a><span class="lineno"> 84</span> <span class="keyword">inline</span> <span class="keywordtype">bool</span> isLeapYear(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> year)</div>
|
||||
<div class="line"><a name="l00085"></a><span class="lineno"> 85</span> {</div>
|
||||
<div class="line"><a name="l00086"></a><span class="lineno"> 86</span>  <span class="keywordflow">if</span> ((year % 100) == 0)</div>
|
||||
<div class="line"><a name="l00087"></a><span class="lineno"> 87</span>  <span class="keywordflow">return</span> (year % 400) == 0;</div>
|
||||
<div class="line"><a name="l00088"></a><span class="lineno"> 88</span>  <span class="keywordflow">else</span></div>
|
||||
<div class="line"><a name="l00089"></a><span class="lineno"> 89</span>  <span class="keywordflow">return</span> (year % 4) == 0;</div>
|
||||
<div class="line"><a name="l00090"></a><span class="lineno"> 90</span> }</div>
|
||||
<div class="line"><a name="l00091"></a><span class="lineno"> 91</span> </div>
|
||||
<div class="line"><a name="l00092"></a><span class="lineno"> 92</span> <span class="keyword">inline</span> uint8_t monthLength(<span class="keyword">const</span> <a class="code" href="structRTCDate.html" title="Stores date information from a realtime clock chip.">RTCDate</a> *date)</div>
|
||||
<div class="line"><a name="l00093"></a><span class="lineno"> 93</span> {</div>
|
||||
<div class="line"><a name="l00094"></a><span class="lineno"> 94</span>  <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> != 2 || !isLeapYear(date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a>))</div>
|
||||
<div class="line"><a name="l00095"></a><span class="lineno"> 95</span>  <span class="keywordflow">return</span> monthLengths[date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> - 1];</div>
|
||||
<div class="line"><a name="l00096"></a><span class="lineno"> 96</span>  <span class="keywordflow">else</span></div>
|
||||
<div class="line"><a name="l00097"></a><span class="lineno"> 97</span>  <span class="keywordflow">return</span> 29;</div>
|
||||
<div class="line"><a name="l00098"></a><span class="lineno"> 98</span> }</div>
|
||||
<div class="line"><a name="l00099"></a><span class="lineno"> 99</span> </div>
|
||||
<div class="line"><a name="l00105"></a><span class="lineno"><a class="code" href="classRTC.html#ada31c5120d18d2dd2863b3d440308da2"> 105</a></span> <a class="code" href="classRTC.html#ada31c5120d18d2dd2863b3d440308da2" title="Constructs a new realtime clock handler.">RTC::RTC</a>()</div>
|
||||
<div class="line"><a name="l00106"></a><span class="lineno"> 106</span>  : midnight(millis() - 9 * MILLIS_PER_HOUR) <span class="comment">// Simulated clock starts at 9am</span></div>
|
||||
<div class="line"><a name="l00107"></a><span class="lineno"> 107</span>  , nvram(0)</div>
|
||||
<div class="line"><a name="l00108"></a><span class="lineno"> 108</span> {</div>
|
||||
<div class="line"><a name="l00109"></a><span class="lineno"> 109</span>  <span class="comment">// Start the simulated date at 1 Jan, 2000.</span></div>
|
||||
<div class="line"><a name="l00110"></a><span class="lineno"> 110</span>  date.<a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> = 1;</div>
|
||||
<div class="line"><a name="l00111"></a><span class="lineno"> 111</span>  date.<a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> = 1;</div>
|
||||
<div class="line"><a name="l00112"></a><span class="lineno"> 112</span>  date.<a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> = 2000;</div>
|
||||
<div class="line"><a name="l00113"></a><span class="lineno"> 113</span> </div>
|
||||
<div class="line"><a name="l00114"></a><span class="lineno"> 114</span>  <span class="comment">// Set all simulated alarms to 6am by default.</span></div>
|
||||
<div class="line"><a name="l00115"></a><span class="lineno"> 115</span>  <span class="keywordflow">for</span> (uint8_t index = 0; index < <a class="code" href="classRTC.html#aee5ae8f600ee5296e65635c0d836fca3" title="Number of alarms that are supported by RTC::readAlarm() and RTC::writeAlarm().">ALARM_COUNT</a>; ++index) {</div>
|
||||
<div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  alarms[index].<a class="code" href="structRTCAlarm.html#a75bdc42acd3ab3ad495680c6b6a34692" title="Hour of the day for the alarm (0-23).">hour</a> = 6;</div>
|
||||
<div class="line"><a name="l00117"></a><span class="lineno"> 117</span>  alarms[index].<a class="code" href="structRTCAlarm.html#ad9a75ceb4b4b3474baa66dd5466e62fe" title="Minute of the hour for the alarm (0-59).">minute</a> = 0;</div>
|
||||
<div class="line"><a name="l00118"></a><span class="lineno"> 118</span>  alarms[index].<a class="code" href="structRTCAlarm.html#a0f2ef7363cb60a26642d5295b77ca19e" title="Additional flags for the alarm.">flags</a> = 0;</div>
|
||||
<div class="line"><a name="l00119"></a><span class="lineno"> 119</span>  }</div>
|
||||
<div class="line"><a name="l00120"></a><span class="lineno"> 120</span> }</div>
|
||||
<div class="line"><a name="l00121"></a><span class="lineno"> 121</span> </div>
|
||||
<div class="line"><a name="l00122"></a><span class="lineno"> 122</span> RTC::~RTC()</div>
|
||||
<div class="line"><a name="l00123"></a><span class="lineno"> 123</span> {</div>
|
||||
<div class="line"><a name="l00124"></a><span class="lineno"> 124</span>  <span class="keywordflow">if</span> (nvram)</div>
|
||||
<div class="line"><a name="l00125"></a><span class="lineno"> 125</span>  free(nvram);</div>
|
||||
<div class="line"><a name="l00126"></a><span class="lineno"> 126</span> }</div>
|
||||
<div class="line"><a name="l00127"></a><span class="lineno"> 127</span> </div>
|
||||
<div class="line"><a name="l00134"></a><span class="lineno"><a class="code" href="classRTC.html#a3690761f29654a2c9e676fcbfa32dd30"> 134</a></span> <span class="keywordtype">bool</span> <a class="code" href="classRTC.html#a3690761f29654a2c9e676fcbfa32dd30" title="Returns true if the realtime clock has updated since the last call to this function.">RTC::hasUpdates</a>()</div>
|
||||
<div class="line"><a name="l00135"></a><span class="lineno"> 135</span> {</div>
|
||||
<div class="line"><a name="l00136"></a><span class="lineno"> 136</span>  <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
|
||||
<div class="line"><a name="l00137"></a><span class="lineno"> 137</span> }</div>
|
||||
<div class="line"><a name="l00138"></a><span class="lineno"> 138</span> </div>
|
||||
<div class="line"><a name="l00144"></a><span class="lineno"><a class="code" href="classRTC.html#aaf0a5c1f32f210a49718d148620b5bec"> 144</a></span> <span class="keywordtype">void</span> <a class="code" href="classRTC.html#aaf0a5c1f32f210a49718d148620b5bec" title="Reads the current time from the realtime clock into value.">RTC::readTime</a>(<a class="code" href="structRTCTime.html" title="Stores time information from a realtime clock chip.">RTCTime</a> *value)</div>
|
||||
<div class="line"><a name="l00145"></a><span class="lineno"> 145</span> {</div>
|
||||
<div class="line"><a name="l00146"></a><span class="lineno"> 146</span>  <span class="comment">// Determine the number of seconds since the last midnight event.</span></div>
|
||||
<div class="line"><a name="l00147"></a><span class="lineno"> 147</span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> sinceMidnight = millis() - midnight;</div>
|
||||
<div class="line"><a name="l00148"></a><span class="lineno"> 148</span>  <span class="keywordflow">if</span> (sinceMidnight >= MILLIS_PER_DAY) {</div>
|
||||
<div class="line"><a name="l00149"></a><span class="lineno"> 149</span>  <span class="comment">// We have overflowed into the next day. Readjust midnight.</span></div>
|
||||
<div class="line"><a name="l00150"></a><span class="lineno"> 150</span>  midnight += MILLIS_PER_DAY;</div>
|
||||
<div class="line"><a name="l00151"></a><span class="lineno"> 151</span>  sinceMidnight -= MILLIS_PER_DAY;</div>
|
||||
<div class="line"><a name="l00152"></a><span class="lineno"> 152</span> </div>
|
||||
<div class="line"><a name="l00153"></a><span class="lineno"> 153</span>  <span class="comment">// Increment the simulated date.</span></div>
|
||||
<div class="line"><a name="l00154"></a><span class="lineno"> 154</span>  <a class="code" href="classRTC.html#adc29d7c43efc5a192d21965da5c3ee1d" title="Adjusts date up or down one day according to flags.">adjustDays</a>(&date, <a class="code" href="classRTC.html#aacbe3ebbf893685950b05327c11d5c37" title="Increment the day, month, or year in a call to adjustDays(), adjustMonths(), or adjustYears().">INCREMENT</a>);</div>
|
||||
<div class="line"><a name="l00155"></a><span class="lineno"> 155</span>  }</div>
|
||||
<div class="line"><a name="l00156"></a><span class="lineno"> 156</span>  value-><a class="code" href="structRTCTime.html#a87b7c02e535d808dcba04c77e34abb91" title="Second within the minute (0-59)">second</a> = (uint8_t)(((sinceMidnight / MILLIS_PER_SECOND) % 60));</div>
|
||||
<div class="line"><a name="l00157"></a><span class="lineno"> 157</span>  value-><a class="code" href="structRTCTime.html#acf2161ca037080dc4b767e636ad8db84" title="Minute within the hour (0-59)">minute</a> = (uint8_t)(((sinceMidnight / MILLIS_PER_MINUTE) % 60));</div>
|
||||
<div class="line"><a name="l00158"></a><span class="lineno"> 158</span>  value-><a class="code" href="structRTCTime.html#a98ba717092ef856dd2b773ba02fcb1a4" title="Hour of the day (0-23)">hour</a> = (uint8_t)(sinceMidnight / MILLIS_PER_HOUR);</div>
|
||||
<div class="line"><a name="l00159"></a><span class="lineno"> 159</span> }</div>
|
||||
<div class="line"><a name="l00160"></a><span class="lineno"> 160</span> </div>
|
||||
<div class="line"><a name="l00169"></a><span class="lineno"><a class="code" href="classRTC.html#aa1e21bf42ebd4456919744ae0f4f631e"> 169</a></span> <span class="keywordtype">void</span> <a class="code" href="classRTC.html#aa1e21bf42ebd4456919744ae0f4f631e" title="Reads the current date from the realtime clock into value.">RTC::readDate</a>(<a class="code" href="structRTCDate.html" title="Stores date information from a realtime clock chip.">RTCDate</a> *value)</div>
|
||||
<div class="line"><a name="l00170"></a><span class="lineno"> 170</span> {</div>
|
||||
<div class="line"><a name="l00171"></a><span class="lineno"> 171</span>  *value = date;</div>
|
||||
<div class="line"><a name="l00172"></a><span class="lineno"> 172</span> }</div>
|
||||
<div class="line"><a name="l00173"></a><span class="lineno"> 173</span> </div>
|
||||
<div class="line"><a name="l00179"></a><span class="lineno"><a class="code" href="classRTC.html#a102e2ec15bf0273d8f7e9ce4b6dcc96e"> 179</a></span> <span class="keywordtype">void</span> <a class="code" href="classRTC.html#a102e2ec15bf0273d8f7e9ce4b6dcc96e" title="Updates the time in the realtime clock to match value.">RTC::writeTime</a>(<span class="keyword">const</span> <a class="code" href="structRTCTime.html" title="Stores time information from a realtime clock chip.">RTCTime</a> *value)</div>
|
||||
<div class="line"><a name="l00180"></a><span class="lineno"> 180</span> {</div>
|
||||
<div class="line"><a name="l00181"></a><span class="lineno"> 181</span>  <span class="comment">// Adjust the position of the last simulated midnight event.</span></div>
|
||||
<div class="line"><a name="l00182"></a><span class="lineno"> 182</span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> sinceMidnight =</div>
|
||||
<div class="line"><a name="l00183"></a><span class="lineno"> 183</span>  value-><a class="code" href="structRTCTime.html#a87b7c02e535d808dcba04c77e34abb91" title="Second within the minute (0-59)">second</a> * MILLIS_PER_SECOND +</div>
|
||||
<div class="line"><a name="l00184"></a><span class="lineno"> 184</span>  value-><a class="code" href="structRTCTime.html#acf2161ca037080dc4b767e636ad8db84" title="Minute within the hour (0-59)">minute</a> * MILLIS_PER_MINUTE +</div>
|
||||
<div class="line"><a name="l00185"></a><span class="lineno"> 185</span>  value-><a class="code" href="structRTCTime.html#a98ba717092ef856dd2b773ba02fcb1a4" title="Hour of the day (0-23)">hour</a> * MILLIS_PER_HOUR;</div>
|
||||
<div class="line"><a name="l00186"></a><span class="lineno"> 186</span>  midnight = millis() - sinceMidnight;</div>
|
||||
<div class="line"><a name="l00187"></a><span class="lineno"> 187</span> }</div>
|
||||
<div class="line"><a name="l00188"></a><span class="lineno"> 188</span> </div>
|
||||
<div class="line"><a name="l00194"></a><span class="lineno"><a class="code" href="classRTC.html#ae667600d05c8e7b06a93574dd068a4d7"> 194</a></span> <span class="keywordtype">void</span> <a class="code" href="classRTC.html#ae667600d05c8e7b06a93574dd068a4d7" title="Updates the date in the realtime clock to match value.">RTC::writeDate</a>(<span class="keyword">const</span> <a class="code" href="structRTCDate.html" title="Stores date information from a realtime clock chip.">RTCDate</a> *value)</div>
|
||||
<div class="line"><a name="l00195"></a><span class="lineno"> 195</span> {</div>
|
||||
<div class="line"><a name="l00196"></a><span class="lineno"> 196</span>  date = *value;</div>
|
||||
<div class="line"><a name="l00197"></a><span class="lineno"> 197</span> }</div>
|
||||
<div class="line"><a name="l00198"></a><span class="lineno"> 198</span> </div>
|
||||
<div class="line"><a name="l00209"></a><span class="lineno"><a class="code" href="classRTC.html#ade282d7a60147c3f0269f1fcd59c8d66"> 209</a></span> <span class="keywordtype">void</span> <a class="code" href="classRTC.html#ade282d7a60147c3f0269f1fcd59c8d66" title="Reads the details of the alarm with index alarmNum into value.">RTC::readAlarm</a>(uint8_t alarmNum, <a class="code" href="structRTCAlarm.html" title="Stores alarm information from a realtime clock chip.">RTCAlarm</a> *value)</div>
|
||||
<div class="line"><a name="l00210"></a><span class="lineno"> 210</span> {</div>
|
||||
<div class="line"><a name="l00211"></a><span class="lineno"> 211</span>  *value = alarms[alarmNum];</div>
|
||||
<div class="line"><a name="l00212"></a><span class="lineno"> 212</span> }</div>
|
||||
<div class="line"><a name="l00213"></a><span class="lineno"> 213</span> </div>
|
||||
<div class="line"><a name="l00224"></a><span class="lineno"><a class="code" href="classRTC.html#a0e96c91efd9e7a6340effdae3eadf17e"> 224</a></span> <span class="keywordtype">void</span> <a class="code" href="classRTC.html#a0e96c91efd9e7a6340effdae3eadf17e" title="Updates the details of the alarm with index alarmNum from value.">RTC::writeAlarm</a>(uint8_t alarmNum, <span class="keyword">const</span> <a class="code" href="structRTCAlarm.html" title="Stores alarm information from a realtime clock chip.">RTCAlarm</a> *value)</div>
|
||||
<div class="line"><a name="l00225"></a><span class="lineno"> 225</span> {</div>
|
||||
<div class="line"><a name="l00226"></a><span class="lineno"> 226</span>  alarms[alarmNum] = *value;</div>
|
||||
<div class="line"><a name="l00227"></a><span class="lineno"> 227</span> }</div>
|
||||
<div class="line"><a name="l00228"></a><span class="lineno"> 228</span> </div>
|
||||
<div class="line"><a name="l00235"></a><span class="lineno"><a class="code" href="classRTC.html#acfdebfb449710e44e11f9a3675e14fd8"> 235</a></span> <span class="keywordtype">int</span> <a class="code" href="classRTC.html#acfdebfb449710e44e11f9a3675e14fd8" title="Returns the number of bytes of non-volatile memory that can be used for storage of arbitrary settings...">RTC::byteCount</a>()<span class="keyword"> const</span></div>
|
||||
<div class="line"><a name="l00236"></a><span class="lineno"> 236</span> <span class="keyword"></span>{</div>
|
||||
<div class="line"><a name="l00237"></a><span class="lineno"> 237</span>  <span class="keywordflow">return</span> DEFAULT_BYTE_COUNT;</div>
|
||||
<div class="line"><a name="l00238"></a><span class="lineno"> 238</span> }</div>
|
||||
<div class="line"><a name="l00239"></a><span class="lineno"> 239</span> </div>
|
||||
<div class="line"><a name="l00247"></a><span class="lineno"><a class="code" href="classRTC.html#a0f47b10b436e3f9d36e04ec907579431"> 247</a></span> uint8_t <a class="code" href="classRTC.html#a0f47b10b436e3f9d36e04ec907579431" title="Reads the byte at offset within the realtime clock's non-volatile memory.">RTC::readByte</a>(uint8_t offset)</div>
|
||||
<div class="line"><a name="l00248"></a><span class="lineno"> 248</span> {</div>
|
||||
<div class="line"><a name="l00249"></a><span class="lineno"> 249</span>  <span class="keywordflow">if</span> (nvram)</div>
|
||||
<div class="line"><a name="l00250"></a><span class="lineno"> 250</span>  <span class="keywordflow">return</span> nvram[offset];</div>
|
||||
<div class="line"><a name="l00251"></a><span class="lineno"> 251</span>  <span class="keywordflow">else</span></div>
|
||||
<div class="line"><a name="l00252"></a><span class="lineno"> 252</span>  <span class="keywordflow">return</span> 0;</div>
|
||||
<div class="line"><a name="l00253"></a><span class="lineno"> 253</span> }</div>
|
||||
<div class="line"><a name="l00254"></a><span class="lineno"> 254</span> </div>
|
||||
<div class="line"><a name="l00262"></a><span class="lineno"><a class="code" href="classRTC.html#a1cab6397ec04b1e2b3feea5b3cd1f749"> 262</a></span> <span class="keywordtype">void</span> <a class="code" href="classRTC.html#a1cab6397ec04b1e2b3feea5b3cd1f749" title="Writes value to offset within the realtime clock's non-volatile memory.">RTC::writeByte</a>(uint8_t offset, uint8_t value)</div>
|
||||
<div class="line"><a name="l00263"></a><span class="lineno"> 263</span> {</div>
|
||||
<div class="line"><a name="l00264"></a><span class="lineno"> 264</span>  <span class="keywordflow">if</span> (nvram) {</div>
|
||||
<div class="line"><a name="l00265"></a><span class="lineno"> 265</span>  nvram[offset] = value;</div>
|
||||
<div class="line"><a name="l00266"></a><span class="lineno"> 266</span>  } <span class="keywordflow">else</span> {</div>
|
||||
<div class="line"><a name="l00267"></a><span class="lineno"> 267</span>  nvram = (uint8_t *)malloc(DEFAULT_BYTE_COUNT);</div>
|
||||
<div class="line"><a name="l00268"></a><span class="lineno"> 268</span>  <span class="keywordflow">if</span> (nvram) {</div>
|
||||
<div class="line"><a name="l00269"></a><span class="lineno"> 269</span>  memset(nvram, 0, DEFAULT_BYTE_COUNT);</div>
|
||||
<div class="line"><a name="l00270"></a><span class="lineno"> 270</span>  nvram[offset] = value;</div>
|
||||
<div class="line"><a name="l00271"></a><span class="lineno"> 271</span>  }</div>
|
||||
<div class="line"><a name="l00272"></a><span class="lineno"> 272</span>  }</div>
|
||||
<div class="line"><a name="l00273"></a><span class="lineno"> 273</span> }</div>
|
||||
<div class="line"><a name="l00274"></a><span class="lineno"> 274</span> </div>
|
||||
<div class="line"><a name="l00288"></a><span class="lineno"><a class="code" href="classRTC.html#aeca3c8387332e8cabfd09c1806276e5a"> 288</a></span> <span class="keywordtype">int</span> <a class="code" href="classRTC.html#aeca3c8387332e8cabfd09c1806276e5a" title="Reads the value of the temperature sensor and returns the temperature in quarters of a degree celcius...">RTC::readTemperature</a>()</div>
|
||||
<div class="line"><a name="l00289"></a><span class="lineno"> 289</span> {</div>
|
||||
<div class="line"><a name="l00290"></a><span class="lineno"> 290</span>  <span class="keywordflow">return</span> <a class="code" href="classRTC.html#a9ed5480b362a83f1f45c4d3bcf7c3bf8" title="Value that is returned from readTemperature() if the realtime clock chip cannot determine the tempera...">NO_TEMPERATURE</a>;</div>
|
||||
<div class="line"><a name="l00291"></a><span class="lineno"> 291</span> }</div>
|
||||
<div class="line"><a name="l00292"></a><span class="lineno"> 292</span> </div>
|
||||
<div class="line"><a name="l00313"></a><span class="lineno"><a class="code" href="classRTC.html#adc29d7c43efc5a192d21965da5c3ee1d"> 313</a></span> <span class="keywordtype">void</span> <a class="code" href="classRTC.html#adc29d7c43efc5a192d21965da5c3ee1d" title="Adjusts date up or down one day according to flags.">RTC::adjustDays</a>(<a class="code" href="structRTCDate.html" title="Stores date information from a realtime clock chip.">RTCDate</a> *date, uint8_t flags)</div>
|
||||
<div class="line"><a name="l00314"></a><span class="lineno"> 314</span> {</div>
|
||||
<div class="line"><a name="l00315"></a><span class="lineno"> 315</span>  <span class="keywordflow">if</span> (flags & <a class="code" href="classRTC.html#a05b1bd1479afc80682abdd4f3e58dc6f" title="Decrement the day, month, or year in a call to adjustDays(), adjustMonths(), or adjustYears().">DECREMENT</a>) {</div>
|
||||
<div class="line"><a name="l00316"></a><span class="lineno"> 316</span>  --(date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a>);</div>
|
||||
<div class="line"><a name="l00317"></a><span class="lineno"> 317</span>  <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> == 0) {</div>
|
||||
<div class="line"><a name="l00318"></a><span class="lineno"> 318</span>  <span class="keywordflow">if</span> (!(flags & <a class="code" href="classRTC.html#a02ace2d775063be9a99035851c9274eb" title="Wrap around to the beginning of the current month/year rather than advance to the next one...">WRAP</a>)) {</div>
|
||||
<div class="line"><a name="l00319"></a><span class="lineno"> 319</span>  --(date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a>);</div>
|
||||
<div class="line"><a name="l00320"></a><span class="lineno"> 320</span>  <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> == 0)</div>
|
||||
<div class="line"><a name="l00321"></a><span class="lineno"> 321</span>  date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> = 12;</div>
|
||||
<div class="line"><a name="l00322"></a><span class="lineno"> 322</span>  }</div>
|
||||
<div class="line"><a name="l00323"></a><span class="lineno"> 323</span>  date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> = monthLength(date);</div>
|
||||
<div class="line"><a name="l00324"></a><span class="lineno"> 324</span>  }</div>
|
||||
<div class="line"><a name="l00325"></a><span class="lineno"> 325</span>  } <span class="keywordflow">else</span> {</div>
|
||||
<div class="line"><a name="l00326"></a><span class="lineno"> 326</span>  ++(date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a>);</div>
|
||||
<div class="line"><a name="l00327"></a><span class="lineno"> 327</span>  <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> > monthLength(date)) {</div>
|
||||
<div class="line"><a name="l00328"></a><span class="lineno"> 328</span>  <span class="keywordflow">if</span> (!(flags & <a class="code" href="classRTC.html#a02ace2d775063be9a99035851c9274eb" title="Wrap around to the beginning of the current month/year rather than advance to the next one...">WRAP</a>)) {</div>
|
||||
<div class="line"><a name="l00329"></a><span class="lineno"> 329</span>  ++(date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a>);</div>
|
||||
<div class="line"><a name="l00330"></a><span class="lineno"> 330</span>  <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> == 13)</div>
|
||||
<div class="line"><a name="l00331"></a><span class="lineno"> 331</span>  date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> = 1;</div>
|
||||
<div class="line"><a name="l00332"></a><span class="lineno"> 332</span>  }</div>
|
||||
<div class="line"><a name="l00333"></a><span class="lineno"> 333</span>  date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> = 1;</div>
|
||||
<div class="line"><a name="l00334"></a><span class="lineno"> 334</span>  }</div>
|
||||
<div class="line"><a name="l00335"></a><span class="lineno"> 335</span>  }</div>
|
||||
<div class="line"><a name="l00336"></a><span class="lineno"> 336</span> }</div>
|
||||
<div class="line"><a name="l00337"></a><span class="lineno"> 337</span> </div>
|
||||
<div class="line"><a name="l00343"></a><span class="lineno"><a class="code" href="classRTC.html#aeca597e6e37a05716e664242f9cfc5f4"> 343</a></span> <span class="keywordtype">void</span> <a class="code" href="classRTC.html#aeca597e6e37a05716e664242f9cfc5f4" title="Adjusts date up or down one month according to flags.">RTC::adjustMonths</a>(<a class="code" href="structRTCDate.html" title="Stores date information from a realtime clock chip.">RTCDate</a> *date, uint8_t flags)</div>
|
||||
<div class="line"><a name="l00344"></a><span class="lineno"> 344</span> {</div>
|
||||
<div class="line"><a name="l00345"></a><span class="lineno"> 345</span>  <span class="keywordflow">if</span> (flags & <a class="code" href="classRTC.html#a05b1bd1479afc80682abdd4f3e58dc6f" title="Decrement the day, month, or year in a call to adjustDays(), adjustMonths(), or adjustYears().">DECREMENT</a>) {</div>
|
||||
<div class="line"><a name="l00346"></a><span class="lineno"> 346</span>  --(date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a>);</div>
|
||||
<div class="line"><a name="l00347"></a><span class="lineno"> 347</span>  <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> == 0) {</div>
|
||||
<div class="line"><a name="l00348"></a><span class="lineno"> 348</span>  date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> = 12;</div>
|
||||
<div class="line"><a name="l00349"></a><span class="lineno"> 349</span>  <span class="keywordflow">if</span> (!(flags & <a class="code" href="classRTC.html#a02ace2d775063be9a99035851c9274eb" title="Wrap around to the beginning of the current month/year rather than advance to the next one...">WRAP</a>) && date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> > 2000)</div>
|
||||
<div class="line"><a name="l00350"></a><span class="lineno"> 350</span>  --(date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a>);</div>
|
||||
<div class="line"><a name="l00351"></a><span class="lineno"> 351</span>  }</div>
|
||||
<div class="line"><a name="l00352"></a><span class="lineno"> 352</span>  } <span class="keywordflow">else</span> {</div>
|
||||
<div class="line"><a name="l00353"></a><span class="lineno"> 353</span>  ++(date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a>);</div>
|
||||
<div class="line"><a name="l00354"></a><span class="lineno"> 354</span>  <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> == 13) {</div>
|
||||
<div class="line"><a name="l00355"></a><span class="lineno"> 355</span>  date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> = 1;</div>
|
||||
<div class="line"><a name="l00356"></a><span class="lineno"> 356</span>  <span class="keywordflow">if</span> (!(flags & <a class="code" href="classRTC.html#a02ace2d775063be9a99035851c9274eb" title="Wrap around to the beginning of the current month/year rather than advance to the next one...">WRAP</a>) && date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> < 2099)</div>
|
||||
<div class="line"><a name="l00357"></a><span class="lineno"> 357</span>  ++(date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a>);</div>
|
||||
<div class="line"><a name="l00358"></a><span class="lineno"> 358</span>  }</div>
|
||||
<div class="line"><a name="l00359"></a><span class="lineno"> 359</span>  }</div>
|
||||
<div class="line"><a name="l00360"></a><span class="lineno"> 360</span>  uint8_t len = monthLength(date);</div>
|
||||
<div class="line"><a name="l00361"></a><span class="lineno"> 361</span>  <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> > len)</div>
|
||||
<div class="line"><a name="l00362"></a><span class="lineno"> 362</span>  date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> = len;</div>
|
||||
<div class="line"><a name="l00363"></a><span class="lineno"> 363</span> }</div>
|
||||
<div class="line"><a name="l00364"></a><span class="lineno"> 364</span> </div>
|
||||
<div class="line"><a name="l00370"></a><span class="lineno"><a class="code" href="classRTC.html#a31d10cb2f7cac8839bd4be2d858b802d"> 370</a></span> <span class="keywordtype">void</span> <a class="code" href="classRTC.html#a31d10cb2f7cac8839bd4be2d858b802d" title="Adjusts date up or down one year according to flags.">RTC::adjustYears</a>(<a class="code" href="structRTCDate.html" title="Stores date information from a realtime clock chip.">RTCDate</a> *date, uint8_t flags)</div>
|
||||
<div class="line"><a name="l00371"></a><span class="lineno"> 371</span> {</div>
|
||||
<div class="line"><a name="l00372"></a><span class="lineno"> 372</span>  <span class="keywordflow">if</span> (flags & <a class="code" href="classRTC.html#a05b1bd1479afc80682abdd4f3e58dc6f" title="Decrement the day, month, or year in a call to adjustDays(), adjustMonths(), or adjustYears().">DECREMENT</a>) {</div>
|
||||
<div class="line"><a name="l00373"></a><span class="lineno"> 373</span>  --(date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a>);</div>
|
||||
<div class="line"><a name="l00374"></a><span class="lineno"> 374</span>  <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> < 2000)</div>
|
||||
<div class="line"><a name="l00375"></a><span class="lineno"> 375</span>  date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> = 2000;</div>
|
||||
<div class="line"><a name="l00376"></a><span class="lineno"> 376</span>  } <span class="keywordflow">else</span> {</div>
|
||||
<div class="line"><a name="l00377"></a><span class="lineno"> 377</span>  ++(date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a>);</div>
|
||||
<div class="line"><a name="l00378"></a><span class="lineno"> 378</span>  <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> > 2099)</div>
|
||||
<div class="line"><a name="l00379"></a><span class="lineno"> 379</span>  date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> = 2099;</div>
|
||||
<div class="line"><a name="l00380"></a><span class="lineno"> 380</span>  }</div>
|
||||
<div class="line"><a name="l00381"></a><span class="lineno"> 381</span>  uint8_t len = monthLength(date);</div>
|
||||
<div class="line"><a name="l00382"></a><span class="lineno"> 382</span>  <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> > len)</div>
|
||||
<div class="line"><a name="l00383"></a><span class="lineno"> 383</span>  date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> = len;</div>
|
||||
<div class="line"><a name="l00384"></a><span class="lineno"> 384</span> }</div>
|
||||
<div class="line"><a name="l00385"></a><span class="lineno"> 385</span> </div>
|
||||
<div class="line"><a name="l00399"></a><span class="lineno"><a class="code" href="classRTC.html#a525a9c1dad89613708f47a683eb316aa"> 399</a></span> <a class="code" href="classRTC.html#ab2ca0cbee608ec32d3d6e04d40298f11" title="Day of the week corresponding to a date.">RTC::DayOfWeek</a> <a class="code" href="classRTC.html#a525a9c1dad89613708f47a683eb316aa" title="Returns the day of the week corresponding to date.">RTC::dayOfWeek</a>(<span class="keyword">const</span> <a class="code" href="structRTCDate.html" title="Stores date information from a realtime clock chip.">RTCDate</a> *date)</div>
|
||||
<div class="line"><a name="l00400"></a><span class="lineno"> 400</span> {</div>
|
||||
<div class="line"><a name="l00401"></a><span class="lineno"> 401</span>  <span class="comment">// The +4 here adjusts for Jan 1, 2000 being a Saturday.</span></div>
|
||||
<div class="line"><a name="l00402"></a><span class="lineno"> 402</span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> daynum = date-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> + 4;</div>
|
||||
<div class="line"><a name="l00403"></a><span class="lineno"> 403</span>  daynum += monthOffsets[date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> - 1];</div>
|
||||
<div class="line"><a name="l00404"></a><span class="lineno"> 404</span>  <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> > 2 && isLeapYear(date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a>))</div>
|
||||
<div class="line"><a name="l00405"></a><span class="lineno"> 405</span>  ++daynum;</div>
|
||||
<div class="line"><a name="l00406"></a><span class="lineno"> 406</span>  daynum += 365UL * (date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> - 2000);</div>
|
||||
<div class="line"><a name="l00407"></a><span class="lineno"> 407</span>  <span class="keywordflow">if</span> (date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> > 2000)</div>
|
||||
<div class="line"><a name="l00408"></a><span class="lineno"> 408</span>  daynum += ((date-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> - 2001) / 4) + 1;</div>
|
||||
<div class="line"><a name="l00409"></a><span class="lineno"> 409</span>  <span class="keywordflow">return</span> (<a class="code" href="classRTC.html#ab2ca0cbee608ec32d3d6e04d40298f11" title="Day of the week corresponding to a date.">DayOfWeek</a>)((daynum % 7) + 1);</div>
|
||||
<div class="line"><a name="l00410"></a><span class="lineno"> 410</span> }</div>
|
||||
<div class="line"><a name="l00411"></a><span class="lineno"> 411</span> </div>
|
||||
</div><!-- fragment --></div><!-- contents -->
|
||||
<!-- start footer part -->
|
||||
<hr class="footer"/><address class="footer"><small>
|
||||
Generated on Sun Sep 29 2013 09:30:46 for ArduinoLibs by  <a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/>
|
||||
</a> 1.8.1.2
|
||||
</small></address>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user