From 5d8b10141a8d9b48ec35788752e1d07b11754e57 Mon Sep 17 00:00:00 2001 From: gemu2015 Date: Mon, 4 Jan 2021 16:34:44 +0100 Subject: [PATCH] picture buttons part 2 --- tasmota/support_jpeg.ino | 22 ++++++++- tasmota/xdrv_13_display.ino | 88 +++++++++++++++++++++++------------ tasmota/xdsp_05_epaper_29.ino | 1 + tasmota/xdsp_12_ST7789.ino | 12 ++--- tasmota/xdsp_13_ILI9341-2.ino | 5 +- 5 files changed, 83 insertions(+), 45 deletions(-) diff --git a/tasmota/support_jpeg.ino b/tasmota/support_jpeg.ino index 4669b9ad7..2ebce0e4c 100644 --- a/tasmota/support_jpeg.ino +++ b/tasmota/support_jpeg.ino @@ -29,9 +29,27 @@ uint8_t red, grn, blu; uint16_t b , g, r; for (uint32_t cnt=0; cnt> 3) & 0x1f; + g = ((grn >> 2) & 0x3f) << 5; + r = ((red >> 3) & 0x1f) << 11; + *out++ = (r | g | b); + } + +} + +void rgb888_to_565i(uint8_t *in, uint16_t *out, uint32_t len) { +uint8_t red, grn, blu; +uint16_t b , g, r; + + for (uint32_t cnt=0; cnt> 3) & 0x1f; g = ((grn >> 2) & 0x3f) << 5; r = ((red >> 3) & 0x1f) << 11; diff --git a/tasmota/xdrv_13_display.ino b/tasmota/xdrv_13_display.ino index 6bdab9d03..3a1abe6d2 100644 --- a/tasmota/xdrv_13_display.ino +++ b/tasmota/xdrv_13_display.ino @@ -503,7 +503,7 @@ void DisplayText(void) if (ep) { *ep=0; ep++; - Draw_RGB_Bitmap(cp,disp_xpos,disp_ypos); + Draw_RGB_Bitmap(cp,disp_xpos,disp_ypos, false); cp=ep; } } @@ -1423,7 +1423,7 @@ void CmndDisplayDimmer(void) void CmndDisplayBlinkrate(void) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 3)) { - + if (!renderer) XdspCall(FUNC_DISPLAY_BLINKRATE); } @@ -1540,20 +1540,39 @@ void CmndDisplayRows(void) /*********************************************************************************************\ * optional drivers \*********************************************************************************************/ + +#ifdef USE_TOUCH_BUTTONS +// very limited path size, so, add .jpg +void draw_picture(char *path, uint32_t xp, uint32_t yp, uint32_t xs, uint32_t ys, bool inverted) { +char ppath[16]; + strcpy(ppath, path); + uint8_t plen = strlen(path) -1; + if (ppath[plen]=='1') { + // index mode + if (inverted) { + ppath[plen] = '2'; + } + inverted = false; + } + strcat(ppath, ".jpg"); + Draw_RGB_Bitmap(ppath, xp, yp, inverted); +} +#endif + + #ifdef ESP32 #ifdef JPEG_PICTS #include "img_converters.h" #include "esp_jpg_decode.h" bool jpg2rgb888(const uint8_t *src, size_t src_len, uint8_t * out, jpg_scale_t scale); char get_jpeg_size(unsigned char* data, unsigned int data_size, unsigned short *width, unsigned short *height); -void rgb888_to_565(uint8_t *in, uint16_t *out, uint32_t len); #endif // JPEG_PICTS #endif // ESP32 -#if defined(USE_SCRIPT_FATFS) && defined(USE_SCRIPT) +#if defined(USE_SCRIPT_FATFS) && defined(USE_SCRIPT) && defined(USE_DISPLAY) extern FS *fsp; #define XBUFF_LEN 128 -void Draw_RGB_Bitmap(char *file,uint16_t xp, uint16_t yp) { +void Draw_RGB_Bitmap(char *file,uint16_t xp, uint16_t yp, bool inverted ) { if (!renderer) return; File fp; char *ending = strrchr(file,'.'); @@ -1602,34 +1621,41 @@ void Draw_RGB_Bitmap(char *file,uint16_t xp, uint16_t yp) { // jpeg files on ESP32 with more memory #ifdef ESP32 #ifdef JPEG_PICTS - if (psramFound()) { - fp=fsp->open(file,FILE_READ); - if (!fp) return; - uint32_t size = fp.size(); - uint8_t *mem = (uint8_t *)heap_caps_malloc(size+4, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); - if (mem) { - uint8_t res=fp.read(mem, size); - if (res) { - uint16_t xsize; - uint16_t ysize; - if (mem[0]==0xff && mem[1]==0xd8) { - get_jpeg_size(mem, size, &xsize, &ysize); - //Serial.printf(" x,y %d - %d\n",xsize, ysize ); - if (xsize && ysize) { - uint8_t *out_buf = (uint8_t *)heap_caps_malloc((xsize*ysize*3)+4, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); - if (out_buf) { + fp=fsp->open(file,FILE_READ); + if (!fp) return; + uint32_t size = fp.size(); + uint8_t *mem = (uint8_t *)special_malloc(size+4); + if (mem) { + uint8_t res=fp.read(mem, size); + if (res) { + uint16_t xsize; + uint16_t ysize; + if (mem[0]==0xff && mem[1]==0xd8) { + get_jpeg_size(mem, size, &xsize, &ysize); + //Serial.printf(" x,y,fs %d - %d - %d\n",xsize, ysize, size ); + if (xsize && ysize) { + uint8_t *out_buf = (uint8_t *)special_malloc((xsize*ysize*3)+4); + if (out_buf) { + uint16_t *pixb = (uint16_t *)special_malloc((xsize*2)+4); + if (pixb) { uint8_t *ob=out_buf; - jpg2rgb888(mem, size, out_buf, (jpg_scale_t)JPG_SCALE_NONE); - uint16_t pixels=xsize*ysize/XBUFF_LEN; - renderer->setAddrWindow(xp,yp,xp+xsize,yp+ysize); - for(int32_t j=0; jpushColors(rbuff,XBUFF_LEN,true); - OsWatchLoop(); + if (jpg2rgb888(mem, size, out_buf, (jpg_scale_t)JPG_SCALE_NONE)) { + renderer->setAddrWindow(xp,yp,xp+xsize,yp+ysize); + for(int32_t j=0; jpushColors(pixb, xsize, true); + OsWatchLoop(); + } + renderer->setAddrWindow(0,0,0,0); } - renderer->setAddrWindow(0,0,0,0); + free(out_buf); + free(pixb); + } else { free(out_buf); } } diff --git a/tasmota/xdsp_05_epaper_29.ino b/tasmota/xdsp_05_epaper_29.ino index a607bd937..d9c35435f 100644 --- a/tasmota/xdsp_05_epaper_29.ino +++ b/tasmota/xdsp_05_epaper_29.ino @@ -83,6 +83,7 @@ void EpdInitDriver29(void) { #ifdef SHOW_SPLASH // Welcome text + delay(100); renderer->setTextFont(1); renderer->DrawStringAt(50, 50, "Waveshare E-Paper Display!", COLORED,0); renderer->Updateframe(); diff --git a/tasmota/xdsp_12_ST7789.ino b/tasmota/xdsp_12_ST7789.ino index 80cf4d6e5..be3a40da9 100644 --- a/tasmota/xdsp_12_ST7789.ino +++ b/tasmota/xdsp_12_ST7789.ino @@ -112,14 +112,8 @@ void ST7789_InitDriver(void) { #ifdef SHOW_SPLASH // Welcome text renderer->setTextColor(ST7789_WHITE,ST7789_BLACK); - int fontSize = 2; renderer->setTextFont(2); - if (Settings.display_width<240) { - fontSize = 1; - } - renderer->setTextFont(fontSize); - int fontHeight = 12 * fontSize; - renderer->DrawStringAt(30, (Settings.display_height-fontHeight)/2, "ST7789 TFT!", ST7789_WHITE,0); + renderer->DrawStringAt(30, (Settings.display_height-12)/2, "ST7789 TFT!", ST7789_WHITE,0); delay(1000); #endif @@ -131,8 +125,8 @@ void ST7789_InitDriver(void) { #define SDA_2 23 #define SCL_2 32 #ifdef USE_LANBON_L8 - #undef SDA_2 - #undef SCL_2 + #undef SDA_2 + #undef SCL_2 #define SDA_2 4 #define SCL_2 0 #endif // USE_LANBON_L8 diff --git a/tasmota/xdsp_13_ILI9341-2.ino b/tasmota/xdsp_13_ILI9341-2.ino index 6095b5c53..cb0e4616e 100644 --- a/tasmota/xdsp_13_ILI9341-2.ino +++ b/tasmota/xdsp_13_ILI9341-2.ino @@ -94,10 +94,9 @@ void ILI9341_2_InitDriver() #ifdef SHOW_SPLASH // Welcome text renderer->setTextFont(2); - renderer->setTextColor(ILI9341_2_WHITE,ILI9341_2_BLACK); - renderer->DrawStringAt(20, 140, "ILI9341 TFT!", ILI9341_2_RED,0); + renderer->setTextColor(ILI9341_2_WHITE, ILI9341_2_BLACK); + renderer->DrawStringAt(30, (Settings.display_height/2)-12, "ILI9341 TFT!", ILI9341_2_WHITE, 0); delay(1000); - renderer->clearDisplay(); #endif color_type = COLOR_COLOR;