From ea5b6e5c58a814a606a0a57fac3a340cc3294896 Mon Sep 17 00:00:00 2001 From: proddy Date: Mon, 1 Mar 2021 22:21:18 +0100 Subject: [PATCH] remove static functions from System class --- lib/framework/APSettingsService.cpp | 10 +++--- lib/framework/APSettingsService.h | 4 +-- lib/framework/ESP8266React.h | 3 -- lib/framework/MqttSettingsService.cpp | 9 +---- lib/framework/MqttSettingsService.h | 8 ++--- lib/framework/MqttStatus.cpp | 2 ++ lib/framework/MqttStatus.h | 2 -- lib/framework/NetworkStatus.cpp | 4 ++- lib/framework/NetworkStatus.h | 2 +- lib/framework/OTASettingsService.cpp | 6 ++-- lib/framework/OTASettingsService.h | 2 -- lib/framework/SecuritySettingsService.cpp | 2 ++ lib/framework/SecuritySettingsService.h | 2 -- lib/framework/SystemStatus.h | 1 - lib_standalone/SecuritySettingsService.cpp | 2 ++ lib_standalone/SecuritySettingsService.h | 2 -- src/emsesp_stub.hpp | 38 ++++++++++++++++++++++ 17 files changed, 62 insertions(+), 37 deletions(-) create mode 100644 src/emsesp_stub.hpp diff --git a/lib/framework/APSettingsService.cpp b/lib/framework/APSettingsService.cpp index cea52002e..8e460a80c 100644 --- a/lib/framework/APSettingsService.cpp +++ b/lib/framework/APSettingsService.cpp @@ -1,5 +1,7 @@ #include +#include "../../src/emsesp_stub.hpp" // proddy added + APSettingsService::APSettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager) : _httpEndpoint(APSettings::read, APSettings::update, this, server, AP_SETTINGS_SERVICE_PATH, securityManager) , _fsPersistence(APSettings::read, APSettings::update, this, fs, AP_SETTINGS_FILE) @@ -21,7 +23,7 @@ void APSettingsService::reconfigureAP() { void APSettingsService::loop() { // if we have an ETH connection, quit - if (emsesp::System::ethernet_connected()) { + if (emsesp::EMSESP::system_.ethernet_connected()) { return; } unsigned long currentMillis = uuid::get_uptime(); @@ -51,8 +53,8 @@ void APSettingsService::startAP() { WiFi.softAP(_state.ssid.c_str(), _state.password.c_str()); if (!_dnsServer) { IPAddress apIp = WiFi.softAPIP(); - Serial.print(F("Starting captive portal on ")); - Serial.println(apIp); + // Serial.print(F("Starting captive portal on ")); + // Serial.println(apIp); _dnsServer = new DNSServer; _dnsServer->start(DNS_PORT, "*", apIp); } @@ -60,7 +62,7 @@ void APSettingsService::startAP() { void APSettingsService::stopAP() { if (_dnsServer) { - Serial.println(F("Stopping captive portal")); + // Serial.println(F("Stopping captive portal")); _dnsServer->stop(); delete _dnsServer; _dnsServer = nullptr; diff --git a/lib/framework/APSettingsService.h b/lib/framework/APSettingsService.h index 4c3dcd567..e08c7bf92 100644 --- a/lib/framework/APSettingsService.h +++ b/lib/framework/APSettingsService.h @@ -8,9 +8,7 @@ #include #include -#include - -#include "../../src/system.h" // proddy added +#include // proddy added for get_uptime() #define MANAGE_NETWORK_DELAY 10000 diff --git a/lib/framework/ESP8266React.h b/lib/framework/ESP8266React.h index 2abf17d19..0cc007eda 100644 --- a/lib/framework/ESP8266React.h +++ b/lib/framework/ESP8266React.h @@ -5,7 +5,6 @@ #include #include -#include #include #include @@ -25,9 +24,7 @@ #include #include -#ifdef PROGMEM_WWW #include -#endif class ESP8266React { public: diff --git a/lib/framework/MqttSettingsService.cpp b/lib/framework/MqttSettingsService.cpp index 008f882a3..bf1d764dc 100644 --- a/lib/framework/MqttSettingsService.cpp +++ b/lib/framework/MqttSettingsService.cpp @@ -1,13 +1,6 @@ #include -// forward declarators -namespace emsesp { -class EMSESP { - public: - static Mqtt mqtt_; - static DallasSensor dallassensor_; -}; -} // namespace emsesp +#include "../../src/emsesp_stub.hpp" // proddy added /** * Retains a copy of the cstr provided in the pointer provided using dynamic allocation. diff --git a/lib/framework/MqttSettingsService.h b/lib/framework/MqttSettingsService.h index be48248f7..2b7eb5cf4 100644 --- a/lib/framework/MqttSettingsService.h +++ b/lib/framework/MqttSettingsService.h @@ -6,6 +6,7 @@ #include #include #include + #include #define MQTT_RECONNECTION_DELAY 1000 @@ -60,8 +61,7 @@ static String generateClientId() { #define FACTORY_MQTT_MAX_TOPIC_LENGTH 128 #endif - -#define EMSESP_DEFAULT_BOOL_FORMAT 1 // on/off +#define EMSESP_DEFAULT_BOOL_FORMAT 1 // on/off #define EMSESP_DEFAULT_DALLAS_FORMAT 1 // sensorid #define EMSESP_DEFAULT_HA_CLIMATE_FORMAT 1 // current temp #define EMSESP_DEFAULT_MQTT_QOS 0 @@ -69,10 +69,6 @@ static String generateClientId() { #define EMSESP_DEFAULT_HA_ENABLED false #define EMSESP_DEFAULT_PUBLISH_TIME 10 -#include "../../src/system.h" -#include "../../src/mqtt.h" -#include "../../src/dallassensor.h" - class MqttSettings { public: // host and port - if enabled diff --git a/lib/framework/MqttStatus.cpp b/lib/framework/MqttStatus.cpp index cbf88cc70..b1bd0257e 100644 --- a/lib/framework/MqttStatus.cpp +++ b/lib/framework/MqttStatus.cpp @@ -1,5 +1,7 @@ #include +#include "../../src/emsesp_stub.hpp" // proddy added + MqttStatus::MqttStatus(AsyncWebServer * server, MqttSettingsService * mqttSettingsService, SecurityManager * securityManager) : _mqttSettingsService(mqttSettingsService) { server->on(MQTT_STATUS_SERVICE_PATH, diff --git a/lib/framework/MqttStatus.h b/lib/framework/MqttStatus.h index cf7e65480..8e19013e8 100644 --- a/lib/framework/MqttStatus.h +++ b/lib/framework/MqttStatus.h @@ -9,8 +9,6 @@ #include #endif -#include "../../src/mqtt.h" // proddy added - #include #include #include diff --git a/lib/framework/NetworkStatus.cpp b/lib/framework/NetworkStatus.cpp index 1a99aeb8b..e2bbc4069 100644 --- a/lib/framework/NetworkStatus.cpp +++ b/lib/framework/NetworkStatus.cpp @@ -1,5 +1,7 @@ #include +#include "../../src/emsesp_stub.hpp" // proddy added + NetworkStatus::NetworkStatus(AsyncWebServer * server, SecurityManager * securityManager) { server->on(NETWORK_STATUS_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&NetworkStatus::networkStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED)); } @@ -8,7 +10,7 @@ void NetworkStatus::networkStatus(AsyncWebServerRequest * request) { AsyncJsonResponse * response = new AsyncJsonResponse(false, MAX_NETWORK_STATUS_SIZE); JsonObject root = response->getRoot(); - bool ethernet_connected = emsesp::System::ethernet_connected(); + bool ethernet_connected = emsesp::EMSESP::system_.ethernet_connected(); wl_status_t wifi_status = WiFi.status(); // see if Ethernet is connected diff --git a/lib/framework/NetworkStatus.h b/lib/framework/NetworkStatus.h index b907f547d..70ed03505 100644 --- a/lib/framework/NetworkStatus.h +++ b/lib/framework/NetworkStatus.h @@ -4,7 +4,7 @@ #include #include -#include "../../src/system.h" // proddy added +#include #include #include diff --git a/lib/framework/OTASettingsService.cpp b/lib/framework/OTASettingsService.cpp index 100892235..8d7bff722 100644 --- a/lib/framework/OTASettingsService.cpp +++ b/lib/framework/OTASettingsService.cpp @@ -1,5 +1,7 @@ #include +#include "../../src/emsesp_stub.hpp" // proddy added + OTASettingsService::OTASettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager) : _httpEndpoint(OTASettings::read, OTASettings::update, this, server, OTA_SETTINGS_SERVICE_PATH, securityManager) , _fsPersistence(OTASettings::read, OTASettings::update, this, fs, OTA_SETTINGS_FILE) @@ -39,11 +41,11 @@ void OTASettingsService::configureArduinoOTA() { _arduinoOTA->onStart([]() { // Serial.println(F("Starting")); - emsesp::System::upload_status(true); + emsesp::EMSESP::system_.upload_status(true); }); _arduinoOTA->onEnd([]() { // Serial.println(F("\r\nEnd")); - emsesp::System::upload_status(false); + emsesp::EMSESP::system_.upload_status(false); }); // _arduinoOTA->onProgress([](unsigned int progress, unsigned int total) { diff --git a/lib/framework/OTASettingsService.h b/lib/framework/OTASettingsService.h index e977cd5e7..38b3b3a98 100644 --- a/lib/framework/OTASettingsService.h +++ b/lib/framework/OTASettingsService.h @@ -13,8 +13,6 @@ #include #include -#include "../../src/system.h" // proddy added - #ifndef FACTORY_OTA_PORT #define FACTORY_OTA_PORT 8266 #endif diff --git a/lib/framework/SecuritySettingsService.cpp b/lib/framework/SecuritySettingsService.cpp index bdce27505..c5e222513 100644 --- a/lib/framework/SecuritySettingsService.cpp +++ b/lib/framework/SecuritySettingsService.cpp @@ -2,6 +2,8 @@ #if FT_ENABLED(FT_SECURITY) +#include "../../src/emsesp_stub.hpp" // proddy added + SecuritySettingsService::SecuritySettingsService(AsyncWebServer * server, FS * fs) : _httpEndpoint(SecuritySettings::read, SecuritySettings::update, this, server, SECURITY_SETTINGS_PATH, this) , _fsPersistence(SecuritySettings::read, SecuritySettings::update, this, fs, SECURITY_SETTINGS_FILE) diff --git a/lib/framework/SecuritySettingsService.h b/lib/framework/SecuritySettingsService.h index fa273b4e1..3ec8b76af 100644 --- a/lib/framework/SecuritySettingsService.h +++ b/lib/framework/SecuritySettingsService.h @@ -6,8 +6,6 @@ #include #include -#include "../../src/version.h" // added by proddy - #ifndef FACTORY_ADMIN_USERNAME #define FACTORY_ADMIN_USERNAME "admin" #endif diff --git a/lib/framework/SystemStatus.h b/lib/framework/SystemStatus.h index 8bca355dc..bd911befb 100644 --- a/lib/framework/SystemStatus.h +++ b/lib/framework/SystemStatus.h @@ -12,7 +12,6 @@ #include #include // proddy added -#include "../../src/system.h" // proddy added #define MAX_ESP_STATUS_SIZE 1024 #define SYSTEM_STATUS_SERVICE_PATH "/rest/systemStatus" diff --git a/lib_standalone/SecuritySettingsService.cpp b/lib_standalone/SecuritySettingsService.cpp index 08ba401d8..61f42e7c6 100644 --- a/lib_standalone/SecuritySettingsService.cpp +++ b/lib_standalone/SecuritySettingsService.cpp @@ -2,6 +2,8 @@ #if FT_ENABLED(FT_SECURITY) +#include "../../src/emsesp_stub.h" // proddy added + SecuritySettingsService::SecuritySettingsService(AsyncWebServer* server, FS* fs) : _httpEndpoint(SecuritySettings::read, SecuritySettings::update, this, server, SECURITY_SETTINGS_PATH, this), _fsPersistence(SecuritySettings::read, SecuritySettings::update, this, fs, SECURITY_SETTINGS_FILE), diff --git a/lib_standalone/SecuritySettingsService.h b/lib_standalone/SecuritySettingsService.h index 0034d08a4..fda1b7d76 100644 --- a/lib_standalone/SecuritySettingsService.h +++ b/lib_standalone/SecuritySettingsService.h @@ -6,8 +6,6 @@ #include #include -#include "../../src/version.h" // added by proddy - #ifndef FACTORY_ADMIN_USERNAME #define FACTORY_ADMIN_USERNAME "admin" #endif diff --git a/src/emsesp_stub.hpp b/src/emsesp_stub.hpp new file mode 100644 index 000000000..eaca14545 --- /dev/null +++ b/src/emsesp_stub.hpp @@ -0,0 +1,38 @@ +/* + * EMS-ESP - https://github.com/proddy/EMS-ESP + * Copyright 2020 Paul Derbyshire + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef EMSESP_EMSESP_STUB_H +#define EMSESP_EMSESP_STUB_H + +// forward declarator +// used to bind EMS-ESP functions to external frameworks +#include "system.h" +#include "mqtt.h" +#include "dallassensor.h" +#include "version.h" + +namespace emsesp { +class EMSESP { + public: + static Mqtt mqtt_; + static System system_; + static DallasSensor dallassensor_; +}; + +} // namespace emsesp + +#endif