From 8ae0877024dfd7ae2eceb7b738aab4579554fd00 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Wed, 19 Feb 2025 19:36:57 +0100 Subject: [PATCH] fix: reduce timer limit from 64 to 12 in DynamicLampComponent for improved performance --- .../components/dynamic_lamp/dynamic_lamp.cpp | 17 ++++++++--------- esphome/components/dynamic_lamp/dynamic_lamp.h | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/esphome/components/dynamic_lamp/dynamic_lamp.cpp b/esphome/components/dynamic_lamp/dynamic_lamp.cpp index 4d348da1b1..8b91f1df90 100644 --- a/esphome/components/dynamic_lamp/dynamic_lamp.cpp +++ b/esphome/components/dynamic_lamp/dynamic_lamp.cpp @@ -105,7 +105,7 @@ void DynamicLampComponent::dump_config() { //this->add_output_to_lamp("First Lamp", &this->available_outputs_[2]); //this->add_output_to_lamp("First Lamp", &this->available_outputs_[3]); /* std::string lamp_names_str; - for (uint8_t i = 0; i < 64; i++) { + for (uint8_t i = 0; i < 12; i++) { if (this->timers_[i].in_use == true) { lamp_names_str = ""; for (uint8_t j = 0; j < 16; j++) { @@ -283,15 +283,14 @@ bool DynamicLampComponent::add_timer(std::string timer_desc, std::string lamp_li ESP_LOGV(TAG, "Added new timer %s with lamp-list %s, active %d, action %d, hour %d, minute %d, monday %d, tuesday %d, wednesday %d, thursday %d, friday %d, saturday %d, sunday %d", new_timer.timer_desc, lamp_list_str.c_str(), new_timer.active, new_timer.action, new_timer.hour, new_timer.minute, new_timer.monday, new_timer.tuesday, new_timer.wednesday, new_timer.thursday, new_timer.friday, new_timer.saturday, new_timer.sunday); - //ESP_LOGV(TAG, "Size of struct is %" PRIu8 "", static_cast(sizeof(new_timer))); uint8_t save_slot; - for (save_slot = 0; save_slot < 64; save_slot++) { + for (save_slot = 0; save_slot < 12; save_slot++) { if (this->timers_[save_slot].in_use != true) { break; } } - if (save_slot == 64) { - ESP_LOGW(TAG, "No more timer slots available, max 64 timers supported!"); + if (save_slot == 12) { + ESP_LOGW(TAG, "No more timer slots available, max 12 timers supported!"); this->status_set_warning(); return false; } @@ -325,8 +324,8 @@ std::vector DynamicLampComponent::build_lamp_list_from_list_str_(std::stri void DynamicLampComponent::read_timers_to_log() { DynamicLampTimer timer; - for (uint8_t i = 0; i < 64; i++) { - this->fram_->read((0x4000 + (i * 64)), reinterpret_cast(&timer), 64); + for (uint8_t i = 0; i < 12; i++) { + this->fram_->read((0x4000 + (i * 12)), reinterpret_cast(&timer), 64); std::string lamp_names_str = ""; for (uint8_t j = 0; j < 16; j++) { bool lamp_included = static_cast(timer.lamp_list[j / 8] & (1 << (j % 8))); @@ -384,7 +383,7 @@ void DynamicLampComponent::restore_lamp_settings_() { void DynamicLampComponent::restore_timers_() { switch (this->save_mode_) { case SupportedSaveModes::SAVE_MODE_NONE: - for (uint8_t i = 0; i < 64; i++) { + for (uint8_t i = 0; i < 12; i++) { this->timers_[i] = DynamicLampTimer(); this->timers_[i].in_use = false; } @@ -397,7 +396,7 @@ void DynamicLampComponent::restore_timers_() { case SupportedSaveModes::SAVE_MODE_FRAM: DynamicLampTimer timer = DynamicLampTimer(); std::string lamp_names_str; - for (uint8_t i = 0; i < 64; i++) { + for (uint8_t i = 0; i < 12; i++) { this->fram_->read((0x4000 + (i * 64)), reinterpret_cast(&timer), 64); if (timer.validation_bytes[0] == 'V' && timer.validation_bytes[1] == 'D' && timer.validation_bytes[2] == 'L' && timer.validation_bytes[3] == 'T' && timer.in_use == true) { this->timers_[i] = timer; diff --git a/esphome/components/dynamic_lamp/dynamic_lamp.h b/esphome/components/dynamic_lamp/dynamic_lamp.h index fb1ed2406f..14d8ef91ce 100644 --- a/esphome/components/dynamic_lamp/dynamic_lamp.h +++ b/esphome/components/dynamic_lamp/dynamic_lamp.h @@ -126,7 +126,7 @@ class DynamicLampComponent : public Component { CombinedLamp active_lamps_[16]; LinkedOutput available_outputs_[16]; - DynamicLampTimer timers_[64]; + DynamicLampTimer timers_[12]; uint8_t save_mode_; uint8_t lamp_count_ = 0; };