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

Method read

libraries/DHT2pin/dht2pin.cpp:65–91  ·  view source on GitHub ↗

return values: DHTLIB_OK DHTLIB_ERROR_CHECKSUM DHTLIB_ERROR_TIMEOUT

Source from the content-addressed store, hash-verified

63// DHTLIB_ERROR_CHECKSUM
64// DHTLIB_ERROR_TIMEOUT
65int DHT2pin::read()
66{
67 // READ VALUES
68 int rv = _readSensor(DHTLIB_DHT_WAKEUP);
69 if (rv != DHTLIB_OK)
70 {
71 _humidity = DHTLIB_INVALID_VALUE;
72 _temperature = DHTLIB_INVALID_VALUE;
73 return rv; // propagate error value
74 }
75
76 // CONVERT AND STORE
77 _humidity = word(_bits[0], _bits[1]) * 0.1;
78 _temperature = word(_bits[2] & 0x7F, _bits[3]) * 0.1;
79 if (_bits[2] & 0x80) // negative _temperature
80 {
81 _temperature = -_temperature;
82 }
83
84 // TEST CHECKSUM
85 uint8_t sum = _bits[0] + _bits[1] + _bits[2] + _bits[3];
86 if (_bits[4] != sum)
87 {
88 return DHTLIB_ERROR_CHECKSUM;
89 }
90 return DHTLIB_OK;
91}
92
93
94float DHT2pin::temperature()

Callers 1

unittestFunction · 0.45

Calls

no outgoing calls

Tested by 1

unittestFunction · 0.36