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

Method readHumidity

libraries/SHT2x/SHT2x.cpp:199–229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197
198
199bool SHT2x::readHumidity()
200{
201 uint8_t buffer[3];
202
203 if (readBytes(3, (uint8_t*) &buffer[0], 30) == false)
204 {
205 return false;
206 }
207 if (crc8(buffer, 2) != buffer[2])
208 {
209 _error = SHT2x_ERR_CRC_HUM;
210 // return false; // do not fail yet
211 }
212 _rawHumidity = buffer[0] << 8;
213 _rawHumidity += buffer[1];
214 _rawHumidity &= 0xFFFC; // TODO is this mask OK? as humidity is max 12 bit..
215
216 // clear requestType
217 _requestType = SHT2x_REQ_NONE;
218
219 _status = buffer[1] & 0x0003;
220 if (_status == 0xFF) // TODO != 0x02 (need HW to test)
221 {
222 _error = SHT2x_ERR_READBYTES;
223 return false;
224 }
225
226 _error = SHT2x_OK;
227 _lastRead = millis();
228 return true;
229}
230
231
232uint32_t SHT2x::lastRequest()

Callers

nothing calls this directly

Calls 1

crc8Function · 0.85

Tested by

no test coverage detected