From a7fb362e1c0df4d4688bd2ffd950cbcc99d1e37f Mon Sep 17 00:00:00 2001 From: gemu2015 Date: Thu, 3 Sep 2020 12:26:03 +0200 Subject: [PATCH] display touch interface unified --- .../Arduino_ST7789.cpp | 5 +- lib/Arduino_ST7789-gemu-1.0/Arduino_ST7789.h | 2 +- lib/FT5206_Library/src/FT5206.cpp | 2 +- lib/FT5206_Library/src/FT5206.h | 2 + .../src/renderer.cpp | 1 + .../src/renderer.h | 16 +- tasmota/xdrv_10_scripter.ino | 182 +++++++++++++----- tasmota/xdrv_13_display.ino | 182 +++++++++++++++++- tasmota/xdsp_08_ILI9488.ino | 101 +++++----- tasmota/xdsp_10_RA8876.ino | 172 +++-------------- tasmota/xdsp_12_ST7789.ino | 161 +++------------- 11 files changed, 438 insertions(+), 388 deletions(-) diff --git a/lib/Arduino_ST7789-gemu-1.0/Arduino_ST7789.cpp b/lib/Arduino_ST7789-gemu-1.0/Arduino_ST7789.cpp index 344c22dad..487af20de 100755 --- a/lib/Arduino_ST7789-gemu-1.0/Arduino_ST7789.cpp +++ b/lib/Arduino_ST7789-gemu-1.0/Arduino_ST7789.cpp @@ -546,7 +546,7 @@ void Arduino_ST7789::DisplayOnff(int8_t on) { writecommand(ST7789_DISPON); //Display on if (_bp>=0) { #ifdef ST7789_DIMMER - ledcWrite(ESP32_PWM_CHANNEL,255); + ledcWrite(ESP32_PWM_CHANNEL,dimmer); #else digitalWrite(_bp,HIGH); #endif @@ -564,7 +564,8 @@ void Arduino_ST7789::DisplayOnff(int8_t on) { } // dimmer 0-100 -void Arduino_ST7789::dim(uint8_t dimmer) { +void Arduino_ST7789::dim(uint8_t dim) { + dimmer = dim; if (dimmer>15) dimmer=15; dimmer=((float)dimmer/15.0)*255.0; #ifdef ESP32 diff --git a/lib/Arduino_ST7789-gemu-1.0/Arduino_ST7789.h b/lib/Arduino_ST7789-gemu-1.0/Arduino_ST7789.h index f2571a104..2d97346e7 100755 --- a/lib/Arduino_ST7789-gemu-1.0/Arduino_ST7789.h +++ b/lib/Arduino_ST7789-gemu-1.0/Arduino_ST7789.h @@ -161,7 +161,7 @@ class Arduino_ST7789 : public Renderer { boolean _hwSPI; boolean _SPI9bit; boolean _DCbit; - + uint8_t dimmer; int8_t _cs, _dc, _rst, _sid, _sclk, _bp; #if defined(USE_FAST_IO) diff --git a/lib/FT5206_Library/src/FT5206.cpp b/lib/FT5206_Library/src/FT5206.cpp index 29d4c6778..f0b106174 100755 --- a/lib/FT5206_Library/src/FT5206.cpp +++ b/lib/FT5206_Library/src/FT5206.cpp @@ -41,7 +41,7 @@ int FT5206_Class::begin(TwoWire &port, uint8_t addr) } _readByte(FT5206_CHIPID_REG, 1, &val); //Serial.printf("chip id %d\n",val ); - if ((val != FT6206_CHIPID) && (val != FT6236_CHIPID) && (val != FT6236U_CHIPID) && (val != FT5206U_CHIPID)) { + if ((val != FT6206_CHIPID) && (val != FT6236_CHIPID) && (val != FT6236U_CHIPID) && (val != FT5206U_CHIPID) && (val != FT5316_CHIPID) ) { return false; } _init = true; diff --git a/lib/FT5206_Library/src/FT5206.h b/lib/FT5206_Library/src/FT5206.h index 1a9d4d0ad..d8b6a8e3a 100755 --- a/lib/FT5206_Library/src/FT5206.h +++ b/lib/FT5206_Library/src/FT5206.h @@ -49,6 +49,8 @@ github:https://github.com/lewisxhe/FT5206_Library #define FT6236U_CHIPID 0x64 #define FT5206U_CHIPID 0x64 +#define FT5316_CHIPID 0x0a + #define DEVIDE_MODE 0x00 #define TD_STATUS 0x02 #define TOUCH1_XH 0x03 diff --git a/lib/esp-epaper-29-ws-20171230-gemu-1.1/src/renderer.cpp b/lib/esp-epaper-29-ws-20171230-gemu-1.1/src/renderer.cpp index 10806220f..a8f0f9e57 100644 --- a/lib/esp-epaper-29-ws-20171230-gemu-1.1/src/renderer.cpp +++ b/lib/esp-epaper-29-ws-20171230-gemu-1.1/src/renderer.cpp @@ -519,4 +519,5 @@ void VButton::xdrawButton(bool inverted) { wr_redir=0; } + /* END OF FILE */ diff --git a/lib/esp-epaper-29-ws-20171230-gemu-1.1/src/renderer.h b/lib/esp-epaper-29-ws-20171230-gemu-1.1/src/renderer.h index 09347ae29..27ff56efe 100644 --- a/lib/esp-epaper-29-ws-20171230-gemu-1.1/src/renderer.h +++ b/lib/esp-epaper-29-ws-20171230-gemu-1.1/src/renderer.h @@ -46,9 +46,23 @@ private: uint8_t font; }; +typedef union { + uint8_t data; + struct { + uint8_t spare0 : 1; + uint8_t spare1 : 1; + uint8_t spare2 : 1; + uint8_t spare3 : 1; + uint8_t disable : 1; + uint8_t on_off : 1; + uint8_t is_pushbutton : 1; + uint8_t is_virtual : 1; + }; +} TButton_State; + class VButton : public Adafruit_GFX_Button { public: - uint8_t vpower; + TButton_State vpower; void xdrawButton(bool inverted); }; diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index 6353fa38a..cd5f986d2 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -300,12 +300,35 @@ struct T_INDEX { }; struct M_FILT { +#ifdef LARGE_ARRAYS + uint16_t numvals; + uint16_t index; +#else uint8_t numvals; uint8_t index; +#endif // LARGE_ARRAYS float maccu; float rbuff[1]; }; + +#ifdef LARGE_ARRAYS +#undef AND_FILT_MASK +#undef OR_FILT_MASK +#define AND_FILT_MASK 0x7fff +#define OR_FILT_MASK 0x8000 +#undef MAX_ARRAY_SIZE +#define MAX_ARRAY_SIZE 1000 +#else +#undef AND_FILT_MASK +#undef OR_FILT_MASK +#define AND_FILT_MASK 0x7f +#define OR_FILT_MASK 0x80 +#undef MAX_ARRAY_SIZE +#define MAX_ARRAY_SIZE 127 +#endif + + typedef union { uint8_t data; struct { @@ -462,6 +485,8 @@ void RulesTeleperiod(void) { #define SCRIPT_SKIP_SPACES while (*lp==' ' || *lp=='\t') lp++; #define SCRIPT_SKIP_EOL while (*lp==SCRIPT_EOL) lp++; +float *Get_MFAddr(uint8_t index,uint16_t *len,uint16_t *ipos); + // allocates all variables and presets them int16_t Init_Scripter(void) { char *script; @@ -543,12 +568,16 @@ char *script; if ((*lp=='m' || *lp=='M') && *(lp+1)==':') { uint8_t flg=*lp; lp+=2; + if (*lp=='p' && *(lp+1)==':') { + vtypes[vars].bits.is_permanent=1; + lp+=2; + } if (flg=='M') mfilt[numflt].numvals=8; else mfilt[numflt].numvals=5; vtypes[vars].bits.is_filter=1; mfilt[numflt].index=0; if (flg=='M') { - mfilt[numflt].numvals|=0x80; + mfilt[numflt].numvals|=OR_FILT_MASK; } vtypes[vars].index=numflt; numflt++; @@ -587,9 +616,13 @@ char *script; while (*op==' ') op++; if (isdigit(*op)) { // lenght define follows - uint8_t flen=atoi(op); - mfilt[numflt-1].numvals&=0x80; - mfilt[numflt-1].numvals|=flen&0x7f; + uint16_t flen=atoi(op); + if (flen>MAX_ARRAY_SIZE) { + // limit array size + flen=MAX_ARRAY_SIZE; + } + mfilt[numflt-1].numvals&=OR_FILT_MASK; + mfilt[numflt-1].numvals|=flen&AND_FILT_MASK; } } @@ -635,11 +668,11 @@ char *script; uint16_t fsize=0; for (count=0; countnumvals=mfilt[count].numvals; - mp+=sizeof(struct M_FILT)+((mfilt[count].numvals&0x7f)-1)*sizeof(float); + mp+=sizeof(struct M_FILT)+((mfilt[count].numvals&AND_FILT_MASK)-1)*sizeof(float); } glob_script_mem.numvars=vars; @@ -760,12 +793,21 @@ char *script; for (uint8_t count=0; countnumvals&0x7f; + *len=mflp->numvals&AND_FILT_MASK; if (ipos) *ipos=mflp->index; return mflp->rbuff; } - mp+=sizeof(struct M_FILT)+((mflp->numvals&0x7f)-1)*sizeof(float); + mp+=sizeof(struct M_FILT)+((mflp->numvals&AND_FILT_MASK)-1)*sizeof(float); } return 0; } -float Get_MFVal(uint8_t index,uint8_t bind) { +float Get_MFVal(uint8_t index,int16_t bind) { uint8_t *mp=(uint8_t*)glob_script_mem.mfilt; for (uint8_t count=0; countnumvals&0x7f; + uint16_t maxind=mflp->numvals&AND_FILT_MASK; if (!bind) { return mflp->index; } + if (bind<0) { + return maxind; + } if (bind<1 || bind>maxind) bind=maxind; return mflp->rbuff[bind-1]; } - mp+=sizeof(struct M_FILT)+((mflp->numvals&0x7f)-1)*sizeof(float); + mp+=sizeof(struct M_FILT)+((mflp->numvals&AND_FILT_MASK)-1)*sizeof(float); } return 0; } -void Set_MFVal(uint8_t index,uint8_t bind,float val) { +void Set_MFVal(uint8_t index,uint16_t bind,float val) { uint8_t *mp=(uint8_t*)glob_script_mem.mfilt; for (uint8_t count=0; countnumvals&0x7f; + uint16_t maxind=mflp->numvals&AND_FILT_MASK; if (!bind) { mflp->index=val; } else { @@ -1022,7 +1067,7 @@ void Set_MFVal(uint8_t index,uint8_t bind,float val) { } return; } - mp+=sizeof(struct M_FILT)+((mflp->numvals&0x7f)-1)*sizeof(float); + mp+=sizeof(struct M_FILT)+((mflp->numvals&AND_FILT_MASK)-1)*sizeof(float); } } @@ -1032,15 +1077,15 @@ float Get_MFilter(uint8_t index) { for (uint8_t count=0; countnumvals&0x80) { + if (mflp->numvals&OR_FILT_MASK) { // moving average - return mflp->maccu/(mflp->numvals&0x7f); + return mflp->maccu/(mflp->numvals&AND_FILT_MASK); } else { // median, sort array indices return median_array(mflp->rbuff,mflp->numvals); } } - mp+=sizeof(struct M_FILT)+((mflp->numvals&0x7f)-1)*sizeof(float); + mp+=sizeof(struct M_FILT)+((mflp->numvals&AND_FILT_MASK)-1)*sizeof(float); } return 0; } @@ -1050,13 +1095,13 @@ void Set_MFilter(uint8_t index, float invar) { for (uint8_t count=0; countnumvals&0x80) { + if (mflp->numvals&OR_FILT_MASK) { // moving average mflp->maccu-=mflp->rbuff[mflp->index]; mflp->maccu+=invar; mflp->rbuff[mflp->index]=invar; mflp->index++; - if (mflp->index>=(mflp->numvals&0x7f)) mflp->index=0; + if (mflp->index>=(mflp->numvals&AND_FILT_MASK)) mflp->index=0; } else { // median mflp->rbuff[mflp->index]=invar; @@ -1065,7 +1110,7 @@ void Set_MFilter(uint8_t index, float invar) { } break; } - mp+=sizeof(struct M_FILT)+((mflp->numvals&0x7f)-1)*sizeof(float); + mp+=sizeof(struct M_FILT)+((mflp->numvals&AND_FILT_MASK)-1)*sizeof(float); } } @@ -2140,7 +2185,7 @@ chknext: } } else { if (index>glob_script_mem.si_num) { - fvar=glob_script_mem.si_num; + index=glob_script_mem.si_num; } strlcpy(str,glob_script_mem.last_index_string+(index*glob_script_mem.max_ssize),glob_script_mem.max_ssize); } @@ -2691,7 +2736,7 @@ chknext: if (index<1 || index>MAXBUTTONS) index=1; index--; if (buttons[index]) { - fvar=buttons[index]->vpower&0x80; + fvar=buttons[index]->vpower.on_off; } else { fvar=-1; } @@ -2807,7 +2852,7 @@ chknext: #if defined(USE_TTGO_WATCH) && defined(USE_FT5206) if (!strncmp(vname,"wtch(",5)) { lp=GetNumericResult(lp+5,OPER_EQU,&fvar,0); - fvar=FT5206_touched(fvar); + fvar=Touch_Status(fvar); lp++; len=0; goto exit; @@ -3430,7 +3475,7 @@ int16_t Run_Scripter(const char *type, int8_t tlen, char *js) { int16_t Run_script_sub(const char *type, int8_t tlen, JsonObject *jo) { uint8_t vtype=0,sindex,xflg,floop=0,globvindex,fromscriptcmd=0; char *lp_next; - int8_t globaindex,saindex; + int16_t globaindex,saindex; struct T_INDEX ind; uint8_t operand,lastop,numeric=1,if_state[IF_NEST],if_exe[IF_NEST],if_result[IF_NEST],and_or,ifstck=0; if_state[ifstck]=0; @@ -3762,7 +3807,7 @@ int16_t Run_script_sub(const char *type, int8_t tlen, JsonObject *jo) { if ((vtype&STYPE)==0) { // numeric result if (glob_script_mem.type[ind.index].bits.is_filter) { - uint8_t len=0; + uint16_t len=0; float *fa=Get_MFAddr(index,&len,0); //Serial.printf(">> 2 %d\n",(uint32_t)*fa); if (fa && len) ws2812_set_array(fa,len,fvar); @@ -4175,12 +4220,26 @@ void Scripter_save_pvars(void) { for (uint8_t count=0; countPMEM_SIZE) { - vtp[count].bits.is_permanent=0; - return; + if (vtp[count].bits.is_filter) { + // save array + uint16_t len=0; + float *fa=Get_MFAddr(index,&len,0); + mlen+=sizeof(float)*len; + if (mlen>glob_script_mem.script_pram_size) { + vtp[count].bits.is_permanent=0; + return; + } + while (len--) { + *fp++=*fa++; + } + } else { + mlen+=sizeof(float); + if (mlen>glob_script_mem.script_pram_size) { + vtp[count].bits.is_permanent=0; + return; + } + *fp++=glob_script_mem.fvars[index]; } - *fp++=glob_script_mem.fvars[index]; } } char *cp=(char*)fp; @@ -4190,7 +4249,7 @@ void Scripter_save_pvars(void) { char *sp=glob_script_mem.glob_snp+(index*glob_script_mem.max_ssize); uint8_t slen=strlen(sp); mlen+=slen+1; - if (mlen>PMEM_SIZE) { + if (mlen>glob_script_mem.script_pram_size) { vtp[count].bits.is_permanent=0; return; } @@ -6013,6 +6072,9 @@ const char SCRIPT_MSG_GOPT4[] PROGMEM = const char SCRIPT_MSG_GOPT5[] PROGMEM = "new Date(0,1,1,%d,%d)"; +const char SCRIPT_MSG_GOPT6[] PROGMEM = +"title:'%s',isStacked:false,vAxis:{viewWindow:{min:%d,max:%d}}%s"; + const char SCRIPT_MSG_GTE1[] PROGMEM = "'%s'"; #define GLIBS_MAIN 1<<0 @@ -6022,11 +6084,11 @@ const char SCRIPT_MSG_GTE1[] PROGMEM = "'%s'"; #define MAX_GARRAY 4 -char *gc_get_arrays(char *lp, float **arrays, uint8_t *ranum, uint8_t *rentries, uint8_t *ipos) { +char *gc_get_arrays(char *lp, float **arrays, uint8_t *ranum, uint16_t *rentries, uint16_t *ipos) { struct T_INDEX ind; uint8_t vtype; -uint8 entries=0; -uint8_t cipos=0; +uint16 entries=0; +uint16_t cipos=0; uint8_t anum=0; while (anum> 2 %d\n",(uint32_t)*fa); + //Serial.printf(">> 2 %d\n",len); if (fa && len>=entries) { if (!entries) { entries = len; @@ -6295,12 +6357,12 @@ void ScriptWebShow(char mc) { } else { if (mc=='w') { - WSContentSend_PD(PSTR("%s"),tmp); + WSContentSend_PD(PSTR("%s"),lin); } else { if (optflg) { - WSContentSend_PD(PSTR("
%s
"),tmp); + WSContentSend_PD(PSTR("
%s
"),lin); } else { - WSContentSend_PD(PSTR("{s}%s{e}"),tmp); + WSContentSend_PD(PSTR("{s}%s{e}"),lin); } } } @@ -6388,8 +6450,8 @@ exgc: float *arrays[MAX_GARRAY]; uint8_t anum=0; - uint8 entries=0; - uint8 ipos=0; + uint16_t entries=0; + uint16_t ipos=0; lp=gc_get_arrays(lp, &arrays[0], &anum, &entries, &ipos); if (anum>nanum) { @@ -6434,10 +6496,19 @@ exgc: lp=GetStringResult(lp,OPER_EQU,label,0); SCRIPT_SKIP_SPACES - int8_t todflg=-1; + int16_t divflg=1; + int16_t todflg=-1; if (!strncmp(label,"cnt",3)) { todflg=atoi(&label[3]); if (todflg>=entries) todflg=entries-1; + } else { + uint16 segments=1; + for (uint32_t cnt=0; cnt -#include Renderer *renderer; @@ -757,7 +756,28 @@ void DisplayText(void) #ifdef USE_TOUCH_BUTTONS case 'b': - { int16_t num,gxp,gyp,gxs,gys,outline,fill,textcolor,textsize; + { int16_t num,gxp,gyp,gxs,gys,outline,fill,textcolor,textsize; uint8_t dflg=1; + if (*cp=='e' || *cp=='d') { + // enable disable + uint8_t dis=0; + if (*cp=='d') dis=1; + cp++; + var=atoiv(cp,&num); + num=num%MAXBUTTONS; + cp+=var; + if (buttons[num]) { + buttons[num]->vpower.disable=dis; + if (!dis) { + if (buttons[num]->vpower.is_virtual) buttons[num]->xdrawButton(buttons[num]->vpower.on_off); + else buttons[num]->xdrawButton(bitRead(power,num)); + } + } + break; + } + if (*cp=='-') { + cp++; + dflg=0; + } var=atoiv(cp,&num); cp+=var; cp++; @@ -797,16 +817,23 @@ void DisplayText(void) if (renderer) { buttons[num]= new VButton(); if (buttons[num]) { - buttons[num]->vpower=bflags; buttons[num]->initButtonUL(renderer,gxp,gyp,gxs,gys,renderer->GetColorFromIndex(outline),\ - renderer->GetColorFromIndex(fill),renderer->GetColorFromIndex(textcolor),bbuff,textsize); + renderer->GetColorFromIndex(fill),renderer->GetColorFromIndex(textcolor),bbuff,textsize); if (!bflags) { // power button - buttons[num]->xdrawButton(bitRead(power,num)); + if (dflg) buttons[num]->xdrawButton(bitRead(power,num)); + buttons[num]->vpower.is_virtual=0; } else { // virtual button - buttons[num]->vpower&=0x7f; - buttons[num]->xdrawButton(buttons[num]->vpower&0x80); + buttons[num]->vpower.is_virtual=1; + if (bflags==2) { + // push + buttons[num]->vpower.is_pushbutton=1; + } else { + // toggle + buttons[num]->vpower.is_pushbutton=0; + } + if (dflg) buttons[num]->xdrawButton(buttons[num]->vpower.on_off); } } } @@ -2019,7 +2046,146 @@ void AddValue(uint8_t num,float fval) { } } } -#endif +#endif // USE_GRAPH + +#ifdef USE_FT5206 + +// touch panel controller +#undef FT5206_address +#define FT5206_address 0x38 + +#include +FT5206_Class *touchp; +TP_Point pLoc; + + +extern VButton *buttons[]; +bool FT5206_found; + +bool Touch_Init(TwoWire &i2c) { + FT5206_found = false; + touchp = new FT5206_Class(); + if (touchp->begin(i2c, FT5206_address)) { + I2cSetActiveFound(FT5206_address, "FT5206"); + FT5206_found = true; + } + return FT5206_found; +} + +uint32_t Touch_Status(uint32_t sel) { + if (FT5206_found) { + switch (sel) { + case 0: + return touchp->touched(); + case 1: + return pLoc.x; + case 2: + return pLoc.y; + } + return 0; + } else { + return 0; + } +} + +#ifdef USE_TOUCH_BUTTONS +void Touch_MQTT(uint8_t index, const char *cp) { + ResponseTime_P(PSTR(",\"FT5206\":{\"%s%d\":\"%d\"}}"), cp, index+1, buttons[index]->vpower.on_off); + MqttPublishTeleSensor(); +} + +void Touch_RDW_BUTT(uint32_t count, uint32_t pwr) { + buttons[count]->xdrawButton(pwr); + if (pwr) buttons[count]->vpower.on_off = 1; + else buttons[count]->vpower.on_off = 0; +} + +// check digitizer hit +void Touch_Check(void(*rotconvert)(int16_t *x, int16_t *y)) { +uint16_t temp; +uint8_t rbutt=0; +uint8_t vbutt=0; + + + if (touchp->touched()) { + // did find a hit + pLoc = touchp->getPoint(0); + + if (renderer) { + + rotconvert(&pLoc.x, &pLoc.y); + + //AddLog_P2(LOG_LEVEL_INFO, PSTR("touch %d - %d"), pLoc.x, pLoc.y); + // now must compare with defined buttons + for (uint8_t count=0; countvpower.disable) { + if (buttons[count]->contains(pLoc.x, pLoc.y)) { + // did hit + buttons[count]->press(true); + if (buttons[count]->justPressed()) { + if (!buttons[count]->vpower.is_virtual) { + uint8_t pwr=bitRead(power, rbutt); + if (!SendKey(KEY_BUTTON, rbutt+1, POWER_TOGGLE)) { + ExecuteCommandPower(rbutt+1, POWER_TOGGLE, SRC_BUTTON); + Touch_RDW_BUTT(count, !pwr); + } + } else { + // virtual button + const char *cp; + if (!buttons[count]->vpower.is_pushbutton) { + // toggle button + buttons[count]->vpower.on_off ^= 1; + cp="TBT"; + } else { + // push button + buttons[count]->vpower.on_off = 1; + cp="PBT"; + } + buttons[count]->xdrawButton(buttons[count]->vpower.on_off); + Touch_MQTT(count,cp); + } + } + } + if (!buttons[count]->vpower.is_virtual) { + rbutt++; + } else { + vbutt++; + } + } + } + } + } else { + // no hit + for (uint8_t count=0; countpress(false); + if (buttons[count]->justReleased()) { + if (buttons[count]->vpower.is_virtual) { + if (buttons[count]->vpower.is_pushbutton) { + // push button + buttons[count]->vpower.on_off = 0; + Touch_MQTT(count,"PBT"); + buttons[count]->xdrawButton(buttons[count]->vpower.on_off); + } + } + } + if (!buttons[count]->vpower.is_virtual) { + // check if power button stage changed + uint8_t pwr = bitRead(power, rbutt); + uint8_t vpwr = buttons[count]->vpower.on_off; + if (pwr != vpwr) { + Touch_RDW_BUTT(count, pwr); + } + rbutt++; + } + } + } + pLoc.x = 0; + pLoc.y = 0; + } +} +#endif // USE_TOUCH_BUTTONS +#endif // USE_FT5206 /*********************************************************************************************\ * Interface diff --git a/tasmota/xdsp_08_ILI9488.ino b/tasmota/xdsp_08_ILI9488.ino index e49e7bffe..b1e738fd4 100644 --- a/tasmota/xdsp_08_ILI9488.ino +++ b/tasmota/xdsp_08_ILI9488.ino @@ -27,18 +27,12 @@ #define COLORED 1 #define UNCOLORED 0 -// touch panel controller -#define FT6236_address 0x38 - // using font 8 is opional (num=3) // very badly readable, but may be useful for graphs #define USE_TINY_FONT #include -#include - -TouchLocation ili9488_pLoc; uint8_t ili9488_ctouch_counter = 0; // currently fixed @@ -47,13 +41,7 @@ uint8_t ili9488_ctouch_counter = 0; extern uint8_t *buffer; extern uint8_t color_type; ILI9488 *ili9488; - -#ifdef USE_TOUCH_BUTTONS -extern VButton *buttons[]; -#endif - extern const uint16_t picture[]; -uint8_t FT6236_found; /*********************************************************************************************/ @@ -126,30 +114,52 @@ void ILI9488_InitDriver() #endif color_type = COLOR_COLOR; - // start digitizer with fixed adress - - if (I2cEnabled(XI2C_38) && I2cSetDevice(FT6236_address)) { - FT6236begin(FT6236_address); - FT6236_found=1; - I2cSetActiveFound(FT6236_address, "FT6236"); - } else { - FT6236_found=0; - } - + // start digitizer +#ifdef USE_FT5206 + Touch_Init(Wire); +#endif } } +#ifdef USE_FT5206 #ifdef USE_TOUCH_BUTTONS -void ILI9488_MQTT(uint8_t count,const char *cp) { - ResponseTime_P(PSTR(",\"RA8876\":{\"%s%d\":\"%d\"}}"), cp,count+1,(buttons[count]->vpower&0x80)>>7); - MqttPublishTeleSensor(); + +void ILI9488_RotConvert(int16_t *x, int16_t *y) { +int16_t temp; + if (renderer) { + uint8_t rot=renderer->getRotation(); + switch (rot) { + case 0: + temp=*y; + *y=renderer->height()-*x; + *x=temp; + break; + case 1: + break; + case 2: + break; + case 3: + temp=*y; + *y=*x; + *x=renderer->width()-temp; + break; + } + } } -void ILI9488_RDW_BUTT(uint32_t count,uint32_t pwr) { - buttons[count]->xdrawButton(pwr); - if (pwr) buttons[count]->vpower|=0x80; - else buttons[count]->vpower&=0x7f; +// check digitizer hit +void ILI9488_CheckTouch(void) { + ili9488_ctouch_counter++; + if (2 == ili9488_ctouch_counter) { + // every 100 ms should be enough + ili9488_ctouch_counter = 0; + Touch_Check(ILI9488_RotConvert); + } } +#endif // USE_TOUCH_BUTTONS +#endif // USE_FT5206 + +/* // check digitizer hit void FT6236Check() { uint16_t temp; @@ -181,12 +191,11 @@ if (2 == ili9488_ctouch_counter) { // now must compare with defined buttons for (uint8_t count=0; countvpower&0x7f; if (buttons[count]->contains(ili9488_pLoc.x,ili9488_pLoc.y)) { // did hit buttons[count]->press(true); if (buttons[count]->justPressed()) { - if (!bflags) { + if (!buttons[count]->vpower.is_virtual) { uint8_t pwr=bitRead(power,rbutt); if (!SendKey(KEY_BUTTON, rbutt+1, POWER_TOGGLE)) { ExecuteCommandPower(rbutt+1, POWER_TOGGLE, SRC_BUTTON); @@ -195,21 +204,21 @@ if (2 == ili9488_ctouch_counter) { } else { // virtual button const char *cp; - if (bflags==1) { + if (!buttons[count]->vpower.is_pushbutton) { // toggle button - buttons[count]->vpower^=0x80; + buttons[count]->vpower.on_off^=1; cp="TBT"; } else { // push button - buttons[count]->vpower|=0x80; + buttons[count]->vpower.on_off=1; cp="PBT"; } - buttons[count]->xdrawButton(buttons[count]->vpower&0x80); + buttons[count]->xdrawButton(buttons[count]->vpower.on_off); ILI9488_MQTT(count,cp); } } } - if (!bflags) { + if (!buttons[count]->vpower.is_virtual) { rbutt++; } else { vbutt++; @@ -221,23 +230,21 @@ if (2 == ili9488_ctouch_counter) { // no hit for (uint8_t count=0; countvpower&0x7f; buttons[count]->press(false); if (buttons[count]->justReleased()) { - uint8_t bflags=buttons[count]->vpower&0x7f; - if (bflags>0) { - if (bflags>1) { + if (buttons[count]->vpower.is_virtual) { + if (buttons[count]->vpower.is_pushbutton) { // push button - buttons[count]->vpower&=0x7f; + buttons[count]->vpower.on_off=0; ILI9488_MQTT(count,"PBT"); } - buttons[count]->xdrawButton(buttons[count]->vpower&0x80); + buttons[count]->xdrawButton(buttons[count]->vpower.on_off); } } - if (!bflags) { + if (!buttons[count]->vpower.is_virtual) { // check if power button stage changed uint8_t pwr=bitRead(power,rbutt); - uint8_t vpwr=(buttons[count]->vpower&0x80)>>7; + uint8_t vpwr=buttons[count]->vpower.on_off; if (pwr!=vpwr) { ILI9488_RDW_BUTT(count,pwr); } @@ -251,6 +258,8 @@ if (2 == ili9488_ctouch_counter) { } } #endif // USE_TOUCH_BUTTONS +*/ + /*********************************************************************************************/ /*********************************************************************************************\ * Interface @@ -270,7 +279,9 @@ bool Xdsp08(uint8_t function) break; case FUNC_DISPLAY_EVERY_50_MSECOND: #ifdef USE_TOUCH_BUTTONS - if (FT6236_found) FT6236Check(); + if (FT5206_found) { + ILI9488_CheckTouch(); + } #endif break; } diff --git a/tasmota/xdsp_10_RA8876.ino b/tasmota/xdsp_10_RA8876.ino index aa8e82f4d..47b909b4c 100644 --- a/tasmota/xdsp_10_RA8876.ino +++ b/tasmota/xdsp_10_RA8876.ino @@ -27,29 +27,17 @@ #define COLORED 1 #define UNCOLORED 0 -// touch panel controller -#define FT5316_address 0x38 - // using font 8 is opional (num=3) // very badly readable, but may be useful for graphs #define USE_TINY_FONT #include -#include -TouchLocation ra8876_pLoc; uint8_t ra8876_ctouch_counter = 0; - -#ifdef USE_TOUCH_BUTTONS -extern VButton *buttons[]; -#endif - extern uint8_t *buffer; extern uint8_t color_type; RA8876 *ra8876; -uint8_t FT5316_found; - /*********************************************************************************************/ void RA8876_InitDriver() { @@ -114,147 +102,41 @@ void RA8876_InitDriver() #endif color_type = COLOR_COLOR; - if (I2cEnabled(XI2C_39) && I2cSetDevice(FT5316_address)) { - FT6236begin(FT5316_address); - FT5316_found=1; - I2cSetActiveFound(FT5316_address, "FT5316"); - } else { - FT5316_found=0; - } +#ifdef USE_FT5206 + Touch_Init(Wire); +#endif } } -#ifdef USE_TOUCH_BUTTONS -void RA8876_MQTT(uint8_t count,const char *cp) { - ResponseTime_P(PSTR(",\"RA8876\":{\"%s%d\":\"%d\"}}"), cp,count+1,(buttons[count]->vpower&0x80)>>7); - MqttPublishTeleSensor(); -} -void RA8876_RDW_BUTT(uint32_t count,uint32_t pwr) { - buttons[count]->xdrawButton(pwr); - if (pwr) buttons[count]->vpower|=0x80; - else buttons[count]->vpower&=0x7f; +#ifdef USE_FT5206 +#ifdef USE_TOUCH_BUTTONS + +// no rotation support +void RA8876_RotConvert(int16_t *x, int16_t *y) { +int16_t temp; + if (renderer) { + *x=*x*renderer->width()/800; + *y=*y*renderer->height()/480; + + *x = renderer->width() - *x; + *y = renderer->height() - *y; + } } // check digitizer hit -void FT5316Check() { -uint16_t temp; -uint8_t rbutt=0,vbutt=0; -ra8876_ctouch_counter++; -if (2 == ra8876_ctouch_counter) { - // every 100 ms should be enough - ra8876_ctouch_counter=0; - // panel has 800x480 - if (FT6236readTouchLocation(&ra8876_pLoc,1)) { - ra8876_pLoc.x=ra8876_pLoc.x*RA8876_TFTWIDTH/800; - ra8876_pLoc.y=ra8876_pLoc.y*RA8876_TFTHEIGHT/480; - // did find a hit - - if (renderer) { - - // rotation not supported - ra8876_pLoc.x=RA8876_TFTWIDTH-ra8876_pLoc.x; - ra8876_pLoc.y=RA8876_TFTHEIGHT-ra8876_pLoc.y; - - /* - uint8_t rot=renderer->getRotation(); - switch (rot) { - case 0: - //temp=pLoc.y; - pLoc.x=renderer->width()-pLoc.x; - pLoc.y=renderer->height()-pLoc.y; - //pLoc.x=temp; - break; - case 1: - break; - case 2: - break; - case 3: - temp=pLoc.y; - pLoc.y=pLoc.x; - pLoc.x=renderer->width()-temp; - break; - } - */ - //AddLog_P2(LOG_LEVEL_INFO, PSTR(">> %d,%d"),ra8876_pLoc.x,ra8876_pLoc.y); - - - //Serial.printf("loc x: %d , loc y: %d\n",pLoc.x,pLoc.y); - - // now must compare with defined buttons - for (uint8_t count=0; countvpower&0x7f; - if (buttons[count]->contains(ra8876_pLoc.x,ra8876_pLoc.y)) { - // did hit - buttons[count]->press(true); - if (buttons[count]->justPressed()) { - if (!bflags) { - // real button - uint8_t pwr=bitRead(power,rbutt); - if (!SendKey(KEY_BUTTON, rbutt+1, POWER_TOGGLE)) { - ExecuteCommandPower(rbutt+1, POWER_TOGGLE, SRC_BUTTON); - RA8876_RDW_BUTT(count,!pwr); - } - } else { - // virtual button - const char *cp; - if (bflags==1) { - // toggle button - buttons[count]->vpower^=0x80; - cp="TBT"; - } else { - // push button - buttons[count]->vpower|=0x80; - cp="PBT"; - } - buttons[count]->xdrawButton(buttons[count]->vpower&0x80); - RA8876_MQTT(count,cp); - } - } - } - if (!bflags) { - rbutt++; - } else { - vbutt++; - } - } - } - } - } else { - // no hit - for (uint8_t count=0; countvpower&0x7f; - buttons[count]->press(false); - if (buttons[count]->justReleased()) { - if (bflags>0) { - if (bflags>1) { - // push button - buttons[count]->vpower&=0x7f; - RA8876_MQTT(count,"PBT"); - } - buttons[count]->xdrawButton(buttons[count]->vpower&0x80); - } - } - if (!bflags) { - // check if power button stage changed - uint8_t pwr=bitRead(power,rbutt); - uint8_t vpwr=(buttons[count]->vpower&0x80)>>7; - if (pwr!=vpwr) { - RA8876_RDW_BUTT(count,pwr); - } - rbutt++; - } - } - } - ra8876_pLoc.x=0; - ra8876_pLoc.y=0; +void RA8876_CheckTouch(void) { + ra8876_ctouch_counter++; + if (2 == ra8876_ctouch_counter) { + // every 100 ms should be enough + ra8876_ctouch_counter = 0; + Touch_Check(RA8876_RotConvert); } } -} -#endif // USE_TOUCH_BUTTONS +#endif // USE_TOUCH_BUTTONS +#endif // USE_FT5206 + /* void testall() { ra8876->clearScreen(0); @@ -452,8 +334,8 @@ bool Xdsp10(uint8_t function) result = true; break; case FUNC_DISPLAY_EVERY_50_MSECOND: -#ifdef USE_TOUCH_BUTTONS - if (FT5316_found) FT5316Check(); +#ifdef USE_FT5206 + if (FT5206_found) RA8876_CheckTouch(); #endif break; } diff --git a/tasmota/xdsp_12_ST7789.ino b/tasmota/xdsp_12_ST7789.ino index 3b2ef8d82..d31c55fa4 100644 --- a/tasmota/xdsp_12_ST7789.ino +++ b/tasmota/xdsp_12_ST7789.ino @@ -17,6 +17,7 @@ along with this program. If not, see . */ +//#ifdef USE_SPI #ifdef USE_SPI #ifdef USE_DISPLAY #ifdef USE_DISPLAY_ST7789 @@ -50,12 +51,6 @@ extern uint8_t color_type; Arduino_ST7789 *st7789; #ifdef USE_FT5206 -#ifdef USE_TOUCH_BUTTONS -extern VButton *buttons[]; -#endif -FT5206_Class *touchp; -uint8_t FT5206_found; -TP_Point st7789_pLoc; uint8_t st7789_ctouch_counter = 0; #endif // USE_FT5206 @@ -142,155 +137,51 @@ void ST7789_InitDriver() #define SDA_2 23 #define SCL_2 32 Wire1.begin(SDA_2, SCL_2, 400000); - touchp = new FT5206_Class(); - if (touchp->begin(Wire1, FT5206_address)) { - FT5206_found=1; - //I2cSetDevice(FT5206_address); - I2cSetActiveFound(FT5206_address, "FT5206"); - } else { - FT5206_found=0; - } + Touch_Init(Wire1); #endif // USE_FT5206 #endif // ESP32 } } - #ifdef ESP32 #ifdef USE_FT5206 #ifdef USE_TOUCH_BUTTONS -void ST7789_MQTT(uint8_t count,const char *cp) { - ResponseTime_P(PSTR(",\"ST7789\":{\"%s%d\":\"%d\"}}"), cp,count+1,(buttons[count]->vpower&0x80)>>7); - MqttPublishTeleSensor(); -} -uint32_t FT5206_touched(uint32_t sel) { - if (touchp) { - switch (sel) { +void ST7789_RotConvert(int16_t *x, int16_t *y) { +int16_t temp; + if (renderer) { + uint8_t rot=renderer->getRotation(); + switch (rot) { case 0: - return touchp->touched(); + break; case 1: - return st7789_pLoc.x; + temp=*y; + *y=renderer->height()-*x; + *x=temp; + break; case 2: - return st7789_pLoc.y; + *x=renderer->width()-*x; + *y=renderer->height()-*y; + break; + case 3: + temp=*y; + *y=*x; + *x=renderer->width()-temp; + break; } - return 0; - } else { - return 0; } } -void ST7789_RDW_BUTT(uint32_t count,uint32_t pwr) { - buttons[count]->xdrawButton(pwr); - if (pwr) buttons[count]->vpower|=0x80; - else buttons[count]->vpower&=0x7f; -} // check digitizer hit -void FT5206Check() { -uint16_t temp; -uint8_t rbutt=0,vbutt=0; +void ST7789_CheckTouch() { st7789_ctouch_counter++; -if (2 == st7789_ctouch_counter) { - // every 100 ms should be enough - st7789_ctouch_counter=0; - - if (touchp->touched()) { - // did find a hit - st7789_pLoc = touchp->getPoint(0); - if (renderer) { - uint8_t rot=renderer->getRotation(); - switch (rot) { - case 0: - break; - case 1: - temp=st7789_pLoc.y; - st7789_pLoc.y=renderer->height()-st7789_pLoc.x; - st7789_pLoc.x=temp; - break; - case 2: - st7789_pLoc.x=renderer->width()-st7789_pLoc.x; - st7789_pLoc.y=renderer->height()-st7789_pLoc.y; - break; - case 3: - temp=st7789_pLoc.y; - st7789_pLoc.y=st7789_pLoc.x; - st7789_pLoc.x=renderer->width()-temp; - break; - } - //AddLog_P2(LOG_LEVEL_INFO, PSTR("touch %d - %d"), st7789_pLoc.x, st7789_pLoc.y); - // now must compare with defined buttons - for (uint8_t count=0; countvpower&0x7f; - if (buttons[count]->contains(st7789_pLoc.x,st7789_pLoc.y)) { - // did hit - buttons[count]->press(true); - if (buttons[count]->justPressed()) { - if (!bflags) { - uint8_t pwr=bitRead(power,rbutt); - if (!SendKey(KEY_BUTTON, rbutt+1, POWER_TOGGLE)) { - ExecuteCommandPower(rbutt+1, POWER_TOGGLE, SRC_BUTTON); - ST7789_RDW_BUTT(count,!pwr); - } - } else { - // virtual button - const char *cp; - if (bflags==1) { - // toggle button - buttons[count]->vpower^=0x80; - cp="TBT"; - } else { - // push button - buttons[count]->vpower|=0x80; - cp="PBT"; - } - buttons[count]->xdrawButton(buttons[count]->vpower&0x80); - ST7789_MQTT(count,cp); - } - } - } - if (!bflags) { - rbutt++; - } else { - vbutt++; - } - } - } - } - } else { - // no hit - for (uint8_t count=0; countvpower&0x7f; - buttons[count]->press(false); - if (buttons[count]->justReleased()) { - uint8_t bflags=buttons[count]->vpower&0x7f; - if (bflags>0) { - if (bflags>1) { - // push button - buttons[count]->vpower&=0x7f; - ST7789_MQTT(count,"PBT"); - } - buttons[count]->xdrawButton(buttons[count]->vpower&0x80); - } - } - if (!bflags) { - // check if power button stage changed - uint8_t pwr=bitRead(power,rbutt); - uint8_t vpwr=(buttons[count]->vpower&0x80)>>7; - if (pwr!=vpwr) { - ST7789_RDW_BUTT(count,pwr); - } - rbutt++; - } - } - } - st7789_pLoc.x=0; - st7789_pLoc.y=0; + if (2 == st7789_ctouch_counter) { + // every 100 ms should be enough + st7789_ctouch_counter = 0; + Touch_Check(ST7789_RotConvert); } } -} #endif // USE_TOUCH_BUTTONS #endif // USE_FT5206 #endif // ESP32 @@ -317,7 +208,7 @@ bool Xdsp12(uint8_t function) #ifdef USE_FT5206 #ifdef USE_TOUCH_BUTTONS if (FT5206_found) { - FT5206Check(); + ST7789_CheckTouch(); } #endif #endif // USE_FT5206