mirror of https://github.com/arendst/Tasmota.git
Merge pull request #10401 from gemu2015/picture_buttons
Picture buttons
This commit is contained in:
commit
c2cc343e38
|
@ -1579,6 +1579,8 @@ void Adafruit_GFX_Button::initButtonUL(
|
|||
strncpy(_label, label, 9);
|
||||
}
|
||||
|
||||
void draw_picture(char *path, uint32_t xp, uint32_t yp, uint32_t xs, uint32_t ys, bool inverted);
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Draw the button on the screen
|
||||
|
@ -1598,16 +1600,20 @@ void Adafruit_GFX_Button::drawButton(boolean inverted) {
|
|||
text = _fillcolor;
|
||||
}
|
||||
|
||||
if (_label[0]=='/') {
|
||||
// picture path
|
||||
draw_picture(_label, _x1, _y1, _w, _h, inverted);
|
||||
_gfx->drawRect(_x1, _y1, _w, _h, text);
|
||||
} else {
|
||||
uint8_t r = min(_w, _h) / 4; // Corner radius
|
||||
_gfx->fillRoundRect(_x1, _y1, _w, _h, r, fill);
|
||||
_gfx->drawRoundRect(_x1, _y1, _w, _h, r, outline);
|
||||
|
||||
_gfx->setCursor(_x1 + (_w/2) - (strlen(_label) * 3 * _textsize_x),
|
||||
_y1 + (_h/2) - (4 * _textsize_y));
|
||||
_gfx->setCursor(_x1 + (_w/2) - (strlen(_label) * 3 * _textsize_x), _y1 + (_h/2) - (4 * _textsize_y));
|
||||
_gfx->setTextColor(text);
|
||||
_gfx->setTextSize(_textsize_x, _textsize_y);
|
||||
_gfx->print(_label);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
|
|
|
@ -545,6 +545,12 @@ void ILI9341_2::DisplayOnff(int8_t on) {
|
|||
}
|
||||
}
|
||||
|
||||
void ILI9341_2::invertDisplay(boolean i) {
|
||||
ILI9341_2_CS_LOW
|
||||
writecmd(i ? ILI9341_2_INVOFF : ILI9341_2_INVON);
|
||||
ILI9341_2_CS_HIGH
|
||||
}
|
||||
|
||||
void ili9342_dimm(uint8_t dim);
|
||||
|
||||
// dimmer 0-100
|
||||
|
|
|
@ -119,30 +119,6 @@ class ILI9341_2 : public Renderer {
|
|||
ILI9341_2(int8_t cs, int8_t res, int8_t dc, int8_t bp);
|
||||
|
||||
void init(uint16_t width, uint16_t height);
|
||||
/*
|
||||
void begin(void);
|
||||
void DisplayInit(int8_t p,int8_t size,int8_t rot,int8_t font);
|
||||
void setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
|
||||
void setScrollArea(uint16_t topFixedArea, uint16_t bottomFixedArea);
|
||||
void scroll(uint16_t pixels);
|
||||
void pushColor(uint16_t color);
|
||||
void pushColors(uint16_t *data, uint8_t len, boolean first);
|
||||
//void drawImage(const uint8_t* img, uint16_t x, uint16_t y, uint16_t w, uint16_t h);
|
||||
void fillScreen(uint16_t color);
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color);
|
||||
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
|
||||
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
|
||||
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h,uint16_t color);
|
||||
void setRotation(uint8_t r);
|
||||
void invertDisplay(boolean i);
|
||||
uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
|
||||
void DisplayOnff(int8_t on);
|
||||
void writecommand(uint8_t c);
|
||||
void writedata(uint8_t d);
|
||||
void write16BitColor(uint16_t color);
|
||||
void commandList(uint8_t *addr);
|
||||
void hw_spi_init();
|
||||
void dim(uint8_t contrast);*/
|
||||
uint16_t GetColorFromIndex(uint8_t index);
|
||||
|
||||
private:
|
||||
|
@ -161,7 +137,7 @@ class ILI9341_2 : public Renderer {
|
|||
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
|
||||
void dim(uint8_t dim);
|
||||
void pushColors(uint16_t *data, uint8_t len, boolean first);
|
||||
|
||||
void invertDisplay(boolean i);
|
||||
void spiwrite(uint8_t c);
|
||||
void spiwrite16(uint16_t c);
|
||||
void spiwrite32(uint32_t c);
|
||||
|
|
|
@ -503,6 +503,16 @@ void ILI9488::scroll(uint16_t pixels){
|
|||
}*/
|
||||
|
||||
void ILI9488::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
|
||||
if (!x0 && !y0 && !x1 && !y1) {
|
||||
x0=0;
|
||||
y0=0;
|
||||
x1=_width;
|
||||
y1=_height;
|
||||
}
|
||||
setAddrWindow_int(x0, y0, x1-1, y1-1);
|
||||
}
|
||||
|
||||
void ILI9488::setAddrWindow_int(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
|
||||
uint8_t flag=0;
|
||||
|
||||
if (!x0 && !y0 && !x1 && !y1) {
|
||||
|
@ -594,6 +604,7 @@ void ILI9488::pushColor(uint16_t color) {
|
|||
ILI9488_STOP
|
||||
}
|
||||
|
||||
#if 1
|
||||
void ILI9488::pushColors(uint16_t *data, uint8_t len, boolean first) {
|
||||
uint16_t color;
|
||||
uint8_t buff[len*3+1];
|
||||
|
@ -616,6 +627,17 @@ void ILI9488::pushColors(uint16_t *data, uint8_t len, boolean first) {
|
|||
ILI9488_STOP
|
||||
|
||||
}
|
||||
#else
|
||||
|
||||
void ILI9488::pushColors(uint16_t *data, uint8_t len, boolean first) {
|
||||
uint16_t color;
|
||||
|
||||
while (len--) {
|
||||
write16BitColor(*data++);
|
||||
}
|
||||
ILI9488_STOP
|
||||
}
|
||||
#endif
|
||||
|
||||
void ILI9488::write16BitColor(uint16_t color){
|
||||
// #if (__STM32F1__)
|
||||
|
@ -688,7 +710,7 @@ void ILI9488::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
|||
|
||||
if((x < 0) ||(x >= _width) || (y < 0) || (y >= _height)) return;
|
||||
|
||||
setAddrWindow(x,y,x+1,y+1);
|
||||
setAddrWindow_int(x,y,x+1,y+1);
|
||||
write16BitColor(color);
|
||||
ILI9488_STOP
|
||||
}
|
||||
|
@ -702,7 +724,7 @@ void ILI9488::drawFastVLine(int16_t x, int16_t y, int16_t h,
|
|||
if((y+h-1) >= _height)
|
||||
h = _height-y;
|
||||
|
||||
setAddrWindow(x, y, x, y+h-1);
|
||||
setAddrWindow_int(x, y, x, y+h-1);
|
||||
|
||||
uint8_t r = (color & 0xF800) >> 11;
|
||||
uint8_t g = (color & 0x07E0) >> 5;
|
||||
|
@ -770,7 +792,7 @@ void ILI9488::drawFastHLine(int16_t x, int16_t y, int16_t w,
|
|||
if((x >= _width) || (y >= _height)) return;
|
||||
if((x+w-1) >= _width) w = _width-x;
|
||||
|
||||
setAddrWindow(x, y, x+w-1, y);
|
||||
setAddrWindow_int(x, y, x+w-1, y);
|
||||
|
||||
uint8_t r = (color & 0xF800) >> 11;
|
||||
uint8_t g = (color & 0x07E0) >> 5;
|
||||
|
@ -905,7 +927,7 @@ void ILI9488::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t colo
|
|||
if((x + w - 1) >= _width) w = _width - x;
|
||||
if((y + h - 1) >= _height) h = _height - y;
|
||||
|
||||
setAddrWindow(x, y, x+w-1, y+h-1);
|
||||
setAddrWindow_int(x, y, x+w-1, y+h-1);
|
||||
//ILI9488_START
|
||||
|
||||
uint8_t r = (color & 0xF800) >> 11;
|
||||
|
@ -1050,7 +1072,7 @@ void ILI9488::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t colo
|
|||
if((x + w - 1) >= _width) w = _width - x;
|
||||
if((y + h - 1) >= _height) h = _height - y;
|
||||
|
||||
setAddrWindow(x, y, x+w-1, y+h-1);
|
||||
setAddrWindow_int(x, y, x+w-1, y+h-1);
|
||||
|
||||
uint8_t r = (color & 0xF800) >> 11;
|
||||
uint8_t g = (color & 0x07E0) >> 5;
|
||||
|
|
|
@ -136,6 +136,7 @@ class ILI9488 : public Renderer {
|
|||
|
||||
void begin(void);
|
||||
void DisplayInit(int8_t p,int8_t size,int8_t rot,int8_t font);
|
||||
void setAddrWindow_int(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
|
||||
void setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
|
||||
void setScrollArea(uint16_t topFixedArea, uint16_t bottomFixedArea);
|
||||
void scroll(uint16_t pixels);
|
||||
|
|
|
@ -32,6 +32,10 @@
|
|||
//#define USE_GFX_FONTS
|
||||
#define USE_TINY_FONT
|
||||
|
||||
#ifdef ESP32
|
||||
#define USE_ICON_FONT
|
||||
#endif
|
||||
|
||||
uint8_t wr_redir=0;
|
||||
|
||||
uint8_t *buffer;
|
||||
|
@ -223,27 +227,32 @@ void Renderer::setTextFont(uint8_t f) {
|
|||
break;
|
||||
case 7:
|
||||
selected_font = &RAFont;
|
||||
break;
|
||||
default:
|
||||
font=0;
|
||||
selected_font = &Font12;
|
||||
break;
|
||||
}
|
||||
#else
|
||||
#ifdef USE_EPD_FONTS
|
||||
if (1 == font) {
|
||||
switch (font) {
|
||||
selected_font = &Font12;
|
||||
} else {
|
||||
#ifdef USE_TINY_FONT
|
||||
if (2 == font) {
|
||||
break;
|
||||
case 2:
|
||||
selected_font = &Font24;
|
||||
} else {
|
||||
break;
|
||||
case 3:
|
||||
#ifdef USE_TINY_FONT
|
||||
selected_font = &Font8;
|
||||
}
|
||||
#else
|
||||
#else
|
||||
selected_font = &Font24;
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
selected_font = &Font12;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -513,6 +522,9 @@ void Renderer::setDrawMode(uint8_t mode) {
|
|||
drawmode=mode;
|
||||
}
|
||||
|
||||
void Renderer::invertDisplay(boolean i) {
|
||||
}
|
||||
|
||||
void VButton::xdrawButton(bool inverted) {
|
||||
wr_redir=1;
|
||||
drawButton(inverted);
|
||||
|
@ -520,4 +532,6 @@ void VButton::xdrawButton(bool inverted) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* END OF FILE */
|
||||
|
|
|
@ -35,6 +35,7 @@ public:
|
|||
virtual void dim(uint8_t contrast);
|
||||
virtual void pushColors(uint16_t *data, uint8_t len, boolean first);
|
||||
virtual void setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
|
||||
virtual void invertDisplay(boolean i);
|
||||
void setDrawMode(uint8_t mode);
|
||||
uint8_t drawmode;
|
||||
virtual void FastString(uint16_t x,uint16_t y,uint16_t tcolor, const char* str);
|
||||
|
|
|
@ -86,6 +86,11 @@ uint32_t FlashWriteMaxSector(void) {
|
|||
uint8_t* FlashDirectAccess(void) {
|
||||
return (uint8_t*)(0x40200000 + (FlashWriteStartSector() * SPI_FLASH_SEC_SIZE));
|
||||
}
|
||||
|
||||
void *special_malloc(uint32_t size) {
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*********************************************************************************************\
|
||||
|
@ -414,4 +419,13 @@ uint8_t* FlashDirectAccess(void) {
|
|||
return data;
|
||||
}
|
||||
|
||||
|
||||
void *special_malloc(uint32_t size) {
|
||||
if (psramFound()) {
|
||||
return heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
} else {
|
||||
return malloc(size);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ESP32
|
|
@ -29,9 +29,27 @@ uint8_t red, grn, blu;
|
|||
uint16_t b , g, r;
|
||||
|
||||
for (uint32_t cnt=0; cnt<len; cnt++) {
|
||||
red = *in++;
|
||||
grn = *in++;
|
||||
blu = *in++;
|
||||
grn = *in++;
|
||||
red = *in++;
|
||||
|
||||
b = (blu >> 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<len; cnt++) {
|
||||
blu = 255-*in++;
|
||||
grn = 255-*in++;
|
||||
red = 255-*in++;
|
||||
|
||||
b = (blu >> 3) & 0x1f;
|
||||
g = ((grn >> 2) & 0x3f) << 5;
|
||||
r = ((red >> 3) & 0x1f) << 11;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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,11 +1621,10 @@ 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);
|
||||
uint8_t *mem = (uint8_t *)special_malloc(size+4);
|
||||
if (mem) {
|
||||
uint8_t res=fp.read(mem, size);
|
||||
if (res) {
|
||||
|
@ -1614,22 +1632,30 @@ void Draw_RGB_Bitmap(char *file,uint16_t xp, uint16_t yp) {
|
|||
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 );
|
||||
//Serial.printf(" x,y,fs %d - %d - %d\n",xsize, ysize, size );
|
||||
if (xsize && ysize) {
|
||||
uint8_t *out_buf = (uint8_t *)heap_caps_malloc((xsize*ysize*3)+4, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
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;
|
||||
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; j<pixels; j++) {
|
||||
uint16_t rbuff[XBUFF_LEN*2];
|
||||
rgb888_to_565(ob, rbuff, XBUFF_LEN);
|
||||
ob+=XBUFF_LEN*3;
|
||||
renderer->pushColors(rbuff,XBUFF_LEN,true);
|
||||
for(int32_t j=0; j<ysize; j++) {
|
||||
if (inverted==false) {
|
||||
rgb888_to_565(ob, pixb, xsize);
|
||||
} else {
|
||||
rgb888_to_565i(ob, pixb, xsize);
|
||||
}
|
||||
ob+=xsize*3;
|
||||
renderer->pushColors(pixb, xsize, true);
|
||||
OsWatchLoop();
|
||||
}
|
||||
renderer->setAddrWindow(0,0,0,0);
|
||||
}
|
||||
free(out_buf);
|
||||
free(pixb);
|
||||
} else {
|
||||
free(out_buf);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue