1-Wire and ENS210 driver stack
ENS210_Result.hpp
Go to the documentation of this file.
1 /**
2  * @file ENS210_Result.hpp
3  * @brief ENS210 measurement-result types and conversion helpers.
4  *
5  * @par References
6  * Vendor-provided Arduino driver:
7  * https://github.com/sciosense/ENS210_driver (2020-04-06, v3).
8  *
9  * @par Update history
10  * - 27-October-2023 Dave Nadler Initial version.
11  */
12 
13 #ifndef ENS210_RESULT_HPP_INCLUDED
14 #define ENS210_RESULT_HPP_INCLUDED
15 
16 #include <stdint.h>
17 #include <cmath> // pow
18 
19 /// Measurement result from ENS210
21  enum ENS210_Result_status_T : uint8_t {
22  Status_NA = 0, ///< nothing here yet...
23  Status_OK = 1, ///< The value was read, the CRC matches, and data is valid.
24  Status_Invalid = 2, ///< The value was read, the CRC matches, but the data is invalid (e.g. the measurement was not yet finished).
25  Status_CRC_error = 3, ///< The value was read, but the CRC over the payload (valid and data) does not match.
26  Status_I2C_error = 4, ///< There was an I2C communication error attempting to read the value.
27  };
29  // Note: raw values have been stripped of checksum; just the interesting 16-bit data here.
30  uint16_t rawTemperature; ///< temperature in 1/64 Kelvin, corrected for solder offset
31  uint16_t rawHumidity; ///< relative humidity in 1/512%RH (ie a value of 51200 means 100% relative humidity)
32  ENS210_Result_T() : status(Status_NA), rawTemperature(0), rawHumidity(0) {};
33  float TempKelvin() const; // Convert to Kelvin
34  int TempKelvinx10() const { return (10*((unsigned int)rawTemperature))/64; };
35  float TempCelsius() const; // Convert to Celsius
36  int TempCelsiusX10() const { return TempKelvinx10() - (int)(273.15*10); };
37  float TempFahrenheit() const; // Convert to Fahrenheit
38  int TempFahrenheitx10() const;// Convert to Fahrenheit times 10, integer
39  float HumidityPercent() const; ///< Fetch relative humidity 0% to 100.0%
40  int HumidityPercentX10() const { return (10*((int)rawHumidity))/512; }; ///< Fetch relative humidity % x10, ie 395 means 39.5% relative humidity
41  float AbsoluteHumidityPercent() const; // Convert to %aH
42  void DiagPrintf() const;
43 };
44 
45 #endif /* ENS210_RESULT_HPP_INCLUDED */
float AbsoluteHumidityPercent() const
Fetch relative humidity % x10, ie 395 means 39.5% relative humidity.
Measurement result from ENS210.
uint16_t rawHumidity
relative humidity in 1/512RH (ie a value of 51200 means 100% relative humidity)
float HumidityPercent() const
Fetch relative humidity 0% to 100.0%.
The value was read, the CRC matches, and data is valid.
There was an I2C communication error attempting to read the value.
The value was read, the CRC matches, but the data is invalid (e.g. the measurement was not yet finish...
uint16_t rawTemperature
temperature in 1/64 Kelvin, corrected for solder offset
nothing here yet...
The value was read, but the CRC over the payload (valid and data) does not match. ...