| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- /*
- xsns_interface.ino - Sensor interface support for Sonoff-Tasmota
- Copyright (C) 2018 Theo Arends inspired by ESPEasy
- 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 <http://www.gnu.org/licenses/>.
- */
- #ifdef XFUNC_PTR_IN_ROM
- boolean (* const xsns_func_ptr[])(byte) PROGMEM = { // Sensor Function Pointers for simple implementation of sensors
- #else
- boolean (* const xsns_func_ptr[])(byte) = { // Sensor Function Pointers for simple implementation of sensors
- #endif
- #ifdef XSNS_01
- &Xsns01,
- #endif
- #ifdef XSNS_02
- &Xsns02,
- #endif
- #ifdef XSNS_03
- &Xsns03,
- #endif
- #ifdef XSNS_04
- &Xsns04,
- #endif
- #ifdef XSNS_05
- &Xsns05,
- #endif
- #ifdef XSNS_06
- &Xsns06,
- #endif
- #ifdef XSNS_07
- &Xsns07,
- #endif
- #ifdef XSNS_08
- &Xsns08,
- #endif
- #ifdef XSNS_09
- &Xsns09,
- #endif
- #ifdef XSNS_10
- &Xsns10,
- #endif
- #ifdef XSNS_11
- &Xsns11,
- #endif
- #ifdef XSNS_12
- &Xsns12,
- #endif
- #ifdef XSNS_13
- &Xsns13,
- #endif
- #ifdef XSNS_14
- &Xsns14,
- #endif
- #ifdef XSNS_15
- &Xsns15,
- #endif
- #ifdef XSNS_16
- &Xsns16,
- #endif
- #ifdef XSNS_17
- &Xsns17,
- #endif
- #ifdef XSNS_18
- &Xsns18,
- #endif
- #ifdef XSNS_19
- &Xsns19,
- #endif
- #ifdef XSNS_20
- &Xsns20,
- #endif
- #ifdef XSNS_21
- &Xsns21,
- #endif
- #ifdef XSNS_22
- &Xsns22,
- #endif
- #ifdef XSNS_23
- &Xsns23,
- #endif
- #ifdef XSNS_24
- &Xsns24,
- #endif
- #ifdef XSNS_25
- &Xsns25,
- #endif
- #ifdef XSNS_26
- &Xsns26,
- #endif
- #ifdef XSNS_27
- &Xsns27,
- #endif
- #ifdef XSNS_28
- &Xsns28,
- #endif
- #ifdef XSNS_29
- &Xsns29,
- #endif
- #ifdef XSNS_30
- &Xsns30,
- #endif
- #ifdef XSNS_31
- &Xsns31,
- #endif
- #ifdef XSNS_32
- &Xsns32,
- #endif
- #ifdef XSNS_33
- &Xsns33,
- #endif
- #ifdef XSNS_34
- &Xsns34,
- #endif
- #ifdef XSNS_35
- &Xsns35,
- #endif
- #ifdef XSNS_36
- &Xsns36,
- #endif
- #ifdef XSNS_37
- &Xsns37,
- #endif
- #ifdef XSNS_38
- &Xsns38,
- #endif
- #ifdef XSNS_39
- &Xsns39,
- #endif
- #ifdef XSNS_40
- &Xsns40,
- #endif
- #ifdef XSNS_41
- &Xsns41,
- #endif
- #ifdef XSNS_42
- &Xsns42,
- #endif
- #ifdef XSNS_43
- &Xsns43,
- #endif
- #ifdef XSNS_44
- &Xsns44,
- #endif
- #ifdef XSNS_45
- &Xsns45,
- #endif
- #ifdef XSNS_46
- &Xsns46,
- #endif
- #ifdef XSNS_47
- &Xsns47,
- #endif
- #ifdef XSNS_48
- &Xsns48,
- #endif
- #ifdef XSNS_49
- &Xsns49,
- #endif
- #ifdef XSNS_50
- &Xsns50,
- #endif
- // Optional user defined sensors in range 91 - 99
- #ifdef XSNS_91
- &Xsns91,
- #endif
- #ifdef XSNS_92
- &Xsns92,
- #endif
- #ifdef XSNS_93
- &Xsns93,
- #endif
- #ifdef XSNS_94
- &Xsns94,
- #endif
- #ifdef XSNS_95
- &Xsns95,
- #endif
- #ifdef XSNS_96
- &Xsns96,
- #endif
- #ifdef XSNS_97
- &Xsns97,
- #endif
- #ifdef XSNS_98
- &Xsns98,
- #endif
- #ifdef XSNS_99
- &Xsns99
- #endif
- };
- const uint8_t xsns_present = sizeof(xsns_func_ptr) / sizeof(xsns_func_ptr[0]); // Number of External Sensors found
- /*********************************************************************************************\
- * Function call to all xsns
- \*********************************************************************************************/
- boolean XsnsNextCall(byte Function, uint8_t &xsns_index)
- {
- xsns_index++;
- if (xsns_index == xsns_present) { xsns_index = 0; }
- #ifdef USE_DEBUG_DRIVER
- while (!XsnsEnabled(xsns_index) && !xsns_index) { // Perform at least first sensor (counter)
- xsns_index++;
- if (xsns_index == xsns_present) { xsns_index = 0; }
- }
- #endif
- // WifiAddDelayWhenDisconnected();
- return xsns_func_ptr[xsns_index](Function);
- }
- boolean XsnsCall(byte Function)
- {
- boolean result = false;
- #ifdef PROFILE_XSNS_EVERY_SECOND
- uint32_t profile_start_millis = millis();
- #endif // PROFILE_XSNS_EVERY_SECOND
- for (byte x = 0; x < xsns_present; x++) {
- #ifdef USE_DEBUG_DRIVER
- if (XsnsEnabled(x)) {
- #endif
- #ifdef PROFILE_XSNS_SENSOR_EVERY_SECOND
- uint32_t profile_start_millis = millis();
- #endif // PROFILE_XSNS_SENSOR_EVERY_SECOND
- // WifiAddDelayWhenDisconnected();
- 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);
- }
- }
- #endif // PROFILE_XSNS_SENSOR_EVERY_SECOND
- if (result) break;
- #ifdef USE_DEBUG_DRIVER
- }
- #endif
- }
- #ifdef PROFILE_XSNS_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 took %u mS"), uptime, Function, profile_millis);
- AddLog(LOG_LEVEL_DEBUG);
- }
- }
- #endif // PROFILE_XSNS_EVERY_SECOND
- return result;
- }
|