Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added passive mode for Sen5x sensor (required for Ike@ Vindstyrka) #19388

Merged
merged 3 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tasmota/include/tasmota_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t berry_no_autoexec : 1; // bit 7 (v12.5.0.3) - SetOption153 - (Berry) Disable autoexec.be on restart (1)
uint32_t berry_light_scheme : 1; // bit 8 (v12.5.0.3) - SetOption154 - (Berry) Handle berry led using RMT0 as additional WS2812 scheme
uint32_t zcfallingedge : 1; // bit 9 (v13.0.0.1) - SetOption155 - (ZCDimmer) Enable rare falling Edge dimmer instead of leading edge
uint32_t spare10 : 1; // bit 10
uint32_t sen5x_passive_mode : 1; // bit 10 (v13.1.0.1) - SetOption156 - (Sen5x) Run in passive mode when there is another I2C master (e.g. Ike* Vindstyrka), i.e. do not set up Sen5x sensor, higher polling interval
uint32_t spare11 : 1; // bit 11
uint32_t spare12 : 1; // bit 12
uint32_t spare13 : 1; // bit 13
Expand Down
37 changes: 23 additions & 14 deletions tasmota/tasmota_xsns_sensor/xsns_103_sen5x.ino
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#define XI2C_76 76 // See I2CDEVICES.md

#define SEN5X_ADDRESS 0x69
#define SEN5X_PASSIVE_MODE_INTERVAL 10

#include <SensirionI2CSen5x.h>
#include <Wire.h>
Expand Down Expand Up @@ -83,25 +84,26 @@ void sen5x_Init(void) {
else {
sen5x->begin(Wire);
}
int error_stop = sen5x->deviceReset();
if (error_stop != 0) {
DEBUG_SENSOR_LOG(PSTR("Sensirion SEN5X failed to reset device (I2C Bus %d)"), usingI2cBus);
return;
}
// Wait 1 second for sensors to start recording + 100ms for reset command
delay(1100);
int error_start = sen5x->startMeasurement();
if (error_start != 0) {
DEBUG_SENSOR_LOG(PSTR("Sensirion SEN5X failed to start measurement (I2C Bus %d)"), usingI2cBus);
return;

if (!Settings->flag6.sen5x_passive_mode) {
int error_stop = sen5x->deviceReset();
if (error_stop != 0) {
DEBUG_SENSOR_LOG(PSTR("Sensirion SEN5X failed to reset device (I2C Bus %d)"), usingI2cBus);
return;
}
// Wait 1 second for sensors to start recording + 100ms for reset command
delay(1100);
int error_start = sen5x->startMeasurement();
if (error_start != 0) {
DEBUG_SENSOR_LOG(PSTR("Sensirion SEN5X failed to start measurement (I2C Bus %d)"), usingI2cBus);
return;
}
}

SEN5XDATA = (SEN5XDATA_s *)calloc(1, sizeof(struct SEN5XDATA_s));
I2cSetActiveFound(SEN5X_ADDRESS, "SEN5X", usingI2cBus);
}

#define SAVE_PERIOD 30

void SEN5XUpdate(void) { // Perform every second to ensure proper operation of the baseline compensation algorithm
uint16_t error;
char errorMessage[256];
Expand Down Expand Up @@ -215,7 +217,14 @@ bool Xsns103(uint32_t function) {
else if (SEN5XDATA != nullptr) {
switch (function) {
case FUNC_EVERY_SECOND:
SEN5XUpdate();
if (Settings->flag6.sen5x_passive_mode) {
if (TasmotaGlobal.uptime % SEN5X_PASSIVE_MODE_INTERVAL == 0) {
SEN5XUpdate();
}
}
else {
SEN5XUpdate();
}
break;
case FUNC_JSON_APPEND:
SEN5XShow(1);
Expand Down