Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
4.8 KiB

6 years ago
6 years ago
6 years ago
8 years ago
6 years ago
8 years ago
7 years ago
6 years ago
6 years ago
6 years ago
6 years ago
8 years ago
6 years ago
8 years ago
6 years ago
6 years ago
6 years ago
  1. /*
  2. ESPurna
  3. Copyright (C) 2016-2018 by Xose Pérez <xose dot perez at gmail dot com>
  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. Module key prefix: esp (shared with others)
  15. */
  16. #include "config/all.h"
  17. #include <vector>
  18. std::vector<void (*)()> _loop_callbacks;
  19. std::vector<void (*)()> _reload_callbacks;
  20. // -----------------------------------------------------------------------------
  21. // GENERAL CALLBACKS
  22. // -----------------------------------------------------------------------------
  23. void espurnaRegisterLoop(void (*callback)()) {
  24. _loop_callbacks.push_back(callback);
  25. }
  26. void espurnaRegisterReload(void (*callback)()) {
  27. _reload_callbacks.push_back(callback);
  28. }
  29. void espurnaReload() {
  30. for (unsigned char i = 0; i < _reload_callbacks.size(); i++) {
  31. (_reload_callbacks[i])();
  32. }
  33. }
  34. // -----------------------------------------------------------------------------
  35. // BOOTING
  36. // -----------------------------------------------------------------------------
  37. void setup() {
  38. // -------------------------------------------------------------------------
  39. // Basic modules, will always run
  40. // -------------------------------------------------------------------------
  41. // Init EEPROM
  42. eepromSetup();
  43. // Init persistance and terminal features
  44. settingsSetup();
  45. // Cache initial free heap value
  46. getInitialFreeHeap();
  47. // Serial debug
  48. // Requires SETTINGS
  49. #if DEBUG_SUPPORT
  50. debugSetup();
  51. #endif
  52. // Load devices data
  53. // Requires SETTINGS
  54. deviceSetup();
  55. // Init Serial, SPIFFS and system check
  56. // Requires EEPROM and DEBUG
  57. systemSetup();
  58. // Show welcome message and system configuration
  59. info();
  60. wifiSetup();
  61. otaSetup();
  62. #if TELNET_SUPPORT
  63. telnetSetup();
  64. #endif
  65. // -------------------------------------------------------------------------
  66. // Check if system is stable
  67. // -------------------------------------------------------------------------
  68. #if SYSTEM_CHECK_ENABLED
  69. if (!systemCheck()) return;
  70. #endif
  71. // -------------------------------------------------------------------------
  72. // Next modules will be only loaded if system is flagged as stable
  73. // -------------------------------------------------------------------------
  74. // Init webserver required before any module that uses API
  75. #if WEB_SUPPORT
  76. webSetup();
  77. wsSetup();
  78. #if DEBUG_WEB_SUPPORT
  79. debugWebSetup();
  80. #endif
  81. #endif
  82. #if API_SUPPORT
  83. apiSetup();
  84. #endif
  85. // lightSetup must be called before relaySetup
  86. #if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
  87. lightSetup();
  88. #endif
  89. relaySetup();
  90. #if BUTTON_SUPPORT
  91. buttonSetup();
  92. #endif
  93. #if ENCODER_SUPPORT && (LIGHT_PROVIDER != LIGHT_PROVIDER_NONE)
  94. encoderSetup();
  95. #endif
  96. #if LED_SUPPORT
  97. ledSetup();
  98. #endif
  99. #if MQTT_SUPPORT
  100. mqttSetup();
  101. #endif
  102. #if MDNS_SERVER_SUPPORT
  103. mdnsServerSetup();
  104. #endif
  105. #if MDNS_CLIENT_SUPPORT
  106. mdnsClientSetup();
  107. #endif
  108. #if LLMNR_SUPPORT
  109. llmnrSetup();
  110. #endif
  111. #if NETBIOS_SUPPORT
  112. netbiosSetup();
  113. #endif
  114. #if SSDP_SUPPORT
  115. ssdpSetup();
  116. #endif
  117. #if NTP_SUPPORT
  118. ntpSetup();
  119. #endif
  120. #if I2C_SUPPORT
  121. i2cSetup();
  122. #endif
  123. #ifdef ITEAD_SONOFF_RFBRIDGE
  124. rfbSetup();
  125. #endif
  126. #if ALEXA_SUPPORT
  127. alexaSetup();
  128. #endif
  129. #if NOFUSS_SUPPORT
  130. nofussSetup();
  131. #endif
  132. #if INFLUXDB_SUPPORT
  133. idbSetup();
  134. #endif
  135. #if THINGSPEAK_SUPPORT
  136. tspkSetup();
  137. #endif
  138. #if RFM69_SUPPORT
  139. rfm69Setup();
  140. #endif
  141. #if RF_SUPPORT
  142. rfSetup();
  143. #endif
  144. #if IR_SUPPORT
  145. irSetup();
  146. #endif
  147. #if DOMOTICZ_SUPPORT
  148. domoticzSetup();
  149. #endif
  150. #if HOMEASSISTANT_SUPPORT
  151. haSetup();
  152. #endif
  153. #if SENSOR_SUPPORT
  154. sensorSetup();
  155. #endif
  156. #if SCHEDULER_SUPPORT
  157. schSetup();
  158. #endif
  159. #if UART_MQTT_SUPPORT
  160. uartmqttSetup();
  161. #endif
  162. // 3rd party code hook
  163. #if USE_EXTRA
  164. extraSetup();
  165. #endif
  166. saveSettings();
  167. }
  168. void loop() {
  169. // Call registered loop callbacks
  170. for (unsigned char i = 0; i < _loop_callbacks.size(); i++) {
  171. (_loop_callbacks[i])();
  172. }
  173. }