DHT-sensor-library/html/_d_h_t_8h_source.html
2020-09-08 20:38:54 +00:00

84 lines
18 KiB
HTML

<!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>DHT sensor library: DHT.h 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/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">DHT sensor library
</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 -->
<!-- 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="headertitle">
<div class="title">DHT.h</div> </div>
</div><!--header-->
<div class="contents">
<a href="_d_h_t_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;</div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span>&#160;<span class="preprocessor">#ifndef DHT_H</span></div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span>&#160;<span class="preprocessor">#define DHT_H</span></div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span>&#160;</div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span>&#160;<span class="preprocessor">#include &quot;Arduino.h&quot;</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="comment">/* Uncomment to enable printing out nice debug messages. */</span></div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span>&#160;<span class="comment">//#define DHT_DEBUG</span></div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span>&#160;</div><div class="line"><a name="l00026"></a><span class="lineno"><a class="line" href="_d_h_t_8h.html#afe84d42042833e4e334c977b93ff2407"> 26</a></span>&#160;<span class="preprocessor">#define DEBUG_PRINTER \</span></div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span>&#160;<span class="preprocessor"> Serial </span></div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span>&#160;<span class="preprocessor"></span><span class="comment">/* Setup debug printing macros. */</span><span class="preprocessor"></span></div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span>&#160;<span class="preprocessor">#ifdef DHT_DEBUG</span></div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span>&#160;<span class="preprocessor">#define DEBUG_PRINT(...) \</span></div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span>&#160;<span class="preprocessor"> { DEBUG_PRINTER.print(__VA_ARGS__); }</span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span>&#160;<span class="preprocessor">#define DEBUG_PRINTLN(...) \</span></div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span>&#160;<span class="preprocessor"> { DEBUG_PRINTER.println(__VA_ARGS__); }</span></div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span>&#160;<span class="preprocessor">#else</span></div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span>&#160;<span class="preprocessor">#define DEBUG_PRINT(...) \</span></div><div class="line"><a name="l00038"></a><span class="lineno"><a class="line" href="_d_h_t_8h.html#a88edd2aa4feabff4af21a997d5d8aa23"> 38</a></span>&#160;<span class="preprocessor"> {} </span></div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span>&#160;<span class="preprocessor">#define DEBUG_PRINTLN(...) \</span></div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span>&#160;<span class="preprocessor"> {} </span></div><div class="line"><a name="l00041"></a><span class="lineno"><a class="line" href="_d_h_t_8h.html#ae414eccb9fbdc7c0cc6edfc588a3aa34"> 41</a></span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span>&#160;</div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span>&#160;<span class="comment">/* Define types of sensors. */</span></div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span>&#160;<span class="preprocessor">#define DHT11 11 </span></div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span>&#160;<span class="preprocessor">#define DHT12 12 </span></div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span>&#160;<span class="preprocessor">#define DHT22 22 </span></div><div class="line"><a name="l00047"></a><span class="lineno"><a class="line" href="_d_h_t_8h.html#ac7ca444ad6788a4e3686a83bc036efb6"> 47</a></span>&#160;<span class="preprocessor">#define DHT21 21 </span></div><div class="line"><a name="l00048"></a><span class="lineno"><a class="line" href="_d_h_t_8h.html#a1574ee8a0bebaff3165f634e2717d4e7"> 48</a></span>&#160;<span class="preprocessor">#define AM2301 21 </span></div><div class="line"><a name="l00050"></a><span class="lineno"><a class="line" href="_d_h_t_8h.html#af718013a29c2115b00d7c77d2f28084b"> 50</a></span>&#160;<span class="preprocessor">#if (TARGET_NAME == ARDUINO_NANO33BLE)</span></div><div class="line"><a name="l00051"></a><span class="lineno"><a class="line" href="_d_h_t_8h.html#a3de32b1bf162072c5e2d695bea5bb296"> 51</a></span>&#160;<span class="preprocessor">#ifndef microsecondsToClockCycles</span></div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>&#160;</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>&#160;<span class="preprocessor">#define microsecondsToClockCycles(a) ((a) * (SystemCoreClock / 1000000L))</span></div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00059"></a><span class="lineno"><a class="line" href="_d_h_t_8h.html#aa4a5bbc71d71ab25856c1366b6ca15bb"> 59</a></span>&#160;</div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span>&#160;<span class="keyword">class </span><a class="code" href="class_d_h_t.html">DHT</a> {</div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span>&#160;<span class="keyword">public</span>:</div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>&#160; <a class="code" href="class_d_h_t.html#afa429167bfeba848ab824fee0043f79d">DHT</a>(uint8_t pin, uint8_t type, uint8_t count = 6);</div><div class="line"><a name="l00066"></a><span class="lineno"><a class="line" href="class_d_h_t.html"> 66</a></span>&#160; <span class="keywordtype">void</span> <a class="code" href="class_d_h_t.html#a5fea0c753872b62f0ea423b03b6a0ac0">begin</a>(uint8_t usec = 55);</div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span>&#160; <span class="keywordtype">float</span> <a class="code" href="class_d_h_t.html#a68be09105aa7d831bb473c9d774918cf">readTemperature</a>(<span class="keywordtype">bool</span> S = <span class="keyword">false</span>, <span class="keywordtype">bool</span> force = <span class="keyword">false</span>);</div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>&#160; <span class="keywordtype">float</span> <a class="code" href="class_d_h_t.html#a582df4d39cd56b4acbd47fbe75aedcc3">convertCtoF</a>(<span class="keywordtype">float</span>);</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span>&#160; <span class="keywordtype">float</span> <a class="code" href="class_d_h_t.html#a90530e38a2f47893e4767dda1d00d2a4">convertFtoC</a>(<span class="keywordtype">float</span>);</div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span>&#160; <span class="keywordtype">float</span> <a class="code" href="class_d_h_t.html#a47724a419777972edf68cd5b8aa85569">computeHeatIndex</a>(<span class="keywordtype">bool</span> isFahrenheit = <span class="keyword">true</span>);</div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span>&#160; <span class="keywordtype">float</span> <a class="code" href="class_d_h_t.html#a47724a419777972edf68cd5b8aa85569">computeHeatIndex</a>(<span class="keywordtype">float</span> temperature, <span class="keywordtype">float</span> percentHumidity,</div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span>&#160; <span class="keywordtype">bool</span> isFahrenheit = <span class="keyword">true</span>);</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>&#160; <span class="keywordtype">float</span> <a class="code" href="class_d_h_t.html#a5f8c84378abe4eeecf34f09e2cdf90a0">readHumidity</a>(<span class="keywordtype">bool</span> force = <span class="keyword">false</span>);</div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span>&#160; <span class="keywordtype">bool</span> <a class="code" href="class_d_h_t.html#a4c1508f2997a5d03968b3afdeae70e03">read</a>(<span class="keywordtype">bool</span> force = <span class="keyword">false</span>);</div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>&#160;</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span>&#160;<span class="keyword">private</span>:</div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span>&#160; uint8_t data[5];</div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>&#160; uint8_t _pin, _type;</div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span>&#160;<span class="preprocessor">#ifdef __AVR</span></div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span>&#160; <span class="comment">// Use direct GPIO access on an 8-bit AVR so keep track of the port and</span></div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span>&#160; <span class="comment">// bitmask for the digital pin connected to the DHT. Other platforms will use</span></div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span>&#160; <span class="comment">// digitalRead.</span></div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span>&#160; uint8_t _bit, _port;</div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span>&#160; uint32_t _lastreadtime, _maxcycles;</div><div class="line"><a name="l00086"></a><span class="lineno"> 86</span>&#160; <span class="keywordtype">bool</span> _lastresult;</div><div class="line"><a name="l00087"></a><span class="lineno"> 87</span>&#160; uint8_t pullTime; <span class="comment">// Time (in usec) to pull up data line before reading</span></div><div class="line"><a name="l00088"></a><span class="lineno"> 88</span>&#160;</div><div class="line"><a name="l00089"></a><span class="lineno"> 89</span>&#160; uint32_t expectPulse(<span class="keywordtype">bool</span> level);</div><div class="line"><a name="l00090"></a><span class="lineno"> 90</span>&#160;};</div><div class="line"><a name="l00091"></a><span class="lineno"> 91</span>&#160;</div><div class="line"><a name="l00095"></a><span class="lineno"> 95</span>&#160;<span class="keyword">class </span><a class="code" href="class_interrupt_lock.html">InterruptLock</a> {</div><div class="line"><a name="l00096"></a><span class="lineno"> 96</span>&#160;<span class="keyword">public</span>:</div><div class="line"><a name="l00097"></a><span class="lineno"> 97</span>&#160; <a class="code" href="class_interrupt_lock.html">InterruptLock</a>() {</div><div class="line"><a name="l00098"></a><span class="lineno"><a class="line" href="class_interrupt_lock.html"> 98</a></span>&#160;<span class="preprocessor">#if !defined(ARDUINO_ARCH_NRF52)</span></div><div class="line"><a name="l00099"></a><span class="lineno"> 99</span>&#160; noInterrupts();</div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00101"></a><span class="lineno"> 101</span>&#160; }</div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span>&#160; ~<a class="code" href="class_interrupt_lock.html">InterruptLock</a>() {</div><div class="line"><a name="l00103"></a><span class="lineno"> 103</span>&#160;<span class="preprocessor">#if !defined(ARDUINO_ARCH_NRF52)</span></div><div class="line"><a name="l00104"></a><span class="lineno"> 104</span>&#160; interrupts();</div><div class="line"><a name="l00105"></a><span class="lineno"> 105</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00106"></a><span class="lineno"> 106</span>&#160; }</div><div class="line"><a name="l00107"></a><span class="lineno"> 107</span>&#160;};</div><div class="line"><a name="l00108"></a><span class="lineno"> 108</span>&#160;</div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span>&#160;<span class="preprocessor">#endif</span></div><div class="ttc" id="class_d_h_t_html_a582df4d39cd56b4acbd47fbe75aedcc3"><div class="ttname"><a href="class_d_h_t.html#a582df4d39cd56b4acbd47fbe75aedcc3">DHT::convertCtoF</a></div><div class="ttdeci">float convertCtoF(float)</div><div class="ttdoc">Converts Celcius to Fahrenheit. </div><div class="ttdef"><b>Definition:</b> DHT.cpp:133</div></div>
<div class="ttc" id="class_d_h_t_html_afa429167bfeba848ab824fee0043f79d"><div class="ttname"><a href="class_d_h_t.html#afa429167bfeba848ab824fee0043f79d">DHT::DHT</a></div><div class="ttdeci">DHT(uint8_t pin, uint8_t type, uint8_t count=6)</div><div class="ttdoc">Instantiates a new DHT class. </div><div class="ttdef"><b>Definition:</b> DHT.cpp:43</div></div>
<div class="ttc" id="class_d_h_t_html_a90530e38a2f47893e4767dda1d00d2a4"><div class="ttname"><a href="class_d_h_t.html#a90530e38a2f47893e4767dda1d00d2a4">DHT::convertFtoC</a></div><div class="ttdeci">float convertFtoC(float)</div><div class="ttdoc">Converts Fahrenheit to Celcius. </div><div class="ttdef"><b>Definition:</b> DHT.cpp:141</div></div>
<div class="ttc" id="class_d_h_t_html_a4c1508f2997a5d03968b3afdeae70e03"><div class="ttname"><a href="class_d_h_t.html#a4c1508f2997a5d03968b3afdeae70e03">DHT::read</a></div><div class="ttdeci">bool read(bool force=false)</div><div class="ttdoc">Read value from sensor or return last one from less than two seconds. </div><div class="ttdef"><b>Definition:</b> DHT.cpp:232</div></div>
<div class="ttc" id="class_d_h_t_html_a47724a419777972edf68cd5b8aa85569"><div class="ttname"><a href="class_d_h_t.html#a47724a419777972edf68cd5b8aa85569">DHT::computeHeatIndex</a></div><div class="ttdeci">float computeHeatIndex(bool isFahrenheit=true)</div><div class="ttdoc">Compute Heat Index Simplified version that reads temp and humidity from sensor. </div><div class="ttdef"><b>Definition:</b> DHT.cpp:175</div></div>
<div class="ttc" id="class_d_h_t_html"><div class="ttname"><a href="class_d_h_t.html">DHT</a></div><div class="ttdoc">Class that stores state and functions for DHT. </div><div class="ttdef"><b>Definition:</b> DHT.h:66</div></div>
<div class="ttc" id="class_d_h_t_html_a5fea0c753872b62f0ea423b03b6a0ac0"><div class="ttname"><a href="class_d_h_t.html#a5fea0c753872b62f0ea423b03b6a0ac0">DHT::begin</a></div><div class="ttdeci">void begin(uint8_t usec=55)</div><div class="ttdoc">Setup sensor pins and set pull timings. </div><div class="ttdef"><b>Definition:</b> DHT.cpp:64</div></div>
<div class="ttc" id="class_d_h_t_html_a68be09105aa7d831bb473c9d774918cf"><div class="ttname"><a href="class_d_h_t.html#a68be09105aa7d831bb473c9d774918cf">DHT::readTemperature</a></div><div class="ttdeci">float readTemperature(bool S=false, bool force=false)</div><div class="ttdoc">Read temperature. </div><div class="ttdef"><b>Definition:</b> DHT.cpp:86</div></div>
<div class="ttc" id="class_interrupt_lock_html"><div class="ttname"><a href="class_interrupt_lock.html">InterruptLock</a></div><div class="ttdoc">Class that defines Interrupt Lock Avaiability. </div><div class="ttdef"><b>Definition:</b> DHT.h:98</div></div>
<div class="ttc" id="class_d_h_t_html_a5f8c84378abe4eeecf34f09e2cdf90a0"><div class="ttname"><a href="class_d_h_t.html#a5f8c84378abe4eeecf34f09e2cdf90a0">DHT::readHumidity</a></div><div class="ttdeci">float readHumidity(bool force=false)</div><div class="ttdoc">Read Humidity. </div><div class="ttdef"><b>Definition:</b> DHT.cpp:149</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>