From 390c0882d150598306340c1e5c30df259300d925 Mon Sep 17 00:00:00 2001 From: Magnus Persson Date: Sun, 8 May 2022 09:54:25 +0200 Subject: [PATCH] Applied pre-commit on v1.0 source --- src/calc.cpp | 8 +++++--- src/config.cpp | 5 +++-- src/config.hpp | 9 +++------ src/helper.cpp | 4 +++- src/main.cpp | 9 ++++++--- src/pushtarget.cpp | 26 +++++++++++++++++--------- src/pushtarget.hpp | 4 ++-- src/tempsensor.cpp | 5 +++-- src/webserver.cpp | 23 ++++++++++++----------- src/webserver.hpp | 4 ++-- src/wifi.cpp | 8 ++++---- 11 files changed, 60 insertions(+), 45 deletions(-) diff --git a/src/calc.cpp b/src/calc.cpp index eac7985..392a417 100644 --- a/src/calc.cpp +++ b/src/calc.cpp @@ -35,7 +35,8 @@ int createFormula(RawFormulaData &fd, char *formulaBuffer, int noAngles = 0; RawFormulaData fd2; - // Check how many valid values we have got and make sure we have a full series. + // Check how many valid values we have got and make sure we have a full + // series. for (int i = 0; i < FORMULA_DATA_SIZE; i++) { if (fd.a[i]) { fd2.a[noAngles] = fd.a[i]; @@ -50,7 +51,7 @@ int createFormula(RawFormulaData &fd, char *formulaBuffer, order, noAngles); #endif - if (noAngles <3) { + if (noAngles < 3) { ErrorFileLog errLog; errLog.addEntry(F("CALC: Not enough values for deriving formula")); return ERR_FORMULA_NOTENOUGHVALUES; @@ -62,7 +63,8 @@ int createFormula(RawFormulaData &fd, char *formulaBuffer, // Returned value is 0 if no error if (ret == 0) { #if LOG_LEVEL == 6 && !defined(CALC_DISABLE_LOGGING) - Log.verbose(F("CALC: Finshied processing data points, order = %d." CR), order); + Log.verbose(F("CALC: Finshied processing data points, order = %d." CR), + order); #endif // Print the formula based on 'order' diff --git a/src/config.cpp b/src/config.cpp index 18b12d9..8c0083e 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -390,7 +390,7 @@ bool AdvancedConfig::saveFile() { doc[PARAM_HW_PUSH_INTERVAL_HTTP3] = this->getPushIntervalHttp3(); doc[PARAM_HW_PUSH_INTERVAL_INFLUX] = this->getPushIntervalInflux(); doc[PARAM_HW_PUSH_INTERVAL_MQTT] = this->getPushIntervalMqtt(); - doc[PARAM_HW_TEMPSENSOR_RESOLUTION] = this->getTempSensorResolution(); + doc[PARAM_HW_TEMPSENSOR_RESOLUTION] = this->getTempSensorResolution(); doc[PARAM_HW_IGNORE_LOW_ANGLES] = this->isIgnoreLowAnges(); #if LOG_LEVEL == 6 && !defined(DISABLE_LOGGING) @@ -479,7 +479,8 @@ bool AdvancedConfig::loadFile() { if (!doc[PARAM_HW_PUSH_INTERVAL_MQTT].isNull()) this->setPushIntervalMqtt(doc[PARAM_HW_PUSH_INTERVAL_MQTT].as()); if (!doc[PARAM_HW_TEMPSENSOR_RESOLUTION].isNull()) - this->setTempSensorResolution(doc[PARAM_HW_TEMPSENSOR_RESOLUTION].as()); + this->setTempSensorResolution( + doc[PARAM_HW_TEMPSENSOR_RESOLUTION].as()); if (!doc[PARAM_HW_IGNORE_LOW_ANGLES].isNull()) setIgnoreLowAnges(doc[PARAM_HW_IGNORE_LOW_ANGLES].as()); diff --git a/src/config.hpp b/src/config.hpp index 9dcd885..160e110 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -87,9 +87,8 @@ class AdvancedConfig { } int getTempSensorResolution() { return _tempSensorResolution; } - void setTempSensorResolution(int t) { - if (t>=9 && t<=12) - _tempSensorResolution = t; + void setTempSensorResolution(int t) { + if (t >= 9 && t <= 12) _tempSensorResolution = t; } float getDefaultCalibrationTemp() { return _defaultCalibrationTemp; } @@ -130,9 +129,7 @@ class AdvancedConfig { } const bool isIgnoreLowAnges() { return _IgnoreLowAnges; } - void setIgnoreLowAnges(bool b) { - _IgnoreLowAnges = b; - } + void setIgnoreLowAnges(bool b) { _IgnoreLowAnges = b; } bool saveFile(); bool loadFile(); diff --git a/src/helper.cpp b/src/helper.cpp index b8c441c..fdcff16 100644 --- a/src/helper.cpp +++ b/src/helper.cpp @@ -318,7 +318,9 @@ void PerfLogging::pushInflux() { if (!myConfig.isInfluxDb2Active()) return; if (myConfig.isInfluxSSL()) { - Log.warning(F("PERF: InfluxDB2 with SSL is not supported when pushing performance data, skipping" CR)); + Log.warning( + F("PERF: InfluxDB2 with SSL is not supported when pushing performance " + "data, skipping" CR)); return; } diff --git a/src/main.cpp b/src/main.cpp index 3f7b679..380275e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,7 +32,7 @@ SOFTWARE. #include #include -//#define FORCE_GRAVITY_MODE +// #define FORCE_GRAVITY_MODE // Define constats for this program #ifdef DEACTIVATE_SLEEPMODE @@ -275,8 +275,11 @@ bool loopReadGravity() { bool pushExpired = (abs((int32_t)(millis() - pushMillis)) > (myConfig.getSleepInterval() * 1000)); - if (myAdvancedConfig.isIgnoreLowAnges() && (angle < myConfig.getFormulaData().a[0]) ) { - Log.warning(F("Main: Angle is lower than water, so we regard this as faulty and dont send any data." CR)); + if (myAdvancedConfig.isIgnoreLowAnges() && + (angle < myConfig.getFormulaData().a[0])) { + Log.warning( + F("Main: Angle is lower than water, so we regard this as faulty and " + "dont send any data." CR)); pushExpired = false; } diff --git a/src/pushtarget.cpp b/src/pushtarget.cpp index f083e76..cca94c3 100644 --- a/src/pushtarget.cpp +++ b/src/pushtarget.cpp @@ -204,9 +204,11 @@ void PushTarget::sendInfluxDb2(TemplatingEngine& engine, bool isSecure) { String auth = "Token " + String(myConfig.getInfluxDb2PushToken()); if (isSecure) { -#if defined( ESP8266 ) +#if defined(ESP8266) if (runMode == RunMode::configurationMode) { - Log.notice(F("PUSH: Skipping InfluxDB since SSL is enabled and we are in config mode." CR)); + Log.notice( + F("PUSH: Skipping InfluxDB since SSL is enabled and we are in config " + "mode." CR)); _lastCode = -100; return; } @@ -217,7 +219,7 @@ void PushTarget::sendInfluxDb2(TemplatingEngine& engine, bool isSecure) { probeMaxFragement(serverPath); _httpSecure.setTimeout(myAdvancedConfig.getPushTimeout() * 1000); _httpSecure.begin(_wifiSecure, serverPath); - _httpSecure.addHeader(F("Authorization"), auth.c_str()); + _httpSecure.addHeader(F("Authorization"), auth.c_str()); _httpSecure.setReuse(true); _lastCode = _httpSecure.POST(doc); } else { @@ -293,9 +295,11 @@ void PushTarget::sendHttpPost(TemplatingEngine& engine, bool isSecure, #endif if (isSecure) { -#if defined( ESP8266 ) +#if defined(ESP8266) if (runMode == RunMode::configurationMode) { - Log.notice(F("PUSH: Skipping HTTP since SSL is enabled and we are in config mode." CR)); + Log.notice( + F("PUSH: Skipping HTTP since SSL is enabled and we are in config " + "mode." CR)); _lastCode = -100; return; } @@ -370,9 +374,11 @@ void PushTarget::sendHttpGet(TemplatingEngine& engine, bool isSecure) { #endif if (isSecure) { -#if defined( ESP8266 ) +#if defined(ESP8266) if (runMode == RunMode::configurationMode) { - Log.notice(F("PUSH: Skipping HTTP since SSL is enabled and we are in config mode." CR)); + Log.notice( + F("PUSH: Skipping HTTP since SSL is enabled and we are in config " + "mode." CR)); _lastCode = -100; return; } @@ -424,9 +430,11 @@ void PushTarget::sendMqtt(TemplatingEngine& engine, bool isSecure) { int port = myConfig.getMqttPort(); if (myConfig.isMqttSSL()) { -#if defined( ESP8266 ) +#if defined(ESP8266) if (runMode == RunMode::configurationMode) { - Log.notice(F("PUSH: Skipping MQTT since SSL is enabled and we are in config mode." CR)); + Log.notice( + F("PUSH: Skipping MQTT since SSL is enabled and we are in config " + "mode." CR)); _lastCode = -100; return; } diff --git a/src/pushtarget.hpp b/src/pushtarget.hpp index e657565..02b2485 100644 --- a/src/pushtarget.hpp +++ b/src/pushtarget.hpp @@ -45,7 +45,7 @@ class PushTarget { void sendHttpPost(TemplatingEngine& engine, bool isSecure, int index); void sendHttpGet(TemplatingEngine& engine, bool isSecure); void addHttpHeader(HTTPClient& http, String header); - void probeMaxFragement( String& serverPath ); + void probeMaxFragement(String& serverPath); public: void sendAll(float angle, float gravitySG, float corrGravitySG, float tempC, @@ -68,7 +68,7 @@ class PushTarget { class PushIntervalTracker { private: - int _counters[5] = { 0, 0, 0, 0, 0 }; + int _counters[5] = {0, 0, 0, 0, 0}; void update(const int index, const int defaultValue); public: diff --git a/src/tempsensor.cpp b/src/tempsensor.cpp index fda5eb6..7f98ad6 100644 --- a/src/tempsensor.cpp +++ b/src/tempsensor.cpp @@ -51,8 +51,9 @@ void TempSensor::setup() { if (mySensors.getDS18Count()) { #if !defined(TSEN_DISABLE_LOGGING) - Log.notice(F("TSEN: Found %d temperature sensor(s). Using %d resolution" CR), - mySensors.getDS18Count(), myAdvancedConfig.getTempSensorResolution()); + Log.notice( + F("TSEN: Found %d temperature sensor(s). Using %d resolution" CR), + mySensors.getDS18Count(), myAdvancedConfig.getTempSensorResolution()); #endif } diff --git a/src/webserver.cpp b/src/webserver.cpp index 02ed67a..71cc2b3 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -576,9 +576,9 @@ void WebServerHandler::webHandleConfigGravity() { myConfig.setGravityTempAdj( _server->arg(PARAM_GRAVITY_TEMP_ADJ).equalsIgnoreCase("on") ? true : false); - else - myConfig.setGravityTempAdj(false); - + else + myConfig.setGravityTempAdj(false); + myConfig.saveFile(); _server->sendHeader("Location", "/config.htm#collapseGravity", true); _server->send(302, "text/plain", "Gravity config updated"); @@ -623,7 +623,7 @@ void WebServerHandler::webHandleConfigHardware() { myConfig.setGyroTemp( _server->arg(PARAM_GYRO_TEMP).equalsIgnoreCase("on") ? true : false); else - myConfig.setGyroTemp(false); + myConfig.setGyroTemp(false); myConfig.saveFile(); _server->sendHeader("Location", "/config.htm#collapseHardware", true); @@ -695,8 +695,10 @@ void WebServerHandler::webHandleConfigAdvancedWrite() { _server->arg(PARAM_HW_TEMPSENSOR_RESOLUTION).toInt()); if (_server->hasArg(PARAM_HW_IGNORE_LOW_ANGLES)) myAdvancedConfig.setIgnoreLowAnges( - _server->arg(PARAM_HW_IGNORE_LOW_ANGLES).equalsIgnoreCase("on") ? true : false); - else + _server->arg(PARAM_HW_IGNORE_LOW_ANGLES).equalsIgnoreCase("on") + ? true + : false); + else myAdvancedConfig.setIgnoreLowAnges(false); myAdvancedConfig.saveFile(); @@ -1195,7 +1197,7 @@ bool WebServerHandler::setupWebServer() { MDNS.addService("http", "tcp", 80); // Show files in the filessytem at startup -#if defined( ESP8266 ) +#if defined(ESP8266) FSInfo fs; LittleFS.info(fs); Log.notice(F("WEB : File system Total=%d, Used=%d." CR), fs.totalBytes, @@ -1209,12 +1211,11 @@ bool WebServerHandler::setupWebServer() { LittleFS.remove(dir.fileName().c_str()); } } -#else // defined( ESP32 ) +#else // defined( ESP32 ) File root = LittleFS.open("/"); - File f = root.openNextFile(); + File f = root.openNextFile(); while (f) { - Log.notice(F("WEB : File=%s, %d bytes" CR), f.name(), - f.size()); + Log.notice(F("WEB : File=%s, %d bytes" CR), f.name(), f.size()); if (!f.size()) { Log.notice(F("WEB : Empty file detected, removing file." CR)); LittleFS.remove(f.name()); diff --git a/src/webserver.hpp b/src/webserver.hpp index 6a68ac8..e166158 100644 --- a/src/webserver.hpp +++ b/src/webserver.hpp @@ -28,12 +28,12 @@ SOFTWARE. #include #include #include -#define MAX_SKETCH_SPACE 1044464 +#define MAX_SKETCH_SPACE 1044464 #else // defined (ESP32) #include +#include #include #include -#include #define MAX_SKETCH_SPACE 1835008 #endif #include diff --git a/src/wifi.cpp b/src/wifi.cpp index 1885eb6..3fcb9be 100644 --- a/src/wifi.cpp +++ b/src/wifi.cpp @@ -85,7 +85,7 @@ bool WifiConnection::hasConfig() { myConfig.saveFile(); return true; } -#else // defined( ESP32 ) +#else // defined( ESP32 ) #warning "Cant read SSID property on ESP32 until a connection has been made!" #endif @@ -285,9 +285,9 @@ bool WifiConnection::connect() { connectAsync(1); if (waitForConnection(timeout)) { - Log.notice( - F("WIFI: Connected to second SSID %s, making secondary default." CR), - myConfig.getWifiSSID(1)); + Log.notice(F("WIFI: Connected to second SSID %s, making secondary " + "default." CR), + myConfig.getWifiSSID(1)); myConfig.swapPrimaryWifi(); myConfig.saveFile();