mirror of
https://github.com/esphome/esphome.git
synced 2024-11-14 02:58:11 +01:00
Fix cut-off on 2.13" waveshare/ttgo epaper displays (#4255)
The controller of the 2.13" waveshare/ttgo epaper displays operates with a 128x250 buffer, while only 122x250 pixels are shown. While this can be ignored for rotations 0/270°, with roations 90/180°, 6 pixels are cut-off from the top or left edge. This change introduces a distinction between object width and controller width, resulting in pixel-perfect rotations.
This commit is contained in:
parent
443c3c2a56
commit
b5fbe0b145
2 changed files with 23 additions and 3 deletions
|
@ -137,7 +137,7 @@ void HOT WaveshareEPaper::draw_absolute_pixel_internal(int x, int y, Color color
|
||||||
if (x >= this->get_width_internal() || y >= this->get_height_internal() || x < 0 || y < 0)
|
if (x >= this->get_width_internal() || y >= this->get_height_internal() || x < 0 || y < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const uint32_t pos = (x + y * this->get_width_internal()) / 8u;
|
const uint32_t pos = (x + y * this->get_width_controller()) / 8u;
|
||||||
const uint8_t subpos = x & 0x07;
|
const uint8_t subpos = x & 0x07;
|
||||||
// flip logic
|
// flip logic
|
||||||
if (!color.is_on()) {
|
if (!color.is_on()) {
|
||||||
|
@ -146,7 +146,9 @@ void HOT WaveshareEPaper::draw_absolute_pixel_internal(int x, int y, Color color
|
||||||
this->buffer_[pos] &= ~(0x80 >> subpos);
|
this->buffer_[pos] &= ~(0x80 >> subpos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uint32_t WaveshareEPaper::get_buffer_length_() { return this->get_width_internal() * this->get_height_internal() / 8u; }
|
uint32_t WaveshareEPaper::get_buffer_length_() {
|
||||||
|
return this->get_width_controller() * this->get_height_internal() / 8u;
|
||||||
|
}
|
||||||
void WaveshareEPaper::start_command_() {
|
void WaveshareEPaper::start_command_() {
|
||||||
this->dc_pin_->digital_write(false);
|
this->dc_pin_->digital_write(false);
|
||||||
this->enable();
|
this->enable();
|
||||||
|
@ -291,7 +293,7 @@ void HOT WaveshareEPaperTypeA::display() {
|
||||||
// COMMAND SET RAM X ADDRESS START END POSITION
|
// COMMAND SET RAM X ADDRESS START END POSITION
|
||||||
this->command(0x44);
|
this->command(0x44);
|
||||||
this->data(0x00);
|
this->data(0x00);
|
||||||
this->data((this->get_width_internal() - 1) >> 3);
|
this->data((this->get_width_controller() - 1) >> 3);
|
||||||
// COMMAND SET RAM Y ADDRESS START END POSITION
|
// COMMAND SET RAM Y ADDRESS START END POSITION
|
||||||
this->command(0x45);
|
this->command(0x45);
|
||||||
this->data(this->get_height_internal() - 1);
|
this->data(this->get_height_internal() - 1);
|
||||||
|
@ -392,12 +394,26 @@ int WaveshareEPaperTypeA::get_width_internal() {
|
||||||
case TTGO_EPAPER_2_13_IN_B73:
|
case TTGO_EPAPER_2_13_IN_B73:
|
||||||
case TTGO_EPAPER_2_13_IN_B74:
|
case TTGO_EPAPER_2_13_IN_B74:
|
||||||
case TTGO_EPAPER_2_13_IN_B1:
|
case TTGO_EPAPER_2_13_IN_B1:
|
||||||
|
return 122;
|
||||||
case WAVESHARE_EPAPER_2_9_IN:
|
case WAVESHARE_EPAPER_2_9_IN:
|
||||||
case WAVESHARE_EPAPER_2_9_IN_V2:
|
case WAVESHARE_EPAPER_2_9_IN_V2:
|
||||||
return 128;
|
return 128;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
// The controller of the 2.13" displays has a buffer larger than screen size
|
||||||
|
int WaveshareEPaperTypeA::get_width_controller() {
|
||||||
|
switch (this->model_) {
|
||||||
|
case WAVESHARE_EPAPER_2_13_IN:
|
||||||
|
case TTGO_EPAPER_2_13_IN:
|
||||||
|
case TTGO_EPAPER_2_13_IN_B73:
|
||||||
|
case TTGO_EPAPER_2_13_IN_B74:
|
||||||
|
case TTGO_EPAPER_2_13_IN_B1:
|
||||||
|
return 128;
|
||||||
|
default:
|
||||||
|
return this->get_width_internal();
|
||||||
|
}
|
||||||
|
}
|
||||||
int WaveshareEPaperTypeA::get_height_internal() {
|
int WaveshareEPaperTypeA::get_height_internal() {
|
||||||
switch (this->model_) {
|
switch (this->model_) {
|
||||||
case WAVESHARE_EPAPER_1_54_IN:
|
case WAVESHARE_EPAPER_1_54_IN:
|
||||||
|
|
|
@ -54,6 +54,8 @@ class WaveshareEPaper : public PollingComponent,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual int get_width_controller() { return this->get_width_internal(); };
|
||||||
|
|
||||||
uint32_t get_buffer_length_();
|
uint32_t get_buffer_length_();
|
||||||
uint32_t reset_duration_{200};
|
uint32_t reset_duration_{200};
|
||||||
|
|
||||||
|
@ -111,6 +113,8 @@ class WaveshareEPaperTypeA : public WaveshareEPaper {
|
||||||
|
|
||||||
int get_height_internal() override;
|
int get_height_internal() override;
|
||||||
|
|
||||||
|
int get_width_controller() override;
|
||||||
|
|
||||||
uint32_t full_update_every_{30};
|
uint32_t full_update_every_{30};
|
||||||
uint32_t at_update_{0};
|
uint32_t at_update_{0};
|
||||||
WaveshareEPaperTypeAModel model_;
|
WaveshareEPaperTypeAModel model_;
|
||||||
|
|
Loading…
Reference in a new issue