From a2e4ad90ba8f90094e22e74eca39b203ea218e03 Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Sat, 31 May 2025 09:52:42 +0200 Subject: [PATCH] [nextion] Allocate NextionQueue in PSRAM (if available) (#8979) --- esphome/components/nextion/nextion.cpp | 27 ++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/esphome/components/nextion/nextion.cpp b/esphome/components/nextion/nextion.cpp index 38e37300af..66812170be 100644 --- a/esphome/components/nextion/nextion.cpp +++ b/esphome/components/nextion/nextion.cpp @@ -1003,8 +1003,13 @@ uint16_t Nextion::recv_ret_string_(std::string &response, uint32_t timeout, bool * @param variable_name Name for the queue */ void Nextion::add_no_result_to_queue_(const std::string &variable_name) { - // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) - nextion::NextionQueue *nextion_queue = new nextion::NextionQueue; + ExternalRAMAllocator allocator(ExternalRAMAllocator::ALLOW_FAILURE); + nextion::NextionQueue *nextion_queue = allocator.allocate(1); + if (nextion_queue == nullptr) { + ESP_LOGW(TAG, "Failed to allocate NextionQueue"); + return; + } + new (nextion_queue) nextion::NextionQueue(); // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) nextion_queue->component = new nextion::NextionComponentBase; @@ -1137,8 +1142,13 @@ void Nextion::add_to_get_queue(NextionComponentBase *component) { if ((!this->is_setup() && !this->ignore_is_setup_)) return; - // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) - nextion::NextionQueue *nextion_queue = new nextion::NextionQueue; + ExternalRAMAllocator allocator(ExternalRAMAllocator::ALLOW_FAILURE); + nextion::NextionQueue *nextion_queue = allocator.allocate(1); + if (nextion_queue == nullptr) { + ESP_LOGW(TAG, "Failed to allocate NextionQueue"); + return; + } + new (nextion_queue) nextion::NextionQueue(); nextion_queue->component = component; nextion_queue->queue_time = millis(); @@ -1165,8 +1175,13 @@ void Nextion::add_addt_command_to_queue(NextionComponentBase *component) { if ((!this->is_setup() && !this->ignore_is_setup_) || this->is_sleeping()) return; - // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) - nextion::NextionQueue *nextion_queue = new nextion::NextionQueue; + ExternalRAMAllocator allocator(ExternalRAMAllocator::ALLOW_FAILURE); + nextion::NextionQueue *nextion_queue = allocator.allocate(1); + if (nextion_queue == nullptr) { + ESP_LOGW(TAG, "Failed to allocate NextionQueue"); + return; + } + new (nextion_queue) nextion::NextionQueue(); nextion_queue->component = component; nextion_queue->queue_time = millis();