Review components files

This commit is contained in:
Edward Firmo
2024-04-08 23:47:16 +02:00
parent 88cca0d1bf
commit 10e0a47b6f
18 changed files with 385 additions and 369 deletions

View File

@@ -1,13 +1,12 @@
// utilities.cpp
#include "utilities.h"
#include <cstdint>
#include <cstring>
#include <cstdlib> // For malloc/free
#ifdef USE_ESP_IDF
#include "esp_heap_caps.h"
#elif defined(USE_ARDUINO)
#include "esp32-hal-psram.h"
#endif // ESP-IDF vs ARDUINO
#endif
namespace nspanel_ha_blueprint {
@@ -19,20 +18,21 @@ namespace nspanel_ha_blueprint {
UtilitiesGroups = static_cast<UtilitiesGroupValues*>(heap_caps_malloc(8 * sizeof(UtilitiesGroupValues), MALLOC_CAP_SPIRAM));
#elif defined(USE_ARDUINO)
UtilitiesGroups = static_cast<UtilitiesGroupValues*>(ps_malloc(8 * sizeof(UtilitiesGroupValues)));
#endif // ESP-IDF vs ARDUINO
#endif
if (!UtilitiesGroups) UtilitiesGroups = new UtilitiesGroupValues[8]; // Fallback to internal SRAM if PSRAM is not available or not supported
if (!UtilitiesGroups) return; // Fail nicely if no memory is available
if (!UtilitiesGroups) return; // Fail nicely if no memory is available
// Initialize UtilitiesGroups with default values
const UtilitiesGroupValues initialUtilitiesGroups[8] = {
{ "grid", "\0", "\0", 0 },
{ "group01", "\0", "\0", 0 },
{ "group02", "\0", "\0", 0 },
{ "group03", "\0", "\0", 0 },
{ "group04", "\0", "\0", 0 },
{ "group05", "\0", "\0", 0 },
{ "group06", "\0", "\0", 0 },
{ "home", "\0", "\0", 0 }
{"grid", "\0", "\0", 0},
{"group01", "\0", "\0", 0},
{"group02", "\0", "\0", 0},
{"group03", "\0", "\0", 0},
{"group04", "\0", "\0", 0},
{"group05", "\0", "\0", 0},
{"group06", "\0", "\0", 0},
{"home", "\0", "\0", 0}
};
for (size_t i = 0; i < 8; ++i) {
@@ -45,7 +45,7 @@ namespace nspanel_ha_blueprint {
void cleanupUtilitiesGroups() {
if (UtilitiesGroups != nullptr) {
free(UtilitiesGroups); // Compatible with both heap_caps_malloc and ps_malloc
free(UtilitiesGroups); // Compatible with both heap_caps_malloc and ps_malloc
UtilitiesGroups = nullptr; // Prevent dangling pointers
}
}