diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 58e084d34..08b5942e8 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,4 +1,7 @@ -/* 6.3.0.3 20181105 +/* 6.3.0.4 20181106 + * Add command SetSensorXX 0/1 to disable/re-enable compiled xsns_XX_sensor.ino driver + * + * 6.3.0.3 20181105 * Fix hardware serial pin configuration. To keep using hardware serial swap current Rx/Tx pin configuration only (#4280) * Add more strict checks for GPIO selections * Add optional hardware serial when GPIO13(Rx) and GPIO15(Tx) are selected removing hardware serial from GPIO01(Tx) and GPIO03(Rx) (#4288) diff --git a/sonoff/i18n.h b/sonoff/i18n.h index 587987c4d..73e1d0be2 100644 --- a/sonoff/i18n.h +++ b/sonoff/i18n.h @@ -183,6 +183,7 @@ #define D_CMND_DRIVER "Driver" #define D_CMND_SAVEDATA "SaveData" #define D_CMND_SETOPTION "SetOption" +#define D_CMND_SETSENSOR "SetSensor" #define D_CMND_TEMPERATURE_RESOLUTION "TempRes" #define D_CMND_HUMIDITY_RESOLUTION "HumRes" #define D_CMND_PRESSURE_RESOLUTION "PressRes" diff --git a/sonoff/settings.h b/sonoff/settings.h index 677a02bf3..032ea530d 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -320,8 +320,12 @@ struct SYSCFG { uint16_t mcp230xx_int_timer; // 718 uint8_t rgbwwTable[5]; // 71A - byte free_71F[149]; // 71F + byte free_71F[109]; // 71F + uint32_t monitors; // 78C + uint32_t displays; // 790 + uint32_t drivers[4]; // 794 + uint32_t sensors[4]; // 7A4 uint32_t energy_kWhtotal_time; // 7B4 unsigned long weight_item; // 7B8 Weight of one item in gram * 10 diff --git a/sonoff/settings.ino b/sonoff/settings.ino index 072cabf2f..88c6838a3 100644 --- a/sonoff/settings.ino +++ b/sonoff/settings.ino @@ -635,6 +635,8 @@ void SettingsDefaultSet2() for (byte j = 0; j < 5; j++) { Settings.rgbwwTable[j] = 255; } + + memset(&Settings.monitors, 0xFF, 40); // Enable all possible monitors, displays, drivers and sensors } /********************************************************************************************/ @@ -846,6 +848,9 @@ void SettingsDelta() if (Settings.version < 0x06030002) { Settings.timezone_minutes = 0; } + if (Settings.version < 0x06030004) { + memset(&Settings.monitors, 0xFF, 40); // Enable all possible monitors, displays, drivers and sensors + } Settings.version = VERSION; SettingsSave(1); diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index a7cb1ce9a..a0ad03c13 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -50,6 +50,10 @@ typedef unsigned long power_t; // Power (Relay) type #define MAX_DOMOTICZ_SNS_IDX 12 // Max number of Domoticz sensors indices #define MAX_KNX_GA 10 // Max number of KNX Group Addresses to read that can be set #define MAX_KNX_CB 10 // Max number of KNX Group Addresses to write that can be set +#define MAX_XNRG_DRIVERS 32 // Max number of allowed energy drivers +#define MAX_XDSP_DRIVERS 32 // Max number of allowed display drivers +#define MAX_XDRV_DRIVERS 100 // Max number of allowed driver drivers +#define MAX_XSNS_DRIVERS 100 // Max number of allowed sensor drivers #define MAX_RULE_MEMS 5 // Max number of saved vars #define MAX_RULE_SETS 3 // Max number of rule sets of size 512 characters #define MAX_RULE_SIZE 512 // Max number of characters in rules diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 3ef470de4..42a541162 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -81,7 +81,7 @@ enum TasmotaCommands { CMND_MODULE, CMND_MODULES, CMND_GPIO, CMND_GPIOS, CMND_PWM, CMND_PWMFREQUENCY, CMND_PWMRANGE, CMND_COUNTER, CMND_COUNTERTYPE, CMND_COUNTERDEBOUNCE, CMND_BUTTONDEBOUNCE, CMND_SWITCHDEBOUNCE, CMND_SLEEP, CMND_UPGRADE, CMND_UPLOAD, CMND_OTAURL, CMND_SERIALLOG, CMND_SYSLOG, CMND_LOGHOST, CMND_LOGPORT, CMND_IPADDRESS, CMND_NTPSERVER, CMND_AP, CMND_SSID, CMND_PASSWORD, CMND_HOSTNAME, - CMND_WIFICONFIG, CMND_FRIENDLYNAME, CMND_SWITCHMODE, + CMND_WIFICONFIG, CMND_FRIENDLYNAME, CMND_SWITCHMODE, CMND_SETSENSOR, CMND_TELEPERIOD, CMND_RESTART, CMND_RESET, CMND_TIMEZONE, CMND_TIMESTD, CMND_TIMEDST, CMND_ALTITUDE, CMND_LEDPOWER, CMND_LEDSTATE, CMND_I2CSCAN, CMND_SERIALSEND, CMND_BAUDRATE, CMND_SERIALDELIMITER, CMND_DRIVER }; const char kTasmotaCommands[] PROGMEM = @@ -91,7 +91,7 @@ const char kTasmotaCommands[] PROGMEM = D_CMND_MODULE "|" D_CMND_MODULES "|" D_CMND_GPIO "|" D_CMND_GPIOS "|" D_CMND_PWM "|" D_CMND_PWMFREQUENCY "|" D_CMND_PWMRANGE "|" D_CMND_COUNTER "|" D_CMND_COUNTERTYPE "|" D_CMND_COUNTERDEBOUNCE "|" D_CMND_BUTTONDEBOUNCE "|" D_CMND_SWITCHDEBOUNCE "|" D_CMND_SLEEP "|" D_CMND_UPGRADE "|" D_CMND_UPLOAD "|" D_CMND_OTAURL "|" D_CMND_SERIALLOG "|" D_CMND_SYSLOG "|" D_CMND_LOGHOST "|" D_CMND_LOGPORT "|" D_CMND_IPADDRESS "|" D_CMND_NTPSERVER "|" D_CMND_AP "|" D_CMND_SSID "|" D_CMND_PASSWORD "|" D_CMND_HOSTNAME "|" - D_CMND_WIFICONFIG "|" D_CMND_FRIENDLYNAME "|" D_CMND_SWITCHMODE "|" + D_CMND_WIFICONFIG "|" D_CMND_FRIENDLYNAME "|" D_CMND_SWITCHMODE "|" D_CMND_SETSENSOR "|" D_CMND_TELEPERIOD "|" D_CMND_RESTART "|" D_CMND_RESET "|" D_CMND_TIMEZONE "|" D_CMND_TIMESTD "|" D_CMND_TIMEDST "|" D_CMND_ALTITUDE "|" D_CMND_LEDPOWER "|" D_CMND_LEDSTATE "|" D_CMND_I2CSCAN "|" D_CMND_SERIALSEND "|" D_CMND_BAUDRATE "|" D_CMND_SERIALDELIMITER "|" D_CMND_DRIVER; @@ -777,6 +777,13 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, (2 == ptype) ? stemp1 : (1 == ptype) ? GetStateText(bitRead(Settings.flag3.data, pindex)) : GetStateText(bitRead(Settings.flag.data, pindex))); } } + else if ((CMND_SETSENSOR == command_code) && (index < MAX_XSNS_DRIVERS)) { + if ((payload >= 0) && XsnsPresent(index)) { + bitWrite(Settings.sensors[index / 32], index % 32, payload &1); + if (1 == payload) { restart_flag = 2; } // To safely re-enable a sensor currently most sensor need to follow complete restart init cycle + } + snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_XVALUE, command, XsnsGetSensors().c_str()); + } else if (CMND_TEMPERATURE_RESOLUTION == command_code) { if ((payload >= 0) && (payload <= 3)) { Settings.flag2.temperature_resolution = payload; diff --git a/sonoff/sonoff_version.h b/sonoff/sonoff_version.h index 733bad937..7bb3242ae 100644 --- a/sonoff/sonoff_version.h +++ b/sonoff/sonoff_version.h @@ -20,7 +20,7 @@ #ifndef _SONOFF_VERSION_H_ #define _SONOFF_VERSION_H_ -#define VERSION 0x06030003 +#define VERSION 0x06030004 #define D_PROGRAMNAME "Sonoff-Tasmota" #define D_AUTHOR "Theo Arends" diff --git a/sonoff/support.ino b/sonoff/support.ino index c2856a782..bbc81b1a3 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -2221,81 +2221,6 @@ void RtcInit() TickerRtc.attach(1, RtcSecond); } -#ifndef USE_ADC_VCC -/*********************************************************************************************\ - * ADC support -\*********************************************************************************************/ - -uint16_t adc_last_value = 0; - -uint16_t AdcRead() -{ - uint16_t analog = 0; - for (byte i = 0; i < 32; i++) { - analog += analogRead(A0); - delay(1); - } - analog >>= 5; - return analog; -} - -#ifdef USE_RULES -void AdcEvery250ms() -{ - uint16_t new_value = AdcRead(); - if ((new_value < adc_last_value -10) || (new_value > adc_last_value +10)) { - adc_last_value = new_value; - uint16_t value = adc_last_value / 10; - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"ANALOG\":{\"A0div10\":%d}}"), (value > 99) ? 100 : value); - XdrvRulesProcess(); - } -} -#endif // USE_RULES - -void AdcShow(boolean json) -{ - uint16_t analog = AdcRead(); - - if (json) { - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"ANALOG\":{\"A0\":%d}"), mqtt_data, analog); -#ifdef USE_WEBSERVER - } else { - snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_ANALOG, mqtt_data, "", 0, analog); -#endif // USE_WEBSERVER - } -} - -/*********************************************************************************************\ - * Interface -\*********************************************************************************************/ - -#define XSNS_02 - -boolean Xsns02(byte function) -{ - boolean result = false; - - if (pin[GPIO_ADC0] < 99) { - switch (function) { -#ifdef USE_RULES - case FUNC_EVERY_250_MSECOND: - AdcEvery250ms(); - break; -#endif // USE_RULES - case FUNC_JSON_APPEND: - AdcShow(1); - break; -#ifdef USE_WEBSERVER - case FUNC_WEB_APPEND: - AdcShow(0); - break; -#endif // USE_WEBSERVER - } - } - return result; -} -#endif // USE_ADC_VCC - /*********************************************************************************************\ * Syslog * diff --git a/sonoff/xdrv_03_energy.ino b/sonoff/xdrv_03_energy.ino index 717ff234c..93bae4078 100644 --- a/sonoff/xdrv_03_energy.ino +++ b/sonoff/xdrv_03_energy.ino @@ -22,7 +22,10 @@ * Energy \*********************************************************************************************/ -#define ENERGY_NONE 0 +#define XDRV_03 3 +#define XSNS_03 3 + +#define ENERGY_NONE 0 #define FEATURE_POWER_LIMIT true @@ -656,8 +659,6 @@ void EnergyShow(boolean json) * Interface \*********************************************************************************************/ -#define XDRV_03 - boolean Xdrv03(byte function) { boolean result = false; @@ -681,8 +682,6 @@ boolean Xdrv03(byte function) return result; } -#define XSNS_03 - boolean Xsns03(byte function) { boolean result = false; diff --git a/sonoff/xplg_wemohue.ino b/sonoff/xplg_wemohue.ino index dbdf3d27b..8bd5e529c 100644 --- a/sonoff/xplg_wemohue.ino +++ b/sonoff/xplg_wemohue.ino @@ -1,14 +1,18 @@ /* xplg_wemohue.ino - wemo and hue support for Sonoff-Tasmota + Copyright (C) 2018 Heiko Krupp and Theo Arends + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along with this program. If not, see . */ diff --git a/sonoff/xsns_01_counter.ino b/sonoff/xsns_01_counter.ino index b5822cac7..0c4271f81 100644 --- a/sonoff/xsns_01_counter.ino +++ b/sonoff/xsns_01_counter.ino @@ -21,6 +21,8 @@ * Counter sensors (water meters, electricity meters etc.) \*********************************************************************************************/ +#define XSNS_01 1 + unsigned long last_counter_timer[MAX_COUNTERS]; // Last counter time in micro seconds void CounterUpdate(byte index) @@ -139,8 +141,6 @@ void CounterShow(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_01 - boolean Xsns01(byte function) { boolean result = false; diff --git a/sonoff/xsns_02_analog.ino b/sonoff/xsns_02_analog.ino new file mode 100644 index 000000000..ce794b3a2 --- /dev/null +++ b/sonoff/xsns_02_analog.ino @@ -0,0 +1,94 @@ +/* + xsns_02_analog.ino - ESP8266 ADC support for Sonoff-Tasmota + + Copyright (C) 2018 Theo Arends + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef USE_ADC_VCC +/*********************************************************************************************\ + * ADC support +\*********************************************************************************************/ + +#define XSNS_02 2 + +uint16_t adc_last_value = 0; + +uint16_t AdcRead() +{ + uint16_t analog = 0; + for (byte i = 0; i < 32; i++) { + analog += analogRead(A0); + delay(1); + } + analog >>= 5; + return analog; +} + +#ifdef USE_RULES +void AdcEvery250ms() +{ + uint16_t new_value = AdcRead(); + if ((new_value < adc_last_value -10) || (new_value > adc_last_value +10)) { + adc_last_value = new_value; + uint16_t value = adc_last_value / 10; + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"ANALOG\":{\"A0div10\":%d}}"), (value > 99) ? 100 : value); + XdrvRulesProcess(); + } +} +#endif // USE_RULES + +void AdcShow(boolean json) +{ + uint16_t analog = AdcRead(); + + if (json) { + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"ANALOG\":{\"A0\":%d}"), mqtt_data, analog); +#ifdef USE_WEBSERVER + } else { + snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_ANALOG, mqtt_data, "", 0, analog); +#endif // USE_WEBSERVER + } +} + +/*********************************************************************************************\ + * Interface +\*********************************************************************************************/ + +boolean Xsns02(byte function) +{ + boolean result = false; + + if (pin[GPIO_ADC0] < 99) { + switch (function) { +#ifdef USE_RULES + case FUNC_EVERY_250_MSECOND: + AdcEvery250ms(); + break; +#endif // USE_RULES + case FUNC_JSON_APPEND: + AdcShow(1); + break; +#ifdef USE_WEBSERVER + case FUNC_WEB_APPEND: + AdcShow(0); + break; +#endif // USE_WEBSERVER + } + } + return result; +} + +#endif // USE_ADC_VCC diff --git a/sonoff/xsns_04_snfsc.ino b/sonoff/xsns_04_snfsc.ino index 1628e9abf..a294ad32f 100644 --- a/sonoff/xsns_04_snfsc.ino +++ b/sonoff/xsns_04_snfsc.ino @@ -53,6 +53,8 @@ \*********************************************************************************************/ +#define XSNS_04 4 + uint16_t sc_value[5] = { 0 }; void SonoffScSend(const char *data) @@ -152,8 +154,6 @@ void SonoffScShow(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_04 - boolean Xsns04(byte function) { boolean result = false; diff --git a/sonoff/xsns_05_ds18b20.ino b/sonoff/xsns_05_ds18b20.ino index fa0f4fee8..1f96ba5b6 100644 --- a/sonoff/xsns_05_ds18b20.ino +++ b/sonoff/xsns_05_ds18b20.ino @@ -22,6 +22,8 @@ * DS18B20 - Temperature - Single sensor \*********************************************************************************************/ +#define XSNS_05 5 + #define W1_SKIP_ROM 0xCC #define W1_CONVERT_TEMP 0x44 #define W1_READ_SCRATCHPAD 0xBE @@ -215,8 +217,6 @@ void Ds18b20Show(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_05 - boolean Xsns05(byte function) { boolean result = false; diff --git a/sonoff/xsns_05_ds18x20.ino b/sonoff/xsns_05_ds18x20.ino index 474f26e2e..10625c0c8 100644 --- a/sonoff/xsns_05_ds18x20.ino +++ b/sonoff/xsns_05_ds18x20.ino @@ -21,6 +21,9 @@ /*********************************************************************************************\ * DS18B20 - Temperature - Multiple sensors \*********************************************************************************************/ + +#define XSNS_05 5 + //#define USE_DS18x20_RECONFIGURE // When sensor is lost keep retrying or re-configure #define DS18S20_CHIPID 0x10 // +/-0.5C 9-bit @@ -464,8 +467,6 @@ void Ds18x20Show(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_05 - boolean Xsns05(byte function) { boolean result = false; diff --git a/sonoff/xsns_05_ds18x20_legacy.ino b/sonoff/xsns_05_ds18x20_legacy.ino index 03754bbe1..385278432 100644 --- a/sonoff/xsns_05_ds18x20_legacy.ino +++ b/sonoff/xsns_05_ds18x20_legacy.ino @@ -22,6 +22,8 @@ * DS18B20 - Temperature \*********************************************************************************************/ +#define XSNS_05 5 + #define DS18S20_CHIPID 0x10 #define DS18B20_CHIPID 0x28 #define MAX31850_CHIPID 0x3B @@ -218,8 +220,6 @@ void Ds18x20Show(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_05 - boolean Xsns05(byte function) { boolean result = false; diff --git a/sonoff/xsns_06_dht.ino b/sonoff/xsns_06_dht.ino index 048337d25..1434b4f47 100644 --- a/sonoff/xsns_06_dht.ino +++ b/sonoff/xsns_06_dht.ino @@ -26,6 +26,8 @@ * Source: Adafruit Industries https://github.com/adafruit/DHT-sensor-library \*********************************************************************************************/ +#define XSNS_06 6 + #define DHT_MAX_SENSORS 3 #define DHT_MAX_RETRY 8 @@ -238,8 +240,6 @@ void DhtShow(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_06 - boolean Xsns06(byte function) { boolean result = false; diff --git a/sonoff/xsns_07_sht1x.ino b/sonoff/xsns_07_sht1x.ino index 8771dab7f..f636a8cf3 100644 --- a/sonoff/xsns_07_sht1x.ino +++ b/sonoff/xsns_07_sht1x.ino @@ -28,6 +28,8 @@ * I2C Address: None \*********************************************************************************************/ +#define XSNS_07 7 + enum { SHT1X_CMD_MEASURE_TEMP = B00000011, SHT1X_CMD_MEASURE_RH = B00000101, @@ -218,8 +220,6 @@ void ShtShow(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_07 - boolean Xsns07(byte function) { boolean result = false; diff --git a/sonoff/xsns_08_htu21.ino b/sonoff/xsns_08_htu21.ino index 61266e106..9a24050f0 100644 --- a/sonoff/xsns_08_htu21.ino +++ b/sonoff/xsns_08_htu21.ino @@ -27,6 +27,8 @@ * I2C Address: 0x40 \*********************************************************************************************/ +#define XSNS_08 8 + #define HTU21_ADDR 0x40 #define SI7013_CHIPID 0x0D @@ -279,8 +281,6 @@ void HtuShow(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_08 - boolean Xsns08(byte function) { boolean result = false; diff --git a/sonoff/xsns_09_bmp.ino b/sonoff/xsns_09_bmp.ino index 36070578a..bcc4632bd 100755 --- a/sonoff/xsns_09_bmp.ino +++ b/sonoff/xsns_09_bmp.ino @@ -27,6 +27,8 @@ * I2C Address: 0x76 or 0x77 \*********************************************************************************************/ +#define XSNS_09 9 + #define BMP_ADDR1 0x76 #define BMP_ADDR2 0x77 @@ -585,8 +587,6 @@ void BmpShow(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_09 - boolean Xsns09(byte function) { boolean result = false; diff --git a/sonoff/xsns_10_bh1750.ino b/sonoff/xsns_10_bh1750.ino index 1dd18d90a..2cdc9bcbd 100644 --- a/sonoff/xsns_10_bh1750.ino +++ b/sonoff/xsns_10_bh1750.ino @@ -25,6 +25,8 @@ * I2C Address: 0x23 or 0x5C \*********************************************************************************************/ +#define XSNS_10 10 + #define BH1750_ADDR1 0x23 #define BH1750_ADDR2 0x5C @@ -114,8 +116,6 @@ void Bh1750Show(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_10 - boolean Xsns10(byte function) { boolean result = false; diff --git a/sonoff/xsns_11_veml6070.ino b/sonoff/xsns_11_veml6070.ino index 68d25234a..590f61300 100644 --- a/sonoff/xsns_11_veml6070.ino +++ b/sonoff/xsns_11_veml6070.ino @@ -94,6 +94,8 @@ * I2C Address: 0x38 and 0x39 \*********************************************************************************************/ +#define XSNS_11 11 + #define VEML6070_ADDR_H 0x39 // on some PCB boards the address can be changed by a solder point, #define VEML6070_ADDR_L 0x38 // to have no address conflicts with other I2C sensors and/or hardware #define VEML6070_INTEGRATION_TIME 3 // IT_4 = 500msec integration time, because the precission is 4 times higher then IT_0.5 @@ -305,8 +307,6 @@ void Veml6070Show(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_11 - boolean Xsns11(byte function) { boolean result = false; diff --git a/sonoff/xsns_12_ads1115.ino b/sonoff/xsns_12_ads1115.ino index bcfb6dfad..06da4acd4 100644 --- a/sonoff/xsns_12_ads1115.ino +++ b/sonoff/xsns_12_ads1115.ino @@ -40,6 +40,8 @@ * ADS1115_REG_CONFIG_PGA_0_256V // 16x gain +/- 0.256V 1 bit = 0.0078125mV \*********************************************************************************************/ +#define XSNS_12 12 + #define ADS1115_ADDRESS_ADDR_GND 0x48 // address pin low (GND) #define ADS1115_ADDRESS_ADDR_VDD 0x49 // address pin high (VCC) #define ADS1115_ADDRESS_ADDR_SDA 0x4A // address pin tied to SDA pin @@ -210,8 +212,6 @@ void Ads1115Show(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_12 - boolean Xsns12(byte function) { boolean result = false; diff --git a/sonoff/xsns_12_ads1115_i2cdev.ino b/sonoff/xsns_12_ads1115_i2cdev.ino index 588a37ac5..dcfab91c7 100644 --- a/sonoff/xsns_12_ads1115_i2cdev.ino +++ b/sonoff/xsns_12_ads1115_i2cdev.ino @@ -40,6 +40,8 @@ * ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV \*********************************************************************************************/ +#define XSNS_12 12 + #include ADS1115 adc0; @@ -130,8 +132,6 @@ void Ads1115Show(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_12 - boolean Xsns12(byte function) { boolean result = false; diff --git a/sonoff/xsns_13_ina219.ino b/sonoff/xsns_13_ina219.ino index deb4d5f4f..6f0e2c1e9 100644 --- a/sonoff/xsns_13_ina219.ino +++ b/sonoff/xsns_13_ina219.ino @@ -19,9 +19,6 @@ #ifdef USE_I2C #ifdef USE_INA219 - -#define XSNS_13 13 - /*********************************************************************************************\ * INA219 - Low voltage (max 32V!) Current sensor * @@ -30,6 +27,8 @@ * I2C Address: 0x40, 0x41 0x44 or 0x45 \*********************************************************************************************/ +#define XSNS_13 13 + #define INA219_ADDRESS1 (0x40) // 1000000 (A0+A1=GND) #define INA219_ADDRESS2 (0x41) // 1000000 (A0=Vcc, A1=GND) #define INA219_ADDRESS3 (0x44) // 1000000 (A0=GND, A1=Vcc) diff --git a/sonoff/xsns_14_sht3x.ino b/sonoff/xsns_14_sht3x.ino index c3c8b2f9c..c9b36571b 100755 --- a/sonoff/xsns_14_sht3x.ino +++ b/sonoff/xsns_14_sht3x.ino @@ -25,6 +25,8 @@ * I2C Address: 0x44, 0x45 or 0x70 (SHTC3) \*********************************************************************************************/ +#define XSNS_14 14 + #define SHT3X_ADDR_GND 0x44 // address pin low (GND) #define SHT3X_ADDR_VDD 0x45 // address pin high (VDD) #define SHTC3_ADDR 0x70 // address for shtc3 sensor @@ -138,8 +140,6 @@ void Sht3xShow(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_14 - boolean Xsns14(byte function) { boolean result = false; diff --git a/sonoff/xsns_15_mhz19.ino b/sonoff/xsns_15_mhz19.ino index 3b9945bca..5b9817561 100644 --- a/sonoff/xsns_15_mhz19.ino +++ b/sonoff/xsns_15_mhz19.ino @@ -18,9 +18,6 @@ */ #ifdef USE_MHZ19 - -#define XSNS_15 15 - /*********************************************************************************************\ * MH-Z19 - CO2 sensor * @@ -33,6 +30,8 @@ * Select filter usage on low stability readings \*********************************************************************************************/ +#define XSNS_15 15 + enum MhzFilterOptions {MHZ19_FILTER_OFF, MHZ19_FILTER_OFF_ALLSAMPLES, MHZ19_FILTER_FAST, MHZ19_FILTER_MEDIUM, MHZ19_FILTER_SLOW}; #define MHZ19_FILTER_OPTION MHZ19_FILTER_FAST @@ -246,18 +245,14 @@ void MhzEverySecond() /*********************************************************************************************\ * Command Sensor15 + * + * 0 - (Not implemented) ABC Off + * 1 - (Not implemented) ABC On + * 2 - Manual start = ABC Off + * 3 - (Not implemented) Optional filter settings + * 9 - Reset \*********************************************************************************************/ -/* - 0 - ABC Off - 1 - ABC On - 2 - Manual start = ABC Off - - 3 - Optional filter settings - - 9 - Reset -*/ - bool MhzCommandSensor() { boolean serviced = true; diff --git a/sonoff/xsns_16_tsl2561.ino b/sonoff/xsns_16_tsl2561.ino index 61308aa20..8f2884c25 100644 --- a/sonoff/xsns_16_tsl2561.ino +++ b/sonoff/xsns_16_tsl2561.ino @@ -27,6 +27,8 @@ * I2C Addresses: 0x29 (low), 0x39 (float) or 0x49 (high) \*********************************************************************************************/ +#define XSNS_16 16 + #include Tsl2561 Tsl(Wire); @@ -118,8 +120,6 @@ void Tsl2561Show(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_16 - boolean Xsns16(byte function) { boolean result = false; diff --git a/sonoff/xsns_17_senseair.ino b/sonoff/xsns_17_senseair.ino index a810a0e27..7a2060dd9 100644 --- a/sonoff/xsns_17_senseair.ino +++ b/sonoff/xsns_17_senseair.ino @@ -26,6 +26,8 @@ * Hardware Serial will be selected if GPIO1 = [SAir Rx] and GPIO3 = [SAir Tx] \*********************************************************************************************/ +#define XSNS_17 17 + #define SENSEAIR_MODBUS_SPEED 9600 #define SENSEAIR_DEVICE_ADDRESS 0xFE // Any address #define SENSEAIR_READ_REGISTER 0x04 // Command Read @@ -175,8 +177,6 @@ void SenseairShow(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_17 - boolean Xsns17(byte function) { boolean result = false; diff --git a/sonoff/xsns_18_pms5003.ino b/sonoff/xsns_18_pms5003.ino index fb2aca0fb..ec605cf46 100644 --- a/sonoff/xsns_18_pms5003.ino +++ b/sonoff/xsns_18_pms5003.ino @@ -25,6 +25,8 @@ * Hardware Serial will be selected if GPIO3 = [PMS5003] \*********************************************************************************************/ +#define XSNS_18 18 + #include TasmotaSerial *PmsSerial; @@ -156,8 +158,6 @@ void PmsShow(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_18 - boolean Xsns18(byte function) { boolean result = false; diff --git a/sonoff/xsns_19_mgs.ino b/sonoff/xsns_19_mgs.ino index f27b734fd..75fbea5b8 100644 --- a/sonoff/xsns_19_mgs.ino +++ b/sonoff/xsns_19_mgs.ino @@ -26,6 +26,8 @@ * https://github.com/Seeed-Studio/Mutichannel_Gas_Sensor.git \*********************************************************************************************/ +#define XSNS_19 19 + #ifndef MGS_SENSOR_ADDR #define MGS_SENSOR_ADDR 0x04 // Default Mutichannel Gas sensor i2c address #endif @@ -89,8 +91,6 @@ void MGSShow(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_19 - boolean Xsns19(byte function) { boolean result = false; diff --git a/sonoff/xsns_20_novasds.ino b/sonoff/xsns_20_novasds.ino index 815041cab..8a584571c 100644 --- a/sonoff/xsns_20_novasds.ino +++ b/sonoff/xsns_20_novasds.ino @@ -25,10 +25,12 @@ * Hardware Serial will be selected if GPIO3 = [SDS0X01] \*********************************************************************************************/ +#define XSNS_20 20 + #include #ifndef WORKING_PERIOD - #define WORKING_PERIOD 5 +#define WORKING_PERIOD 5 #endif TasmotaSerial *NovaSdsSerial; @@ -169,8 +171,6 @@ void NovaSdsShow(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_20 - boolean Xsns20(byte function) { boolean result = false; diff --git a/sonoff/xsns_21_sgp30.ino b/sonoff/xsns_21_sgp30.ino index 5fef47bfd..ff6cbb749 100644 --- a/sonoff/xsns_21_sgp30.ino +++ b/sonoff/xsns_21_sgp30.ino @@ -27,6 +27,8 @@ * I2C Address: 0x58 \*********************************************************************************************/ +#define XSNS_21 21 + #include "Adafruit_SGP30.h" Adafruit_SGP30 sgp; @@ -88,8 +90,6 @@ void Sgp30Show(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_21 - boolean Xsns21(byte function) { boolean result = false; diff --git a/sonoff/xsns_22_sr04.ino b/sonoff/xsns_22_sr04.ino index 775ea93c9..9d447b3f3 100644 --- a/sonoff/xsns_22_sr04.ino +++ b/sonoff/xsns_22_sr04.ino @@ -26,6 +26,8 @@ * - https://www.dfrobot.com/wiki/index.php/Weather-proof_Ultrasonic_Sensor_SKU_:_SEN0207 \*********************************************************************************************/ +#define XSNS_22 22 + uint8_t sr04_echo_pin = 0; uint8_t sr04_trig_pin = 0; @@ -146,8 +148,6 @@ void Sr04Show(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_22 - boolean Xsns22(byte function) { boolean result = false; diff --git a/sonoff/xsns_23_sdm120.ino b/sonoff/xsns_23_sdm120.ino index e5cc64418..5c2dfa630 100644 --- a/sonoff/xsns_23_sdm120.ino +++ b/sonoff/xsns_23_sdm120.ino @@ -25,6 +25,8 @@ * Based on: https://github.com/reaper7/SDM_Energy_Meter \*********************************************************************************************/ +#define XSNS_23 23 + #include TasmotaSerial *SDM120Serial; @@ -270,8 +272,6 @@ void SDM120Show(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_23 - boolean Xsns23(byte function) { boolean result = false; diff --git a/sonoff/xsns_24_si1145.ino b/sonoff/xsns_24_si1145.ino index 95ad930af..d84eef62f 100644 --- a/sonoff/xsns_24_si1145.ino +++ b/sonoff/xsns_24_si1145.ino @@ -27,9 +27,7 @@ * I2C Addresses: 0x60 \*********************************************************************************************/ -uint8_t si1145_type = 0; - -/********************************************************************************************/ +#define XSNS_24 24 #define SI114X_ADDR 0X60 // @@ -184,6 +182,8 @@ uint8_t si1145_type = 0; #define SI114X_IRQEN_PS2 0x08 #define SI114X_IRQEN_PS3 0x10 +uint8_t si1145_type = 0; + /********************************************************************************************/ uint8_t Si1145ReadByte(uint8_t reg) @@ -349,8 +349,6 @@ void Si1145Show(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_24 - boolean Xsns24(byte function) { boolean result = false; diff --git a/sonoff/xsns_25_sdm630.ino b/sonoff/xsns_25_sdm630.ino index c3513fd42..8c5e556fc 100644 --- a/sonoff/xsns_25_sdm630.ino +++ b/sonoff/xsns_25_sdm630.ino @@ -25,6 +25,8 @@ * Based on: https://github.com/reaper7/SDM_Energy_Meter \*********************************************************************************************/ +#define XSNS_25 25 + #include TasmotaSerial *SDM630Serial; @@ -325,8 +327,6 @@ void SDM630Show(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_25 - boolean Xsns25(byte function) { boolean result = false; diff --git a/sonoff/xsns_26_lm75ad.ino b/sonoff/xsns_26_lm75ad.ino index 1fd0f4448..ba2f39b16 100644 --- a/sonoff/xsns_26_lm75ad.ino +++ b/sonoff/xsns_26_lm75ad.ino @@ -28,6 +28,8 @@ * I2C Address: 0x48 - 0x4F \*********************************************************************************************/ +#define XSNS_26 26 + #define LM75AD_ADDRESS1 0x48 #define LM75AD_ADDRESS2 0x49 #define LM75AD_ADDRESS3 0x4A @@ -101,8 +103,6 @@ void LM75ADShow(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_26 - boolean Xsns26(byte function) { boolean result = false; diff --git a/sonoff/xsns_27_apds9960.ino b/sonoff/xsns_27_apds9960.ino index d2e5dbc8b..1b99e4304 100644 --- a/sonoff/xsns_27_apds9960.ino +++ b/sonoff/xsns_27_apds9960.ino @@ -27,9 +27,6 @@ #ifdef USE_I2C #ifdef USE_APDS9960 - -#define XSNS_27 27 - /*********************************************************************************************\ * APDS9960 - Digital Proximity Ambient Light RGB and Gesture Sensor * @@ -39,6 +36,8 @@ * I2C Address: 0x39 \*********************************************************************************************/ +#define XSNS_27 27 + #if defined(USE_SHT) || defined(USE_VEML6070) || defined(USE_TSL2561) #warning **** Turned off conflicting drivers SHT and VEML6070 **** #ifdef USE_SHT diff --git a/sonoff/xsns_28_tm1638.ino b/sonoff/xsns_28_tm1638.ino index a81344880..7dd62d2b5 100644 --- a/sonoff/xsns_28_tm1638.ino +++ b/sonoff/xsns_28_tm1638.ino @@ -24,6 +24,8 @@ * Uses GPIO TM16 DIO, TM16 CLK and TM16 STB \*********************************************************************************************/ +#define XSNS_28 28 + #define TM1638_COLOR_NONE 0 #define TM1638_COLOR_RED 1 #define TM1638_COLOR_GREEN 2 @@ -196,8 +198,6 @@ void TmShow(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_28 - boolean Xsns28(byte function) { boolean result = false; diff --git a/sonoff/xsns_29_mcp230xx.ino b/sonoff/xsns_29_mcp230xx.ino index 9dbaf406a..867fa54ec 100644 --- a/sonoff/xsns_29_mcp230xx.ino +++ b/sonoff/xsns_29_mcp230xx.ino @@ -19,7 +19,6 @@ #ifdef USE_I2C #ifdef USE_MCP230xx - /*********************************************************************************************\ MCP23008/17 - I2C GPIO EXPANDER diff --git a/sonoff/xsns_30_mpr121.ino b/sonoff/xsns_30_mpr121.ino index 86191c079..4021247a6 100644 --- a/sonoff/xsns_30_mpr121.ino +++ b/sonoff/xsns_30_mpr121.ino @@ -43,6 +43,12 @@ #ifdef USE_I2C #ifdef USE_MPR121 +/** + * @ingroup group1 + * Assign Tasmota sensor model ID + */ +#define XSNS_30 30 + /** @defgroup group1 MPR121 * MPR121 preprocessor directives * @{ @@ -384,12 +390,6 @@ void Mpr121Show(struct mpr121 *pS, byte function) * Interface \*********************************************************************************************/ -/** - * @ingroup group1 - * Assign Tasmota sensor model ID - */ -#define XSNS_30 - /** * The function Xsns30() interfaces Tasmota with the driver. * diff --git a/sonoff/xsns_31_ccs811.ino b/sonoff/xsns_31_ccs811.ino index d57c9cb06..93bda1a4f 100644 --- a/sonoff/xsns_31_ccs811.ino +++ b/sonoff/xsns_31_ccs811.ino @@ -27,6 +27,8 @@ * I2C Address: 0x5A assumes ADDR connected to Gnd, Wake also must be grounded \*********************************************************************************************/ +#define XSNS_31 31 + #include "Adafruit_CCS811.h" Adafruit_CCS811 ccs; @@ -101,8 +103,6 @@ void CCS811Show(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_31 - boolean Xsns31(byte function) { boolean result = false; diff --git a/sonoff/xsns_32_mpu6050.ino b/sonoff/xsns_32_mpu6050.ino index 58ac705a3..c41549775 100644 --- a/sonoff/xsns_32_mpu6050.ino +++ b/sonoff/xsns_32_mpu6050.ino @@ -1,5 +1,5 @@ /* - xsns_32_MPU_6050.ino - MPU_6050 gyroscope and temperature sensor support for Sonoff-Tasmota + xsns_32_mpu6050.ino - MPU6050 gyroscope and temperature sensor support for Sonoff-Tasmota Copyright (C) 2018 Oliver Welter @@ -20,14 +20,16 @@ #ifdef USE_I2C #ifdef USE_MPU6050 /*********************************************************************************************\ - * MPU_6050 3 axis gyroscope and temperature sensor + * MPU6050 3 axis gyroscope and temperature sensor * * Source: Oliver Welter, with special thanks to Jeff Rowberg * * I2C Address: 0x68 or 0x69 with AD0 HIGH \*********************************************************************************************/ -#define D_SENSOR_MPU6050 "MPU6050" +#define XSNS_32 32 + +#define D_SENSOR_MPU6050 "MPU6050" #define MPU_6050_ADDR_AD0_LOW 0x68 #define MPU_6050_ADDR_AD0_HIGH 0x69 @@ -173,8 +175,6 @@ void MPU_6050Show(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_32 - boolean Xsns32(byte function) { boolean result = false; diff --git a/sonoff/xsns_33_ds3231.ino b/sonoff/xsns_33_ds3231.ino index df18c73db..bc5c4ba3b 100644 --- a/sonoff/xsns_33_ds3231.ino +++ b/sonoff/xsns_33_ds3231.ino @@ -32,9 +32,11 @@ I2C Address: 0x68 \*********************************************************************************************/ +#define XSNS_33 33 + //DS3232 I2C Address #ifndef USE_RTC_ADDR - #define USE_RTC_ADDR 0x68 +#define USE_RTC_ADDR 0x68 #endif //DS3232 Register Addresses @@ -134,8 +136,6 @@ void SetDS3231Time (uint32_t epoch_time) { Interface \*********************************************************************************************/ -#define XSNS_33 - boolean Xsns33(byte function) { boolean result = false; diff --git a/sonoff/xsns_35_tx20.ino b/sonoff/xsns_35_tx20.ino index d87c6de25..91a80ba81 100644 --- a/sonoff/xsns_35_tx20.ino +++ b/sonoff/xsns_35_tx20.ino @@ -26,6 +26,8 @@ * https://www.john.geek.nz/2011/07/la-crosse-tx20-anemometer-communication-protocol/ \*********************************************************************************************/ +#define XSNS_35 35 + #define TX20_BIT_TIME 1220 // microseconds #define TX20_RESET_VALUES 60 // seconds @@ -194,8 +196,6 @@ void Tx20Show(boolean json) * Interface \*********************************************************************************************/ -#define XSNS_35 - boolean Xsns35(byte function) { boolean result = false; diff --git a/sonoff/xsns_interface.ino b/sonoff/xsns_interface.ino index a51ab5947..522ef7665 100644 --- a/sonoff/xsns_interface.ino +++ b/sonoff/xsns_interface.ino @@ -260,19 +260,296 @@ boolean (* const xsns_func_ptr[])(byte) PROGMEM = { // Sensor Function Pointers const uint8_t xsns_present = sizeof(xsns_func_ptr) / sizeof(xsns_func_ptr[0]); // Number of External Sensors found uint8_t xsns_index = 0; +const uint8_t kXsnsList[] PROGMEM = { +#ifdef XSNS_01 + XSNS_01, +#endif + +#ifdef XSNS_02 + XSNS_02, +#endif + +#ifdef XSNS_03 + XSNS_03, +#endif + +#ifdef XSNS_04 + XSNS_04, +#endif + +#ifdef XSNS_05 + XSNS_05, +#endif + +#ifdef XSNS_06 + XSNS_06, +#endif + +#ifdef XSNS_07 + XSNS_07, +#endif + +#ifdef XSNS_08 + XSNS_08, +#endif + +#ifdef XSNS_09 + XSNS_09, +#endif + +#ifdef XSNS_10 + XSNS_10, +#endif + +#ifdef XSNS_11 + XSNS_11, +#endif + +#ifdef XSNS_12 + XSNS_12, +#endif + +#ifdef XSNS_13 + XSNS_13, +#endif + +#ifdef XSNS_14 + XSNS_14, +#endif + +#ifdef XSNS_15 + XSNS_15, +#endif + +#ifdef XSNS_16 + XSNS_16, +#endif + +#ifdef XSNS_17 + XSNS_17, +#endif + +#ifdef XSNS_18 + XSNS_18, +#endif + +#ifdef XSNS_19 + XSNS_19, +#endif + +#ifdef XSNS_20 + XSNS_20, +#endif + +#ifdef XSNS_21 + XSNS_21, +#endif + +#ifdef XSNS_22 + XSNS_22, +#endif + +#ifdef XSNS_23 + XSNS_23, +#endif + +#ifdef XSNS_24 + XSNS_24, +#endif + +#ifdef XSNS_25 + XSNS_25, +#endif + +#ifdef XSNS_26 + XSNS_26, +#endif + +#ifdef XSNS_27 + XSNS_27, +#endif + +#ifdef XSNS_28 + XSNS_28, +#endif + +#ifdef XSNS_29 + XSNS_29, +#endif + +#ifdef XSNS_30 + XSNS_30, +#endif + +#ifdef XSNS_31 + XSNS_31, +#endif + +#ifdef XSNS_32 + XSNS_32, +#endif + +#ifdef XSNS_33 + XSNS_33, +#endif + +#ifdef XSNS_34 + XSNS_34, +#endif + +#ifdef XSNS_35 + XSNS_35, +#endif + +#ifdef XSNS_36 + XSNS_36, +#endif + +#ifdef XSNS_37 + XSNS_37, +#endif + +#ifdef XSNS_38 + XSNS_38, +#endif + +#ifdef XSNS_39 + XSNS_39, +#endif + +#ifdef XSNS_40 + XSNS_40, +#endif + +#ifdef XSNS_41 + XSNS_41, +#endif + +#ifdef XSNS_42 + XSNS_42, +#endif + +#ifdef XSNS_43 + XSNS_43, +#endif + +#ifdef XSNS_44 + XSNS_44, +#endif + +#ifdef XSNS_45 + XSNS_45, +#endif + +#ifdef XSNS_46 + XSNS_46, +#endif + +#ifdef XSNS_47 + XSNS_47, +#endif + +#ifdef XSNS_48 + XSNS_48, +#endif + +#ifdef XSNS_49 + XSNS_49, +#endif + +#ifdef XSNS_50 + XSNS_50, +#endif + +// Optional user defined sensors in range 91 - 99 + +#ifdef XSNS_91 + XSNS_91, +#endif + +#ifdef XSNS_92 + XSNS_92, +#endif + +#ifdef XSNS_93 + XSNS_93, +#endif + +#ifdef XSNS_94 + XSNS_94, +#endif + +#ifdef XSNS_95 + XSNS_95, +#endif + +#ifdef XSNS_96 + XSNS_96, +#endif + +#ifdef XSNS_97 + XSNS_97, +#endif + +#ifdef XSNS_98 + XSNS_98, +#endif + +#ifdef XSNS_99 + XSNS_99 +#endif +}; + + /*********************************************************************************************\ * Function call to all xsns \*********************************************************************************************/ -uint8_t XsnsPresent() +boolean XsnsEnabled(byte sns_index) { - return xsns_present; + if (sns_index < sizeof(kXsnsList)) { + uint8_t index = pgm_read_byte(kXsnsList + sns_index); + return bitRead(Settings.sensors[index / 32], index % 32); + } + return 1; +} + +boolean XsnsPresent(byte sns_index) +{ + uint8_t index = 0; + for (byte i = 0; i < sizeof(kXsnsList); i++) { + index = pgm_read_byte(kXsnsList + i); + if (index == sns_index) { return true; } + } + return false; +} + +String XsnsGetSensors() +{ + char state[2] = { 0 }; + + String data = F("["); + for (byte i = 0; i < MAX_XSNS_DRIVERS; i++) { + if (i && (!(i % 10))) { data += F(","); } + if (!(i % 10)) { data += F("\""); } + state[0] = '-'; + if (XsnsPresent(i)) { state[0] = bitRead(Settings.sensors[i / 32], i % 32) ? '1' : '0'; } + data += String(state); + if (i && (!((i +1) % 10))) { data += F("\""); } + } + data += F("]"); + + return data; } boolean XsnsNextCall(byte Function) { xsns_index++; - if (xsns_index == xsns_present) xsns_index = 0; + if (xsns_index == xsns_present) { xsns_index = 0; } + while (!XsnsEnabled(xsns_index) && !xsns_index) { // Perform at least first sensor (counter) + xsns_index++; + if (xsns_index == xsns_present) { xsns_index = 0; } + } if (global_state.wifi_down) { delay(DRIVER_BOOT_DELAY); } return xsns_func_ptr[xsns_index](Function); } @@ -286,24 +563,26 @@ boolean XsnsCall(byte Function) #endif // PROFILE_XSNS_EVERY_SECOND for (byte x = 0; x < xsns_present; x++) { + if (XsnsEnabled(x)) { #ifdef PROFILE_XSNS_SENSOR_EVERY_SECOND - uint32_t profile_start_millis = millis(); + uint32_t profile_start_millis = millis(); #endif // PROFILE_XSNS_SENSOR_EVERY_SECOND - if (global_state.wifi_down) { delay(DRIVER_BOOT_DELAY); } - result = xsns_func_ptr[x](Function); + if (global_state.wifi_down) { delay(DRIVER_BOOT_DELAY); } + result = xsns_func_ptr[x](Function); #ifdef PROFILE_XSNS_SENSOR_EVERY_SECOND - uint32_t profile_millis = millis() - profile_start_millis; - if (profile_millis) { - if (FUNC_EVERY_SECOND == Function) { - snprintf_P(log_data, sizeof(log_data), PSTR("PRF: At %08u XsnsCall %d to Sensor %d took %u mS"), uptime, Function, x, profile_millis); - AddLog(LOG_LEVEL_DEBUG); + uint32_t profile_millis = millis() - profile_start_millis; + if (profile_millis) { + if (FUNC_EVERY_SECOND == Function) { + snprintf_P(log_data, sizeof(log_data), PSTR("PRF: At %08u XsnsCall %d to Sensor %d took %u mS"), uptime, Function, x, profile_millis); + AddLog(LOG_LEVEL_DEBUG); + } } - } #endif // PROFILE_XSNS_SENSOR_EVERY_SECOND - if (result) break; + if (result) break; + } } #ifdef PROFILE_XSNS_EVERY_SECOND