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.

168 lines
4.0 KiB

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