MCPcopy Create free account
hub / github.com/RobTillaart/Arduino / read

Method read

libraries/DHTstable/DHTStable.cpp:108–142  ·  view source on GitHub ↗

return values: DHTLIB_OK DHTLIB_ERROR_CHECKSUM DHTLIB_ERROR_TIMEOUT

Source from the content-addressed store, hash-verified

106// DHTLIB_ERROR_CHECKSUM
107// DHTLIB_ERROR_TIMEOUT
108int DHTStable::read(uint8_t pin)
109{
110 // READ VALUES
111 if (_disableIRQ) noInterrupts();
112 int rv = _readSensor(pin, DHTLIB_DHT_WAKEUP);
113 if (_disableIRQ) interrupts();
114 if (rv != DHTLIB_OK)
115 {
116 _humidity = DHTLIB_INVALID_VALUE; // NaN preferred?
117 _temperature = DHTLIB_INVALID_VALUE; // NaN preferred?
118 return rv; // propagate error value
119 }
120 // CONVERT AND STORE
121 _humidity = word(_bits[0], _bits[1]) * 0.1;
122 int16_t t = ((_bits[2] & 0x7F) * 256 + _bits[3]);
123 if (t == 0)
124 {
125 _temperature = 0.0; // prevent -0.0;
126 }
127 else
128 {
129 _temperature = t * 0.1;
130 if((_bits[2] & 0x80) == 0x80 )
131 {
132 _temperature = -_temperature;
133 }
134 }
135 // TEST CHECKSUM
136 uint8_t sum = _bits[0] + _bits[1] + _bits[2] + _bits[3];
137 if (_bits[4] != sum)
138 {
139 return DHTLIB_ERROR_CHECKSUM;
140 }
141 return DHTLIB_OK;
142}
143
144
145/////////////////////////////////////////////////////

Callers 1

unittestFunction · 0.45

Calls

no outgoing calls

Tested by 1

unittestFunction · 0.36