Skip to content

Commit 338d38f

Browse files
committed
add(component): ENS161 support, mention low power option
1 parent e52f1db commit 338d38f

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/components/i2c/WipperSnapper_I2C.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
350350
_ds2484->configureDriver(msgDeviceInitReq);
351351
drivers.push_back(_ds2484);
352352
WS_DEBUG_PRINTLN("DS2484 Initialized Successfully!");
353-
} else if (strcmp("ens160", msgDeviceInitReq->i2c_device_name) == 0) {
353+
} else if ((strcmp("ens160", msgDeviceInitReq->i2c_device_name) == 0) ||
354+
(strcmp("ens161", msgDeviceInitReq->i2c_device_name) == 0)) {
354355
_ens160 = new WipperSnapper_I2C_Driver_ENS160(this->_i2c, i2cAddress);
355356
if (!_ens160->begin()) {
356357
WS_DEBUG_PRINTLN("ERROR: Failed to initialize ENS160!");

src/components/i2c/drivers/WipperSnapper_I2C_Driver_ENS160.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

130133
protected:
131-
ScioSense_ENS160 *_ens160; ///< ENS160 object
134+
ScioSense_ENS160 *_ens16x; ///< ENS160/1 object
132135
};
133136

134137
#endif // WipperSnapper_I2C_Driver_ENS160

0 commit comments

Comments
 (0)