mirror of
https://github.com/esphome/esphome.git
synced 2026-06-24 16:20:42 +00:00
[nextion] Replace static std::string COMMAND_DELIMITER with constexpr (#15195)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
This commit is contained in:
@@ -10,6 +10,10 @@ namespace nextion {
|
||||
|
||||
static const char *const TAG = "nextion";
|
||||
|
||||
// Nextion command terminator: three consecutive 0xFF bytes (per Nextion Instruction Set v1.1).
|
||||
static constexpr uint8_t COMMAND_DELIMITER[3] = {0xFF, 0xFF, 0xFF};
|
||||
static constexpr size_t DELIMITER_SIZE = sizeof(COMMAND_DELIMITER);
|
||||
|
||||
void Nextion::setup() {
|
||||
this->is_setup_ = false;
|
||||
this->connection_state_.ignore_is_setup_ = true;
|
||||
@@ -415,7 +419,8 @@ void Nextion::process_nextion_commands_() {
|
||||
#ifdef NEXTION_PROTOCOL_LOG
|
||||
this->print_queue_members_();
|
||||
#endif
|
||||
while ((to_process_length = this->command_data_.find(COMMAND_DELIMITER)) != std::string::npos) {
|
||||
while ((to_process_length = this->command_data_.find(reinterpret_cast<const char *>(COMMAND_DELIMITER), 0,
|
||||
DELIMITER_SIZE)) != std::string::npos) {
|
||||
#ifdef USE_NEXTION_MAX_COMMANDS_PER_LOOP
|
||||
if (++commands_processed > this->max_commands_per_loop_) {
|
||||
ESP_LOGW(TAG, "Command processing limit exceeded");
|
||||
@@ -423,8 +428,8 @@ void Nextion::process_nextion_commands_() {
|
||||
}
|
||||
#endif // USE_NEXTION_MAX_COMMANDS_PER_LOOP
|
||||
ESP_LOGN(TAG, "queue size: %zu", this->nextion_queue_.size());
|
||||
while (to_process_length + COMMAND_DELIMITER.length() < this->command_data_.length() &&
|
||||
static_cast<uint8_t>(this->command_data_[to_process_length + COMMAND_DELIMITER.length()]) == 0xFF) {
|
||||
while (to_process_length + DELIMITER_SIZE < this->command_data_.length() &&
|
||||
static_cast<uint8_t>(this->command_data_[to_process_length + DELIMITER_SIZE]) == 0xFF) {
|
||||
++to_process_length;
|
||||
ESP_LOGN(TAG, "Add 0xFF");
|
||||
}
|
||||
@@ -829,7 +834,7 @@ void Nextion::process_nextion_commands_() {
|
||||
break;
|
||||
}
|
||||
|
||||
this->command_data_.erase(0, to_process_length + COMMAND_DELIMITER.length() + 1);
|
||||
this->command_data_.erase(0, to_process_length + DELIMITER_SIZE + 1);
|
||||
}
|
||||
|
||||
const uint32_t ms = App.get_loop_component_start_time();
|
||||
|
||||
@@ -29,8 +29,6 @@ class NextionComponentBase;
|
||||
|
||||
using nextion_writer_t = display::DisplayWriter<Nextion>;
|
||||
|
||||
static const std::string COMMAND_DELIMITER{static_cast<char>(255), static_cast<char>(255), static_cast<char>(255)};
|
||||
|
||||
#ifdef USE_NEXTION_COMMAND_SPACING
|
||||
class NextionCommandPacer {
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user