1
0
mirror of https://github.com/taigrr/arduinolibs synced 2025-01-18 04:33:12 -08:00

Update docs

This commit is contained in:
Rhys Weatherley
2013-09-29 09:34:55 +10:00
parent 17f4fb4873
commit 8b7f9606ee
409 changed files with 21357 additions and 18181 deletions

View File

@@ -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: LCD.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&#160;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,208 +63,12 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
<li><a href="files.html"><span>File&#160;List</span></a></li>
</ul>
</div>
<div class="header">
<div class="headertitle">
<div class="title">LCD.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 &quot;Software&quot;),</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 &quot;AS IS&quot;, 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 &quot;LCD.h&quot;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;avr/pgmspace.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#if defined(ARDUINO) &amp;&amp; ARDUINO &gt;= 100</span>
<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">#include &lt;Arduino.h&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#else</span>
<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#include &lt;WProgram.h&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
<a name="l00030"></a>00030 <span class="preprocessor"></span>
<a name="l00031"></a>00031 <span class="preprocessor">#define LCD_BACK_LIGHT 3 // Default LCD backlight is on D3</span>
<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#define LCD_BUTTON_PIN A0 // Button state is on A0</span>
<a name="l00033"></a>00033 <span class="preprocessor"></span>
<a name="l00034"></a>00034 <span class="preprocessor">#define DEBOUNCE_DELAY 10 // Delay in ms to debounce buttons</span>
<a name="l00035"></a>00035 <span class="preprocessor"></span>
<a name="l00130"></a>00130 <span class="keywordtype">void</span> LCD::init()
<a name="l00131"></a>00131 {
<a name="l00132"></a>00132 <span class="comment">// The Freetronics display is 16x2.</span>
<a name="l00133"></a>00133 begin(16, 2);
<a name="l00134"></a>00134
<a name="l00135"></a>00135 <span class="comment">// Configure the backlight pin, but don&#39;t activate it yet in</span>
<a name="l00136"></a>00136 <span class="comment">// case the application sets it to something else during setup().</span>
<a name="l00137"></a>00137 <span class="comment">// Initialization will be forced in the first call to getButton().</span>
<a name="l00138"></a>00138 _backlightPin = LCD_BACK_LIGHT;
<a name="l00139"></a>00139 backlightInit = <span class="keyword">false</span>;
<a name="l00140"></a>00140
<a name="l00141"></a>00141 <span class="comment">// Initialise button input.</span>
<a name="l00142"></a>00142 pinMode(LCD_BUTTON_PIN, INPUT);
<a name="l00143"></a>00143 digitalWrite(LCD_BUTTON_PIN, LOW);
<a name="l00144"></a>00144 prevButton = LCD_BUTTON_NONE;
<a name="l00145"></a>00145 debounceButton = LCD_BUTTON_NONE;
<a name="l00146"></a>00146 lastDebounce = 0;
<a name="l00147"></a>00147 eatRelease = <span class="keyword">false</span>;
<a name="l00148"></a>00148
<a name="l00149"></a>00149 <span class="comment">// Initialize screen saver.</span>
<a name="l00150"></a>00150 timeout = 0;
<a name="l00151"></a>00151 lastRestore = millis();
<a name="l00152"></a>00152 screenSaved = <span class="keyword">false</span>;
<a name="l00153"></a>00153 mode = <a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28a3f1e62d5fcd314d6ff067d3e74c4bf5f" title="Turn off both the display and the backlight when the screen saver is activated.">DisplayOff</a>;
<a name="l00154"></a>00154 }
<a name="l00155"></a>00155
<a name="l00182"></a><a class="code" href="classLCD.html#a0b9b3b954290e7a3d94cdc829582b0a8">00182</a> <span class="keywordtype">void</span> <a class="code" href="classLCD.html#a0b9b3b954290e7a3d94cdc829582b0a8" title="Sets the back light pin for the LCD shield.">LCD::setBacklightPin</a>(uint8_t pin)
<a name="l00183"></a>00183 {
<a name="l00184"></a>00184 <span class="keywordflow">if</span> (_backlightPin != pin) {
<a name="l00185"></a>00185 <span class="keywordflow">if</span> (backlightInit) {
<a name="l00186"></a>00186 <span class="comment">// Restore the previous backlight pin to input, floating.</span>
<a name="l00187"></a>00187 pinMode(_backlightPin, INPUT);
<a name="l00188"></a>00188 digitalWrite(_backlightPin, LOW);
<a name="l00189"></a>00189
<a name="l00190"></a>00190 <span class="comment">// Need to re-initialize the backlight at the earliest opportunity.</span>
<a name="l00191"></a>00191 backlightInit = <span class="keyword">false</span>;
<a name="l00192"></a>00192 }
<a name="l00193"></a>00193 _backlightPin = pin;
<a name="l00194"></a>00194 }
<a name="l00195"></a>00195 }
<a name="l00196"></a>00196
<a name="l00206"></a><a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89">00206</a> <span class="keywordtype">void</span> <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">LCD::display</a>()
<a name="l00207"></a>00207 {
<a name="l00208"></a>00208 <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">LiquidCrystal::display</a>();
<a name="l00209"></a>00209 pinMode(_backlightPin, OUTPUT);
<a name="l00210"></a>00210 digitalWrite(_backlightPin, HIGH);
<a name="l00211"></a>00211 screenSaved = <span class="keyword">false</span>;
<a name="l00212"></a>00212 backlightInit = <span class="keyword">true</span>;
<a name="l00213"></a>00213 lastRestore = millis();
<a name="l00214"></a>00214 }
<a name="l00215"></a>00215
<a name="l00223"></a><a class="code" href="classLCD.html#af3974da6d988ba2d21c25135ada12108">00223</a> <span class="keywordtype">void</span> <a class="code" href="classLCD.html#af3974da6d988ba2d21c25135ada12108" title="Turns off the display of text on the LCD and the back light.">LCD::noDisplay</a>()
<a name="l00224"></a>00224 {
<a name="l00225"></a>00225 <span class="keywordflow">if</span> (mode == <a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28a3f1e62d5fcd314d6ff067d3e74c4bf5f" title="Turn off both the display and the backlight when the screen saver is activated.">DisplayOff</a>)
<a name="l00226"></a>00226 <a class="code" href="classLCD.html#af3974da6d988ba2d21c25135ada12108" title="Turns off the display of text on the LCD and the back light.">LiquidCrystal::noDisplay</a>();
<a name="l00227"></a>00227 pinMode(_backlightPin, OUTPUT);
<a name="l00228"></a>00228 digitalWrite(_backlightPin, LOW);
<a name="l00229"></a>00229 screenSaved = <span class="keyword">true</span>;
<a name="l00230"></a>00230 backlightInit = <span class="keyword">true</span>;
<a name="l00231"></a>00231 }
<a name="l00232"></a>00232
<a name="l00268"></a><a class="code" href="classLCD.html#a56d1f68532c779c65fbbd071fb444801">00268</a> <span class="keywordtype">void</span> <a class="code" href="classLCD.html#a56d1f68532c779c65fbbd071fb444801" title="Sets the current screen saver mode.">LCD::setScreenSaverMode</a>(<a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28" title="Screen saver mode that controls the display and back light.">ScreenSaverMode</a> mode)
<a name="l00269"></a>00269 {
<a name="l00270"></a>00270 <span class="keywordflow">if</span> (this-&gt;mode != mode) {
<a name="l00271"></a>00271 this-&gt;mode = mode;
<a name="l00272"></a>00272 <span class="keywordflow">if</span> (screenSaved)
<a name="l00273"></a>00273 <a class="code" href="classLCD.html#af3974da6d988ba2d21c25135ada12108" title="Turns off the display of text on the LCD and the back light.">noDisplay</a>();
<a name="l00274"></a>00274 <span class="keywordflow">else</span>
<a name="l00275"></a>00275 <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();
<a name="l00276"></a>00276 }
<a name="l00277"></a>00277 }
<a name="l00278"></a>00278
<a name="l00294"></a><a class="code" href="classLCD.html#af9a2326d034fa159d384ec16223c924f">00294</a> <span class="keywordtype">void</span> <a class="code" href="classLCD.html#af9a2326d034fa159d384ec16223c924f" title="Enables the screen saver and causes it to activate after timeoutSecs of inactivity on the buttons...">LCD::enableScreenSaver</a>(<span class="keywordtype">int</span> timeoutSecs)
<a name="l00295"></a>00295 {
<a name="l00296"></a>00296 <span class="keywordflow">if</span> (timeoutSecs &lt; 0)
<a name="l00297"></a>00297 timeout = 0;
<a name="l00298"></a>00298 <span class="keywordflow">else</span>
<a name="l00299"></a>00299 timeout = ((<span class="keywordtype">unsigned</span> long)timeoutSecs) * 1000;
<a name="l00300"></a>00300 <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();
<a name="l00301"></a>00301 }
<a name="l00302"></a>00302
<a name="l00308"></a><a class="code" href="classLCD.html#a85c3a4694b105731404df36e35e5b26e">00308</a> <span class="keywordtype">void</span> <a class="code" href="classLCD.html#a85c3a4694b105731404df36e35e5b26e" title="Disables the screen saver.">LCD::disableScreenSaver</a>()
<a name="l00309"></a>00309 {
<a name="l00310"></a>00310 timeout = 0;
<a name="l00311"></a>00311 <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();
<a name="l00312"></a>00312 }
<a name="l00313"></a>00313
<a name="l00321"></a>00321 <span class="comment">// Button mapping table generated by genlookup.c</span>
<a name="l00322"></a>00322 <span class="keyword">static</span> prog_uint8_t <span class="keyword">const</span> buttonMappings[] PROGMEM = {
<a name="l00323"></a>00323 2, 0, 0, 0, 3, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 1,
<a name="l00324"></a>00324 1, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0
<a name="l00325"></a>00325 };
<a name="l00326"></a>00326 <span class="preprocessor">#define mapButton(value) (pgm_read_byte(&amp;(buttonMappings[(value) &gt;&gt; 5])))</span>
<a name="l00327"></a>00327 <span class="preprocessor"></span>
<a name="l00353"></a><a class="code" href="classLCD.html#ac1e80e2603bd1cf0276c36092c416292">00353</a> <span class="keywordtype">int</span> <a class="code" href="classLCD.html#ac1e80e2603bd1cf0276c36092c416292" title="Gets the next button press, release, or idle event.">LCD::getButton</a>()
<a name="l00354"></a>00354 {
<a name="l00355"></a>00355 <span class="comment">// Initialize the backlight for the first time if necessary.</span>
<a name="l00356"></a>00356 <span class="keywordflow">if</span> (!backlightInit)
<a name="l00357"></a>00357 <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();
<a name="l00358"></a>00358
<a name="l00359"></a>00359 <span class="comment">// Read the currently pressed button.</span>
<a name="l00360"></a>00360 <span class="keywordtype">int</span> button = mapButton(analogRead(LCD_BUTTON_PIN));
<a name="l00361"></a>00361
<a name="l00362"></a>00362 <span class="comment">// Debounce the button state.</span>
<a name="l00363"></a>00363 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> currentTime = millis();
<a name="l00364"></a>00364 <span class="keywordflow">if</span> (button != debounceButton)
<a name="l00365"></a>00365 lastDebounce = currentTime;
<a name="l00366"></a>00366 debounceButton = button;
<a name="l00367"></a>00367 <span class="keywordflow">if</span> ((currentTime - lastDebounce) &lt; DEBOUNCE_DELAY)
<a name="l00368"></a>00368 button = prevButton;
<a name="l00369"></a>00369
<a name="l00370"></a>00370 <span class="comment">// Process the button event if the state has changed.</span>
<a name="l00371"></a>00371 <span class="keywordflow">if</span> (prevButton == LCD_BUTTON_NONE &amp;&amp; button != LCD_BUTTON_NONE) {
<a name="l00372"></a>00372 prevButton = button;
<a name="l00373"></a>00373 <span class="keywordflow">if</span> (screenSaved) {
<a name="l00374"></a>00374 <span class="comment">// Button pressed when screen saver active.</span>
<a name="l00375"></a>00375 <span class="keywordflow">if</span> (mode == <a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28a781f3c5e42506bf4f86ba06d69b23d35" title="Same as BacklightOff but the screen saver is only deactivated when Select is pressed; other buttons h...">BacklightOnSelect</a>) {
<a name="l00376"></a>00376 <span class="comment">// Turn on the back light only if Select was pressed.</span>
<a name="l00377"></a>00377 <span class="keywordflow">if</span> (button == LCD_BUTTON_SELECT) {
<a name="l00378"></a>00378 pinMode(_backlightPin, OUTPUT);
<a name="l00379"></a>00379 digitalWrite(_backlightPin, HIGH);
<a name="l00380"></a>00380 screenSaved = <span class="keyword">false</span>;
<a name="l00381"></a>00381 backlightInit = <span class="keyword">true</span>;
<a name="l00382"></a>00382 }
<a name="l00383"></a>00383 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (mode == <a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28a3f1e62d5fcd314d6ff067d3e74c4bf5f" title="Turn off both the display and the backlight when the screen saver is activated.">DisplayOff</a>) {
<a name="l00384"></a>00384 <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();
<a name="l00385"></a>00385 eatRelease = <span class="keyword">true</span>;
<a name="l00386"></a>00386 <span class="keywordflow">return</span> LCD_BUTTON_NONE;
<a name="l00387"></a>00387 } <span class="keywordflow">else</span> {
<a name="l00388"></a>00388 <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();
<a name="l00389"></a>00389 }
<a name="l00390"></a>00390 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (mode == <a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28a781f3c5e42506bf4f86ba06d69b23d35" title="Same as BacklightOff but the screen saver is only deactivated when Select is pressed; other buttons h...">BacklightOnSelect</a> &amp;&amp; button != LCD_BUTTON_SELECT) {
<a name="l00391"></a>00391 eatRelease = <span class="keyword">false</span>;
<a name="l00392"></a>00392 <span class="keywordflow">return</span> button;
<a name="l00393"></a>00393 }
<a name="l00394"></a>00394 eatRelease = <span class="keyword">false</span>;
<a name="l00395"></a>00395 lastRestore = currentTime;
<a name="l00396"></a>00396 <span class="keywordflow">return</span> button;
<a name="l00397"></a>00397 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (prevButton != LCD_BUTTON_NONE &amp;&amp; button == LCD_BUTTON_NONE) {
<a name="l00398"></a>00398 button = -prevButton;
<a name="l00399"></a>00399 prevButton = LCD_BUTTON_NONE;
<a name="l00400"></a>00400 lastRestore = currentTime;
<a name="l00401"></a>00401 <span class="keywordflow">if</span> (eatRelease) {
<a name="l00402"></a>00402 eatRelease = <span class="keyword">false</span>;
<a name="l00403"></a>00403 <span class="keywordflow">return</span> LCD_BUTTON_NONE;
<a name="l00404"></a>00404 }
<a name="l00405"></a>00405 <span class="keywordflow">return</span> button;
<a name="l00406"></a>00406 } <span class="keywordflow">else</span> {
<a name="l00407"></a>00407 <span class="keywordflow">if</span> (!screenSaved &amp;&amp; prevButton == LCD_BUTTON_NONE &amp;&amp;
<a name="l00408"></a>00408 timeout != 0 &amp;&amp; (currentTime - lastRestore) &gt;= timeout)
<a name="l00409"></a>00409 <a class="code" href="classLCD.html#af3974da6d988ba2d21c25135ada12108" title="Turns off the display of text on the LCD and the back light.">noDisplay</a>(); <span class="comment">// Activate screen saver.</span>
<a name="l00410"></a>00410 <span class="keywordflow">return</span> LCD_BUTTON_NONE;
<a name="l00411"></a>00411 }
<a name="l00412"></a>00412 }
</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">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a></div>
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Pages</a></div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
@@ -265,8 +77,211 @@ 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&#160;
<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_48f64e79f12bd77ba047e9e436ec978c.html">LCD</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">LCD.cpp</div> </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;<span class="comment">/*</span></div>
<div class="line"><a name="l00002"></a><span class="lineno"> 2</span>&#160;<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>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00004"></a><span class="lineno"> 4</span>&#160;<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>&#160;<span class="comment"> * copy of this software and associated documentation files (the &quot;Software&quot;),</span></div>
<div class="line"><a name="l00006"></a><span class="lineno"> 6</span>&#160;<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>&#160;<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>&#160;<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>&#160;<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>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00011"></a><span class="lineno"> 11</span>&#160;<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>&#160;<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>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00014"></a><span class="lineno"> 14</span>&#160;<span class="comment"> * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS</span></div>
<div class="line"><a name="l00015"></a><span class="lineno"> 15</span>&#160;<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>&#160;<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>&#160;<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>&#160;<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>&#160;<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>&#160;<span class="comment"> * DEALINGS IN THE SOFTWARE.</span></div>
<div class="line"><a name="l00021"></a><span class="lineno"> 21</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00022"></a><span class="lineno"> 22</span>&#160;</div>
<div class="line"><a name="l00023"></a><span class="lineno"> 23</span>&#160;<span class="preprocessor">#include &quot;LCD.h&quot;</span></div>
<div class="line"><a name="l00024"></a><span class="lineno"> 24</span>&#160;<span class="preprocessor">#include &lt;avr/pgmspace.h&gt;</span></div>
<div class="line"><a name="l00025"></a><span class="lineno"> 25</span>&#160;<span class="preprocessor">#if defined(ARDUINO) &amp;&amp; ARDUINO &gt;= 100</span></div>
<div class="line"><a name="l00026"></a><span class="lineno"> 26</span>&#160;<span class="preprocessor"></span><span class="preprocessor">#include &lt;Arduino.h&gt;</span></div>
<div class="line"><a name="l00027"></a><span class="lineno"> 27</span>&#160;<span class="preprocessor">#else</span></div>
<div class="line"><a name="l00028"></a><span class="lineno"> 28</span>&#160;<span class="preprocessor"></span><span class="preprocessor">#include &lt;WProgram.h&gt;</span></div>
<div class="line"><a name="l00029"></a><span class="lineno"> 29</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00030"></a><span class="lineno"> 30</span>&#160;<span class="preprocessor"></span></div>
<div class="line"><a name="l00031"></a><span class="lineno"> 31</span>&#160;<span class="preprocessor">#define LCD_BACK_LIGHT 3 // Default LCD backlight is on D3</span></div>
<div class="line"><a name="l00032"></a><span class="lineno"> 32</span>&#160;<span class="preprocessor"></span><span class="preprocessor">#define LCD_BUTTON_PIN A0 // Button state is on A0</span></div>
<div class="line"><a name="l00033"></a><span class="lineno"> 33</span>&#160;<span class="preprocessor"></span></div>
<div class="line"><a name="l00034"></a><span class="lineno"> 34</span>&#160;<span class="preprocessor">#define DEBOUNCE_DELAY 10 // Delay in ms to debounce buttons</span></div>
<div class="line"><a name="l00035"></a><span class="lineno"> 35</span>&#160;<span class="preprocessor"></span></div>
<div class="line"><a name="l00130"></a><span class="lineno"> 130</span>&#160;<span class="keywordtype">void</span> LCD::init()</div>
<div class="line"><a name="l00131"></a><span class="lineno"> 131</span>&#160;{</div>
<div class="line"><a name="l00132"></a><span class="lineno"> 132</span>&#160; <span class="comment">// The Freetronics display is 16x2.</span></div>
<div class="line"><a name="l00133"></a><span class="lineno"> 133</span>&#160; begin(16, 2);</div>
<div class="line"><a name="l00134"></a><span class="lineno"> 134</span>&#160;</div>
<div class="line"><a name="l00135"></a><span class="lineno"> 135</span>&#160; <span class="comment">// Configure the backlight pin, but don&#39;t activate it yet in</span></div>
<div class="line"><a name="l00136"></a><span class="lineno"> 136</span>&#160; <span class="comment">// case the application sets it to something else during setup().</span></div>
<div class="line"><a name="l00137"></a><span class="lineno"> 137</span>&#160; <span class="comment">// Initialization will be forced in the first call to getButton().</span></div>
<div class="line"><a name="l00138"></a><span class="lineno"> 138</span>&#160; _backlightPin = LCD_BACK_LIGHT;</div>
<div class="line"><a name="l00139"></a><span class="lineno"> 139</span>&#160; backlightInit = <span class="keyword">false</span>;</div>
<div class="line"><a name="l00140"></a><span class="lineno"> 140</span>&#160;</div>
<div class="line"><a name="l00141"></a><span class="lineno"> 141</span>&#160; <span class="comment">// Initialise button input.</span></div>
<div class="line"><a name="l00142"></a><span class="lineno"> 142</span>&#160; pinMode(LCD_BUTTON_PIN, INPUT);</div>
<div class="line"><a name="l00143"></a><span class="lineno"> 143</span>&#160; digitalWrite(LCD_BUTTON_PIN, LOW);</div>
<div class="line"><a name="l00144"></a><span class="lineno"> 144</span>&#160; prevButton = LCD_BUTTON_NONE;</div>
<div class="line"><a name="l00145"></a><span class="lineno"> 145</span>&#160; debounceButton = LCD_BUTTON_NONE;</div>
<div class="line"><a name="l00146"></a><span class="lineno"> 146</span>&#160; lastDebounce = 0;</div>
<div class="line"><a name="l00147"></a><span class="lineno"> 147</span>&#160; eatRelease = <span class="keyword">false</span>;</div>
<div class="line"><a name="l00148"></a><span class="lineno"> 148</span>&#160;</div>
<div class="line"><a name="l00149"></a><span class="lineno"> 149</span>&#160; <span class="comment">// Initialize screen saver.</span></div>
<div class="line"><a name="l00150"></a><span class="lineno"> 150</span>&#160; timeout = 0;</div>
<div class="line"><a name="l00151"></a><span class="lineno"> 151</span>&#160; lastRestore = millis();</div>
<div class="line"><a name="l00152"></a><span class="lineno"> 152</span>&#160; screenSaved = <span class="keyword">false</span>;</div>
<div class="line"><a name="l00153"></a><span class="lineno"> 153</span>&#160; mode = <a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28a3f1e62d5fcd314d6ff067d3e74c4bf5f" title="Turn off both the display and the backlight when the screen saver is activated.">DisplayOff</a>;</div>
<div class="line"><a name="l00154"></a><span class="lineno"> 154</span>&#160;}</div>
<div class="line"><a name="l00155"></a><span class="lineno"> 155</span>&#160;</div>
<div class="line"><a name="l00182"></a><span class="lineno"><a class="code" href="classLCD.html#a0b9b3b954290e7a3d94cdc829582b0a8"> 182</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="classLCD.html#a0b9b3b954290e7a3d94cdc829582b0a8" title="Sets the back light pin for the LCD shield.">LCD::setBacklightPin</a>(uint8_t pin)</div>
<div class="line"><a name="l00183"></a><span class="lineno"> 183</span>&#160;{</div>
<div class="line"><a name="l00184"></a><span class="lineno"> 184</span>&#160; <span class="keywordflow">if</span> (_backlightPin != pin) {</div>
<div class="line"><a name="l00185"></a><span class="lineno"> 185</span>&#160; <span class="keywordflow">if</span> (backlightInit) {</div>
<div class="line"><a name="l00186"></a><span class="lineno"> 186</span>&#160; <span class="comment">// Restore the previous backlight pin to input, floating.</span></div>
<div class="line"><a name="l00187"></a><span class="lineno"> 187</span>&#160; pinMode(_backlightPin, INPUT);</div>
<div class="line"><a name="l00188"></a><span class="lineno"> 188</span>&#160; digitalWrite(_backlightPin, LOW);</div>
<div class="line"><a name="l00189"></a><span class="lineno"> 189</span>&#160;</div>
<div class="line"><a name="l00190"></a><span class="lineno"> 190</span>&#160; <span class="comment">// Need to re-initialize the backlight at the earliest opportunity.</span></div>
<div class="line"><a name="l00191"></a><span class="lineno"> 191</span>&#160; backlightInit = <span class="keyword">false</span>;</div>
<div class="line"><a name="l00192"></a><span class="lineno"> 192</span>&#160; }</div>
<div class="line"><a name="l00193"></a><span class="lineno"> 193</span>&#160; _backlightPin = pin;</div>
<div class="line"><a name="l00194"></a><span class="lineno"> 194</span>&#160; }</div>
<div class="line"><a name="l00195"></a><span class="lineno"> 195</span>&#160;}</div>
<div class="line"><a name="l00196"></a><span class="lineno"> 196</span>&#160;</div>
<div class="line"><a name="l00206"></a><span class="lineno"><a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89"> 206</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">LCD::display</a>()</div>
<div class="line"><a name="l00207"></a><span class="lineno"> 207</span>&#160;{</div>
<div class="line"><a name="l00208"></a><span class="lineno"> 208</span>&#160; <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">LiquidCrystal::display</a>();</div>
<div class="line"><a name="l00209"></a><span class="lineno"> 209</span>&#160; pinMode(_backlightPin, OUTPUT);</div>
<div class="line"><a name="l00210"></a><span class="lineno"> 210</span>&#160; digitalWrite(_backlightPin, HIGH);</div>
<div class="line"><a name="l00211"></a><span class="lineno"> 211</span>&#160; screenSaved = <span class="keyword">false</span>;</div>
<div class="line"><a name="l00212"></a><span class="lineno"> 212</span>&#160; backlightInit = <span class="keyword">true</span>;</div>
<div class="line"><a name="l00213"></a><span class="lineno"> 213</span>&#160; lastRestore = millis();</div>
<div class="line"><a name="l00214"></a><span class="lineno"> 214</span>&#160;}</div>
<div class="line"><a name="l00215"></a><span class="lineno"> 215</span>&#160;</div>
<div class="line"><a name="l00223"></a><span class="lineno"><a class="code" href="classLCD.html#af3974da6d988ba2d21c25135ada12108"> 223</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="classLCD.html#af3974da6d988ba2d21c25135ada12108" title="Turns off the display of text on the LCD and the back light.">LCD::noDisplay</a>()</div>
<div class="line"><a name="l00224"></a><span class="lineno"> 224</span>&#160;{</div>
<div class="line"><a name="l00225"></a><span class="lineno"> 225</span>&#160; <span class="keywordflow">if</span> (mode == <a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28a3f1e62d5fcd314d6ff067d3e74c4bf5f" title="Turn off both the display and the backlight when the screen saver is activated.">DisplayOff</a>)</div>
<div class="line"><a name="l00226"></a><span class="lineno"> 226</span>&#160; <a class="code" href="classLCD.html#af3974da6d988ba2d21c25135ada12108" title="Turns off the display of text on the LCD and the back light.">LiquidCrystal::noDisplay</a>();</div>
<div class="line"><a name="l00227"></a><span class="lineno"> 227</span>&#160; pinMode(_backlightPin, OUTPUT);</div>
<div class="line"><a name="l00228"></a><span class="lineno"> 228</span>&#160; digitalWrite(_backlightPin, LOW);</div>
<div class="line"><a name="l00229"></a><span class="lineno"> 229</span>&#160; screenSaved = <span class="keyword">true</span>;</div>
<div class="line"><a name="l00230"></a><span class="lineno"> 230</span>&#160; backlightInit = <span class="keyword">true</span>;</div>
<div class="line"><a name="l00231"></a><span class="lineno"> 231</span>&#160;}</div>
<div class="line"><a name="l00232"></a><span class="lineno"> 232</span>&#160;</div>
<div class="line"><a name="l00268"></a><span class="lineno"><a class="code" href="classLCD.html#a56d1f68532c779c65fbbd071fb444801"> 268</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="classLCD.html#a56d1f68532c779c65fbbd071fb444801" title="Sets the current screen saver mode.">LCD::setScreenSaverMode</a>(<a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28" title="Screen saver mode that controls the display and back light.">ScreenSaverMode</a> mode)</div>
<div class="line"><a name="l00269"></a><span class="lineno"> 269</span>&#160;{</div>
<div class="line"><a name="l00270"></a><span class="lineno"> 270</span>&#160; <span class="keywordflow">if</span> (this-&gt;mode != mode) {</div>
<div class="line"><a name="l00271"></a><span class="lineno"> 271</span>&#160; this-&gt;mode = mode;</div>
<div class="line"><a name="l00272"></a><span class="lineno"> 272</span>&#160; <span class="keywordflow">if</span> (screenSaved)</div>
<div class="line"><a name="l00273"></a><span class="lineno"> 273</span>&#160; <a class="code" href="classLCD.html#af3974da6d988ba2d21c25135ada12108" title="Turns off the display of text on the LCD and the back light.">noDisplay</a>();</div>
<div class="line"><a name="l00274"></a><span class="lineno"> 274</span>&#160; <span class="keywordflow">else</span></div>
<div class="line"><a name="l00275"></a><span class="lineno"> 275</span>&#160; <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();</div>
<div class="line"><a name="l00276"></a><span class="lineno"> 276</span>&#160; }</div>
<div class="line"><a name="l00277"></a><span class="lineno"> 277</span>&#160;}</div>
<div class="line"><a name="l00278"></a><span class="lineno"> 278</span>&#160;</div>
<div class="line"><a name="l00294"></a><span class="lineno"><a class="code" href="classLCD.html#af9a2326d034fa159d384ec16223c924f"> 294</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="classLCD.html#af9a2326d034fa159d384ec16223c924f" title="Enables the screen saver and causes it to activate after timeoutSecs of inactivity on the buttons...">LCD::enableScreenSaver</a>(<span class="keywordtype">int</span> timeoutSecs)</div>
<div class="line"><a name="l00295"></a><span class="lineno"> 295</span>&#160;{</div>
<div class="line"><a name="l00296"></a><span class="lineno"> 296</span>&#160; <span class="keywordflow">if</span> (timeoutSecs &lt; 0)</div>
<div class="line"><a name="l00297"></a><span class="lineno"> 297</span>&#160; timeout = 0;</div>
<div class="line"><a name="l00298"></a><span class="lineno"> 298</span>&#160; <span class="keywordflow">else</span></div>
<div class="line"><a name="l00299"></a><span class="lineno"> 299</span>&#160; timeout = ((<span class="keywordtype">unsigned</span> long)timeoutSecs) * 1000;</div>
<div class="line"><a name="l00300"></a><span class="lineno"> 300</span>&#160; <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();</div>
<div class="line"><a name="l00301"></a><span class="lineno"> 301</span>&#160;}</div>
<div class="line"><a name="l00302"></a><span class="lineno"> 302</span>&#160;</div>
<div class="line"><a name="l00308"></a><span class="lineno"><a class="code" href="classLCD.html#a85c3a4694b105731404df36e35e5b26e"> 308</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="classLCD.html#a85c3a4694b105731404df36e35e5b26e" title="Disables the screen saver.">LCD::disableScreenSaver</a>()</div>
<div class="line"><a name="l00309"></a><span class="lineno"> 309</span>&#160;{</div>
<div class="line"><a name="l00310"></a><span class="lineno"> 310</span>&#160; timeout = 0;</div>
<div class="line"><a name="l00311"></a><span class="lineno"> 311</span>&#160; <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();</div>
<div class="line"><a name="l00312"></a><span class="lineno"> 312</span>&#160;}</div>
<div class="line"><a name="l00313"></a><span class="lineno"> 313</span>&#160;</div>
<div class="line"><a name="l00321"></a><span class="lineno"> 321</span>&#160;<span class="comment">// Button mapping table generated by genlookup.c</span></div>
<div class="line"><a name="l00322"></a><span class="lineno"> 322</span>&#160;<span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <span class="keyword">const</span> buttonMappings[] PROGMEM = {</div>
<div class="line"><a name="l00323"></a><span class="lineno"> 323</span>&#160; 2, 0, 0, 0, 3, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 1,</div>
<div class="line"><a name="l00324"></a><span class="lineno"> 324</span>&#160; 1, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0</div>
<div class="line"><a name="l00325"></a><span class="lineno"> 325</span>&#160;};</div>
<div class="line"><a name="l00326"></a><span class="lineno"> 326</span>&#160;<span class="preprocessor">#define mapButton(value) (pgm_read_byte(&amp;(buttonMappings[(value) &gt;&gt; 5])))</span></div>
<div class="line"><a name="l00327"></a><span class="lineno"> 327</span>&#160;<span class="preprocessor"></span></div>
<div class="line"><a name="l00353"></a><span class="lineno"><a class="code" href="classLCD.html#ac1e80e2603bd1cf0276c36092c416292"> 353</a></span>&#160;<span class="keywordtype">int</span> <a class="code" href="classLCD.html#ac1e80e2603bd1cf0276c36092c416292" title="Gets the next button press, release, or idle event.">LCD::getButton</a>()</div>
<div class="line"><a name="l00354"></a><span class="lineno"> 354</span>&#160;{</div>
<div class="line"><a name="l00355"></a><span class="lineno"> 355</span>&#160; <span class="comment">// Initialize the backlight for the first time if necessary.</span></div>
<div class="line"><a name="l00356"></a><span class="lineno"> 356</span>&#160; <span class="keywordflow">if</span> (!backlightInit)</div>
<div class="line"><a name="l00357"></a><span class="lineno"> 357</span>&#160; <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();</div>
<div class="line"><a name="l00358"></a><span class="lineno"> 358</span>&#160;</div>
<div class="line"><a name="l00359"></a><span class="lineno"> 359</span>&#160; <span class="comment">// Read the currently pressed button.</span></div>
<div class="line"><a name="l00360"></a><span class="lineno"> 360</span>&#160; <span class="keywordtype">int</span> button = mapButton(analogRead(LCD_BUTTON_PIN));</div>
<div class="line"><a name="l00361"></a><span class="lineno"> 361</span>&#160;</div>
<div class="line"><a name="l00362"></a><span class="lineno"> 362</span>&#160; <span class="comment">// Debounce the button state.</span></div>
<div class="line"><a name="l00363"></a><span class="lineno"> 363</span>&#160; <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> currentTime = millis();</div>
<div class="line"><a name="l00364"></a><span class="lineno"> 364</span>&#160; <span class="keywordflow">if</span> (button != debounceButton)</div>
<div class="line"><a name="l00365"></a><span class="lineno"> 365</span>&#160; lastDebounce = currentTime;</div>
<div class="line"><a name="l00366"></a><span class="lineno"> 366</span>&#160; debounceButton = button;</div>
<div class="line"><a name="l00367"></a><span class="lineno"> 367</span>&#160; <span class="keywordflow">if</span> ((currentTime - lastDebounce) &lt; DEBOUNCE_DELAY)</div>
<div class="line"><a name="l00368"></a><span class="lineno"> 368</span>&#160; button = prevButton;</div>
<div class="line"><a name="l00369"></a><span class="lineno"> 369</span>&#160;</div>
<div class="line"><a name="l00370"></a><span class="lineno"> 370</span>&#160; <span class="comment">// Process the button event if the state has changed.</span></div>
<div class="line"><a name="l00371"></a><span class="lineno"> 371</span>&#160; <span class="keywordflow">if</span> (prevButton == LCD_BUTTON_NONE &amp;&amp; button != LCD_BUTTON_NONE) {</div>
<div class="line"><a name="l00372"></a><span class="lineno"> 372</span>&#160; prevButton = button;</div>
<div class="line"><a name="l00373"></a><span class="lineno"> 373</span>&#160; <span class="keywordflow">if</span> (screenSaved) {</div>
<div class="line"><a name="l00374"></a><span class="lineno"> 374</span>&#160; <span class="comment">// Button pressed when screen saver active.</span></div>
<div class="line"><a name="l00375"></a><span class="lineno"> 375</span>&#160; <span class="keywordflow">if</span> (mode == <a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28a781f3c5e42506bf4f86ba06d69b23d35" title="Same as BacklightOff but the screen saver is only deactivated when Select is pressed; other buttons h...">BacklightOnSelect</a>) {</div>
<div class="line"><a name="l00376"></a><span class="lineno"> 376</span>&#160; <span class="comment">// Turn on the back light only if Select was pressed.</span></div>
<div class="line"><a name="l00377"></a><span class="lineno"> 377</span>&#160; <span class="keywordflow">if</span> (button == LCD_BUTTON_SELECT) {</div>
<div class="line"><a name="l00378"></a><span class="lineno"> 378</span>&#160; pinMode(_backlightPin, OUTPUT);</div>
<div class="line"><a name="l00379"></a><span class="lineno"> 379</span>&#160; digitalWrite(_backlightPin, HIGH);</div>
<div class="line"><a name="l00380"></a><span class="lineno"> 380</span>&#160; screenSaved = <span class="keyword">false</span>;</div>
<div class="line"><a name="l00381"></a><span class="lineno"> 381</span>&#160; backlightInit = <span class="keyword">true</span>;</div>
<div class="line"><a name="l00382"></a><span class="lineno"> 382</span>&#160; }</div>
<div class="line"><a name="l00383"></a><span class="lineno"> 383</span>&#160; } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (mode == <a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28a3f1e62d5fcd314d6ff067d3e74c4bf5f" title="Turn off both the display and the backlight when the screen saver is activated.">DisplayOff</a>) {</div>
<div class="line"><a name="l00384"></a><span class="lineno"> 384</span>&#160; <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();</div>
<div class="line"><a name="l00385"></a><span class="lineno"> 385</span>&#160; eatRelease = <span class="keyword">true</span>;</div>
<div class="line"><a name="l00386"></a><span class="lineno"> 386</span>&#160; <span class="keywordflow">return</span> LCD_BUTTON_NONE;</div>
<div class="line"><a name="l00387"></a><span class="lineno"> 387</span>&#160; } <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00388"></a><span class="lineno"> 388</span>&#160; <a class="code" href="classLCD.html#a5b07cf05e8e5e7c53654f5ca0cf58b89" title="Turns on the display of text on the LCD and the back light.">display</a>();</div>
<div class="line"><a name="l00389"></a><span class="lineno"> 389</span>&#160; }</div>
<div class="line"><a name="l00390"></a><span class="lineno"> 390</span>&#160; } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (mode == <a class="code" href="classLCD.html#a264bf94308c95d8598426e13dc8cdb28a781f3c5e42506bf4f86ba06d69b23d35" title="Same as BacklightOff but the screen saver is only deactivated when Select is pressed; other buttons h...">BacklightOnSelect</a> &amp;&amp; button != LCD_BUTTON_SELECT) {</div>
<div class="line"><a name="l00391"></a><span class="lineno"> 391</span>&#160; eatRelease = <span class="keyword">false</span>;</div>
<div class="line"><a name="l00392"></a><span class="lineno"> 392</span>&#160; <span class="keywordflow">return</span> button;</div>
<div class="line"><a name="l00393"></a><span class="lineno"> 393</span>&#160; }</div>
<div class="line"><a name="l00394"></a><span class="lineno"> 394</span>&#160; eatRelease = <span class="keyword">false</span>;</div>
<div class="line"><a name="l00395"></a><span class="lineno"> 395</span>&#160; lastRestore = currentTime;</div>
<div class="line"><a name="l00396"></a><span class="lineno"> 396</span>&#160; <span class="keywordflow">return</span> button;</div>
<div class="line"><a name="l00397"></a><span class="lineno"> 397</span>&#160; } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (prevButton != LCD_BUTTON_NONE &amp;&amp; button == LCD_BUTTON_NONE) {</div>
<div class="line"><a name="l00398"></a><span class="lineno"> 398</span>&#160; button = -prevButton;</div>
<div class="line"><a name="l00399"></a><span class="lineno"> 399</span>&#160; prevButton = LCD_BUTTON_NONE;</div>
<div class="line"><a name="l00400"></a><span class="lineno"> 400</span>&#160; lastRestore = currentTime;</div>
<div class="line"><a name="l00401"></a><span class="lineno"> 401</span>&#160; <span class="keywordflow">if</span> (eatRelease) {</div>
<div class="line"><a name="l00402"></a><span class="lineno"> 402</span>&#160; eatRelease = <span class="keyword">false</span>;</div>
<div class="line"><a name="l00403"></a><span class="lineno"> 403</span>&#160; <span class="keywordflow">return</span> LCD_BUTTON_NONE;</div>
<div class="line"><a name="l00404"></a><span class="lineno"> 404</span>&#160; }</div>
<div class="line"><a name="l00405"></a><span class="lineno"> 405</span>&#160; <span class="keywordflow">return</span> button;</div>
<div class="line"><a name="l00406"></a><span class="lineno"> 406</span>&#160; } <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00407"></a><span class="lineno"> 407</span>&#160; <span class="keywordflow">if</span> (!screenSaved &amp;&amp; prevButton == LCD_BUTTON_NONE &amp;&amp;</div>
<div class="line"><a name="l00408"></a><span class="lineno"> 408</span>&#160; timeout != 0 &amp;&amp; (currentTime - lastRestore) &gt;= timeout)</div>
<div class="line"><a name="l00409"></a><span class="lineno"> 409</span>&#160; <a class="code" href="classLCD.html#af3974da6d988ba2d21c25135ada12108" title="Turns off the display of text on the LCD and the back light.">noDisplay</a>(); <span class="comment">// Activate screen saver.</span></div>
<div class="line"><a name="l00410"></a><span class="lineno"> 410</span>&#160; <span class="keywordflow">return</span> LCD_BUTTON_NONE;</div>
<div class="line"><a name="l00411"></a><span class="lineno"> 411</span>&#160; }</div>
<div class="line"><a name="l00412"></a><span class="lineno"> 412</span>&#160;}</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 &#160;<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>