xdrv_interface.ino 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. xdrv_interface.ino - Driver interface support for Sonoff-Tasmota
  3. Copyright (C) 2018 Theo Arends inspired by ESPEasy
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #ifdef XFUNC_PTR_IN_ROM
  16. boolean (* const xdrv_func_ptr[])(byte) PROGMEM = { // Driver Function Pointers
  17. #else
  18. boolean (* const xdrv_func_ptr[])(byte) = { // Driver Function Pointers
  19. #endif
  20. #ifdef XDRV_01
  21. &Xdrv01,
  22. #endif
  23. #ifdef XDRV_02
  24. &Xdrv02,
  25. #endif
  26. #ifdef XDRV_03
  27. &Xdrv03,
  28. #endif
  29. #ifdef XDRV_04
  30. &Xdrv04,
  31. #endif
  32. #ifdef XDRV_05
  33. &Xdrv05,
  34. #endif
  35. #ifdef XDRV_06
  36. &Xdrv06,
  37. #endif
  38. #ifdef XDRV_07
  39. &Xdrv07,
  40. #endif
  41. #ifdef XDRV_08
  42. &Xdrv08,
  43. #endif
  44. #ifdef XDRV_09
  45. &Xdrv09,
  46. #endif
  47. #ifdef XDRV_10
  48. &Xdrv10,
  49. #endif
  50. #ifdef XDRV_11
  51. &Xdrv11,
  52. #endif
  53. #ifdef XDRV_12
  54. &Xdrv12,
  55. #endif
  56. #ifdef XDRV_13
  57. &Xdrv13,
  58. #endif
  59. #ifdef XDRV_14
  60. &Xdrv14,
  61. #endif
  62. #ifdef XDRV_15
  63. &Xdrv15,
  64. #endif
  65. #ifdef XDRV_16
  66. &Xdrv16,
  67. #endif
  68. #ifdef XDRV_17
  69. &Xdrv17,
  70. #endif
  71. #ifdef XDRV_18
  72. &Xdrv18,
  73. #endif
  74. #ifdef XDRV_19
  75. &Xdrv19,
  76. #endif
  77. #ifdef XDRV_20
  78. &Xdrv20,
  79. #endif
  80. #ifdef XDRV_21
  81. &Xdrv21,
  82. #endif
  83. #ifdef XDRV_22
  84. &Xdrv22,
  85. #endif
  86. #ifdef XDRV_23
  87. &Xdrv23,
  88. #endif
  89. #ifdef XDRV_24
  90. &Xdrv24,
  91. #endif
  92. #ifdef XDRV_25
  93. &Xdrv25,
  94. #endif
  95. #ifdef XDRV_26
  96. &Xdrv26,
  97. #endif
  98. #ifdef XDRV_27
  99. &Xdrv27,
  100. #endif
  101. #ifdef XDRV_28
  102. &Xdrv28,
  103. #endif
  104. #ifdef XDRV_29
  105. &Xdrv29,
  106. #endif
  107. #ifdef XDRV_30
  108. &Xdrv30,
  109. #endif
  110. #ifdef XDRV_31
  111. &Xdrv31,
  112. #endif
  113. #ifdef XDRV_32
  114. &Xdrv32,
  115. #endif
  116. // Optional user defined drivers in range 91 - 99
  117. #ifdef XDRV_91
  118. &Xdrv91,
  119. #endif
  120. #ifdef XDRV_92
  121. &Xdrv92,
  122. #endif
  123. #ifdef XDRV_93
  124. &Xdrv93,
  125. #endif
  126. #ifdef XDRV_94
  127. &Xdrv94,
  128. #endif
  129. #ifdef XDRV_95
  130. &Xdrv95,
  131. #endif
  132. #ifdef XDRV_96
  133. &Xdrv96,
  134. #endif
  135. #ifdef XDRV_97
  136. &Xdrv97,
  137. #endif
  138. #ifdef XDRV_98
  139. &Xdrv98,
  140. #endif
  141. #ifdef XDRV_99
  142. &Xdrv99
  143. #endif
  144. };
  145. const uint8_t xdrv_present = sizeof(xdrv_func_ptr) / sizeof(xdrv_func_ptr[0]); // Number of drivers found
  146. boolean XdrvCommand(uint8_t grpflg, char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload, uint16_t payload16)
  147. {
  148. // XdrvMailbox.valid = 1;
  149. XdrvMailbox.index = index;
  150. XdrvMailbox.data_len = data_len;
  151. XdrvMailbox.payload16 = payload16;
  152. XdrvMailbox.payload = payload;
  153. XdrvMailbox.grpflg = grpflg;
  154. XdrvMailbox.topic = type;
  155. XdrvMailbox.data = dataBuf;
  156. return XdrvCall(FUNC_COMMAND);
  157. }
  158. boolean XdrvMqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uint16_t sdataBuf)
  159. {
  160. XdrvMailbox.index = stopicBuf;
  161. XdrvMailbox.data_len = sdataBuf;
  162. XdrvMailbox.topic = topicBuf;
  163. XdrvMailbox.data = dataBuf;
  164. return XdrvCall(FUNC_MQTT_DATA);
  165. }
  166. boolean XdrvRulesProcess(void)
  167. {
  168. return XdrvCall(FUNC_RULES_PROCESS);
  169. }
  170. void ShowFreeMem(const char *where)
  171. {
  172. char stemp[20];
  173. snprintf_P(stemp, sizeof(stemp), where);
  174. XdrvMailbox.data = stemp;
  175. XdrvCall(FUNC_FREE_MEM);
  176. }
  177. /*********************************************************************************************\
  178. * Function call to all xdrv
  179. \*********************************************************************************************/
  180. boolean XdrvCall(byte Function)
  181. {
  182. boolean result = false;
  183. for (byte x = 0; x < xdrv_present; x++) {
  184. // WifiAddDelayWhenDisconnected();
  185. result = xdrv_func_ptr[x](Function);
  186. if (result) break;
  187. }
  188. return result;
  189. }