forked from arendst/Tasmota
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxdrv_interface.ino
215 lines (168 loc) · 3.62 KB
/
xdrv_interface.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
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/>.
*/
boolean (* const xdrv_func_ptr[])(byte) PROGMEM = { // Driver Function Pointers
#ifdef XDRV_01
&Xdrv01,
#endif
#ifdef XDRV_02
&Xdrv02,
#endif
#ifdef XDRV_03
&Xdrv03,
#endif
#ifdef XDRV_04
&Xdrv04,
#endif
#ifdef XDRV_05
&Xdrv05,
#endif
#ifdef XDRV_06
&Xdrv06,
#endif
#ifdef XDRV_07
&Xdrv07,
#endif
#ifdef XDRV_08
&Xdrv08,
#endif
#ifdef XDRV_09
&Xdrv09,
#endif
#ifdef XDRV_10
&Xdrv10,
#endif
#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
};
const uint8_t xdrv_present = sizeof(xdrv_func_ptr) / sizeof(xdrv_func_ptr[0]); // Number of drivers found
boolean XdrvCommand(uint8_t grpflg, char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload, uint16_t payload16)
{
// XdrvMailbox.valid = 1;
XdrvMailbox.index = index;
XdrvMailbox.data_len = data_len;
XdrvMailbox.payload16 = payload16;
XdrvMailbox.payload = payload;
XdrvMailbox.grpflg = grpflg;
XdrvMailbox.topic = type;
XdrvMailbox.data = dataBuf;
return XdrvCall(FUNC_COMMAND);
}
void XdrvSetPower(power_t mpower)
{
// 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);
}
boolean XdrvRulesProcess()
{
return XdrvCall(FUNC_RULES_PROCESS);
}
void ShowFreeMem(const char *where)
{
char stemp[20];
snprintf_P(stemp, sizeof(stemp), where);
XdrvMailbox.data = stemp;
XdrvCall(FUNC_FREE_MEM);
}
/*********************************************************************************************\
* Function call to all xdrv
*
* FUNC_PRE_INIT
* FUNC_INIT
* FUNC_LOOP
* 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
* FUNC_RULES_PROCESS
* FUNC_FREE_MEM
\*********************************************************************************************/
boolean XdrvCall(byte Function)
{
boolean result = false;
for (byte x = 0; x < xdrv_present; x++) {
result = xdrv_func_ptr[x](Function);
if (result) break;
}
return result;
}