2018-01-05 11:26:19 +00:00
|
|
|
/*
|
|
|
|
xdrv_interface.ino - Driver 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/>.
|
|
|
|
*/
|
|
|
|
|
2018-01-24 16:31:20 +00:00
|
|
|
boolean (* const xdrv_func_ptr[])(byte) PROGMEM = { // Driver Function Pointers
|
2018-01-05 11:26:19 +00:00
|
|
|
#ifdef XDRV_01
|
2018-01-24 16:31:20 +00:00
|
|
|
&Xdrv01,
|
2018-01-05 11:26:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_02
|
2018-01-24 16:31:20 +00:00
|
|
|
&Xdrv02,
|
2018-01-05 11:26:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_03
|
2018-01-24 16:31:20 +00:00
|
|
|
&Xdrv03,
|
2018-01-05 11:26:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_04
|
2018-01-24 16:31:20 +00:00
|
|
|
&Xdrv04,
|
2018-01-05 11:26:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_05
|
2018-01-24 16:31:20 +00:00
|
|
|
&Xdrv05,
|
2018-01-05 11:26:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_06
|
2018-01-24 16:31:20 +00:00
|
|
|
&Xdrv06,
|
2018-01-05 11:26:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_07
|
2018-01-24 16:31:20 +00:00
|
|
|
&Xdrv07,
|
2018-01-05 11:26:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_08
|
2018-01-24 16:31:20 +00:00
|
|
|
&Xdrv08,
|
2018-01-05 11:26:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_09
|
2018-01-24 16:31:20 +00:00
|
|
|
&Xdrv09,
|
2018-01-05 11:26:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_10
|
2018-01-24 16:31:20 +00:00
|
|
|
&Xdrv10,
|
2018-01-05 11:26:19 +00:00
|
|
|
#endif
|
2018-02-08 14:20:03 +00:00
|
|
|
|
|
|
|
#ifdef XDRV_11
|
|
|
|
&Xdrv11,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_12
|
|
|
|
&Xdrv12,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_13
|
|
|
|
&Xdrv13,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_14
|
|
|
|
&Xdrv14,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_15
|
|
|
|
&Xdrv15,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_16
|
|
|
|
&Xdrv16,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_17
|
|
|
|
&Xdrv17,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_18
|
|
|
|
&Xdrv18,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_19
|
|
|
|
&Xdrv19,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_20
|
|
|
|
&Xdrv20,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Optional user defined drivers in range 91 - 99
|
|
|
|
|
|
|
|
#ifdef XDRV_91
|
|
|
|
&Xdrv91,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_92
|
|
|
|
&Xdrv92,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_93
|
|
|
|
&Xdrv93,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_94
|
|
|
|
&Xdrv94,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_95
|
|
|
|
&Xdrv95,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_96
|
|
|
|
&Xdrv96,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_97
|
|
|
|
&Xdrv97,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_98
|
|
|
|
&Xdrv98,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XDRV_99
|
|
|
|
&Xdrv99
|
|
|
|
#endif
|
2018-01-24 16:31:20 +00:00
|
|
|
};
|
2018-01-05 11:26:19 +00:00
|
|
|
|
2018-01-24 16:31:20 +00:00
|
|
|
const uint8_t xdrv_present = sizeof(xdrv_func_ptr) / sizeof(xdrv_func_ptr[0]); // Number of drivers found
|
2018-01-05 11:26:19 +00:00
|
|
|
|
2018-02-27 13:59:46 +00:00
|
|
|
boolean XdrvCommand(uint8_t grpflg, char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload, uint16_t payload16)
|
2018-01-05 11:26:19 +00:00
|
|
|
{
|
|
|
|
// XdrvMailbox.valid = 1;
|
|
|
|
XdrvMailbox.index = index;
|
|
|
|
XdrvMailbox.data_len = data_len;
|
2018-02-27 13:59:46 +00:00
|
|
|
XdrvMailbox.payload16 = payload16;
|
2018-01-05 11:26:19 +00:00
|
|
|
XdrvMailbox.payload = payload;
|
2018-02-27 13:59:46 +00:00
|
|
|
XdrvMailbox.grpflg = grpflg;
|
2018-01-05 11:26:19 +00:00
|
|
|
XdrvMailbox.topic = type;
|
|
|
|
XdrvMailbox.data = dataBuf;
|
|
|
|
|
|
|
|
return XdrvCall(FUNC_COMMAND);
|
|
|
|
}
|
|
|
|
|
2018-01-20 11:12:39 +00:00
|
|
|
void XdrvSetPower(power_t mpower)
|
2018-01-05 11:26:19 +00:00
|
|
|
{
|
|
|
|
// XdrvMailbox.valid = 1;
|
|
|
|
XdrvMailbox.index = mpower;
|
|
|
|
|
|
|
|
XdrvCall(FUNC_SET_POWER);
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean XdrvMqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uint16_t sdataBuf)
|
|
|
|
{
|
|
|
|
XdrvMailbox.index = stopicBuf;
|
|
|
|
XdrvMailbox.data_len = sdataBuf;
|
|
|
|
XdrvMailbox.topic = topicBuf;
|
|
|
|
XdrvMailbox.data = dataBuf;
|
|
|
|
|
|
|
|
return XdrvCall(FUNC_MQTT_DATA);
|
|
|
|
}
|
|
|
|
|
2018-05-24 15:23:20 +01:00
|
|
|
boolean XdrvRulesProcess()
|
|
|
|
{
|
|
|
|
return XdrvCall(FUNC_RULES_PROCESS);
|
|
|
|
}
|
|
|
|
|
2018-01-05 11:26:19 +00:00
|
|
|
/*********************************************************************************************\
|
|
|
|
* Function call to all xdrv
|
2018-01-20 11:12:39 +00:00
|
|
|
*
|
2018-06-04 17:10:38 +01:00
|
|
|
* FUNC_PRE_INIT
|
2018-01-20 11:12:39 +00:00
|
|
|
* FUNC_INIT
|
2018-03-02 14:38:37 +00:00
|
|
|
* FUNC_LOOP
|
2018-01-20 11:12:39 +00:00
|
|
|
* FUNC_MQTT_SUBSCRIBE
|
|
|
|
* FUNC_MQTT_INIT
|
|
|
|
* return FUNC_MQTT_DATA
|
|
|
|
* return FUNC_COMMAND
|
|
|
|
* FUNC_SET_POWER
|
|
|
|
* FUNC_SHOW_SENSOR
|
|
|
|
* FUNC_EVERY_SECOND
|
|
|
|
* FUNC_EVERY_50_MSECOND
|
2018-05-24 15:23:20 +01:00
|
|
|
* FUNC_RULES_PROCESS
|
2018-01-05 11:26:19 +00:00
|
|
|
\*********************************************************************************************/
|
|
|
|
|
|
|
|
boolean XdrvCall(byte Function)
|
|
|
|
{
|
|
|
|
boolean result = false;
|
|
|
|
|
|
|
|
for (byte x = 0; x < xdrv_present; x++) {
|
|
|
|
result = xdrv_func_ptr[x](Function);
|
2018-03-02 14:38:37 +00:00
|
|
|
if (result) break;
|
2018-01-05 11:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|