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