Skip to content

Commit b78c359

Browse files
committed
Fix light sensor not recording to event for TSL2591
1 parent bb31f5e commit b78c359

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

src/components/i2c/controller.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ static const std::map<std::string, FnCreateI2CDriver> I2cFactory = {
6060
const char *driver_name) -> drvBase * {
6161
return new drvBme680(i2c, addr, mux_channel, driver_name);
6262
}},
63+
{"bme688",
64+
[](TwoWire *i2c, uint16_t addr, uint32_t mux_channel,
65+
const char *driver_name) -> drvBase * {
66+
return new drvBme680(i2c, addr, mux_channel, driver_name);
67+
}},
6368
{"BMP280",
6469
[](TwoWire *i2c, uint16_t addr, uint32_t mux_channel,
6570
const char *driver_name) -> drvBase * {
@@ -195,6 +200,11 @@ static const std::map<std::string, FnCreateI2CDriver> I2cFactory = {
195200
const char *driver_name) -> drvBase * {
196201
return new drvScd4x(i2c, addr, mux_channel, driver_name);
197202
}},
203+
{"scd41",
204+
[](TwoWire *i2c, uint16_t addr, uint32_t mux_channel,
205+
const char *driver_name) -> drvBase * {
206+
return new drvScd4x(i2c, addr, mux_channel, driver_name);
207+
}},
198208
{"scd30",
199209
[](TwoWire *i2c, uint16_t addr, uint32_t mux_channel,
200210
const char *driver_name) -> drvBase * {
@@ -470,7 +480,7 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
470480
if (strcmp(device_descriptor.i2c_bus_scl, "default") != 0) {
471481
WS_DEBUG_PRINTLN("[i2c] Non-default I2C bus specified!");
472482
if (_i2c_bus_alt == nullptr) {
473-
WS_DEBUG_PRINT("[i2c] Initializing alternative i2c bus...");
483+
WS_DEBUG_PRINTLN("[i2c] Initializing alternative i2c bus...");
474484
_i2c_bus_alt = new I2cHardware();
475485
_i2c_bus_alt->InitBus(false, device_descriptor.i2c_bus_sda,
476486
device_descriptor.i2c_bus_scl);
@@ -595,6 +605,7 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
595605
WS_DEBUG_PRINTLN("[i2c] ERROR: I2C driver failed to initialize!");
596606
device_status =
597607
wippersnapper_i2c_I2cDeviceStatus_I2C_DEVICE_STATUS_FAIL_INIT;
608+
// TODO: In offline mode, turn red and HALT
598609
if (!PublishI2cDeviceAddedorReplaced(device_descriptor, device_status))
599610
return false;
600611
return true;
@@ -603,6 +614,7 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
603614
WS_DEBUG_PRINTLN("[i2c] ERROR: I2C driver type not found or unsupported!");
604615
device_status =
605616
wippersnapper_i2c_I2cDeviceStatus_I2C_DEVICE_STATUS_FAIL_UNSUPPORTED_SENSOR;
617+
// TODO: In offline mode, turn red and HALT
606618
if (!PublishI2cDeviceAddedorReplaced(device_descriptor, device_status))
607619
return false;
608620
return true;

src/components/i2c/drivers/drvBase.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#ifndef DRV_BASE_H
1717
#define DRV_BASE_H
18-
#include "Wippersnapper_V2.h"
1918
#include <Adafruit_Sensor.h>
2019
#include <Arduino.h>
2120
#include <protos/i2c.pb.h>
@@ -566,7 +565,6 @@ class drvBase {
566565
return it->second(sensors_event);
567566
}
568567

569-
// private:
570568
// Lambda function type for all GetEventX() function calls
571569
using fnGetEvent = std::function<bool(sensors_event_t *)>;
572570

src/components/i2c/drivers/drvDps310.h

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#ifndef DRV_DPS310_H
1717
#define DRV_DPS310_H
18-
18+
#include "Wippersnapper_V2.h"
1919
#include "drvBase.h"
2020
#include <Adafruit_DPS310.h>
2121

@@ -63,19 +63,26 @@ class drvDps310 : public drvBase {
6363
bool begin() override {
6464
// initialize DPS310
6565
_dps310 = new Adafruit_DPS310();
66-
if (!_dps310->begin_I2C((uint8_t)_address, _i2c))
67-
return false;
66+
if (!_dps310->begin_I2C((uint8_t)_address, _i2c)) {
67+
WS_DEBUG_PRINTLN("DPS310 not found");
68+
return false;
69+
}
6870

6971
// init OK, perform sensor configuration
7072
_dps310->configureTemperature(DPS310_64HZ, DPS310_64SAMPLES);
7173
_dps310->configurePressure(DPS310_64HZ, DPS310_64SAMPLES);
7274
_dps_temp = _dps310->getTemperatureSensor();
73-
if (_dps_temp == NULL)
74-
return false;
75+
if (_dps_temp == NULL) {
76+
WS_DEBUG_PRINTLN("Temperature sensor not found");
77+
return false;
78+
}
7579
_dps_pressure = _dps310->getPressureSensor();
76-
if (_dps_pressure == NULL)
77-
return false;
78-
80+
if (_dps_pressure == NULL) {
81+
WS_DEBUG_PRINTLN("Pressure sensor not found");
82+
return false;
83+
}
84+
// Wait for the first reading to complete
85+
delay(1000);
7986
return true;
8087
}
8188

@@ -89,8 +96,10 @@ class drvDps310 : public drvBase {
8996
*/
9097
/*******************************************************************************/
9198
bool getEventAmbientTemp(sensors_event_t *tempEvent) {
92-
if (!_dps310->temperatureAvailable())
93-
return false;
99+
if (!_dps310->temperatureAvailable()) {
100+
WS_DEBUG_PRINTLN("Temperature not available");
101+
return false;
102+
}
94103

95104
_dps_temp->getEvent(tempEvent);
96105
return true;
@@ -106,8 +115,10 @@ class drvDps310 : public drvBase {
106115
*/
107116
/*******************************************************************************/
108117
bool getEventPressure(sensors_event_t *pressureEvent) {
109-
if (!_dps310->pressureAvailable())
110-
return false;
118+
if (!_dps310->pressureAvailable()) {
119+
WS_DEBUG_PRINTLN("Pressure not available");
120+
return false;
121+
}
111122

112123
_dps_pressure->getEvent(pressureEvent);
113124
return true;

src/components/i2c/model.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ float GetValueFromSensorsEvent(wippersnapper_sensor_SensorType sensor_type,
217217
case wippersnapper_sensor_SensorType_SENSOR_TYPE_UNITLESS_PERCENT:
218218
value = event->unitless_percent;
219219
break;
220+
case wippersnapper_sensor_SensorType_SENSOR_TYPE_LIGHT:
221+
value = event->light;
222+
break;
220223
default:
221224
value = 0.0;
222225
break;

0 commit comments

Comments
 (0)