[Cleanup] Uncrustify files

This commit is contained in:
TD-er committed 2026-09-01 17:09:23 +02:00
1 parent 5e86820672
commit 8370cd47b3
8 files changed
+147 -138

No files matched your search

+20 -28
View File
@@ -4,7 +4,6 @@
#include "../Helpers/Misc.h"
#include "../Helpers/StringConverter.h"
void EventQueueStruct::add(const String& event, bool deduplicate)
{
if (!deduplicate || !isDuplicate(event)) {
@@ -13,36 +12,31 @@ void EventQueueStruct::add(const String& event, bool deduplicate)
reserve_special(tmp, event.length(), 0);
tmp = event;
#ifdef USE_SECOND_HEAP
# ifdef USE_SECOND_HEAP
// Do not add to the list while on 2nd heap
HeapSelectDram ephemeral;
#endif
# endif // ifdef USE_SECOND_HEAP
_eventQueue.emplace_back(std::move(tmp));
#else
#else // if defined(USE_SECOND_HEAP) || defined(ESP32)
_eventQueue.push_back(event);
#endif
#endif // if defined(USE_SECOND_HEAP) || defined(ESP32)
}
}
void EventQueueStruct::add(const __FlashStringHelper *event, bool deduplicate)
{
String str;
move_special(str, String(event), 0);
add(str, deduplicate);
}
void EventQueueStruct::addDeDup(const String& event)
{
add(event, true);
}
void EventQueueStruct::addDeDup(const __FlashStringHelper *event)
{
add(event, true);
}
void EventQueueStruct::addDeDup(const String& event) { add(event, true); }
void EventQueueStruct::addDeDup(const __FlashStringHelper *event) { add(event, true); }
void EventQueueStruct::addMove(String&& event, bool deduplicate)
{
@@ -53,12 +47,13 @@ void EventQueueStruct::addMove(String&& event, bool deduplicate)
String tmp;
move_special(tmp, std::move(event), 0);
#ifdef USE_SECOND_HEAP
# ifdef USE_SECOND_HEAP
// Do not add to the list while on 2nd heap
HeapSelectDram ephemeral;
#endif
# endif // ifdef USE_SECOND_HEAP
_eventQueue.emplace_back(std::move(tmp));
#else
#else // if defined(USE_SECOND_HEAP) || defined(ESP32)
_eventQueue.emplace_back(std::move(event));
#endif // ifdef USE_SECOND_HEAP
}
@@ -69,15 +64,15 @@ void EventQueueStruct::add(taskIndex_t TaskIndex, const String& varName, const S
if (Settings.UseRules) {
if (eventValue.isEmpty()) {
addMove(strformat(
F("%s#%s"),
getTaskDeviceName(TaskIndex).c_str(),
varName.c_str()));
F("%s#%s"),
getTaskDeviceName(TaskIndex).c_str(),
varName.c_str()));
} else {
addMove(strformat(
F("%s#%s=%s"),
getTaskDeviceName(TaskIndex).c_str(),
varName.c_str(),
eventValue.c_str()));
F("%s#%s=%s"),
getTaskDeviceName(TaskIndex).c_str(),
varName.c_str(),
eventValue.c_str()));
}
}
}
@@ -113,10 +108,7 @@ bool EventQueueStruct::getNext(String& event)
return true;
}
void EventQueueStruct::clear()
{
_eventQueue.clear();
}
void EventQueueStruct::clear() { _eventQueue.clear(); }
bool EventQueueStruct::isEmpty() const
{
+22 -15
View File
@@ -11,25 +11,33 @@
struct EventQueueStruct {
EventQueueStruct() = default;
void add(const String& event,
bool deduplicate = false);
void add(const String& event,
bool deduplicate = false);
void add(const __FlashStringHelper *event,
bool deduplicate = false);
void add(const __FlashStringHelper *event,
bool deduplicate = false);
void addDeDup(const String& event);
void addDeDup(const String& event);
void addDeDup(const __FlashStringHelper *event);
void addDeDup(const __FlashStringHelper *event);
void addMove(String&& event,
bool deduplicate = false);
void addMove(String&& event,
bool deduplicate = false);
// Add event formatted as Taskname#varName=eventvalue
void add(taskIndex_t TaskIndex, const String& varName, const String& eventValue);
void add(taskIndex_t TaskIndex, const String& varName, int eventValue);
void add(taskIndex_t TaskIndex, const __FlashStringHelper * varName, const String& eventValue);
void add(taskIndex_t TaskIndex, const __FlashStringHelper * varName, int eventValue);
void add(taskIndex_t TaskIndex,
const String& varName,
const String& eventValue);
void add(taskIndex_t TaskIndex,
const String& varName,
int eventValue);
void add(taskIndex_t TaskIndex,
const __FlashStringHelper *varName,
const String & eventValue);
void add(taskIndex_t TaskIndex,
const __FlashStringHelper *varName,
int eventValue);
bool getNext(String& event);
@@ -37,15 +45,14 @@ struct EventQueueStruct {
bool isEmpty() const;
std::size_t size() {
return _eventQueue.size();
}
std::size_t size() { return _eventQueue.size(); }
private:
bool isDuplicate(const String& event);
std::list<String>_eventQueue;
};
+17 -16
View File
@@ -143,28 +143,29 @@ bool LogEntry_t::validForSubscriber(uint8_t subscriber) const
{
return isValid() && (subscriber < NR_LOG_TO_DESTINATIONS) && bitRead(_subscriberPendingRead, subscriber);
}
/*
size_t LogEntry_t::print(Print& out, size_t offset, size_t length) const
{
if (offset > _strLength) { return 0; }
size_t LogEntry_t::print(Print& out, size_t offset, size_t length) const
{
if (offset > _strLength) { return 0; }
const char*begin = (const char *)_message;
const char*end = begin;
const char*begin = (const char *)_message;
const char*end = begin;
if (_strLength > (offset + length)) {
if (_strLength > (offset + length)) {
end += (offset + length);
}
else {
}
else {
end += _strLength;
}
const char*pos = begin + offset;
}
const char*pos = begin + offset;
for (; pos != end; ++pos) {
for (; pos != end; ++pos) {
if ((*pos == '\0') || (out.write(*pos) == 0)) { return pos - begin - offset; }
}
return pos - begin - offset;
}
*/
}
return pos - begin - offset;
}
*/
String LogEntry_t::getMessage() const
{
if (_message == nullptr) { return EMPTY_STRING; }
@@ -180,7 +181,7 @@ bool LogEntry_t::hasExpired(size_t freeMem) const
auto age = timePassedSince(_timestamp);
if (!isValid()) {
return true;
return true;
}
if (freeMem < LOGENTRY_FREEMEM_THRESHOLD) {
+9 -8
View File
@@ -46,16 +46,17 @@ struct LogEntry_t {
return isValid();
}
void setSubscribers();
void setSubscribers();
void markReadBySubscriber(uint8_t subscriber);
void markReadBySubscriber(uint8_t subscriber);
bool validForSubscriber(uint8_t subscriber) const;
/*
size_t print(Print& out,
size_t offset = 0,
size_t length = std::numeric_limits<size_t>::max()) const;
*/
bool validForSubscriber(uint8_t subscriber) const;
/*
size_t print(Print& out,
size_t offset = 0,
size_t length = std::numeric_limits<size_t>::max()) const;
*/
String getMessage() const;
bool hasExpired(size_t freeMem) const;
+1 -1
View File
@@ -253,7 +253,7 @@ bool EspEasy_Console_Port::process_serialWriteBuffer()
return totalWritten > 0;
}
const size_t chunkSize = availableForWrite > CONSOLE_MAX_WRITE_CHUNKSIZE
? CONSOLE_MAX_WRITE_CHUNKSIZE
: availableForWrite;
+46 -46
View File
@@ -31,17 +31,15 @@ extern "C" {
// FIXME TD-er: For ESP32 you need to provide the task number, or nullptr to get from the calling task.
uint32_t getCurrentFreeStack() {
return ((uint8_t *)esp_cpu_get_sp()) -
#if ESP_IDF_VERSION_MAJOR <= 5
pxTaskGetStackStart(nullptr);
#else
xTaskGetStackStart(nullptr);
#endif
return ((uint8_t *)esp_cpu_get_sp()) -
# if ESP_IDF_VERSION_MAJOR <= 5
pxTaskGetStackStart(nullptr);
# else
xTaskGetStackStart(nullptr);
# endif // if ESP_IDF_VERSION_MAJOR <= 5
}
uint32_t getFreeStackWatermark() {
return uxTaskGetStackHighWaterMark(nullptr);
}
uint32_t getFreeStackWatermark() { return uxTaskGetStackHighWaterMark(nullptr); }
#else // ifdef ESP32
@@ -52,11 +50,9 @@ uint32_t getCurrentFreeStack() {
return 4 * (sp - g_pcont->stack);
}
uint32_t getFreeStackWatermark() {
return cont_get_free_stack(g_pcont);
}
uint32_t getFreeStackWatermark() { return cont_get_free_stack(g_pcont); }
bool allocatedOnStack(const void *address) {
bool allocatedOnStack(const void *address) {
register uint32_t *sp asm ("a1");
if (sp < address) { return false; }
@@ -65,7 +61,6 @@ bool allocatedOnStack(const void *address) {
#endif // ESP32
/********************************************************************************************\
Get free system mem
\*********************************************************************************************/
@@ -80,6 +75,7 @@ uint32_t FreeMem()
}
#ifdef USE_SECOND_HEAP
uint32_t FreeMem2ndHeap()
{
HeapSelectIram ephemeral;
@@ -89,7 +85,6 @@ uint32_t FreeMem2ndHeap()
#endif // ifdef USE_SECOND_HEAP
uint32_t getMaxFreeBlock()
{
const uint32_t freemem = FreeMem();
@@ -172,10 +167,7 @@ void* special_realloc(void *ptr, size_t size) {
return res;
}
void *special_calloc(size_t num, size_t size)
{
return special_calloc(num, size, true);
}
void* special_calloc(size_t num, size_t size) { return special_calloc(num, size, true); }
void* special_calloc(size_t num, size_t size, bool preferHeap) {
void *res = nullptr;
@@ -187,7 +179,8 @@ void* special_calloc(size_t num, size_t size, bool preferHeap) {
}
#else // ifdef ESP32
# ifdef USE_SECOND_HEAP
if (!preferHeap || size > 64 || FreeMem() < 5000) {
if (!preferHeap || (size > 64) || (FreeMem() < 5000)) {
// Try allocating on ESP8266 2nd heap, only when sufficiently large data is needed
HeapSelectIram ephemeral;
@@ -205,20 +198,19 @@ void* special_calloc(size_t num, size_t size, bool preferHeap) {
res = calloc(num, size);
}
#if defined(ESP8266) && defined(USE_SECOND_HEAP)
if (res == nullptr) {
// Not successful, try allocating on (ESP8266) 2nd heap
HeapSelectIram ephemeral;
res = calloc(num, size);
}
#endif
#endif // if defined(ESP8266) && defined(USE_SECOND_HEAP)
return res;
}
#ifdef ESP8266
bool String_reserve_special(String& str, size_t size) {
return String_reserve_special(str, size, 48);
}
bool String_reserve_special(String& str, size_t size) { return String_reserve_special(str, size, 48); }
bool String_reserve_special(String& str, size_t size, size_t strLengthThreshold) {
@@ -226,36 +218,42 @@ bool String_reserve_special(String& str, size_t size, size_t strLengthThreshold)
// Nothing needs to be done
return true;
}
#ifdef USE_SECOND_HEAP
if (size >= strLengthThreshold || FreeMem() < 5000) {
# ifdef USE_SECOND_HEAP
if ((size >= strLengthThreshold) || (FreeMem() < 5000)) {
// Only try to store larger strings here as those tend to be kept for a longer period.
HeapSelectIram ephemeral;
// String does round up to nearest multiple of 16 bytes, so no need to round up to multiples of 32 bit here
if (str.reserve(size)) {
return true;
}
}
#endif
# endif // ifdef USE_SECOND_HEAP
return str.reserve(size);
}
#endif
#endif // ifdef ESP8266
#ifdef ESP32
// Special class to get access to the protected String functions
// This class only has a constructor which will perform
// This class only has a constructor which will perform
// the requested allocation in PSRAM when possible
class PSRAM_String : public String {
public:
PSRAM_String(size_t size) : String() {
sso.isSSO = 0; // setSSO(false);
ptr.buff = nullptr; // setBuffer(nullptr);
ptr.cap = 0; // setCapacity(0);
ptr.len = 0; // setLen(0);
class PSRAM_String : public String
{
public:
if (size != 0 && size > capacity() && UsePSRAM()) {
PSRAM_String(size_t size) : String() {
sso.isSSO = 0; // setSSO(false);
ptr.buff = nullptr; // setBuffer(nullptr);
ptr.cap = 0; // setCapacity(0);
ptr.len = 0; // setLen(0);
if ((size != 0) && (size > capacity()) && UsePSRAM()) {
size_t newSize = (size + 16) & (~0xf);
void *ptr = special_calloc(1, newSize);
void *ptr = special_calloc(1, newSize);
if (ptr != nullptr) {
setSSO(false);
setBuffer((char *)ptr);
@@ -264,21 +262,22 @@ class PSRAM_String : public String {
}
}
}
};
bool String_reserve_special(String& str, size_t size) {
return String_reserve_special(str, size, 48);
}
}; // class PSRAM_String
bool String_reserve_special(String& str, size_t size) { return String_reserve_special(str, size, 48); }
bool String_reserve_special(String& str, size_t size, size_t strLengthThreshold) {
if (size == 0) {
return true;
}
if (!UsePSRAM()) {
return str.reserve(size);
}
if (str.length() <= size) {
// As we like to move this to PSRAM, it also makes sense
// As we like to move this to PSRAM, it also makes sense
// to do this when the length equals size
PSRAM_String psram_str(size);
@@ -293,7 +292,7 @@ bool String_reserve_special(String& str, size_t size, size_t strLengthThreshold)
// Needs to be empty, so the buffer is moved.
// N.B. String::clear() = String::setlen(0))
str = std::move(psram_str);
str.clear();
str.clear();
if (tmp.length()) {
str = tmp;
@@ -301,4 +300,5 @@ bool String_reserve_special(String& str, size_t size, size_t strLengthThreshold)
}
return true;
}
#endif
#endif // ifdef ESP32
+22 -16
View File
@@ -1,8 +1,8 @@
#ifndef HELPERS_MEMORY_H
#define HELPERS_MEMORY_H
# define HELPERS_MEMORY_H
#include "../../ESPEasy_common.h"
# include "../../ESPEasy_common.h"
/*********************************************************************************************\
Memory management
@@ -13,17 +13,17 @@
// See: https://github.com/esp8266/Arduino/issues/2557
// https://github.com/esp8266/Arduino/issues/5148#issuecomment-424329183
// https://github.com/letscontrolit/ESPEasy/issues/1824
#ifdef ESP32
# ifdef ESP32
// FIXME TD-er: For ESP32 you need to provide the task number, or nullptr to get from the calling task.
uint32_t getCurrentFreeStack();
uint32_t getFreeStackWatermark();
#else // ifdef ESP32
# else // ifdef ESP32
extern "C" {
# include <cont.h>
# include <cont.h>
extern cont_t *g_pcont;
}
@@ -33,35 +33,41 @@ uint32_t getFreeStackWatermark();
bool allocatedOnStack(const void *address);
#endif // ESP32
# endif // ESP32
/********************************************************************************************\
Get free system mem
\*********************************************************************************************/
uint32_t FreeMem();
#ifdef USE_SECOND_HEAP
# ifdef USE_SECOND_HEAP
uint32_t FreeMem2ndHeap();
#endif
# endif
uint32_t getMaxFreeBlock();
#endif
#endif // ifndef HELPERS_MEMORY_H
/********************************************************************************************\
Special alloc functions to allocate in PSRAM if available
\*********************************************************************************************/
void *special_malloc(uint32_t size);
void *special_realloc(void *ptr, size_t size);
void *special_calloc(size_t num, size_t size);
void *special_calloc(size_t num, size_t size, bool preferHeap);
void* special_malloc(uint32_t size);
void* special_realloc(void *ptr,
size_t size);
void* special_calloc(size_t num,
size_t size);
void* special_calloc(size_t num,
size_t size,
bool preferHeap);
// Perform a special memory allocate for the buffer pointer in the String object
// Allocation is tried either on 2nd heap (ESP8266) or PSRAM (ESP32)
// when possible.
bool String_reserve_special(String& str, size_t size);
bool String_reserve_special(String& str, size_t size, size_t strLengthThreshold);
bool String_reserve_special(String& str,
size_t size);
bool String_reserve_special(String& str,
size_t size,
size_t strLengthThreshold);
+10 -8
View File
@@ -2,7 +2,7 @@
#include "../Helpers/StringConverter.h"
//#include "../WebServer/HTML_wrappers.h"
// #include "../WebServer/HTML_wrappers.h"
#include "../WebServer/Markup.h"
@@ -68,7 +68,8 @@ void KeyValueWriter_WebForm::write(const KeyValueStruct& kv)
const size_t nrValues = kv._values.size();
const bool format_pre =
!plain_text &&
// !summary_value_only &&
// !summary_value_only &&
(nrValues > 1 || kv._format == KeyValueStruct::Format::PreFormatted);
const bool format_note =
@@ -123,12 +124,13 @@ void KeyValueWriter_WebForm::write(const KeyValueStruct& kv)
}
#if FEATURE_TASKVALUE_UNIT_OF_MEASURE
// May need to include the unit before ending </pre>
// or else it will be shown on the next line
if (!plain_text && (nrValues == 1) && !summary_value_only) {
addUnit(kv.getUnit());
}
#endif
#endif // if FEATURE_TASKVALUE_UNIT_OF_MEASURE
if (format_pre) { getPrint().print(F("</pre>")); }
@@ -147,7 +149,7 @@ void KeyValueWriter_WebForm::write(const KeyValueStruct& kv)
UP_KeyValueWriter KeyValueWriter_WebForm::createChild()
{
UP_KeyValueWriter_WebForm child(new (std::nothrow) KeyValueWriter_WebForm(this));
UP_KeyValueWriter_WebForm child(new (std::nothrow) KeyValueWriter_WebForm(this));
return std::move(child);
@@ -156,7 +158,7 @@ UP_KeyValueWriter KeyValueWriter_WebForm::createChild()
UP_KeyValueWriter KeyValueWriter_WebForm::createChild(const String& header)
{
UP_KeyValueWriter_WebForm child(new (std::nothrow) KeyValueWriter_WebForm(header, this));
UP_KeyValueWriter_WebForm child(new (std::nothrow) KeyValueWriter_WebForm(header, this));
return std::move(child);
@@ -177,7 +179,7 @@ UP_KeyValueWriter KeyValueWriter_WebForm::createChildArray(const String& header)
UP_KeyValueWriter KeyValueWriter_WebForm::createNew()
{
UP_KeyValueWriter_WebForm child(new (std::nothrow) KeyValueWriter_WebForm());
UP_KeyValueWriter_WebForm child(new (std::nothrow) KeyValueWriter_WebForm());
return std::move(child);
@@ -186,7 +188,7 @@ UP_KeyValueWriter KeyValueWriter_WebForm::createNew()
UP_KeyValueWriter KeyValueWriter_WebForm::createNew(const String& header)
{
UP_KeyValueWriter_WebForm child(new (std::nothrow) KeyValueWriter_WebForm(header));
UP_KeyValueWriter_WebForm child(new (std::nothrow) KeyValueWriter_WebForm(header));
return std::move(child);
@@ -195,4 +197,4 @@ UP_KeyValueWriter KeyValueWriter_WebForm::createNew(const String& header)
bool KeyValueWriter_WebForm::allowHTML() const {
return true;
}
}