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

* Added a passive mode in sen5x sensor for parasitic installations. This skips reset & initialization of sensor on startup and reduces the polling to every 10 seconds to not interfere with and confuse the other I2C master on the bus, e.g. Ike* Vindstyrka.

* Removed obsolete updateCount. Cleanup.
This commit is contained in:
Andre H. Beckedorf 2023-08-26 16:14:30 +02:00 committed by GitHub
parent ab94b16d8d
commit 8683bc7722
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 15 deletions

View File

@ -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_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 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 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 spare11 : 1; // bit 11
uint32_t spare12 : 1; // bit 12 uint32_t spare12 : 1; // bit 12
uint32_t spare13 : 1; // bit 13 uint32_t spare13 : 1; // bit 13

View File

@ -32,6 +32,7 @@
#define XI2C_76 76 // See I2CDEVICES.md #define XI2C_76 76 // See I2CDEVICES.md
#define SEN5X_ADDRESS 0x69 #define SEN5X_ADDRESS 0x69
#define SEN5X_PASSIVE_MODE_INTERVAL 10
#include <SensirionI2CSen5x.h> #include <SensirionI2CSen5x.h>
#include <Wire.h> #include <Wire.h>
@ -83,6 +84,8 @@ void sen5x_Init(void) {
else { else {
sen5x->begin(Wire); sen5x->begin(Wire);
} }
if (!Settings->flag6.sen5x_passive_mode) {
int error_stop = sen5x->deviceReset(); int error_stop = sen5x->deviceReset();
if (error_stop != 0) { if (error_stop != 0) {
DEBUG_SENSOR_LOG(PSTR("Sensirion SEN5X failed to reset device (I2C Bus %d)"), usingI2cBus); DEBUG_SENSOR_LOG(PSTR("Sensirion SEN5X failed to reset device (I2C Bus %d)"), usingI2cBus);
@ -95,13 +98,12 @@ void sen5x_Init(void) {
DEBUG_SENSOR_LOG(PSTR("Sensirion SEN5X failed to start measurement (I2C Bus %d)"), usingI2cBus); DEBUG_SENSOR_LOG(PSTR("Sensirion SEN5X failed to start measurement (I2C Bus %d)"), usingI2cBus);
return; return;
} }
}
SEN5XDATA = (SEN5XDATA_s *)calloc(1, sizeof(struct SEN5XDATA_s)); SEN5XDATA = (SEN5XDATA_s *)calloc(1, sizeof(struct SEN5XDATA_s));
I2cSetActiveFound(SEN5X_ADDRESS, "SEN5X", usingI2cBus); I2cSetActiveFound(SEN5X_ADDRESS, "SEN5X", usingI2cBus);
} }
#define SAVE_PERIOD 30
void SEN5XUpdate(void) { // Perform every second to ensure proper operation of the baseline compensation algorithm void SEN5XUpdate(void) { // Perform every second to ensure proper operation of the baseline compensation algorithm
uint16_t error; uint16_t error;
char errorMessage[256]; char errorMessage[256];
@ -215,7 +217,14 @@ bool Xsns103(uint32_t function) {
else if (SEN5XDATA != nullptr) { else if (SEN5XDATA != nullptr) {
switch (function) { switch (function) {
case FUNC_EVERY_SECOND: case FUNC_EVERY_SECOND:
if (Settings->flag6.sen5x_passive_mode) {
if (TasmotaGlobal.uptime % SEN5X_PASSIVE_MODE_INTERVAL == 0) {
SEN5XUpdate(); SEN5XUpdate();
}
}
else {
SEN5XUpdate();
}
break; break;
case FUNC_JSON_APPEND: case FUNC_JSON_APPEND:
SEN5XShow(1); SEN5XShow(1);