From b9110f602fcd28ead0ed01b39a6a807a6b8c8235 Mon Sep 17 00:00:00 2001 From: gemu2015 Date: Sun, 11 Apr 2021 07:49:13 +0200 Subject: [PATCH] add full partial and full refresh --- lib/libesp32_epdiy/src/epd4in7.cpp | 34 +++++++++++++++++++++++------ lib/libesp32_epdiy/src/epd4in7.h | 1 + tasmota/xdsp_16_esp32_epaper_47.ino | 4 ++-- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/lib/libesp32_epdiy/src/epd4in7.cpp b/lib/libesp32_epdiy/src/epd4in7.cpp index 93a9f859d..4f041b473 100644 --- a/lib/libesp32_epdiy/src/epd4in7.cpp +++ b/lib/libesp32_epdiy/src/epd4in7.cpp @@ -44,10 +44,14 @@ extern uint8_t *buffer; -int temperature; +int temperature = 25; EpdiyHighlevelState hl; +uint16_t Epd47::GetColorFromIndex(uint8_t index) { + return index & 0xf; +} + Epd47::Epd47(int16_t dwidth, int16_t dheight) : Renderer(dwidth, dheight) { width = dwidth; height = dheight; @@ -63,11 +67,27 @@ int32_t Epd47::Init(void) { void Epd47::DisplayInit(int8_t p, int8_t size, int8_t rot, int8_t font) { - if (p == DISPLAY_INIT_FULL) { + + if (p == DISPLAY_INIT_MODE) { epd_poweron(); epd_clear(); epd_poweroff(); } + if (p == DISPLAY_INIT_FULL) { + memset(hl.back_fb, 0xff, width * height / 2); + epd_poweron(); + epd_clear(); + epd_hl_update_screen(&hl, MODE_GC16, temperature); + epd_poweroff(); + return; + } + if (p == DISPLAY_INIT_PARTIAL) { + memset(hl.back_fb, 0xff, width * height / 2); + epd_poweron(); + epd_hl_update_screen(&hl, MODE_GL16, temperature); + epd_poweroff(); + return; + } setRotation(rot); setTextWrap(false); cp437(true); @@ -94,6 +114,7 @@ void Epd47::fillScreen(uint16_t color) { void Epd47::drawPixel(int16_t x, int16_t y, uint16_t color) { uint16_t xp = x; uint16_t yp = y; +uint8_t *buf_ptr; switch (getRotation()) { case 1: @@ -107,14 +128,13 @@ uint16_t yp = y; case 3: _swap(xp, yp); yp = height - yp - 1; + break; } - uint32_t maxsize = width * height / 2; - uint8_t *buf_ptr = &buffer[yp * width / 2 + xp / 2]; - if ((uint32_t)buf_ptr >= (uint32_t)buffer + maxsize) { - return; - } + if (xp >= width) return; + if (yp >= height) return; + buf_ptr = &buffer[yp * width / 2 + xp / 2]; if (xp % 2) { *buf_ptr = (*buf_ptr & 0x0F) | (color << 4); diff --git a/lib/libesp32_epdiy/src/epd4in7.h b/lib/libesp32_epdiy/src/epd4in7.h index 86717e7f3..79a3081bb 100644 --- a/lib/libesp32_epdiy/src/epd4in7.h +++ b/lib/libesp32_epdiy/src/epd4in7.h @@ -51,6 +51,7 @@ public: void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); void setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1); void pushColors(uint16_t *data, uint16_t len, boolean first); + uint16_t GetColorFromIndex(uint8_t index); private: uint16_t width; uint16_t height; diff --git a/tasmota/xdsp_16_esp32_epaper_47.ino b/tasmota/xdsp_16_esp32_epaper_47.ino index 63605c42a..990c92fdf 100644 --- a/tasmota/xdsp_16_esp32_epaper_47.ino +++ b/tasmota/xdsp_16_esp32_epaper_47.ino @@ -53,7 +53,7 @@ void EpdInitDriver47(void) { epd47->Init(); renderer = epd47; - renderer->DisplayInit(DISPLAY_INIT_FULL, Settings.display_size, Settings.display_rotate, Settings.display_font); + renderer->DisplayInit(DISPLAY_INIT_MODE, Settings.display_size, Settings.display_rotate, Settings.display_font); renderer->setTextColor(EPD47_BLACK, EPD47_WHITE); #ifdef SHOW_SPLASH @@ -98,4 +98,4 @@ bool Xdsp16(uint8_t function) #endif // USE_LILYGO47 #endif // USE_DISPLAY -#endif // ESP32 \ No newline at end of file +#endif // ESP32