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.

192 lines
4.4 KiB

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