11/* !
2- * @file WipperSnapper_I2C_Driver_ENS160 .h
2+ * @file WipperSnapper_I2C_Driver_ENS16X .h
33 *
4- * Device driver for a ENS160 MOX Gas Sensor.
4+ * Device driver for a ENS160/ENS161 MOX Gas Sensor.
55 *
66 * Adafruit invests time and resources providing this open source code,
77 * please support Adafruit and open-source hardware by purchasing
1313 *
1414 */
1515
16- #ifndef WipperSnapper_I2C_Driver_ENS160_H
17- #define WipperSnapper_I2C_Driver_ENS160_H
16+ #ifndef WipperSnapper_I2C_Driver_ENS16X_H
17+ #define WipperSnapper_I2C_Driver_ENS16X_H
1818
1919#include " WipperSnapper_I2C_Driver.h"
2020#include < ScioSense_ENS160.h>
2323
2424/* *************************************************************************/
2525/* !
26- @brief Class that provides a sensor driver for the ENS160 temperature
27- and humidity sensor .
26+ @brief Class that provides a sensor driver for the ENS16x temperature
27+ and humidity sensors .
2828*/
2929/* *************************************************************************/
30- class WipperSnapper_I2C_Driver_ENS160 : public WipperSnapper_I2C_Driver {
30+ class WipperSnapper_I2C_Driver_ENS16x : public WipperSnapper_I2C_Driver {
3131
3232public:
3333 /* ******************************************************************************/
3434 /* !
35- @brief Constructor for an ENS160 sensor.
35+ @brief Constructor for an ENS16x sensor.
3636 @param i2c
3737 The I2C interface.
3838 @param sensorAddress
3939 7-bit device address.
4040 */
4141 /* ******************************************************************************/
42- WipperSnapper_I2C_Driver_ENS160 (TwoWire *i2c, uint16_t sensorAddress)
42+ WipperSnapper_I2C_Driver_ENS16x (TwoWire *i2c, uint16_t sensorAddress)
4343 : WipperSnapper_I2C_Driver(i2c, sensorAddress) {
4444 _i2c = i2c;
4545 _sensorAddress = sensorAddress;
4646 }
4747
4848 /* ******************************************************************************/
4949 /* !
50- @brief Destructor for an ENS160 sensor.
50+ @brief Destructor for an ENS16x sensor.
5151 */
5252 /* ******************************************************************************/
53- ~WipperSnapper_I2C_Driver_ENS160 () { delete _ens160 ; }
53+ ~WipperSnapper_I2C_Driver_ENS16x () { delete _ens16x ; }
5454
5555 /* ******************************************************************************/
5656 /* !
57- @brief Initializes the ENS160 sensor and begins I2C.
57+ @brief Initializes the ENS16x sensor and begins I2C.
5858 @returns True if initialized successfully, False otherwise.
5959 */
6060 /* ******************************************************************************/
6161 bool begin () {
62- _ens160 = new ScioSense_ENS160 ((TwoWire *)_i2c, (uint8_t )_sensorAddress);
62+ _ens16x = new ScioSense_ENS160 ((TwoWire *)_i2c, (uint8_t )_sensorAddress);
6363
64- // attempt to initialize ENS160
65- if (!_ens160 ->begin ())
64+ // attempt to initialize ENS16x, verify chip id
65+ if (!_ens16x ->begin () || !_ens16x-> available ())
6666 return false ;
6767
68- // Set the mode to standard
69- return _ens160->setMode (ENS160_OPMODE_STD);
68+ /* In future set the mode to ulp for 161 (need to add to adafruit lib), see
69+ * https://github.com/sciosense/ens16x-arduino/blob/d09d25dd0912b729a21366e58b55393a49afc256/src/lib/ens16x/ScioSense_Ens161.h#L10-L22
70+ * _ens16x->revENS16x() == 0 ? ENS160_OPMODE_STD : ENS160_OPMODE_LP/ULP
71+ */
72+ return _ens16x->setMode (ENS160_OPMODE_STD);
7073 }
7174
7275 /* ******************************************************************************/
@@ -76,12 +79,12 @@ class WipperSnapper_I2C_Driver_ENS160 : public WipperSnapper_I2C_Driver {
7679 */
7780 /* ******************************************************************************/
7881 bool ensPerformReading () {
79- return _ens160 ->available () && _ens160 ->measure (true );
82+ return _ens16x ->available () && _ens16x ->measure (true );
8083 }
8184
8285 /* ******************************************************************************/
8386 /* !
84- @brief Reads the ENS160 's eCO2 sensor into an event.
87+ @brief Reads the ENS16x 's eCO2 sensor into an event.
8588 @param eco2Event
8689 Pointer to an adafruit sensor event.
8790 @returns True if the sensor event was obtained successfully, False
@@ -91,13 +94,13 @@ class WipperSnapper_I2C_Driver_ENS160 : public WipperSnapper_I2C_Driver {
9194 bool getEventECO2 (sensors_event_t *eco2Event) {
9295 if (!ensPerformReading ())
9396 return false ;
94- eco2Event->eCO2 = (float )_ens160 ->geteCO2 ();
97+ eco2Event->eCO2 = (float )_ens16x ->geteCO2 ();
9598 return true ;
9699 }
97100
98101 /* ******************************************************************************/
99102 /* !
100- @brief Reads the ENS160 's TVOC sensor into an event.
103+ @brief Reads the ENS16x 's TVOC sensor into an event.
101104 @param tvocEvent
102105 Pointer to an adafruit sensor event.
103106 @returns True if the sensor event was obtained successfully, False
@@ -107,13 +110,13 @@ class WipperSnapper_I2C_Driver_ENS160 : public WipperSnapper_I2C_Driver {
107110 bool getEventTVOC (sensors_event_t *tvocEvent) {
108111 if (!ensPerformReading ())
109112 return false ;
110- tvocEvent->tvoc = (float )_ens160 ->getTVOC ();
113+ tvocEvent->tvoc = (float )_ens16x ->getTVOC ();
111114 return true ;
112115 }
113116
114117 /* ******************************************************************************/
115118 /* !
116- @brief Reads the ENS160 's AQI value into an event.
119+ @brief Reads the ENS16x 's AQI value into an event.
117120 @param rawEvent
118121 Pointer to an adafruit sensor event.
119122 @returns True if the sensor event was obtained successfully, False
@@ -123,12 +126,12 @@ class WipperSnapper_I2C_Driver_ENS160 : public WipperSnapper_I2C_Driver {
123126 bool getEventRaw (sensors_event_t *rawEvent) {
124127 if (!ensPerformReading ())
125128 return false ;
126- rawEvent->data [0 ] = (float )_ens160 ->getAQI ();
129+ rawEvent->data [0 ] = (float )_ens16x ->getAQI ();
127130 return true ;
128131 }
129132
130133protected:
131- ScioSense_ENS160 *_ens160 ; // /< ENS160 object
134+ ScioSense_ENS160 *_ens16x ; // /< ENS16x object
132135};
133136
134- #endif // WipperSnapper_I2C_Driver_ENS160
137+ #endif // WipperSnapper_I2C_Driver_ENS16X_H
0 commit comments