From 9d5d86b06c45b2129ef4c2bd5b2272dfcc738904 Mon Sep 17 00:00:00 2001 From: rrachasak Date: Sun, 22 Dec 2024 21:09:16 +0700 Subject: [PATCH] fix: (Component WaveshareEpaper) Correct display tx cmd --- .../waveshare_epaper/waveshare_epaper.cpp | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/esphome/components/waveshare_epaper/waveshare_epaper.cpp b/esphome/components/waveshare_epaper/waveshare_epaper.cpp index 8834ac1d36..2c47884ba0 100644 --- a/esphome/components/waveshare_epaper/waveshare_epaper.cpp +++ b/esphome/components/waveshare_epaper/waveshare_epaper.cpp @@ -1960,22 +1960,17 @@ void WaveshareEPaper4P2InBV2::initialize() { } void HOT WaveshareEPaper4P2InBV2::display() { - const uint32_t buf_half_len = this->get_buffer_length_() / 2u; - // COMMAND DATA START TRANSMISSION 1 (B/W data) this->command(0x10); this->start_data_(); - for (size_t i = 0; i < buf_half_len; i++) { - this->data(this->buffer_[i]); - } + this->write_array(this->buffer_, this->get_buffer_length_()); this->end_data_(); // COMMAND DATA START TRANSMISSION 2 (RED data) this->command(0x13); this->start_data_(); - for (size_t i = 0; i < buf_half_len; i++) { - this->data(this->buffer_[i + buf_half_len]); - } + for (size_t i = 0; i < this->get_buffer_length_(); i++) + this->write_byte(0xFF); this->end_data_(); delay(2); @@ -2022,19 +2017,20 @@ void WaveshareEPaper4P2InBV2BWR::initialize() { } void HOT WaveshareEPaper4P2InBV2BWR::display() { - // COMMAND DATA START TRANSMISSION 1 (B/W data) - this->command(0x10); - this->start_data_(); - this->write_array(this->buffer_, this->get_buffer_length_()); - this->end_data_(); + const uint32_t buf_len = this->get_buffer_length_() / 2u; - // COMMAND DATA START TRANSMISSION 2 (RED data) - this->command(0x13); - this->start_data_(); - for (size_t i = 0; i < this->get_buffer_length_(); i++) - this->write_byte(0xFF); - this->end_data_(); - delay(2); + this->command(0x10); // Send BW data Transmission + delay(2); // Delay to prevent Watchdog error + for (uint32_t i = 0; i < buf_len; ++i) { + this->data(this->buffer_[i]); + } + + this->command(0x13); // Send red data Transmission + delay(2); // Delay to prevent Watchdog error + for (uint32_t i = 0; i < buf_len; ++i) { + // Red color need to flip bit from the buffer. Otherwise, red will conqure the screen! + this->data(~this->buffer_[buf_len + i]); + } // COMMAND DISPLAY REFRESH this->command(0x12); @@ -3300,4 +3296,4 @@ void WaveshareEPaper13P3InK::dump_config() { } } // namespace waveshare_epaper -} // namespace esphome +} // namespace esphome \ No newline at end of file