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.

208 lines
4.8 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
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 ENCODER_SUPPORT && (LIGHT_PROVIDER != LIGHT_PROVIDER_NONE)
  91. encoderSetup();
  92. #endif
  93. #if LED_SUPPORT
  94. ledSetup();
  95. #endif
  96. #if MQTT_SUPPORT
  97. mqttSetup();
  98. #endif
  99. #if MDNS_SERVER_SUPPORT
  100. mdnsServerSetup();
  101. #endif
  102. #if MDNS_CLIENT_SUPPORT
  103. mdnsClientSetup();
  104. #endif
  105. #if LLMNR_SUPPORT
  106. llmnrSetup();
  107. #endif
  108. #if NETBIOS_SUPPORT
  109. netbiosSetup();
  110. #endif
  111. #if SSDP_SUPPORT
  112. ssdpSetup();
  113. #endif
  114. #if NTP_SUPPORT
  115. ntpSetup();
  116. #endif
  117. #if I2C_SUPPORT
  118. i2cSetup();
  119. #endif
  120. #ifdef ITEAD_SONOFF_RFBRIDGE
  121. rfbSetup();
  122. #endif
  123. #if ALEXA_SUPPORT
  124. alexaSetup();
  125. #endif
  126. #if NOFUSS_SUPPORT
  127. nofussSetup();
  128. #endif
  129. #if INFLUXDB_SUPPORT
  130. idbSetup();
  131. #endif
  132. #if THINGSPEAK_SUPPORT
  133. tspkSetup();
  134. #endif
  135. #if RFM69_SUPPORT
  136. rfm69Setup();
  137. #endif
  138. #if RF_SUPPORT
  139. rfSetup();
  140. #endif
  141. #if IR_SUPPORT
  142. irSetup();
  143. #endif
  144. #if DOMOTICZ_SUPPORT
  145. domoticzSetup();
  146. #endif
  147. #if HOMEASSISTANT_SUPPORT
  148. haSetup();
  149. #endif
  150. #if SENSOR_SUPPORT
  151. sensorSetup();
  152. #endif
  153. #if SCHEDULER_SUPPORT
  154. schSetup();
  155. #endif
  156. #if UART_MQTT_SUPPORT
  157. uartmqttSetup();
  158. #endif
  159. // 3rd party code hook
  160. #if USE_EXTRA
  161. extraSetup();
  162. #endif
  163. // Prepare configuration for version 2.0
  164. migrate();
  165. saveSettings();
  166. }
  167. void loop() {
  168. // Call registered loop callbacks
  169. for (unsigned char i = 0; i < _loop_callbacks.size(); i++) {
  170. (_loop_callbacks[i])();
  171. }
  172. }