-
Notifications
You must be signed in to change notification settings - Fork 0
/
namespace_hardware.html
360 lines (330 loc) · 36.7 KB
/
namespace_hardware.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Plant Watering Sensor: Hardware Namespace Reference</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="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<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 id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">Plant Watering Sensor
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('namespace_hardware.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="summary">
<a href="#enum-members">Enumerations</a> |
<a href="#func-members">Functions</a> </div>
<div class="headertitle">
<div class="title">Hardware Namespace Reference</div> </div>
</div><!--header-->
<div class="contents">
<p>This module is the interface to the <a class="el" href="namespace_hardware.html" title="This module is the interface to the Hardware via GPIO, ADC and Counter. ">Hardware</a> via GPIO, ADC and Counter.
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="enum-members"></a>
Enumerations</h2></td></tr>
<tr class="memitem:acc409c97181a985b78dd4881c8656848"><td class="memItemLeft" align="right" valign="top">enum  </td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_hardware.html#acc409c97181a985b78dd4881c8656848">LedState</a> : uint8_t { <a class="el" href="namespace_hardware.html#acc409c97181a985b78dd4881c8656848ad4f123e7f67cd625e2a3422d21001441">LED_Off</a> = 0x00u,
<a class="el" href="namespace_hardware.html#acc409c97181a985b78dd4881c8656848ae479ae184faf3012957bffb6cfe780b1">LED_Green</a> = 0x01u,
<a class="el" href="namespace_hardware.html#acc409c97181a985b78dd4881c8656848a68aa56446e2947fe770776a6bbc81af9">LED_Red</a> = 0x02u
}<tr class="memdesc:acc409c97181a985b78dd4881c8656848"><td class="mdescLeft"> </td><td class="mdescRight">The state of the current display (LED). <a href="namespace_hardware.html#acc409c97181a985b78dd4881c8656848">More...</a><br /></td></tr>
</td></tr>
<tr class="separator:acc409c97181a985b78dd4881c8656848"><td class="memSeparator" colspan="2"> </td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a1911f7db5cd655f8537610e261cad1a8"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_hardware.html#a1911f7db5cd655f8537610e261cad1a8">setup</a> ()</td></tr>
<tr class="memdesc:a1911f7db5cd655f8537610e261cad1a8"><td class="mdescLeft"> </td><td class="mdescRight">Setup the MCU hardware to the initial values. <a href="#a1911f7db5cd655f8537610e261cad1a8">More...</a><br /></td></tr>
<tr class="separator:a1911f7db5cd655f8537610e261cad1a8"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a4bf62531670f7ce338200505ebfed3db"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_hardware.html#a4bf62531670f7ce338200505ebfed3db">setLedState</a> (<a class="el" href="namespace_hardware.html#acc409c97181a985b78dd4881c8656848">LedState</a> ledState)</td></tr>
<tr class="memdesc:a4bf62531670f7ce338200505ebfed3db"><td class="mdescLeft"> </td><td class="mdescRight">Enable or disable the status LEDs. <a href="#a4bf62531670f7ce338200505ebfed3db">More...</a><br /></td></tr>
<tr class="separator:a4bf62531670f7ce338200505ebfed3db"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a525ddf756e4b9f63b866907b2f9088fa"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_hardware.html#a525ddf756e4b9f63b866907b2f9088fa">sendDoneSignal</a> ()</td></tr>
<tr class="memdesc:a525ddf756e4b9f63b866907b2f9088fa"><td class="mdescLeft"> </td><td class="mdescRight">Send the done signal. <a href="#a525ddf756e4b9f63b866907b2f9088fa">More...</a><br /></td></tr>
<tr class="separator:a525ddf756e4b9f63b866907b2f9088fa"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ac3cdea93de8ebd6a0216dbfc35ce2ee6"><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_hardware.html#ac3cdea93de8ebd6a0216dbfc35ce2ee6">isButtonPressed</a> ()</td></tr>
<tr class="memdesc:ac3cdea93de8ebd6a0216dbfc35ce2ee6"><td class="mdescLeft"> </td><td class="mdescRight">Get the status of the button. <a href="#ac3cdea93de8ebd6a0216dbfc35ce2ee6">More...</a><br /></td></tr>
<tr class="separator:ac3cdea93de8ebd6a0216dbfc35ce2ee6"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a03469c3c4aa1b9abfe64e1a148c0801c"><td class="memItemLeft" align="right" valign="top">uint16_t </td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_hardware.html#a03469c3c4aa1b9abfe64e1a148c0801c">getVoltageValue</a> ()</td></tr>
<tr class="memdesc:a03469c3c4aa1b9abfe64e1a148c0801c"><td class="mdescLeft"> </td><td class="mdescRight">Read the current voltage value. <a href="#a03469c3c4aa1b9abfe64e1a148c0801c">More...</a><br /></td></tr>
<tr class="separator:a03469c3c4aa1b9abfe64e1a148c0801c"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a8d4a4cffef848027149e4326604fdafa"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_hardware.html#a8d4a4cffef848027149e4326604fdafa">shutdownVoltageMeasurement</a> ()</td></tr>
<tr class="memdesc:a8d4a4cffef848027149e4326604fdafa"><td class="mdescLeft"> </td><td class="mdescRight">Shutdown voltage measurement to save power. <a href="#a8d4a4cffef848027149e4326604fdafa">More...</a><br /></td></tr>
<tr class="separator:a8d4a4cffef848027149e4326604fdafa"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:af22843e53b124a161486dedb9799a40e"><td class="memItemLeft" align="right" valign="top">uint8_t </td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_hardware.html#af22843e53b124a161486dedb9799a40e">getOscillatorFrequency</a> ()</td></tr>
<tr class="memdesc:af22843e53b124a161486dedb9799a40e"><td class="mdescLeft"> </td><td class="mdescRight">Try to determine the frequency. <a href="#af22843e53b124a161486dedb9799a40e">More...</a><br /></td></tr>
<tr class="separator:af22843e53b124a161486dedb9799a40e"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ae7b93d93d3a7c1fdde56d43d16162b61"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_hardware.html#ae7b93d93d3a7c1fdde56d43d16162b61">shutdownOscillatorCounter</a> ()</td></tr>
<tr class="memdesc:ae7b93d93d3a7c1fdde56d43d16162b61"><td class="mdescLeft"> </td><td class="mdescRight">Shutdown the counter to save power. <a href="#ae7b93d93d3a7c1fdde56d43d16162b61">More...</a><br /></td></tr>
<tr class="separator:ae7b93d93d3a7c1fdde56d43d16162b61"><td class="memSeparator" colspan="2"> </td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>This module is the interface to the <a class="el" href="namespace_hardware.html" title="This module is the interface to the Hardware via GPIO, ADC and Counter. ">Hardware</a> via GPIO, ADC and Counter. </p>
</div><h2 class="groupheader">Enumeration Type Documentation</h2>
<a id="acc409c97181a985b78dd4881c8656848"></a>
<h2 class="memtitle"><span class="permalink"><a href="#acc409c97181a985b78dd4881c8656848">◆ </a></span>LedState</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">enum <a class="el" href="namespace_hardware.html#acc409c97181a985b78dd4881c8656848">Hardware::LedState</a> : uint8_t</td>
</tr>
</table>
</div><div class="memdoc">
<p>The state of the current display (LED). </p>
<table class="fieldtable">
<tr><th colspan="2">Enumerator</th></tr><tr><td class="fieldname"><a id="acc409c97181a985b78dd4881c8656848ad4f123e7f67cd625e2a3422d21001441"></a>LED_Off </td><td class="fielddoc"><p>The LED is off. </p>
</td></tr>
<tr><td class="fieldname"><a id="acc409c97181a985b78dd4881c8656848ae479ae184faf3012957bffb6cfe780b1"></a>LED_Green </td><td class="fielddoc"><p>The green LED is on. </p>
</td></tr>
<tr><td class="fieldname"><a id="acc409c97181a985b78dd4881c8656848a68aa56446e2947fe770776a6bbc81af9"></a>LED_Red </td><td class="fielddoc"><p>The red LED is on. </p>
</td></tr>
</table>
<p class="definition">Definition at line <a class="el" href="_hardware_8h_source.html#l00034">34</a> of file <a class="el" href="_hardware_8h_source.html">Hardware.h</a>.</p>
<div class="fragment"><div class="line"><a name="l00034"></a><span class="lineno"> 34</span>  : uint8_t {</div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span>  <a class="code" href="namespace_hardware.html#acc409c97181a985b78dd4881c8656848ad4f123e7f67cd625e2a3422d21001441">LED_Off</a> = 0x00u, </div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span>  <a class="code" href="namespace_hardware.html#acc409c97181a985b78dd4881c8656848ae479ae184faf3012957bffb6cfe780b1">LED_Green</a> = 0x01u, </div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span>  <a class="code" href="namespace_hardware.html#acc409c97181a985b78dd4881c8656848a68aa56446e2947fe770776a6bbc81af9">LED_Red</a> = 0x02u, </div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span> };</div><div class="ttc" id="namespace_hardware_html_acc409c97181a985b78dd4881c8656848ae479ae184faf3012957bffb6cfe780b1"><div class="ttname"><a href="namespace_hardware.html#acc409c97181a985b78dd4881c8656848ae479ae184faf3012957bffb6cfe780b1">Hardware::LED_Green</a></div><div class="ttdoc">The green LED is on. </div><div class="ttdef"><b>Definition:</b> <a href="_hardware_8h_source.html#l00036">Hardware.h:36</a></div></div>
<div class="ttc" id="namespace_hardware_html_acc409c97181a985b78dd4881c8656848ad4f123e7f67cd625e2a3422d21001441"><div class="ttname"><a href="namespace_hardware.html#acc409c97181a985b78dd4881c8656848ad4f123e7f67cd625e2a3422d21001441">Hardware::LED_Off</a></div><div class="ttdoc">The LED is off. </div><div class="ttdef"><b>Definition:</b> <a href="_hardware_8h_source.html#l00035">Hardware.h:35</a></div></div>
<div class="ttc" id="namespace_hardware_html_acc409c97181a985b78dd4881c8656848a68aa56446e2947fe770776a6bbc81af9"><div class="ttname"><a href="namespace_hardware.html#acc409c97181a985b78dd4881c8656848a68aa56446e2947fe770776a6bbc81af9">Hardware::LED_Red</a></div><div class="ttdoc">The red LED is on. </div><div class="ttdef"><b>Definition:</b> <a href="_hardware_8h_source.html#l00037">Hardware.h:37</a></div></div>
</div><!-- fragment -->
</div>
</div>
<h2 class="groupheader">Function Documentation</h2>
<a id="af22843e53b124a161486dedb9799a40e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#af22843e53b124a161486dedb9799a40e">◆ </a></span>getOscillatorFrequency()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">uint8_t Hardware::getOscillatorFrequency </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Try to determine the frequency. </p>
<p>I assume the frequency from the oscillator will be somewhere in a kHz range. The maximum frequency of the oscillator is somewhere around 140kHz the lowest (100% water) around 40kHz. Measuring the number of rising edges for ~1ms should generate a usable value.</p>
<p>If no signal is received, 0x00 is returned. If the counter overflows, 0xff is returned. (This should not happen).</p>
<dl class="section return"><dt>Returns</dt><dd>The approximate oscillator frequency in kHz. </dd></dl>
<p class="definition">Definition at line <a class="el" href="_hardware_8cpp_source.html#l00136">136</a> of file <a class="el" href="_hardware_8cpp_source.html">Hardware.cpp</a>.</p>
<div class="fragment"><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>  <span class="comment">// Select external clock source, T0/Pin 7 to enable the counter.</span></div><div class="line"><a name="l00139"></a><span class="lineno"> 139</span>  TCCR0B = (_BV(CS00)|_BV(CS01)|_BV(CS02));</div><div class="line"><a name="l00140"></a><span class="lineno"> 140</span>  <span class="comment">// Reset the counter.</span></div><div class="line"><a name="l00141"></a><span class="lineno"> 141</span>  TCNT0 = 0;</div><div class="line"><a name="l00142"></a><span class="lineno"> 142</span>  <span class="comment">// Clear the overflow flag.</span></div><div class="line"><a name="l00143"></a><span class="lineno"> 143</span>  TIFR0 = _BV(TOV0);</div><div class="line"><a name="l00144"></a><span class="lineno"> 144</span>  <span class="comment">// Wait ~1ms for the result.</span></div><div class="line"><a name="l00145"></a><span class="lineno"> 145</span>  <a class="code" href="namespace_tool.html#a403edfe54b1b8a2cddae03feac5715aa">Tool::delayMs</a>(1);</div><div class="line"><a name="l00146"></a><span class="lineno"> 146</span>  <span class="comment">// Read the result.</span></div><div class="line"><a name="l00147"></a><span class="lineno"> 147</span>  uint8_t result = TCNT0;</div><div class="line"><a name="l00148"></a><span class="lineno"> 148</span>  <span class="comment">// Check the overflow flag.</span></div><div class="line"><a name="l00149"></a><span class="lineno"> 149</span>  <span class="keywordflow">if</span> ((TIFR0 & _BV(TOV0)) != 0) {</div><div class="line"><a name="l00150"></a><span class="lineno"> 150</span>  result = 0xff;</div><div class="line"><a name="l00151"></a><span class="lineno"> 151</span>  }</div><div class="line"><a name="l00152"></a><span class="lineno"> 152</span>  <span class="keywordflow">return</span> result;</div><div class="line"><a name="l00153"></a><span class="lineno"> 153</span> }</div><div class="ttc" id="namespace_tool_html_a403edfe54b1b8a2cddae03feac5715aa"><div class="ttname"><a href="namespace_tool.html#a403edfe54b1b8a2cddae03feac5715aa">Tool::delayMs</a></div><div class="ttdeci">void delayMs(uint16_t delay)</div><div class="ttdoc">Wait approximate the given number of milliseconds. </div><div class="ttdef"><b>Definition:</b> <a href="_tool_8cpp_source.html#l00031">Tool.cpp:31</a></div></div>
</div><!-- fragment -->
</div>
</div>
<a id="a03469c3c4aa1b9abfe64e1a148c0801c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a03469c3c4aa1b9abfe64e1a148c0801c">◆ </a></span>getVoltageValue()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">uint16_t Hardware::getVoltageValue </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Read the current voltage value. </p>
<dl class="section return"><dt>Returns</dt><dd>The current voltage value. ~23 per 0.1V. </dd></dl>
<p class="definition">Definition at line <a class="el" href="_hardware_8cpp_source.html#l00105">105</a> of file <a class="el" href="_hardware_8cpp_source.html">Hardware.cpp</a>.</p>
<div class="fragment"><div class="line"><a name="l00106"></a><span class="lineno"> 106</span> {</div><div class="line"><a name="l00107"></a><span class="lineno"> 107</span>  <span class="comment">// Collect a number of samples and get the average out of them.</span></div><div class="line"><a name="l00108"></a><span class="lineno"> 108</span>  uint16_t values = 0u;</div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span>  <span class="keyword">const</span> uint8_t sampleCount = 32u;</div><div class="line"><a name="l00110"></a><span class="lineno"> 110</span>  <span class="keywordflow">for</span> (uint8_t i = 0; i < sampleCount; ++i) {</div><div class="line"><a name="l00111"></a><span class="lineno"> 111</span>  <span class="comment">// Start the conversion.</span></div><div class="line"><a name="l00112"></a><span class="lineno"> 112</span>  ADCSRA |= _BV(ADSC);</div><div class="line"><a name="l00113"></a><span class="lineno"> 113</span>  <span class="comment">// Wait for the conversion to finish.</span></div><div class="line"><a name="l00114"></a><span class="lineno"> 114</span>  <span class="keywordflow">while</span> ((ADCSRA & _BV(ADSC)) != 0) {</div><div class="line"><a name="l00115"></a><span class="lineno"> 115</span>  _NOP();</div><div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  }</div><div class="line"><a name="l00117"></a><span class="lineno"> 117</span>  <span class="comment">// Read the value.</span></div><div class="line"><a name="l00118"></a><span class="lineno"> 118</span>  uint16_t value = ADCL;</div><div class="line"><a name="l00119"></a><span class="lineno"> 119</span>  value |= ((uint16_t)(ADCH) << 8);</div><div class="line"><a name="l00120"></a><span class="lineno"> 120</span>  <span class="comment">// Add it up to get the average.</span></div><div class="line"><a name="l00121"></a><span class="lineno"> 121</span>  values += value;</div><div class="line"><a name="l00122"></a><span class="lineno"> 122</span>  }</div><div class="line"><a name="l00123"></a><span class="lineno"> 123</span>  <span class="comment">// Return the average of all samples.</span></div><div class="line"><a name="l00124"></a><span class="lineno"> 124</span>  <span class="keywordflow">return</span> (values / sampleCount);</div><div class="line"><a name="l00125"></a><span class="lineno"> 125</span> }</div></div><!-- fragment -->
</div>
</div>
<a id="ac3cdea93de8ebd6a0216dbfc35ce2ee6"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ac3cdea93de8ebd6a0216dbfc35ce2ee6">◆ </a></span>isButtonPressed()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">bool Hardware::isButtonPressed </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Get the status of the button. </p>
<dl class="section return"><dt>Returns</dt><dd>true if the push button is pressed. </dd></dl>
<p class="definition">Definition at line <a class="el" href="_hardware_8cpp_source.html#l00099">99</a> of file <a class="el" href="_hardware_8cpp_source.html">Hardware.cpp</a>.</p>
<div class="fragment"><div class="line"><a name="l00100"></a><span class="lineno"> 100</span> {</div><div class="line"><a name="l00101"></a><span class="lineno"> 101</span>  <span class="keywordflow">return</span> ((PINB & _BV(PINB3)) != 0);</div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span> }</div></div><!-- fragment -->
</div>
</div>
<a id="a525ddf756e4b9f63b866907b2f9088fa"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a525ddf756e4b9f63b866907b2f9088fa">◆ </a></span>sendDoneSignal()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void Hardware::sendDoneSignal </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Send the done signal. </p>
<p class="definition">Definition at line <a class="el" href="_hardware_8cpp_source.html#l00089">89</a> of file <a class="el" href="_hardware_8cpp_source.html">Hardware.cpp</a>.</p>
<div class="fragment"><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>  <span class="comment">// Just set the done line to high for 10ms.</span></div><div class="line"><a name="l00092"></a><span class="lineno"> 92</span>  PORTB |= _BV(DDB0);</div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span>  <a class="code" href="namespace_tool.html#a403edfe54b1b8a2cddae03feac5715aa">Tool::delayMs</a>(10);</div><div class="line"><a name="l00094"></a><span class="lineno"> 94</span>  PORTB &= ~_BV(DDB0);</div><div class="line"><a name="l00095"></a><span class="lineno"> 95</span>  <a class="code" href="namespace_tool.html#a403edfe54b1b8a2cddae03feac5715aa">Tool::delayMs</a>(100);</div><div class="line"><a name="l00096"></a><span class="lineno"> 96</span> }</div><div class="ttc" id="namespace_tool_html_a403edfe54b1b8a2cddae03feac5715aa"><div class="ttname"><a href="namespace_tool.html#a403edfe54b1b8a2cddae03feac5715aa">Tool::delayMs</a></div><div class="ttdeci">void delayMs(uint16_t delay)</div><div class="ttdoc">Wait approximate the given number of milliseconds. </div><div class="ttdef"><b>Definition:</b> <a href="_tool_8cpp_source.html#l00031">Tool.cpp:31</a></div></div>
</div><!-- fragment -->
</div>
</div>
<a id="a4bf62531670f7ce338200505ebfed3db"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a4bf62531670f7ce338200505ebfed3db">◆ </a></span>setLedState()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void Hardware::setLedState </td>
<td>(</td>
<td class="paramtype"><a class="el" href="namespace_hardware.html#acc409c97181a985b78dd4881c8656848">LedState</a> </td>
<td class="paramname"><em>ledState</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Enable or disable the status LEDs. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">ledState</td><td>The LED state. </td></tr>
</table>
</dd>
</dl>
<p class="definition">Definition at line <a class="el" href="_hardware_8cpp_source.html#l00069">69</a> of file <a class="el" href="_hardware_8cpp_source.html">Hardware.cpp</a>.</p>
<div class="fragment"><div class="line"><a name="l00070"></a><span class="lineno"> 70</span> {</div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span>  <span class="keywordflow">switch</span> (ledState) {</div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span>  <span class="keywordflow">case</span> <a class="code" href="namespace_hardware.html#acc409c97181a985b78dd4881c8656848ad4f123e7f67cd625e2a3422d21001441">LED_Off</a>:</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>  <span class="keywordflow">default</span>: <span class="comment">// Set PB0 to Hi-Z;</span></div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span>  DDRB &= (~_BV(DDB1));</div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  PORTB &= (~_BV(PORTB1));</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span>  <span class="keywordflow">break</span>;</div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span>  <span class="keywordflow">case</span> <a class="code" href="namespace_hardware.html#acc409c97181a985b78dd4881c8656848ae479ae184faf3012957bffb6cfe780b1">LED_Green</a>: <span class="comment">// Set PB0 to HIGH.</span></div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  DDRB |= _BV(DDB1);</div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span>  PORTB |= _BV(PORTB1);</div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span>  <span class="keywordflow">break</span>;</div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span>  <span class="keywordflow">case</span> <a class="code" href="namespace_hardware.html#acc409c97181a985b78dd4881c8656848a68aa56446e2947fe770776a6bbc81af9">LED_Red</a>: <span class="comment">// Set PB0 to LOW.</span></div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span>  DDRB |= _BV(DDB1);</div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span>  PORTB &= (~_BV(PORTB1));</div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span>  <span class="keywordflow">break</span>;</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> }</div><div class="ttc" id="namespace_hardware_html_acc409c97181a985b78dd4881c8656848ae479ae184faf3012957bffb6cfe780b1"><div class="ttname"><a href="namespace_hardware.html#acc409c97181a985b78dd4881c8656848ae479ae184faf3012957bffb6cfe780b1">Hardware::LED_Green</a></div><div class="ttdoc">The green LED is on. </div><div class="ttdef"><b>Definition:</b> <a href="_hardware_8h_source.html#l00036">Hardware.h:36</a></div></div>
<div class="ttc" id="namespace_hardware_html_acc409c97181a985b78dd4881c8656848ad4f123e7f67cd625e2a3422d21001441"><div class="ttname"><a href="namespace_hardware.html#acc409c97181a985b78dd4881c8656848ad4f123e7f67cd625e2a3422d21001441">Hardware::LED_Off</a></div><div class="ttdoc">The LED is off. </div><div class="ttdef"><b>Definition:</b> <a href="_hardware_8h_source.html#l00035">Hardware.h:35</a></div></div>
<div class="ttc" id="namespace_hardware_html_acc409c97181a985b78dd4881c8656848a68aa56446e2947fe770776a6bbc81af9"><div class="ttname"><a href="namespace_hardware.html#acc409c97181a985b78dd4881c8656848a68aa56446e2947fe770776a6bbc81af9">Hardware::LED_Red</a></div><div class="ttdoc">The red LED is on. </div><div class="ttdef"><b>Definition:</b> <a href="_hardware_8h_source.html#l00037">Hardware.h:37</a></div></div>
</div><!-- fragment -->
</div>
</div>
<a id="a1911f7db5cd655f8537610e261cad1a8"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a1911f7db5cd655f8537610e261cad1a8">◆ </a></span>setup()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void Hardware::setup </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Setup the MCU hardware to the initial values. </p>
<p class="definition">Definition at line <a class="el" href="_hardware_8cpp_source.html#l00035">35</a> of file <a class="el" href="_hardware_8cpp_source.html">Hardware.cpp</a>.</p>
<div class="fragment"><div class="line"><a name="l00036"></a><span class="lineno"> 36</span> {</div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span>  <span class="comment">// Set the pre-scaler frequency to 2.4MHz.</span></div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span>  CLKPR = _BV(CLKPCE); <span class="comment">// First set the CE bit.</span></div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span>  CLKPR = _BV(CLKPS1); <span class="comment">// ...then set the clock frequency.</span></div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span>  </div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span>  <span class="comment">// Setup PORTB:</span></div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span>  <span class="comment">// - PB0/Pin 5 as output (done signal).</span></div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span>  <span class="comment">// - PB1/Pin 6 keep tristate Hi-Z for the display (LED).</span></div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span>  <span class="comment">// - PB2/Pin 7 as input (oscillator) used for counter.</span></div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span>  <span class="comment">// - PB3/Pin 2 as input (button).</span></div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span>  DDRB = _BV(DDB0);</div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span>  <span class="comment">// Make sure all outputs are low.</span></div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span>  PORTB = 0;</div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span>  </div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span>  <span class="comment">// Setup the ADC for PB4/Pin 3</span></div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span>  <span class="comment">// - Use the internal 1.1V source.</span></div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>  <span class="comment">// - Left align the result.</span></div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span>  <span class="comment">// - Use PB4/Pin 3 as input.</span></div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span>  ADMUX = (_BV(REFS0)|_BV(MUX1));</div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span>  <span class="comment">// - Enable the ADC (to allow enough time to stabilize)</span></div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>  <span class="comment">// - Prescaler to 128, to get 75kHz which should be get an accurate result.</span></div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>  ADCSRA = (_BV(ADEN)|_BV(ADPS2)|_BV(ADPS1)|_BV(ADPS0));</div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span>  <span class="comment">// - Disable the digital in on for PB0, PB1, PB4 to reduce power usage.</span></div><div class="line"><a name="l00059"></a><span class="lineno"> 59</span>  DIDR0 = (_BV(AIN0D)|_BV(AIN1D)|_BV(ADC2D));</div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span>  </div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span>  <span class="comment">// Setup the counter.</span></div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  <span class="comment">// - no compare match, no PWM, no compare output.</span></div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span>  TCCR0A = 0;</div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span>  <span class="comment">// - No Interrupt</span></div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>  TIMSK0 = 0;</div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span> }</div></div><!-- fragment -->
</div>
</div>
<a id="ae7b93d93d3a7c1fdde56d43d16162b61"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae7b93d93d3a7c1fdde56d43d16162b61">◆ </a></span>shutdownOscillatorCounter()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void Hardware::shutdownOscillatorCounter </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Shutdown the counter to save power. </p>
<p>After calling this method, the <a class="el" href="namespace_hardware.html#af22843e53b124a161486dedb9799a40e" title="Try to determine the frequency. ">getOscillatorFrequency()</a> call will not work anymore. </p>
<p class="definition">Definition at line <a class="el" href="_hardware_8cpp_source.html#l00156">156</a> of file <a class="el" href="_hardware_8cpp_source.html">Hardware.cpp</a>.</p>
<div class="fragment"><div class="line"><a name="l00157"></a><span class="lineno"> 157</span> {</div><div class="line"><a name="l00158"></a><span class="lineno"> 158</span>  <span class="comment">// Stop the counter and shutdown the module to save power.</span></div><div class="line"><a name="l00159"></a><span class="lineno"> 159</span>  TCCR0B = 0;</div><div class="line"><a name="l00160"></a><span class="lineno"> 160</span>  PRR |= _BV(PRTIM0);</div><div class="line"><a name="l00161"></a><span class="lineno"> 161</span> }</div></div><!-- fragment -->
</div>
</div>
<a id="a8d4a4cffef848027149e4326604fdafa"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a8d4a4cffef848027149e4326604fdafa">◆ </a></span>shutdownVoltageMeasurement()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void Hardware::shutdownVoltageMeasurement </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Shutdown voltage measurement to save power. </p>
<p class="definition">Definition at line <a class="el" href="_hardware_8cpp_source.html#l00128">128</a> of file <a class="el" href="_hardware_8cpp_source.html">Hardware.cpp</a>.</p>
<div class="fragment"><div class="line"><a name="l00129"></a><span class="lineno"> 129</span> {</div><div class="line"><a name="l00130"></a><span class="lineno"> 130</span>  <span class="comment">// Disable the ADC to save power.</span></div><div class="line"><a name="l00131"></a><span class="lineno"> 131</span>  ADCSRA &= ~_BV(ADEN); <span class="comment">// Disable the ADC</span></div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span>  PRR |= _BV(PRADC); <span class="comment">// Shutdown the ADC to save power.</span></div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span> }</div></div><!-- fragment -->
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="namespace_hardware.html">Hardware</a></li>
<li class="footer">Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.13 </li>
</ul>
</div>
</body>
</html>