mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 12:46:34 +00:00
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:
parent
ab94b16d8d
commit
8683bc7722
@ -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
|
||||||
|
@ -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,25 +84,26 @@ void sen5x_Init(void) {
|
|||||||
else {
|
else {
|
||||||
sen5x->begin(Wire);
|
sen5x->begin(Wire);
|
||||||
}
|
}
|
||||||
int error_stop = sen5x->deviceReset();
|
|
||||||
if (error_stop != 0) {
|
if (!Settings->flag6.sen5x_passive_mode) {
|
||||||
DEBUG_SENSOR_LOG(PSTR("Sensirion SEN5X failed to reset device (I2C Bus %d)"), usingI2cBus);
|
int error_stop = sen5x->deviceReset();
|
||||||
return;
|
if (error_stop != 0) {
|
||||||
}
|
DEBUG_SENSOR_LOG(PSTR("Sensirion SEN5X failed to reset device (I2C Bus %d)"), usingI2cBus);
|
||||||
// Wait 1 second for sensors to start recording + 100ms for reset command
|
return;
|
||||||
delay(1100);
|
}
|
||||||
int error_start = sen5x->startMeasurement();
|
// Wait 1 second for sensors to start recording + 100ms for reset command
|
||||||
if (error_start != 0) {
|
delay(1100);
|
||||||
DEBUG_SENSOR_LOG(PSTR("Sensirion SEN5X failed to start measurement (I2C Bus %d)"), usingI2cBus);
|
int error_start = sen5x->startMeasurement();
|
||||||
return;
|
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));
|
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:
|
||||||
SEN5XUpdate();
|
if (Settings->flag6.sen5x_passive_mode) {
|
||||||
|
if (TasmotaGlobal.uptime % SEN5X_PASSIVE_MODE_INTERVAL == 0) {
|
||||||
|
SEN5XUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SEN5XUpdate();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case FUNC_JSON_APPEND:
|
case FUNC_JSON_APPEND:
|
||||||
SEN5XShow(1);
|
SEN5XShow(1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user