1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 06:33:51 +00:00

[nextion] Add configurable limit for commands processed per loop (#8972)

Co-authored-by: Keith Burzinski <kbx81x@gmail.com>
This commit is contained in:
Edward Firmo
2025-06-10 09:27:46 +02:00
committed by GitHub
parent 3174f7ae86
commit 94848e4811
5 changed files with 69 additions and 31 deletions

View File

@@ -75,6 +75,22 @@ class NextionCommandPacer {
class Nextion : public NextionBase, public PollingComponent, public uart::UARTDevice {
public:
#ifdef USE_NEXTION_MAX_COMMANDS_PER_LOOP
/**
* @brief Set the maximum number of commands to process in each loop iteration
* @param value Maximum number of commands (default: 20)
*
* Limiting the number of commands per loop helps prevent stack overflows
* when a large number of commands are queued at once, especially during boot.
*/
inline void set_max_commands_per_loop(uint16_t value) { this->max_commands_per_loop_ = value; }
/**
* @brief Get the current maximum number of commands allowed per loop iteration
* @return Configured command limit per loop
*/
inline uint16_t get_max_commands_per_loop() const { return this->max_commands_per_loop_; }
#endif // USE_NEXTION_MAX_COMMANDS_PER_LOOP
#ifdef USE_NEXTION_MAX_QUEUE_SIZE
/**
* @brief Set the maximum allowed queue size
@@ -1287,6 +1303,9 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe
bool is_connected() { return this->is_connected_; }
protected:
#ifdef USE_NEXTION_MAX_COMMANDS_PER_LOOP
uint16_t max_commands_per_loop_{1000};
#endif // USE_NEXTION_MAX_COMMANDS_PER_LOOP
#ifdef USE_NEXTION_MAX_QUEUE_SIZE
size_t max_queue_size_{0};
#endif // USE_NEXTION_MAX_QUEUE_SIZE