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.

219 lines
5.0 KiB

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