@@ -50,7 +50,7 @@ class WipperSnapper_I2C_Driver_ENS160 : public WipperSnapper_I2C_Driver {
5050 @brief Destructor for an ENS160 sensor.
5151 */
5252 /* ******************************************************************************/
53- ~WipperSnapper_I2C_Driver_ENS160 () { delete _ens160 ; }
53+ ~WipperSnapper_I2C_Driver_ENS160 () { delete _ens16x ; }
5454
5555 /* ******************************************************************************/
5656 /* !
@@ -59,14 +59,17 @@ class WipperSnapper_I2C_Driver_ENS160 : public WipperSnapper_I2C_Driver {
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,7 +79,7 @@ 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 /* ******************************************************************************/
@@ -91,7 +94,7 @@ 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
@@ -107,7 +110,7 @@ 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
@@ -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 ; // /< ENS160/1 object
132135};
133136
134137#endif // WipperSnapper_I2C_Driver_ENS160
0 commit comments