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.

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