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.

205 lines
4.7 KiB

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