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.

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