From af2d4624b354797feb3fad4a795709862bda7c55 Mon Sep 17 00:00:00 2001 From: Yurii Date: Sun, 17 May 2026 04:38:53 +0300 Subject: [PATCH] chore: fix cpplint --- .github/workflows/ci.yaml | 2 + lib/BufferedWebServer/BufferedWebServer.h | 8 +- lib/CustomOpenTherm/CustomOpenTherm.h | 2 +- lib/HomeAssistantHelper/HomeAssistantHelper.h | 8 +- lib/HomeAssistantHelper/strings.h | 2 +- lib/MqttWriter/MqttWiFiClient.h | 2 +- lib/MqttWriter/MqttWriter.h | 8 +- lib/NetworkUtils/NetworkConnection.cpp | 8 +- lib/NetworkUtils/NetworkConnection.h | 4 +- lib/NetworkUtils/NetworkMgr.h | 4 +- lib/WebServerHandlers/DynamicPage.h | 224 ------------------ lib/WebServerHandlers/StaticPage.h | 6 +- lib/WebServerHandlers/UpgradeHandler.h | 26 +- src/CrashRecorder.h | 12 +- src/HaHelper.h | 50 ++-- src/MainTask.h | 46 ++-- src/MqttTask.h | 16 +- src/OpenThermTask.h | 76 +++--- src/PortalTask.h | 22 +- src/RegulatorTask.h | 6 +- src/Sensors.h | 34 +-- src/SensorsTask.h | 38 +-- src/Settings.h | 4 +- src/defines.h | 4 +- src/main.cpp | 2 +- src/strings.h | 4 +- src/utils.h | 22 +- 27 files changed, 209 insertions(+), 431 deletions(-) delete mode 100644 lib/WebServerHandlers/DynamicPage.h diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e9fa2df..1036d76 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -92,8 +92,10 @@ jobs: -whitespace/indent,\ -whitespace/newline,\ -whitespace/parens,\ + -whitespace/blank_line,\ -readability/braces,\ -readability/todo,\ + -readability/namespace,\ -build/header_guard,\ -build/include_subdir,\ -build/include_what_you_use,\ diff --git a/lib/BufferedWebServer/BufferedWebServer.h b/lib/BufferedWebServer/BufferedWebServer.h index d399272..401279b 100644 --- a/lib/BufferedWebServer/BufferedWebServer.h +++ b/lib/BufferedWebServer/BufferedWebServer.h @@ -1,9 +1,9 @@ class BufferedWebServer { public: - BufferedWebServer(WebServer* webServer, size_t bufferSize = 64) { + explicit BufferedWebServer(WebServer* webServer, size_t bufferSize = 64) { this->webServer = webServer; this->bufferSize = bufferSize; - this->buffer = (uint8_t*)malloc(bufferSize * sizeof(*this->buffer)); + this->buffer = static_cast(malloc(bufferSize * sizeof(*this->buffer))); } ~BufferedWebServer() { @@ -28,7 +28,7 @@ public: if (pretty) { serializeJsonPretty(content, *this); - + } else { serializeJson(content, *this); } @@ -99,4 +99,4 @@ protected: uint8_t* buffer; size_t bufferSize = 64; size_t bufferPos = 0; -}; \ No newline at end of file +}; diff --git a/lib/CustomOpenTherm/CustomOpenTherm.h b/lib/CustomOpenTherm/CustomOpenTherm.h index 3bef65f..7e7a3bc 100644 --- a/lib/CustomOpenTherm/CustomOpenTherm.h +++ b/lib/CustomOpenTherm/CustomOpenTherm.h @@ -7,7 +7,7 @@ public: typedef std::function BeforeSendRequestCallback; typedef std::function AfterSendRequestCallback; - CustomOpenTherm(int inPin = 4, int outPin = 5, bool isSlave = false, bool alwaysReceive = false) : OpenTherm(inPin, outPin, isSlave, alwaysReceive) {} + explicit CustomOpenTherm(int inPin = 4, int outPin = 5, bool isSlave = false, bool alwaysReceive = false) : OpenTherm(inPin, outPin, isSlave, alwaysReceive) {} ~CustomOpenTherm() {} CustomOpenTherm* setDelayCallback(DelayCallback callback = nullptr) { diff --git a/lib/HomeAssistantHelper/HomeAssistantHelper.h b/lib/HomeAssistantHelper/HomeAssistantHelper.h index 990cda1..2c7c004 100644 --- a/lib/HomeAssistantHelper/HomeAssistantHelper.h +++ b/lib/HomeAssistantHelper/HomeAssistantHelper.h @@ -49,7 +49,7 @@ public: if (this->publishEventCallback) { this->publishEventCallback(topic, false); } - + return false; } @@ -114,7 +114,7 @@ public: return topic; } - template + template String getDeviceTopic(T value, char dpvSeparator = '/') { String topic = ""; topic.concat(this->devicePrefix); @@ -147,7 +147,7 @@ public: return topic; } - template + template String getEntityIdWithPrefix(DT domain, VT value, char separator = '_') { String topic = ""; topic.concat(domain); @@ -158,7 +158,7 @@ public: return topic; } - template + template String getUniqueIdWithPrefix(T value, char separator = '_') { String topic = ""; topic.concat(this->devicePrefix); diff --git a/lib/HomeAssistantHelper/strings.h b/lib/HomeAssistantHelper/strings.h index 6b95d01..d9b9029 100644 --- a/lib/HomeAssistantHelper/strings.h +++ b/lib/HomeAssistantHelper/strings.h @@ -1,6 +1,6 @@ #pragma once #ifndef PROGMEM - #define PROGMEM + #define PROGMEM // NOLINT #endif const char HA_ENTITY_BINARY_SENSOR[] PROGMEM = "binary_sensor"; diff --git a/lib/MqttWriter/MqttWiFiClient.h b/lib/MqttWriter/MqttWiFiClient.h index 843e51a..58f6d3a 100644 --- a/lib/MqttWriter/MqttWiFiClient.h +++ b/lib/MqttWriter/MqttWiFiClient.h @@ -21,4 +21,4 @@ public: return false; } #endif -}; \ No newline at end of file +}; diff --git a/lib/MqttWriter/MqttWriter.h b/lib/MqttWriter/MqttWriter.h index 9c0fa45..0c03cbd 100644 --- a/lib/MqttWriter/MqttWriter.h +++ b/lib/MqttWriter/MqttWriter.h @@ -12,10 +12,10 @@ public: typedef std::function PublishEventCallback; typedef std::function FlushEventCallback; - MqttWriter(MqttClient* client, size_t bufferSize = 64) { + explicit MqttWriter(MqttClient* client, size_t bufferSize = 64) { this->client = client; this->bufferSize = bufferSize; - this->buffer = (uint8_t*) malloc(bufferSize * sizeof(*this->buffer)); + this->buffer = static_cast(malloc(bufferSize * sizeof(*this->buffer))); #ifdef ARDUINO_ARCH_ESP32 this->mutex = new std::mutex(); @@ -96,7 +96,7 @@ public: serializeJson(doc, *this); this->flush(); this->client->endMessage(); - + written = this->writeAfterLock; } this->unlock(); @@ -134,7 +134,7 @@ public: this->write(buffer, length); this->flush(); this->client->endMessage(); - + written = this->writeAfterLock; result = written == length; } diff --git a/lib/NetworkUtils/NetworkConnection.cpp b/lib/NetworkUtils/NetworkConnection.cpp index 0f03b88..a98e208 100644 --- a/lib/NetworkUtils/NetworkConnection.cpp +++ b/lib/NetworkUtils/NetworkConnection.cpp @@ -74,7 +74,7 @@ void NetworkConnection::onEvent(System_Event_t *event) { } } break; - + default: break; } @@ -106,7 +106,7 @@ void NetworkConnection::onEvent(WiFiEvent_t event, WiFiEventInfo_t info) { rawDisconnectReason = info.wifi_sta_disconnected.reason; disconnectReason = convertDisconnectReason(info.wifi_sta_disconnected.reason); break; - + default: break; } @@ -146,7 +146,7 @@ NetworkConnection::DisconnectReason NetworkConnection::convertDisconnectReason(u case WIFI_REASON_HANDSHAKE_TIMEOUT: return DisconnectReason::HANDSHAKE_TIMEOUT; #endif - + default: return DisconnectReason::OTHER; } @@ -155,4 +155,4 @@ NetworkConnection::DisconnectReason NetworkConnection::convertDisconnectReason(u bool NetworkConnection::useDhcp = false; NetworkConnection::Status NetworkConnection::status = Status::NONE; NetworkConnection::DisconnectReason NetworkConnection::disconnectReason = DisconnectReason::NONE; -uint8_t NetworkConnection::rawDisconnectReason = 0; \ No newline at end of file +uint8_t NetworkConnection::rawDisconnectReason = 0; diff --git a/lib/NetworkUtils/NetworkConnection.h b/lib/NetworkUtils/NetworkConnection.h index 313d5e4..f6b8910 100644 --- a/lib/NetworkUtils/NetworkConnection.h +++ b/lib/NetworkUtils/NetworkConnection.h @@ -28,7 +28,7 @@ namespace NetworkUtils { static Status status; static DisconnectReason disconnectReason; static uint8_t rawDisconnectReason; - + static void setup(bool useDhcp); static void setUseDhcp(bool value); static void reset(); @@ -44,4 +44,4 @@ namespace NetworkUtils { static DisconnectReason convertDisconnectReason(uint8_t reason); static bool useDhcp; }; -} \ No newline at end of file +} diff --git a/lib/NetworkUtils/NetworkMgr.h b/lib/NetworkUtils/NetworkMgr.h index aadf3dd..ae94712 100644 --- a/lib/NetworkUtils/NetworkMgr.h +++ b/lib/NetworkUtils/NetworkMgr.h @@ -183,7 +183,7 @@ namespace NetworkUtils { wifi_station_dhcpc_set_maxtry(5); #endif - + #if defined(ARDUINO_ARCH_ESP32) && ESP_ARDUINO_VERSION_MAJOR < 3 // Nothing. Because memory leaks when turn off WiFi on ESP32 SDK < 3.0.0 return true; @@ -473,4 +473,4 @@ namespace NetworkUtils { return true; } }; -} \ No newline at end of file +} diff --git a/lib/WebServerHandlers/DynamicPage.h b/lib/WebServerHandlers/DynamicPage.h deleted file mode 100644 index 021f0f3..0000000 --- a/lib/WebServerHandlers/DynamicPage.h +++ /dev/null @@ -1,224 +0,0 @@ -#include - - -class DynamicPage : public RequestHandler { -public: - typedef std::function CanHandleCallback; - typedef std::function BeforeSendCallback; - typedef std::function TemplateCallback; - - DynamicPage(const char* uri, FS* fs, const char* path, const char* cacheHeader = nullptr) { - this->uri = uri; - this->fs = fs; - this->path = path; - this->cacheHeader = cacheHeader; - } - - DynamicPage* setCanHandleCallback(CanHandleCallback callback = nullptr) { - this->canHandleCallback = callback; - - return this; - } - - DynamicPage* setBeforeSendCallback(BeforeSendCallback callback = nullptr) { - this->beforeSendCallback = callback; - - return this; - } - - DynamicPage* setTemplateCallback(TemplateCallback callback = nullptr) { - this->templateCallback = callback; - - return this; - } - - #if defined(ARDUINO_ARCH_ESP32) - bool canHandle(WebServer &server, HTTPMethod method, const String &uri) override { - return this->canHandle(method, uri); - } - #endif - - bool canHandle(HTTPMethod method, const String& uri) override { - return uri.equals(this->uri) && (!this->canHandleCallback || this->canHandleCallback(method, uri)); - } - - bool handle(WebServer& server, HTTPMethod method, const String& uri) override { - if (!this->canHandle(method, uri)) { - return false; - } - - if (this->beforeSendCallback && !this->beforeSendCallback()) { - return true; - } - - File file = this->fs->open(this->path, "r"); - if (!file) { - return false; - - } else if (file.isDirectory()) { - file.close(); - return false; - } - - if (this->cacheHeader != nullptr) { - server.sendHeader(F("Cache-Control"), this->cacheHeader); - } - - #ifdef ARDUINO_ARCH_ESP8266 - if (!server.chunkedResponseModeStart(200, F("text/html"))) { - server.send(505, F("text/html"), F("HTTP1.1 required")); - return true; - } - #else - server.setContentLength(CONTENT_LENGTH_UNKNOWN); - server.send(200, "text/html", emptyString); - #endif - - uint8_t* argStartPos = nullptr; - uint8_t* argEndPos = nullptr; - uint8_t argName[16]; - size_t sizeArgName = 0; - bool argNameProcess = false; - while (file.available()) { - uint8_t buf[64]; - size_t length = file.read(buf, sizeof(buf)); - size_t offset = 0; - - if (argNameProcess) { - argEndPos = (uint8_t*) memchr(buf, '}', length); - - if (argEndPos != nullptr) { - size_t fullSizeArgName = sizeArgName + (argEndPos - buf); - if (fullSizeArgName < sizeof(argName)) { - // copy full arg name - if (argEndPos - buf > 0) { - memcpy(argName + sizeArgName, buf, argEndPos - buf); - } - argName[fullSizeArgName] = '\0'; - - // send arg value - String argValue = this->templateCallback((const char*) argName); - if (argValue.length()) { - server.sendContent(argValue.c_str()); - - } else if (fullSizeArgName > 0) { - server.sendContent("{"); - server.sendContent((const char*) argName); - server.sendContent("}"); - } - - offset = size_t(argEndPos - buf + 1); - sizeArgName = 0; - argNameProcess = false; - } - } - - if (argNameProcess) { - server.sendContent("{"); - - if (sizeArgName > 0) { - argName[sizeArgName] = '\0'; - server.sendContent((const char*) argName); - } - - argNameProcess = false; - } - } - - do { - uint8_t* currentBuf = buf + offset; - size_t currentLength = length - offset; - - argStartPos = (uint8_t*) memchr(currentBuf, '{', currentLength); - - // send all content - if (argStartPos == nullptr) { - if (currentLength > 0) { - server.sendContent((const char*) currentBuf, currentLength); - } - - break; - } - - argEndPos = (uint8_t*) memchr(argStartPos, '}', length - (argStartPos - buf)); - if (argEndPos != nullptr) { - sizeArgName = argEndPos - argStartPos - 1; - - // send all content if arg len > space - if (sizeArgName >= sizeof(argName)) { - if (currentLength > 0) { - server.sendContent((const char*) currentBuf, currentLength); - } - - break; - } - - // arg name - memcpy(argName, argStartPos + 1, sizeArgName); - argName[sizeArgName] = '\0'; - - // send arg value - String argValue = this->templateCallback((const char*) argName); - if (argValue.length()) { - // send content before var - if (argStartPos - buf > 0) { - server.sendContent((const char*) currentBuf, argStartPos - buf); - } - - server.sendContent(argValue.c_str()); - - } else { - server.sendContent((const char*) currentBuf, argEndPos - currentBuf + 1); - } - - offset = size_t(argEndPos - currentBuf + 1); - - } else { - sizeArgName = length - size_t(argStartPos - currentBuf) - 1; - - // send all content if arg len > space - if (sizeArgName >= sizeof(argName)) { - if (currentLength) { - server.sendContent((const char*) currentBuf, currentLength); - } - - break; - } - - // send content before var - if (argStartPos - buf > 0) { - server.sendContent((const char*) currentBuf, argStartPos - buf); - } - - // copy arg name chunk - if (sizeArgName > 0) { - memcpy(argName, argStartPos + 1, sizeArgName); - } - - argNameProcess = true; - - break; - } - } while(true); - } - - file.close(); - - #ifdef ARDUINO_ARCH_ESP8266 - server.chunkedResponseFinalize(); - #else - server.sendContent(emptyString); - #endif - - return true; - } - -protected: - FS* fs = nullptr; - CanHandleCallback canHandleCallback; - BeforeSendCallback beforeSendCallback; - TemplateCallback templateCallback; - const char* uri = nullptr; - const char* path = nullptr; - const char* cacheHeader = nullptr; -}; \ No newline at end of file diff --git a/lib/WebServerHandlers/StaticPage.h b/lib/WebServerHandlers/StaticPage.h index 51ca630..1fe10b5 100644 --- a/lib/WebServerHandlers/StaticPage.h +++ b/lib/WebServerHandlers/StaticPage.h @@ -7,7 +7,7 @@ class StaticPage : public RequestHandler { public: typedef std::function CanHandleCallback; typedef std::function BeforeSendCallback; - + template StaticPage(const char* uri, FS* fs, T path, const char* cacheHeader = nullptr) { this->uri = uri; @@ -84,7 +84,7 @@ public: if (server._eTagEnabled && !this->eTag.isEmpty()) { server.sendHeader(F("ETag"), this->eTag); } - + #if defined(ARDUINO_ARCH_ESP8266) server.streamFile(file, F("text/html"), method); #else @@ -102,4 +102,4 @@ protected: const char* uri = nullptr; String path; const char* cacheHeader = nullptr; -}; \ No newline at end of file +}; diff --git a/lib/WebServerHandlers/UpgradeHandler.h b/lib/WebServerHandlers/UpgradeHandler.h index 6384be3..33f3e7e 100644 --- a/lib/WebServerHandlers/UpgradeHandler.h +++ b/lib/WebServerHandlers/UpgradeHandler.h @@ -28,14 +28,14 @@ public: typedef std::function BeforeUpgradeCallback; typedef std::function AfterUpgradeCallback; - - UpgradeHandler(AsyncURIMatcher uri) : uri(uri) {} - bool canHandle(AsyncWebServerRequest *request) const override final { + explicit UpgradeHandler(AsyncURIMatcher uri) : uri(uri) {} + + bool canHandle(AsyncWebServerRequest *request) const final { if (!request->isHTTP()) { return false; } - + return this->uri.matches(request); } @@ -51,7 +51,7 @@ public: return this; } - void handleRequest(AsyncWebServerRequest *request) override final { + void handleRequest(AsyncWebServerRequest *request) final { if (this->afterUpgradeCallback) { this->afterUpgradeCallback(request, this->firmwareResult, this->filesystemResult); } @@ -63,7 +63,7 @@ public: this->filesystemResult.error.clear(); } - void handleUpload(AsyncWebServerRequest *request, const String &fileName, size_t index, uint8_t *data, size_t dataLength, bool isFinal) override final { + void handleUpload(AsyncWebServerRequest *request, const String &fileName, size_t index, uint8_t *data, size_t dataLength, bool isFinal) final { UpgradeResult* result = nullptr; if (!request->hasParam(asyncsrv::T_name, true, true)) { @@ -123,7 +123,7 @@ public: bool begin = false; if (result->type == UpgradeType::FIRMWARE) { begin = Update.begin(UPDATE_SIZE_UNKNOWN, U_FLASH); - + } else if (result->type == UpgradeType::FILESYSTEM) { begin = Update.begin(UPDATE_SIZE_UNKNOWN, U_SPIFFS); } @@ -135,10 +135,10 @@ public: Log.serrorln(FPSTR(L_PORTAL_OTA), "File '%s', on start: %s", fileName.c_str(), result->error.c_str()); return; } - + Log.sinfoln(FPSTR(L_PORTAL_OTA), "File '%s', started", fileName.c_str()); } - + if (dataLength) { if (Update.write(data, dataLength) != dataLength) { Update.end(false); @@ -154,7 +154,7 @@ public: ); return; } - + result->progress += dataLength; Log.sinfoln( FPSTR(L_PORTAL_OTA), "File '%s', write %d bytes, %d of %d bytes", @@ -179,7 +179,7 @@ public: return; } } - + if (isFinal) { if (!Update.end(true)) { result->status = UpgradeStatus::ERROR_ON_FINISH; @@ -194,7 +194,7 @@ public: } } - bool isRequestHandlerTrivial() const override final { + bool isRequestHandlerTrivial() const final { return false; } @@ -205,4 +205,4 @@ protected: UpgradeResult firmwareResult{UpgradeType::FIRMWARE, UpgradeStatus::NONE}; UpgradeResult filesystemResult{UpgradeType::FILESYSTEM, UpgradeStatus::NONE}; -}; \ No newline at end of file +}; diff --git a/src/CrashRecorder.h b/src/CrashRecorder.h index e795b2a..2a7a94e 100644 --- a/src/CrashRecorder.h +++ b/src/CrashRecorder.h @@ -35,9 +35,9 @@ namespace CrashRecorder { } ext_t; - __NOINIT_ATTR volatile static backtrace_t backtrace; - __NOINIT_ATTR volatile static epc_t epc; - __NOINIT_ATTR volatile static ext_t ext; + __NOINIT_ATTR volatile static backtrace_t backtrace; // NOLINT + __NOINIT_ATTR volatile static epc_t epc; // NOLINT + __NOINIT_ATTR volatile static ext_t ext; // NOLINT uint8_t backtraceMaxLength = sizeof(backtrace.data) / sizeof(*backtrace.data); uint8_t epcMaxLength = sizeof(epc.data) / sizeof(*epc.data); @@ -70,7 +70,7 @@ namespace CrashRecorder { } } #endif - + void init() { if (backtrace.length > backtraceMaxLength) { backtrace.length = 0; @@ -98,7 +98,7 @@ extern "C" void custom_crash_callback(struct rst_info *info, uint32_t stack, uin CrashRecorder::backtrace.continues = false; uint32_t value; for (uint32_t i = stack; i < stack_end; i += 4) { - value = *((uint32_t*) i); + value = *((uint32_t*) i); // NOLINT // keep only addresses in code area if ((value >= 0x40000000) && (value < 0x40300000)) { @@ -129,4 +129,4 @@ extern "C" void custom_crash_callback(struct rst_info *info, uint32_t stack, uin CrashRecorder::epc.length = _length; } -#endif \ No newline at end of file +#endif diff --git a/src/HaHelper.h b/src/HaHelper.h index 77b6bfc..0e334c9 100644 --- a/src/HaHelper.h +++ b/src/HaHelper.h @@ -45,7 +45,7 @@ public: doc[FPSTR(HA_MIN)] = -99; doc[FPSTR(HA_MAX)] = 99; } - + } else if (unit == UnitSystem::IMPERIAL) { doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = FPSTR(HA_UNIT_OF_MEASUREMENT_F); @@ -60,7 +60,7 @@ public: doc[FPSTR(HA_DEVICE_CLASS)] = F("volume_flow_rate"); if (unit == UnitSystem::METRIC) { doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = FPSTR(HA_UNIT_OF_MEASUREMENT_L_MIN); - + } else if (unit == UnitSystem::IMPERIAL) { doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = FPSTR(HA_UNIT_OF_MEASUREMENT_GAL_MIN); } @@ -110,19 +110,19 @@ public: case Sensors::Purpose::OUTDOOR_TEMP: doc[FPSTR(HA_ICON)] = F("mdi:home-thermometer-outline"); break; - + case Sensors::Purpose::INDOOR_TEMP: doc[FPSTR(HA_ICON)] = F("mdi:home-thermometer"); break; - + case Sensors::Purpose::HEATING_TEMP: doc[FPSTR(HA_ICON)] = F("mdi:radiator"); break; - + case Sensors::Purpose::HEATING_RETURN_TEMP: doc[FPSTR(HA_ICON)] = F("mdi:heating-coil"); break; - + case Sensors::Purpose::DHW_TEMP: doc[FPSTR(HA_ICON)] = F("mdi:faucet"); break; @@ -130,7 +130,7 @@ public: case Sensors::Purpose::DHW_RETURN_TEMP: doc[FPSTR(HA_ICON)] = F("mdi:heating-coil"); break; - + case Sensors::Purpose::EXHAUST_TEMP: doc[FPSTR(HA_ICON)] = F("mdi:smoke"); break; @@ -193,7 +193,7 @@ public: doc[FPSTR(HA_DEVICE_CLASS)] = FPSTR(S_TEMPERATURE); if (unit == UnitSystem::METRIC) { doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = FPSTR(HA_UNIT_OF_MEASUREMENT_C); - + } else if (unit == UnitSystem::IMPERIAL) { doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = FPSTR(HA_UNIT_OF_MEASUREMENT_F); } @@ -214,7 +214,7 @@ public: case Sensors::ValueType::BATTERY: Sensors::makeObjectIdWithSuffix(objId, sSensor.name, FPSTR(S_BATTERY)); sName += F(" battery"); - + doc[FPSTR(HA_DEVICE_CLASS)] = FPSTR(S_BATTERY); doc[FPSTR(HA_ENTITY_CATEGORY)] = FPSTR(HA_ENTITY_CATEGORY_DIAGNOSTIC); doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = FPSTR(HA_UNIT_OF_MEASUREMENT_PERCENT); @@ -225,7 +225,7 @@ public: case Sensors::ValueType::RSSI: Sensors::makeObjectIdWithSuffix(objId, sSensor.name, FPSTR(S_RSSI)); sName += F(" RSSI"); - + doc[FPSTR(HA_DEVICE_CLASS)] = F("signal_strength"); doc[FPSTR(HA_ENTITY_CATEGORY)] = FPSTR(HA_ENTITY_CATEGORY_DIAGNOSTIC); doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = F("dBm"); @@ -264,8 +264,8 @@ public: // object id's doc[FPSTR(HA_UNIQUE_ID)] = this->getUniqueIdWithPrefix(objId.c_str()); doc[FPSTR(HA_DEFAULT_ENTITY_ID)] = this->getEntityIdWithPrefix( - sSensor.type == Sensors::Type::MANUAL - ? FPSTR(HA_ENTITY_NUMBER) + sSensor.type == Sensors::Type::MANUAL + ? FPSTR(HA_ENTITY_NUMBER) : FPSTR(HA_ENTITY_SENSOR), objId.c_str() ); @@ -346,7 +346,7 @@ public: doc[FPSTR(HA_NAME)] = sName; } - + const String& configTopic = this->makeConfigTopic(FPSTR(HA_ENTITY_BINARY_SENSOR), objId.c_str()); objId.clear(); @@ -393,7 +393,7 @@ public: doc[FPSTR(HA_NAME)] = sName; } - + const String& configTopic = this->makeConfigTopic(FPSTR(HA_ENTITY_SENSOR), objId.c_str()); objId.clear(); @@ -477,7 +477,7 @@ public: if (unit == UnitSystem::METRIC) { doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = FPSTR(HA_UNIT_OF_MEASUREMENT_C); - + } else if (unit == UnitSystem::IMPERIAL) { doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = FPSTR(HA_UNIT_OF_MEASUREMENT_F); } @@ -535,7 +535,7 @@ public: doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = FPSTR(HA_UNIT_OF_MEASUREMENT_C); doc[FPSTR(HA_MIN)] = 0; doc[FPSTR(HA_MAX)] = 99; - + } else if (unit == UnitSystem::IMPERIAL) { doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = FPSTR(HA_UNIT_OF_MEASUREMENT_F); doc[FPSTR(HA_MIN)] = 32; @@ -569,7 +569,7 @@ public: doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = FPSTR(HA_UNIT_OF_MEASUREMENT_C); doc[FPSTR(HA_MIN)] = 1; doc[FPSTR(HA_MAX)] = 100; - + } else if (unit == UnitSystem::IMPERIAL) { doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = FPSTR(HA_UNIT_OF_MEASUREMENT_F); doc[FPSTR(HA_MIN)] = 33; @@ -604,7 +604,7 @@ public: doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = FPSTR(HA_UNIT_OF_MEASUREMENT_C); doc[FPSTR(HA_MIN)] = 0; doc[FPSTR(HA_MAX)] = 99; - + } else if (unit == UnitSystem::IMPERIAL) { doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = FPSTR(HA_UNIT_OF_MEASUREMENT_F); doc[FPSTR(HA_MIN)] = 32; @@ -638,7 +638,7 @@ public: doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = FPSTR(HA_UNIT_OF_MEASUREMENT_C); doc[FPSTR(HA_MIN)] = 1; doc[FPSTR(HA_MAX)] = 100; - + } else if (unit == UnitSystem::IMPERIAL) { doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = FPSTR(HA_UNIT_OF_MEASUREMENT_F); doc[FPSTR(HA_MIN)] = 33; @@ -789,7 +789,7 @@ public: doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = FPSTR(HA_UNIT_OF_MEASUREMENT_C); doc[FPSTR(HA_MIN)] = -99; doc[FPSTR(HA_MAX)] = 99; - + } else if (unit == UnitSystem::IMPERIAL) { doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = FPSTR(HA_UNIT_OF_MEASUREMENT_F); doc[FPSTR(HA_MIN)] = -146; @@ -823,7 +823,7 @@ public: doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = FPSTR(HA_UNIT_OF_MEASUREMENT_C); doc[FPSTR(HA_MIN)] = 1; doc[FPSTR(HA_MAX)] = 100; - + } else if (unit == UnitSystem::IMPERIAL) { doc[FPSTR(HA_UNIT_OF_MEASUREMENT)] = FPSTR(HA_UNIT_OF_MEASUREMENT_F); doc[FPSTR(HA_MIN)] = 1; @@ -1238,7 +1238,7 @@ public: if (unit == UnitSystem::METRIC) { doc[FPSTR(HA_TEMPERATURE_UNIT)] = "C"; - + } else if (unit == UnitSystem::IMPERIAL) { doc[FPSTR(HA_TEMPERATURE_UNIT)] = "F"; } @@ -1290,7 +1290,7 @@ public: if (unit == UnitSystem::METRIC) { doc[FPSTR(HA_TEMPERATURE_UNIT)] = "C"; - + } else if (unit == UnitSystem::IMPERIAL) { doc[FPSTR(HA_TEMPERATURE_UNIT)] = "F"; } @@ -1393,7 +1393,7 @@ public: bool deleteDhwState() { return this->publish(this->makeConfigTopic(FPSTR(HA_ENTITY_BINARY_SENSOR), F("dhw")).c_str()); } - + bool deleteInputDhwTarget() { return this->publish(this->makeConfigTopic(FPSTR(HA_ENTITY_NUMBER), F("dhw_target")).c_str()); } @@ -1408,4 +1408,4 @@ public: }; const char HaHelper::AVAILABILITY_OT_CONN[] = "{{ iif(value_json.slave.connected, 'online', 'offline') }}"; -const char HaHelper::AVAILABILITY_SENSOR_CONN[] = "{{ iif(value_json.connected, 'online', 'offline') }}"; \ No newline at end of file +const char HaHelper::AVAILABILITY_SENSOR_CONN[] = "{{ iif(value_json.connected, 'online', 'offline') }}"; diff --git a/src/MainTask.h b/src/MainTask.h index f087921..88a4918 100644 --- a/src/MainTask.h +++ b/src/MainTask.h @@ -10,7 +10,7 @@ extern FileData fsNetworkSettings, fsSettings, fsSensorsSettings; class MainTask : public Task { public: - MainTask(bool _enabled = false, unsigned long _interval = 0) : Task(_enabled, _interval) { + explicit MainTask(bool _enabled = false, unsigned long _interval = 0) : Task(_enabled, _interval) { this->blinker = new Blinker(); network->setDelayCallback([this](unsigned int time) { @@ -175,7 +175,7 @@ protected: this->cascadeControl(); this->externalPump(); this->miscRunned = millis(); - + return true; } @@ -200,7 +200,7 @@ protected: minFreeHeapDiff = this->minFreeHeap - minFreeHeap; this->minFreeHeap = minFreeHeap; } - + size_t minMaxFreeBlockHeap = getMaxFreeBlockHeap(true); size_t minMaxFreeBlockHeapDiff = 0; if (minMaxFreeBlockHeap < this->minMaxFreeBlockHeap || this->minMaxFreeBlockHeap == 0) { @@ -229,7 +229,7 @@ protected: if (value < lowTemp) { lowTemp = value; } - + availableSensors++; } @@ -238,7 +238,7 @@ protected: if (value < lowTemp) { lowTemp = value; } - + availableSensors++; } @@ -253,7 +253,7 @@ protected: if (availableSensors) { if (vars.master.heating.freezing) { - if (lowTemp - (float) settings.heating.freezeProtection.highTemp + 0.0001f >= 0.0f) { + if (lowTemp - static_cast(settings.heating.freezeProtection.highTemp) + 0.0001f >= 0.0f) { vars.master.heating.freezing = false; Log.sinfoln( @@ -264,7 +264,7 @@ protected: } } else { - if ((float) settings.heating.freezeProtection.lowTemp - lowTemp + 0.0001f >= 0.0f) { + if (static_cast(settings.heating.freezeProtection.lowTemp) - lowTemp + 0.0001f >= 0.0f) { vars.master.heating.freezing = true; if (!settings.heating.enabled) { @@ -304,7 +304,7 @@ protected: if (!settings.equitherm.enabled && settings.pid.enabled) { emergencyFlags |= 0b00000010; } - + if (settings.opentherm.options.nativeOTC) { emergencyFlags |= 0b00000100; } @@ -353,7 +353,7 @@ protected: if (configuredGpio != GPIO_IS_NOT_CONFIGURED) { digitalWrite(configuredGpio, LOW); } - + if (GPIO_IS_VALID(settings.system.statusLedGpio)) { configuredGpio = settings.system.statusLedGpio; pinMode(configuredGpio, OUTPUT); @@ -437,7 +437,7 @@ protected: Log.sinfoln(FPSTR(L_CASCADE_INPUT), F("Deinitialized on GPIO %hhu"), configuredInputGpio); } - + if (GPIO_IS_VALID(settings.cascadeControl.input.gpio)) { configuredInputGpio = settings.cascadeControl.input.gpio; pinMode(configuredInputGpio, INPUT); @@ -479,7 +479,7 @@ protected: } } } - + if (!settings.cascadeControl.input.enabled || configuredInputGpio == GPIO_IS_NOT_CONFIGURED) { if (!vars.cascadeControl.input) { vars.cascadeControl.input = true; @@ -502,14 +502,14 @@ protected: Log.sinfoln(FPSTR(L_CASCADE_OUTPUT), F("Deinitialized on GPIO %hhu"), configuredOutputGpio); } - + if (GPIO_IS_VALID(settings.cascadeControl.output.gpio)) { configuredOutputGpio = settings.cascadeControl.output.gpio; pinMode(configuredOutputGpio, OUTPUT); digitalWrite( configuredOutputGpio, settings.cascadeControl.output.invertState - ? HIGH + ? HIGH : LOW ); @@ -538,7 +538,7 @@ protected: if (value != outputTempValue) { outputTempValue = value; outputChangedTs = millis(); - + } else if (millis() - outputChangedTs >= settings.cascadeControl.output.thresholdTime * 1000u) { vars.cascadeControl.output = value; @@ -591,14 +591,14 @@ protected: if (configuredGpio != GPIO_IS_NOT_CONFIGURED) { digitalWrite(configuredGpio, LOW); } - + if (GPIO_IS_VALID(settings.externalPump.gpio)) { configuredGpio = settings.externalPump.gpio; pinMode(configuredGpio, OUTPUT); digitalWrite( configuredGpio, settings.externalPump.invertState - ? HIGH + ? HIGH : LOW ); @@ -625,13 +625,13 @@ protected: } else if (vars.master.heating.enabled && !this->heatingEnabled) { this->heatingEnabled = true; } - + if (!settings.externalPump.use) { if (vars.externalPump.state) { digitalWrite( configuredGpio, settings.externalPump.invertState - ? HIGH + ? HIGH : LOW ); @@ -649,7 +649,7 @@ protected: digitalWrite( configuredGpio, settings.externalPump.invertState - ? HIGH + ? HIGH : LOW ); @@ -662,7 +662,7 @@ protected: digitalWrite( configuredGpio, settings.externalPump.invertState - ? HIGH + ? HIGH : LOW ); @@ -683,7 +683,7 @@ protected: digitalWrite( configuredGpio, settings.externalPump.invertState - ? LOW + ? LOW : HIGH ); @@ -697,11 +697,11 @@ protected: digitalWrite( configuredGpio, settings.externalPump.invertState - ? LOW + ? LOW : HIGH ); Log.sinfoln(FPSTR(L_EXTPUMP), F("Enabled: anti stuck")); } } -}; \ No newline at end of file +}; diff --git a/src/MqttTask.h b/src/MqttTask.h index cfb9a05..bc74ec5 100644 --- a/src/MqttTask.h +++ b/src/MqttTask.h @@ -8,7 +8,7 @@ extern FileData fsSettings; class MqttTask : public Task { public: - MqttTask(bool _enabled = false, unsigned long _interval = 0) : Task(_enabled, _interval) { + explicit MqttTask(bool _enabled = false, unsigned long _interval = 0) : Task(_enabled, _interval) { this->wifiClient = new MqttWiFiClient(); this->client = new MqttClient(this->wifiClient); this->writer = new MqttWriter(this->client, 256); @@ -42,7 +42,7 @@ public: this->onDisconnect(); this->connected = false; } - + Task::disable(); Log.sinfoln(FPSTR(L_MQTT), F("Disabled")); @@ -96,7 +96,7 @@ protected: const char* getTaskName() override { return "Mqtt"; } - + /*BaseType_t getTaskCore() override { return 1; }*/ @@ -137,7 +137,7 @@ protected: for (size_t i = 0; i < length && this->client->available(); i++) { payload[i] = this->client->read(); } - + this->onMessage(topic, payload, length); }); @@ -340,7 +340,7 @@ protected: this->haHelper->publishSignalQualityDynamicSensor(sSettings, false); this->haHelper->publishDynamicSensor(sSettings, Sensors::ValueType::TEMPERATURE, settings.system.unitSystem); break; - + default: this->haHelper->publishDynamicSensor(sSettings, Sensors::ValueType::PRIMARY, settings.system.unitSystem); } @@ -443,7 +443,7 @@ protected: } else if (payload[i] == 10) { Log.print(F("\r\n> ")); } else { - Log.print((char) payload[i]); + Log.print(static_cast(payload[i])); } } Log.print(F("\r\n\n")); @@ -567,7 +567,7 @@ protected: this->haHelper->publishSignalQualityDynamicSensor(sSettings, false); this->haHelper->publishDynamicSensor(sSettings, Sensors::ValueType::TEMPERATURE, settings.system.unitSystem); break; - + default: this->haHelper->publishDynamicSensor(sSettings, Sensors::ValueType::PRIMARY, settings.system.unitSystem); } @@ -664,4 +664,4 @@ protected: return this->writer->publish(topic, doc, true); } -}; \ No newline at end of file +}; diff --git a/src/OpenThermTask.h b/src/OpenThermTask.h index ec61619..81158a4 100644 --- a/src/OpenThermTask.h +++ b/src/OpenThermTask.h @@ -3,7 +3,7 @@ extern FileData fsSettings; class OpenThermTask : public Task { public: - OpenThermTask(bool _enabled = false, unsigned long _interval = 0) : Task(_enabled, _interval) {} + explicit OpenThermTask(bool _enabled = false, unsigned long _interval = 0) : Task(_enabled, _interval) {} ~OpenThermTask() { delete this->instance; @@ -41,7 +41,7 @@ protected: uint32_t getTaskStackSize() override { return 7500; } - + BaseType_t getTaskCore() override { return 0; } @@ -160,7 +160,7 @@ protected: if (this->configuredRxLedGpio != GPIO_IS_NOT_CONFIGURED) { digitalWrite(this->configuredRxLedGpio, LOW); } - + if (GPIO_IS_VALID(settings.opentherm.rxLedGpio)) { this->configuredRxLedGpio = settings.opentherm.rxLedGpio; pinMode(this->configuredRxLedGpio, OUTPUT); @@ -178,8 +178,8 @@ protected: && !vars.master.heating.overheat; // DHW settings - vars.master.dhw.enabled = settings.opentherm.options.dhwSupport - && settings.dhw.enabled + vars.master.dhw.enabled = settings.opentherm.options.dhwSupport + && settings.dhw.enabled && !vars.master.dhw.overheat; vars.master.dhw.targetTemp = settings.dhw.target; @@ -236,7 +236,7 @@ protected: F("Failed receive boiler status: %s"), CustomOpenTherm::statusToString(this->instance->getLastResponseStatus()) ); - + } else { vars.slave.heating.active = CustomOpenTherm::isCentralHeatingActive(response); vars.slave.dhw.active = settings.opentherm.options.dhwSupport ? CustomOpenTherm::isHotWaterActive(response) : false; @@ -251,7 +251,7 @@ protected: } else if (vars.slave.diag.active) { vars.slave.diag.active = false; } - + Log.snoticeln( FPSTR(L_OT), F("Received boiler status. Heating: %hhu; DHW: %hhu; flame: %hhu; cooling: %hhu; channel 2: %hhu; fault: %hhu; diag: %hhu"), vars.slave.heating.active, vars.slave.dhw.active, @@ -270,15 +270,15 @@ protected: F("Connected, downtime: %lu s."), (millis() - this->disconnectedTime) / 1000 ); - + this->connectedTime = millis(); vars.slave.connected = true; - + } else if (vars.slave.connected && millis() - this->lastSuccessResponse > 6325) { Log.swarningln( FPSTR(L_OT), F("Disconnected, uptime: %lu s."), - (millis() - this->connectedTime) / 1000 + (millis() - this->connectedTime) / 1000 ); // Mark sensors as disconnected @@ -403,7 +403,7 @@ protected: FPSTR(L_OT), F("Received min modulation: %hhu%%, max power: %.2f kW"), vars.slave.modulation.min, vars.slave.power.max ); - + if (settings.heating.maxModulation < vars.slave.modulation.min) { settings.heating.maxModulation = vars.slave.modulation.min; fsSettings.update(); @@ -519,7 +519,7 @@ protected: Log.swarningln(FPSTR(L_SETTINGS_HEATING), F("Updated max temp: %hhu"), settings.heating.maxTemp); } - + } else { Log.swarningln(FPSTR(L_OT_HEATING), F("Failed receive min/max temp")); } @@ -542,7 +542,7 @@ protected: } else { Log.swarningln(FPSTR(L_OT), F("Failed receive fault code")); } - + } else if (vars.slave.fault.code != 0) { vars.slave.fault.code = 0; } @@ -558,7 +558,7 @@ protected: } else { Log.swarningln(FPSTR(L_OT), F("Failed receive diag code")); } - + } else if (vars.slave.diag.code != 0) { vars.slave.diag.code = 0; } @@ -767,7 +767,7 @@ protected: } } vars.slave.power.current = power; - + Log.snoticeln( FPSTR(L_OT), F("Received modulation level: %hhu%%, power: %.2f of %.2f kW (min: %.2f kW)"), vars.slave.modulation.current, vars.slave.power.current, @@ -1027,7 +1027,7 @@ protected: Log.swarningln(FPSTR(L_OT), F("Failed receive outdoor temp")); } } - + // Update solar storage temp if (Sensors::getAmountByType(Sensors::Type::OT_SOLAR_STORAGE_TEMP, true)) { if (this->updateSolarStorageTemp()) { @@ -1195,7 +1195,7 @@ protected: if (vars.slave.diag.active) { if (this->instance->sendServiceReset()) { Log.sinfoln(FPSTR(L_OT), F("Boiler diagnostic reset successfully")); - + } else { Log.serrorln(FPSTR(L_OT), F("Boiler diagnostic reset failed")); } @@ -1247,7 +1247,7 @@ protected: FPSTR(L_OT_HEATING), F("Set current indoor temp: %.2f (converted: %.2f, response: %.2f)"), indoorTemp, convertedTemp, vars.slave.heating.indoorTemp ); - + } else { Log.swarningln(FPSTR(L_OT_HEATING), F("Failed set current indoor temp")); } @@ -1401,7 +1401,7 @@ protected: ); if (vars.master.heating.overheat) { - if ((float) settings.heating.overheatProtection.lowTemp - highTemp + 0.0001f >= 0.0f) { + if (static_cast(settings.heating.overheatProtection.lowTemp) - highTemp + 0.0001f >= 0.0f) { vars.master.heating.overheat = false; Log.sinfoln( @@ -1411,7 +1411,7 @@ protected: } } else if (vars.slave.heating.active) { - if (highTemp - (float) settings.heating.overheatProtection.highTemp + 0.0001f >= 0.0f) { + if (highTemp - static_cast(settings.heating.overheatProtection.highTemp) + 0.0001f >= 0.0f) { vars.master.heating.overheat = true; Log.swarningln( @@ -1441,7 +1441,7 @@ protected: ); if (vars.master.dhw.overheat) { - if ((float) settings.dhw.overheatProtection.lowTemp - highTemp + 0.0001f >= 0.0f) { + if (static_cast(settings.dhw.overheatProtection.lowTemp) - highTemp + 0.0001f >= 0.0f) { vars.master.dhw.overheat = false; Log.sinfoln( @@ -1451,7 +1451,7 @@ protected: } } else if (vars.slave.dhw.active) { - if (highTemp - (float) settings.dhw.overheatProtection.highTemp + 0.0001f >= 0.0f) { + if (highTemp - static_cast(settings.dhw.overheatProtection.highTemp) + 0.0001f >= 0.0f) { vars.master.dhw.overheat = true; Log.swarningln( @@ -1480,10 +1480,10 @@ protected: if (this->setMasterVersion(vars.master.appVersion, vars.master.type)) { Log.snoticeln( - FPSTR(L_OT), F("Set master version: %u, type: %u"), + FPSTR(L_OT), F("Set master version: %u, type: %u"), vars.master.appVersion, vars.master.type ); - + } else { Log.swarningln(FPSTR(L_OT), F("Failed set master version")); } @@ -1517,7 +1517,7 @@ protected: FPSTR(L_OT), F("Set master member id: %u, flags: %u"), vars.master.memberId, vars.master.flags ); - + } else { Log.swarningln(FPSTR(L_OT), F("Failed set master config")); } @@ -1561,7 +1561,7 @@ protected: OpenThermMessageID::SConfigSMemberIDcode, 0 )); - + if (!CustomOpenTherm::isValidResponse(response)) { return false; @@ -1633,7 +1633,7 @@ protected: const unsigned int request = ((dayOfWeek & 0x07) << 13) | ((ptm->tm_hour & 0x1F) << 8) | (ptm->tm_min & 0x3F); - + const unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest( OpenThermRequestType::WRITE_DATA, OpenThermMessageID::DayTime, @@ -1892,11 +1892,11 @@ protected: * From slave member id code: * id: slave.memberIdCode & 0xFF, * flags: (slave.memberIdCode & 0xFFFF) >> 8 - * @param id - * @param flags - * @param force - * @return true - * @return false + * @param id + * @param flags + * @param force + * @return true + * @return false */ bool setMasterConfig(const uint8_t id, const uint8_t flags, const bool force = false) { const uint8_t rMemberId = (force || id > 0) ? id : vars.slave.memberId; @@ -2350,7 +2350,7 @@ protected: } vars.slave.dhw.flowRate = value; - + return true; } @@ -2393,7 +2393,7 @@ protected: } vars.slave.heating.returnTemp = CustomOpenTherm::getFloat(response); - + return true; } @@ -2432,7 +2432,7 @@ protected: return false; } - const float value = (float) CustomOpenTherm::getInt(response); + const float value = CustomOpenTherm::getInt(response); if (!isValidTemp(value, settings.opentherm.unitSystem, -40, 500)) { return false; } @@ -2456,7 +2456,7 @@ protected: return false; } - const float value = (float) CustomOpenTherm::getInt(response); + const float value = CustomOpenTherm::getInt(response); if (value <= 0) { return false; } @@ -2500,7 +2500,7 @@ protected: } vars.slave.solar.storage = CustomOpenTherm::getFloat(response); - + return true; } @@ -2519,7 +2519,7 @@ protected: } vars.slave.solar.collector = CustomOpenTherm::getFloat(response); - + return true; } diff --git a/src/PortalTask.h b/src/PortalTask.h index 5b4505f..556a659 100644 --- a/src/PortalTask.h +++ b/src/PortalTask.h @@ -18,7 +18,7 @@ extern WebSerial* webSerial; class PortalTask : public LeanTask { public: - PortalTask(bool _enabled = false, unsigned long _interval = 0) : LeanTask(_enabled, _interval) { + explicit PortalTask(bool _enabled = false, unsigned long _interval = 0) : LeanTask(_enabled, _interval) { this->webServer = new AsyncWebServer(80); this->dnsServer = new DNSServer(); } @@ -73,7 +73,7 @@ protected: if (request->authenticate(settings.portal.login, settings.portal.password, PROJECT_NAME)) { return next(); } - + return request->requestAuthentication(AsyncAuthType::AUTH_BASIC, PROJECT_NAME, "Authentication failed"); }); @@ -235,7 +235,7 @@ protected: if (sensorId < 0 || sensorId > 255 || !Sensors::isValidSensorId(sensorId)) { continue; } - + if (jsonToSensorSettings(sensorId, sensor.value(), Sensors::settings[sensorId])) { fsSensorsSettings.update(); changed = true; @@ -407,7 +407,7 @@ protected: responseDoc[sensorId] = Sensors::settings[sensorId].name; } } - + // send response response->setLength(); request->send(response); @@ -436,7 +436,7 @@ protected: response->setLength(); request->send(response); }).addMiddleware(&authMiddleware); - + auto& ssHandler = this->webServer->on("/api/sensor", HTTP_POST, [](AsyncWebServerRequest *request, JsonVariant &requestDoc) { if (vars.states.restarting) { return request->send(503); @@ -459,7 +459,7 @@ protected: if (!Sensors::isValidSensorId(sensorId)) { return request->send(404); } - + // prepare request auto prevSettings = Sensors::settings[sensorId]; bool changed = jsonToSensorSettings(sensorId, requestDoc, Sensors::settings[sensorId]); @@ -471,7 +471,7 @@ protected: auto& sSettings = Sensors::settings[sensorId]; sensorSettingsToJson(sensorId, sSettings, responseDoc); - + // send response response->setLength(); response->setCode(changed ? 201 : 200); @@ -515,7 +515,7 @@ protected: auto *response = new AsyncJsonResponse(); auto& responseDoc = response->getRoot(); varsToJson(vars, responseDoc); - + // send response response->setLength(); response->setCode(changed ? 201 : 200); @@ -570,7 +570,7 @@ protected: docPsram[FPSTR(S_FREE)] = ESP.getFreePsram(); docPsram[FPSTR(S_MIN_FREE)] = ESP.getMinFreePsram(); docPsram[FPSTR(S_MAX_FREE_BLOCK)] = ESP.getMaxAllocPsram(); - + auto docChip = doc[FPSTR(S_CHIP)].to(); docChip[FPSTR(S_MODEL)] = ESP.getChipModel(); docChip[FPSTR(S_REV)] = ESP.getChipRevision(); @@ -605,7 +605,7 @@ protected: docHeap[FPSTR(S_MIN_FREE)] = getFreeHeap(true); docHeap[FPSTR(S_MAX_FREE_BLOCK)] = getMaxFreeBlockHeap(); docHeap[FPSTR(S_MIN_MAX_FREE_BLOCK)] = getMaxFreeBlockHeap(true); - + auto docChip = doc[FPSTR(S_CHIP)].to(); docChip[FPSTR(S_MODEL)] = ESP.getChipModel(); docChip[FPSTR(S_REV)] = ESP.getChipRevision(); @@ -815,4 +815,4 @@ protected: strftime(localNowValue, sizeof(localNowValue), PSTR("%Y-%m-%d-%H-%M-%S"), localNow); snprintf_P(filename, maxSizeFilename, PSTR("%s_%s_%s.json"), networkSettings.hostname, localNowValue, type); } -}; \ No newline at end of file +}; diff --git a/src/RegulatorTask.h b/src/RegulatorTask.h index d67a568..8bd2420 100644 --- a/src/RegulatorTask.h +++ b/src/RegulatorTask.h @@ -5,7 +5,7 @@ GyverPID pidRegulator(0, 0, 0); class RegulatorTask : public LeanTask { public: - RegulatorTask(bool _enabled = false, unsigned long _interval = 0) : LeanTask(_enabled, _interval) {} + explicit RegulatorTask(bool _enabled = false, unsigned long _interval = 0) : LeanTask(_enabled, _interval) {} protected: float prevHeatingTarget = 0.0f; @@ -23,7 +23,7 @@ protected: uint32_t getTaskStackSize() override { return 5000; } - + /*BaseType_t getTaskCore() override { return 1; }*/ @@ -158,7 +158,7 @@ protected: 1.0f / settings.equitherm.exponent ); float etResult = settings.heating.target + settings.equitherm.shift + sf * ( - tempDelta >= 0 + tempDelta >= 0 ? pow(tempDelta, 1.0f / settings.equitherm.exponent) : -(pow(-(tempDelta), 1.0f / settings.equitherm.exponent)) ); diff --git a/src/Sensors.h b/src/Sensors.h index 8095414..a77d7bd 100644 --- a/src/Sensors.h +++ b/src/Sensors.h @@ -35,7 +35,7 @@ public: OT_HEATING_PUMP_HOURS = 25, OT_DHW_PUMP_HOURS = 26, OT_COOLING_HOURS = 27, - + NTC_10K_TEMP = 50, DALLAS_TEMP = 51, BLUETOOTH = 52, @@ -198,7 +198,7 @@ public: auto& sSensor = settings[sensorId]; auto& rSensor = results[sensorId]; - + float compensatedValue = value; if (sSensor.type == Type::HEATING_SETPOINT_TEMP || sSensor.type == Type::MANUAL) { rSensor.values[valueId] = compensatedValue; @@ -221,7 +221,7 @@ public: if (sSensor.filtering && fabsf(rSensor.values[valueId]) >= 0.1f) { rSensor.values[valueId] += (compensatedValue - rSensor.values[valueId]) * sSensor.filteringFactor; - + } else { rSensor.values[valueId] = compensatedValue; } @@ -254,11 +254,11 @@ public: } uint8_t updated = 0; - + // read sensors data for current instance for (uint8_t sensorId = 0; sensorId <= getMaxSensorId(); sensorId++) { auto& sSensor = settings[sensorId]; - + // only target & valid sensors if (!sSensor.enabled || sSensor.type != type) { continue; @@ -301,7 +301,7 @@ public: FPSTR(L_SENSORS), F("#%hhu '%s' new status: %s"), sensorId, sSensor.name, status ? F("CONNECTED") : F("DISCONNECTED") ); - + rSensor.connected = status; } @@ -318,11 +318,11 @@ public: } uint8_t updated = 0; - + // read sensors data for current instance for (uint8_t sensorId = 0; sensorId <= getMaxSensorId(); sensorId++) { auto& sSensor = settings[sensorId]; - + // only target & valid sensors if (!sSensor.enabled || sSensor.type != type) { continue; @@ -345,7 +345,7 @@ public: if (!isValidValueId(valueId)) { return defaultValue; } - + float value = 0.0f; uint8_t amount = 0; @@ -440,13 +440,13 @@ public: return value; } - template + template static String cleanName(T value, char space = ' ') { String res = value; return cleanName(res, space); } - template + template static String& makeObjectId(String& res, T value, char separator = '_') { res = value; cleanName(res); @@ -456,7 +456,7 @@ public: return res; } - template + template static String makeObjectId(T value, char separator = '_') { String res; makeObjectId(res, value, separator); @@ -464,7 +464,7 @@ public: return res; } - template + template static String& makeObjectIdWithSuffix(String& res, TV value, TS suffix, char separator = '_') { res.clear(); makeObjectId(res, value, separator); @@ -474,14 +474,14 @@ public: return res; } - template + template static String makeObjectIdWithSuffix(TV value, TS suffix, char separator = '_') { String res; makeObjectIdWithSuffix(res, value, suffix, separator); return res; } - template + template static String& makeObjectIdWithPrefix(String& res, TV value, TP prefix, char separator = '_') { res = prefix; res += separator; @@ -490,7 +490,7 @@ public: return res; } - template + template static String makeObjectIdWithPrefix(TV value, TP prefix, char separator = '_') { String res; return makeObjectIdWithPrefix(res, value, prefix, separator); @@ -503,4 +503,4 @@ public: uint8_t Sensors::maxSensors = 0; Sensors::Settings* Sensors::settings = nullptr; -Sensors::Result* Sensors::results = nullptr; \ No newline at end of file +Sensors::Result* Sensors::results = nullptr; diff --git a/src/SensorsTask.h b/src/SensorsTask.h index 905bd88..3e23fac 100644 --- a/src/SensorsTask.h +++ b/src/SensorsTask.h @@ -74,7 +74,7 @@ public: } static bool parseAtcData(const NimBLEAdvertisedDevice* device, uint8_t sensorId) { - NimBLEUUID serviceUuid((uint16_t) 0x181A); + NimBLEUUID serviceUuid(static_cast(0x181A)); auto serviceData = device->getServiceData(serviceUuid); if (!serviceData.size()) { @@ -91,7 +91,7 @@ public: ); return false; } - + Log.snoticeln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu, service %s: found ATC1441 format"), sensorId, serviceUuid.toString().c_str() @@ -125,7 +125,7 @@ public: } static bool parsePvvxData(const NimBLEAdvertisedDevice* device, uint8_t sensorId) { - NimBLEUUID serviceUuid((uint16_t) 0x181A); + NimBLEUUID serviceUuid(static_cast(0x181A)); auto serviceData = device->getServiceData(serviceUuid); if (!serviceData.size()) { @@ -142,7 +142,7 @@ public: ); return false; } - + Log.snoticeln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu, service %s: found PVVX format"), sensorId, serviceUuid.toString().c_str() @@ -178,7 +178,7 @@ public: } static bool parseBTHomeData(const NimBLEAdvertisedDevice* device, uint8_t sensorId) { - NimBLEUUID serviceUuid((uint16_t) 0xFCD2); + NimBLEUUID serviceUuid(static_cast(0xFCD2)); auto serviceData = device->getServiceData(serviceUuid); if (!serviceData.size()) { @@ -202,7 +202,7 @@ public: ); return false; } - + Log.snoticeln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu, service %s: found BTHome format"), sensorId, serviceUuid.toString().c_str() @@ -263,7 +263,7 @@ public: break; } - uint16_t rawHumidity = (static_cast(serviceData[serviceDataPos + 1]) << 8) + uint16_t rawHumidity = (static_cast(serviceData[serviceDataPos + 1]) << 8) | static_cast(serviceData[serviceDataPos]); float humidity = static_cast(rawHumidity) * 0.01f; Sensors::setValueById(sensorId, humidity, Sensors::ValueType::HUMIDITY, true, true); @@ -283,7 +283,7 @@ public: break; } - uint16_t batteryMv = (static_cast(serviceData[serviceDataPos + 1]) << 8) + uint16_t batteryMv = (static_cast(serviceData[serviceDataPos + 1]) << 8) | static_cast(serviceData[serviceDataPos]); serviceDataPos += 2; foundData = true; @@ -304,7 +304,7 @@ public: class SensorsTask : public LeanTask { public: - SensorsTask(bool _enabled = false, unsigned long _interval = 0) : LeanTask(_enabled, _interval) { + explicit SensorsTask(bool _enabled = false, unsigned long _interval = 0) : LeanTask(_enabled, _interval) { this->gpioLastPollingTime.reserve(2); // OneWire @@ -506,7 +506,7 @@ protected: for (uint8_t sensorId = 0; sensorId <= Sensors::getMaxSensorId(); sensorId++) { auto& sSensor = Sensors::settings[sensorId]; - + if (!sSensor.enabled || sSensor.type != Sensors::Type::DALLAS_TEMP || sSensor.purpose == Sensors::Purpose::NOT_CONFIGURED) { continue; } @@ -560,7 +560,7 @@ protected: // check & filling sensors address for (uint8_t sensorId = 0; sensorId <= Sensors::getMaxSensorId(); sensorId++) { auto& sSensor = Sensors::settings[sensorId]; - + if (!sSensor.enabled || sSensor.type != Sensors::Type::DALLAS_TEMP || sSensor.purpose == Sensors::Purpose::NOT_CONFIGURED) { continue; @@ -593,7 +593,7 @@ protected: if (sCheckingSensor.type != Sensors::Type::DALLAS_TEMP || checkingSensorId == sensorId) { continue; } - + if (sCheckingSensor.gpio != sSensor.gpio || isEmptyAddress(sCheckingSensor.address)) { continue; } @@ -654,7 +654,7 @@ protected: // read sensors data for current instance for (uint8_t sensorId = 0; sensorId <= Sensors::getMaxSensorId(); sensorId++) { auto& sSensor = Sensors::settings[sensorId]; - + // only target & valid sensors if (!sSensor.enabled || sSensor.type != Sensors::Type::DALLAS_TEMP || sSensor.purpose == Sensors::Purpose::NOT_CONFIGURED) { continue; @@ -662,7 +662,7 @@ protected: } else if (sSensor.gpio != gpio || isEmptyAddress(sSensor.address)) { continue; } - + auto& rSensor = Sensors::results[sensorId]; float value = instance.getTempC(sSensor.address); if (value == DEVICE_DISCONNECTED_C) { @@ -721,7 +721,7 @@ protected: for (uint8_t sensorId = 0; sensorId <= Sensors::getMaxSensorId(); sensorId++) { auto& sSensor = Sensors::settings[sensorId]; - + if (!sSensor.enabled || sSensor.purpose == Sensors::Purpose::NOT_CONFIGURED) { continue; } @@ -772,7 +772,7 @@ protected: if (rSensor.signalQuality > 0) { rSensor.signalQuality--; } - + this->gpioLastPollingTime[sSensor.gpio] = millis(); this->dhtIsPolling = false; }); @@ -805,7 +805,7 @@ protected: void pollingNtcSensors() { for (uint8_t sensorId = 0; sensorId <= Sensors::getMaxSensorId(); sensorId++) { auto& sSensor = Sensors::settings[sensorId]; - + if (!sSensor.enabled || sSensor.type != Sensors::Type::NTC_10K_TEMP || sSensor.purpose == Sensors::Purpose::NOT_CONFIGURED) { continue; } @@ -830,7 +830,7 @@ protected: } const float sensorResistance = value > 1 - ? DEFAULT_NTC_REF_RESISTANCE / (DEFAULT_NTC_VREF / (float) value - 1.0f) + ? DEFAULT_NTC_REF_RESISTANCE / (DEFAULT_NTC_VREF / static_cast(value) - 1.0f) : 0.0f; const float rawTemp = 1.0f / ( 1.0f / (DEFAULT_NTC_NOMINAL_TEMP + 273.15f) + @@ -969,4 +969,4 @@ protected: return result; } -}; \ No newline at end of file +}; diff --git a/src/Settings.h b/src/Settings.h index 2f3e23a..9eab570 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -133,7 +133,7 @@ struct Settings { uint8_t minTemp = DEFAULT_DHW_MIN_TEMP; uint8_t maxTemp = DEFAULT_DHW_MAX_TEMP; uint8_t maxModulation = 100; - + struct { uint8_t highTemp = 95; uint8_t lowTemp = 90; @@ -441,4 +441,4 @@ struct Variables { bool restarting = false; bool upgrading = false; } states; -} vars; \ No newline at end of file +} vars; diff --git a/src/defines.h b/src/defines.h index 411b770..d710c90 100644 --- a/src/defines.h +++ b/src/defines.h @@ -147,7 +147,7 @@ #endif #ifndef PROGMEM - #define PROGMEM + #define PROGMEM // NOLINT #endif #ifdef ARDUINO_ARCH_ESP32 @@ -168,4 +168,4 @@ enum class HysteresisAction : uint8_t { SET_ZERO_TARGET = 1 }; -char buffer[255]; \ No newline at end of file +char buffer[255]; diff --git a/src/main.cpp b/src/main.cpp index 97996a6..950282a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -71,7 +71,7 @@ void setup() { return tm{sec, min, hour}; }); - + Serial.begin(115200); #if ARDUINO_USB_MODE Serial.setTxBufferSize(512); diff --git a/src/strings.h b/src/strings.h index d4b8c62..c3ade14 100644 --- a/src/strings.h +++ b/src/strings.h @@ -1,6 +1,6 @@ #pragma once #ifndef PROGMEM - #define PROGMEM + #define PROGMEM // NOLINT #endif const char L_SETTINGS[] PROGMEM = "SETTINGS"; @@ -224,4 +224,4 @@ const char S_USE_DHCP[] PROGMEM = "useDhcp"; const char S_USER[] PROGMEM = "user"; const char S_VALUE[] PROGMEM = "value"; const char S_VERSION[] PROGMEM = "version"; -const char S_WEBSERIAL[] PROGMEM = "webSerial"; \ No newline at end of file +const char S_WEBSERIAL[] PROGMEM = "webSerial"; diff --git a/src/utils.h b/src/utils.h index 52c5d13..4816606 100644 --- a/src/utils.h +++ b/src/utils.h @@ -7,7 +7,7 @@ String getChipId(const char* prefix = nullptr, const char* suffix = nullptr) { + (prefix != nullptr ? strlen(prefix) : 0) + (suffix != nullptr ? strlen(suffix) : 0) ); - + if (prefix != nullptr) { chipId.concat(prefix); } @@ -139,7 +139,7 @@ inline bool isValidTemp(const float value, UnitSystem unit, const float min = 0. float roundf(float value, uint8_t decimals = 2) { if (decimals == 0) { - return (int)(value + 0.5f); + return static_cast(value + 0.5f); } else if (abs(value) < 0.00000001f) { return 0.0f; @@ -147,7 +147,7 @@ float roundf(float value, uint8_t decimals = 2) { float multiplier = pow10(decimals); value += 0.5f / multiplier * (value < 0.0f ? -1.0f : 1.0f); - return (int)(value * multiplier) / multiplier; + return static_cast(value * multiplier) / multiplier; } inline size_t getTotalHeap() { @@ -470,7 +470,7 @@ void settingsToJson(const Settings& src, JsonVariant dst, bool safe = false) { otOptions[FPSTR(S_ALWAYS_SEND_INDOOR_TEMP)] = src.opentherm.options.alwaysSendIndoorTemp; otOptions[FPSTR(S_NATIVE_OTC)] = src.opentherm.options.nativeOTC; otOptions[FPSTR(S_IMMERGAS_FIX)] = src.opentherm.options.immergasFix; - + auto mqtt = dst[FPSTR(S_MQTT)].to(); mqtt[FPSTR(S_ENABLED)] = src.mqtt.enabled; @@ -486,7 +486,7 @@ void settingsToJson(const Settings& src, JsonVariant dst, bool safe = false) { emergency[FPSTR(S_TARGET)] = roundf(src.emergency.target, 2); emergency[FPSTR(S_TRESHOLD_TIME)] = src.emergency.tresholdTime; } - + auto heating = dst[FPSTR(S_HEATING)].to(); heating[FPSTR(S_ENABLED)] = src.heating.enabled; heating[FPSTR(S_TURBO)] = src.heating.turbo; @@ -1774,8 +1774,8 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false float minTemp = indoorTempControl ? THERMOSTAT_INDOOR_MIN_TEMP : dst.heating.minTemp; float maxTemp = indoorTempControl ? THERMOSTAT_INDOOR_MAX_TEMP : dst.heating.maxTemp; - float value = !src[FPSTR(S_HEATING)][FPSTR(S_TARGET)].isNull() - ? src[FPSTR(S_HEATING)][FPSTR(S_TARGET)].as() + float value = !src[FPSTR(S_HEATING)][FPSTR(S_TARGET)].isNull() + ? src[FPSTR(S_HEATING)][FPSTR(S_TARGET)].as() : dst.heating.target; bool valid = isValidTemp( value, @@ -1801,8 +1801,8 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false // force check dhw target { - float value = !src[FPSTR(S_DHW)][FPSTR(S_TARGET)].isNull() - ? src[FPSTR(S_DHW)][FPSTR(S_TARGET)].as() + float value = !src[FPSTR(S_DHW)][FPSTR(S_TARGET)].isNull() + ? src[FPSTR(S_DHW)][FPSTR(S_TARGET)].as() : dst.dhw.target; bool valid = isValidTemp( value, @@ -2061,7 +2061,7 @@ bool jsonToSensorSettings(const uint8_t sensorId, const JsonVariantConst src, Se for (uint8_t i = 0; i < sizeof(dst.address); i++) { dst.address[i] = 0x00; } - + changed = true; } } @@ -2257,4 +2257,4 @@ bool jsonToVars(const JsonVariantConst src, Variables& dst) { } return changed; -} \ No newline at end of file +}