Remove CONFIG_LWIP_MAX_SOCKETS

This was breaking `web_server`
Solves #2050
This commit is contained in:
Edward Firmo
2024-04-12 09:36:21 +02:00
parent 60078bd680
commit 2a0f92d548
4 changed files with 32 additions and 88 deletions

View File

@@ -4,12 +4,12 @@ import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components.esp32 import add_idf_sdkconfig_option
from esphome.core import CORE, coroutine_with_priority
from esphome.cpp_tools import CppFile
# from esphome.cpp_tools import CppFile
CODEOWNERS = ["@edwardtfn"]
nspanel_ha_blueprint_ns = cg.esphome_ns.namespace('nspanel_ha_blueprint')
MdiIcons = nspanel_ha_blueprint_ns.class_('MdiIcons', cg.Component)
# MdiIcons = nspanel_ha_blueprint_ns.class_('MdiIcons', cg.Component)
CONFIG_SCHEMA = cv.All(
cv.Schema({}),
@@ -27,18 +27,18 @@ async def to_code(config):
add_idf_sdkconfig_option("CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST", True)
add_idf_sdkconfig_option("CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY", True)
add_idf_sdkconfig_option("CONFIG_ESP32_REV_MIN_3", True)
# add_idf_sdkconfig_option("CONFIG_LWIP_MAX_SOCKETS", 5)
# add_idf_sdkconfig_option("CONFIG_MBEDTLS_DYNAMIC_BUFFER", True)
# add_idf_sdkconfig_option("CONFIG_MBEDTLS_DYNAMIC_FREE_CA_CERT", True)
# add_idf_sdkconfig_option("CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA", True)
# add_idf_sdkconfig_option("CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC", True)
# add_idf_sdkconfig_option("CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY", True)
# add_idf_sdkconfig_option("CONFIG_SPIRAM_RODATA", True)
# add_idf_sdkconfig_option("CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP", True)
# add_idf_sdkconfig_option("CONFIG_LWIP_MAX_SOCKETS", 5) # This breakes web_server
add_idf_sdkconfig_option("CONFIG_MBEDTLS_DYNAMIC_BUFFER", True)
add_idf_sdkconfig_option("CONFIG_MBEDTLS_DYNAMIC_FREE_CA_CERT", True)
add_idf_sdkconfig_option("CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA", True)
add_idf_sdkconfig_option("CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC", True)
add_idf_sdkconfig_option("CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY", True)
add_idf_sdkconfig_option("CONFIG_SPIRAM_RODATA", True)
add_idf_sdkconfig_option("CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP", True)
cg.add_define("USE_NSPANEL_HA_BLUEPRINT")
cg.add_global(nspanel_ha_blueprint_ns.using)
# Setup the MdiIcons class instance
mdi_icons = cg.new_Pvariable('mdi_icons')
yield cg.register_component(mdi_icons, config)
# mdi_icons = cg.new_Pvariable('mdi_icons')
# yield cg.register_component(mdi_icons, config)

View File

@@ -1,27 +1,26 @@
// mdiicons.cpp
#include "MdiIcons.h"
#include "mdiicons.h"
#include "esphome/core/log.h"
using namespace esphome;
// Setup method to allocate and initialize the icon pool
MdiIcons::MdiIcons() : iconPool(nullptr), iconPoolSize(0), iconPoolCapacity(100) {}
void MdiIcons::setup() {
iconPool = new MdiIcon[iconPoolCapacity]; // Allocate memory for the icon pool
iconPool = new MdiIcon[iconPoolCapacity];
if (!iconPool) {
ESP_LOGE("MdiIcons", "Failed to allocate memory for icons in PSRAM");
return;
}
memset(iconPool, 0, iconPoolCapacity * sizeof(MdiIcon)); // Initialize memory to zero
memset(iconPool, 0, iconPoolCapacity * sizeof(MdiIcon));
ESP_LOGI("MdiIcons", "Icon pool initialized with capacity %u", iconPoolCapacity);
}
// Method to log the configuration of the icon pool
void MdiIcons::dump_config() {
ESP_LOGCONFIG("MdiIcons", "MDI Icons component initialized with a pool capacity of %u", iconPoolCapacity);
ESP_LOGCONFIG("MdiIcons", "MDI Icons: Initialized with pool capacity %u", iconPoolCapacity);
}
// Method to find an icon by name. Returns a pointer to the icon if found, otherwise nullptr
const MdiIcon* MdiIcons::find_icon(const char* name) const {
for (size_t i = 0; i < iconPoolSize; ++i) {
if (strcmp(iconPool[i].name, name) == 0) {
@@ -31,7 +30,6 @@ const MdiIcon* MdiIcons::find_icon(const char* name) const {
return nullptr;
}
// Method to add a new icon to the pool. Checks for duplicates, resizes the pool if necessary, and adds the icon
bool MdiIcons::add_icon(const char* name, const char* code) {
if (find_icon(name) != nullptr) {
ESP_LOGW("MdiIcons", "Icon '%s' is already in the pool. Not adding again.", name);
@@ -51,7 +49,6 @@ bool MdiIcons::add_icon(const char* name, const char* code) {
return true;
}
// Method to double the capacity of the icon pool when it is full
void MdiIcons::resize_pool() {
size_t newCapacity = iconPoolCapacity * 2;
MdiIcon* newPool = new MdiIcon[newCapacity];

View File

@@ -4,83 +4,30 @@
#define MDI_ICONS_H
#include "esphome/core/component.h"
#include "esphome/core/log.h"
#include <cstring>
// Struct to hold individual icon data
struct MdiIcon {
char name[32]; // Icon name, max length of 31 characters + null terminator
char code[5]; // Icon code, max length of 4 bytes + null terminator (UTF-8 supported)
char name[32]; // Icon name, assuming max length of 31 characters + null terminator
char code[5]; // Icon code, 4 bytes + null terminator (UTF-8 characters)
};
// Class to manage a dynamic pool of MDI icons stored in PSRAM
class MdiIcons : public esphome::Component {
public:
MdiIcons() : iconPool(nullptr), iconPoolSize(0), iconPoolCapacity(100) {}
MdiIcons(); // Constructor declaration
// Component setup override, initializes the icon pool
void setup() override {
iconPool = new MdiIcon[iconPoolCapacity]; // Allocate initial pool in PSRAM
if (!iconPool) {
ESP_LOGE("MdiIcons", "Failed to allocate memory for icons in PSRAM");
return;
}
memset(iconPool, 0, iconPoolCapacity * sizeof(MdiIcon)); // Zero out the memory
ESP_LOGI("MdiIcons", "Initialized icon pool with capacity %u", iconPoolCapacity);
}
void setup() override; // Setup method declaration
void dump_config() override; // Dump config method declaration
// Logs the component configuration
void dump_config() override {
ESP_LOGCONFIG("MdiIcons", "MDI Icons: Initialized with pool capacity %u", iconPoolCapacity);
}
// Finds an icon by name, returns a pointer to the icon or nullptr if not found
const MdiIcon* find_icon(const char* name) const {
for (size_t i = 0; i < iconPoolSize; ++i) {
if (strcmp(iconPool[i].name, name) == 0) {
return &iconPool[i];
}
}
return nullptr;
}
// Adds a new icon to the pool, returns true if successful, false if icon already exists
bool add_icon(const char* name, const char* code) {
if (find_icon(name) != nullptr) {
ESP_LOGW("MdiIcons", "Icon %s is already in the pool", name);
return false;
}
if (iconPoolSize >= iconPoolCapacity) {
resize_pool();
}
strncpy(iconPool[iconPoolSize].name, name, sizeof(MdiIcon::name) - 1);
strncpy(iconPool[iconPoolSize].code, code, sizeof(MdiIcon::code) - 1);
iconPool[iconPoolSize].name[sizeof(MdiIcon::name) - 1] = '\0';
iconPool[iconPoolSize].code[sizeof(MdiIcon::code) - 1] = '\0';
iconPoolSize++;
return true;
}
const MdiIcon* find_icon(const char* name) const; // Method to find an icon by name
bool add_icon(const char* name, const char* code); // Method to add an icon
private:
MdiIcon* iconPool; // Pointer to the icon pool array
size_t iconPoolSize; // Current number of icons in the pool
size_t iconPoolCapacity; // Current maximum capacity of the pool
MdiIcon* iconPool; // Dynamic array of MdiIcons
size_t iconPoolSize; // Number of icons currently in the pool
size_t iconPoolCapacity; // Current capacity of the pool
// Resizes the icon pool to accommodate more icons, called when the current pool is full
void resize_pool() {
size_t newCapacity = iconPoolCapacity * 2;
MdiIcon* newPool = new MdiIcon[newCapacity];
if (!newPool) {
ESP_LOGE("MdiIcons", "Failed to resize icon pool");
return;
}
memcpy(newPool, iconPool, iconPoolSize * sizeof(MdiIcon));
delete[] iconPool;
iconPool = newPool;
iconPoolCapacity = newCapacity;
ESP_LOGI("MdiIcons", "Resized icon pool to capacity %u", iconPoolCapacity);
}
void resize_pool(); // Method to resize the icon pool
};
#endif // MDI_ICONS_H

View File

@@ -17,7 +17,7 @@ substitutions:
invalid_cooldown: "100ms"
bytes_per_char: "1"
##### DON'T CHANGE THIS ######
version: "4.3.4"
version: "4.3.5d1"
##############################
##### External components #####
@@ -27,7 +27,7 @@ external_components:
# path: packages/Blackymas/components
type: git
url: https://github.com/Blackymas/NSPanel_HA_Blueprint
ref: v4.3.4
ref: v4.3.5
components:
- nspanel_ha_blueprint
refresh: 300s