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

Method read

libraries/AM232X/AM232X.cpp:72–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70
71
72int AM232X::read()
73{
74 if (millis() - _lastRead < _readDelay)
75 {
76 return AM232X_READ_TOO_FAST;
77 }
78 _lastRead = millis();
79
80 // READ HUMIDITY AND TEMPERATURE REGISTERS
81 int rv = _readRegister(0x00, 4);
82 if (rv < 0) return rv;
83
84 if (rv != AM232X_OK)
85 {
86 if (_suppressError == false)
87 {
88 _humidity = AM232X_INVALID_VALUE;
89 _temperature = AM232X_INVALID_VALUE;
90 }
91 return rv; // propagate error value
92 }
93
94 // EXTRACT HUMIDITY AND TEMPERATURE
95 _humidity = (_bits[2] * 256 + _bits[3]) * 0.1;
96 int16_t t = ((_bits[4] & 0x7F) * 256 + _bits[5]);
97 if (t == 0)
98 {
99 _temperature = 0.0; // prevent -0.0;
100 }
101 else
102 {
103 _temperature = t * 0.1;
104 if ((_bits[4] & 0x80) == 0x80 )
105 {
106 _temperature = -_temperature;
107 }
108 }
109
110#ifdef AM232X_VALUE_OUT_OF_RANGE
111 // TEST OUT OF RANGE
112 if (_humidity > 100)
113 {
114 return AM232X_HUMIDITY_OUT_OF_RANGE;
115 }
116 if ((_temperature < -40) || (_temperature > 80))
117 {
118 return AM232X_TEMPERATURE_OUT_OF_RANGE;
119 }
120#endif
121
122 return AM232X_OK;
123}
124
125
126float AM232X::getHumidity()

Callers 2

beginMethod · 0.95
_getDataMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected