chore: fix cpplint

This commit is contained in:
Yurii
2026-05-17 04:38:53 +03:00
parent 14d2262d2f
commit af2d4624b3
27 changed files with 209 additions and 431 deletions
+4 -4
View File
@@ -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<uint8_t*>(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;
};
};
+1 -1
View File
@@ -7,7 +7,7 @@ public:
typedef std::function<void(unsigned long, uint8_t)> BeforeSendRequestCallback;
typedef std::function<void(unsigned long, unsigned long, OpenThermResponseStatus, uint8_t)> 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) {
@@ -49,7 +49,7 @@ public:
if (this->publishEventCallback) {
this->publishEventCallback(topic, false);
}
return false;
}
@@ -114,7 +114,7 @@ public:
return topic;
}
template <class T>
template <class T>
String getDeviceTopic(T value, char dpvSeparator = '/') {
String topic = "";
topic.concat(this->devicePrefix);
@@ -147,7 +147,7 @@ public:
return topic;
}
template <class DT, class VT>
template <class DT, class VT>
String getEntityIdWithPrefix(DT domain, VT value, char separator = '_') {
String topic = "";
topic.concat(domain);
@@ -158,7 +158,7 @@ public:
return topic;
}
template <class T>
template <class T>
String getUniqueIdWithPrefix(T value, char separator = '_') {
String topic = "";
topic.concat(this->devicePrefix);
+1 -1
View File
@@ -1,6 +1,6 @@
#pragma once
#ifndef PROGMEM
#define PROGMEM
#define PROGMEM // NOLINT
#endif
const char HA_ENTITY_BINARY_SENSOR[] PROGMEM = "binary_sensor";
+1 -1
View File
@@ -21,4 +21,4 @@ public:
return false;
}
#endif
};
};
+4 -4
View File
@@ -12,10 +12,10 @@ public:
typedef std::function<void(const char*, size_t, size_t, bool)> PublishEventCallback;
typedef std::function<void(size_t, size_t)> 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<uint8_t*>(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;
}
+4 -4
View File
@@ -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;
uint8_t NetworkConnection::rawDisconnectReason = 0;
+2 -2
View File
@@ -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;
};
}
}
+2 -2
View File
@@ -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;
}
};
}
}
-224
View File
@@ -1,224 +0,0 @@
#include <FS.h>
class DynamicPage : public RequestHandler {
public:
typedef std::function<bool(HTTPMethod, const String&)> CanHandleCallback;
typedef std::function<bool()> BeforeSendCallback;
typedef std::function<String(const char*)> 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;
};
+3 -3
View File
@@ -7,7 +7,7 @@ class StaticPage : public RequestHandler {
public:
typedef std::function<bool(HTTPMethod, const String&)> CanHandleCallback;
typedef std::function<bool()> BeforeSendCallback;
template <class T>
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;
};
};
+13 -13
View File
@@ -28,14 +28,14 @@ public:
typedef std::function<bool(AsyncWebServerRequest *request, UpgradeType)> BeforeUpgradeCallback;
typedef std::function<void(AsyncWebServerRequest *request, const UpgradeResult&, const UpgradeResult&)> 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};
};
};