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.

194 lines
4.4 KiB

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