diff --git a/boards/CYD-2432S028/interface.cpp b/boards/CYD-2432S028/interface.cpp index fea72843a..c2f511cda 100644 --- a/boards/CYD-2432S028/interface.cpp +++ b/boards/CYD-2432S028/interface.cpp @@ -1,5 +1,6 @@ #include "interface.h" #include "core/powerSave.h" +#include "core/utils.h" #if defined(HAS_CAPACITIVE_TOUCH) #include "CYD28_TouchscreenC.h" @@ -69,57 +70,11 @@ void _setBrightness(uint8_t brightval) { ledcWrite(TFT_BRIGHT_CHANNEL,dutyCycle); // Channel 0 } -struct box_t -{ - int x; - int y; - int w; - int h; - std::uint16_t color; - int touch_id = -1; - char key; - char key_sh; - - void clear(void) - { - for (int i = 0; i < 8; ++i) - { - tft.fillRect(x, y, w, h,bruceConfig.bgColor); - } - } - void draw(void) - { - int ie = touch_id < 0 ? 4 : 8; - for (int i = 0; i < ie; ++i) - { - tft.drawRect(x, y, w, h,color); - tft.setTextColor(color); - tft.drawChar(key,x+w/2-FM*LW/2,y+h/2-FM*LH/2); - } - } - bool contain(int x, int y) - { - return this->x <= x && x < (this->x + this->w) - && this->y <= y && y < (this->y + this->h); - } -}; - -static constexpr std::size_t box_count = 52; -static box_t box_list[box_count]; - /********************************************************************* ** Function: InputHandler ** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress **********************************************************************/ void InputHandler(void) { - checkPowerSaveTime(); - PrevPress = false; - NextPress = false; - SelPress = false; - AnyKeyPress = false; - EscPress = false; - - int terco=tftWidth/3; if (touch.touched()) { //touch.tirqTouched() && auto t = touch.getPointScaled(); t = touch.getPointScaled(); @@ -138,14 +93,15 @@ void InputHandler(void) { t.y = (tftHeight+20)-tmp; } - //if(t.y>(tftHeight)) { if(!wakeUpScreen()) AnyKeyPress = true; else goto END; - if(t.x>terco*0 && t.xterco*1 && t.xterco*2 && t.x' },//10 - { '?', '/' },//11 - { '/', '/' } //12 - } - }; - int _x = tftWidth/12; - int _y = (tftHeight - 54)/4; - int _xo = _x/2-3; - - int k=0; - for(x2=0; x2<12;x2++) { - for(y2=0; y2<4; y2++) { - box_list[k].key=keys[y2][x2][0]; - box_list[k].key_sh=keys[y2][x2][1]; - box_list[k].color = ~bruceConfig.bgColor; - box_list[k].x=x2*_x; - box_list[k].y=y2*_y+54; - box_list[k].w=_x; - box_list[k].h=_y; - k++; - } - } - // OK - box_list[k].key=' '; - box_list[k].key_sh=' '; - box_list[k].color = ~bruceConfig.bgColor; - box_list[k].x=0; - box_list[k].y=0; - box_list[k].w=53; - box_list[k].h=22; - k++; - // CAP - box_list[k].key=' '; - box_list[k].key_sh=' '; - box_list[k].color = ~bruceConfig.bgColor; - box_list[k].x=55; - box_list[k].y=0; - box_list[k].w=50; - box_list[k].h=22; - k++; - // DEL - box_list[k].key=' '; - box_list[k].key_sh=' '; - box_list[k].color = ~bruceConfig.bgColor; - box_list[k].x=107; - box_list[k].y=0; - box_list[k].w=50; - box_list[k].h=22; - k++; - // SPACE - box_list[k].key=' '; - box_list[k].key_sh=' '; - box_list[k].color = ~bruceConfig.bgColor; - box_list[k].x=159; - box_list[k].y=0; - box_list[k].w=tftWidth-164; - box_list[k].h=22; - - k=0; - x2=0; - y2=0; - - int i=0; - int j=-1; - bool redraw=true; - int cX =0; - int cY =0; - tft.fillScreen(bruceConfig.bgColor); - while(1) { - if(redraw) { - tft.setCursor(0,0); - tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.setTextSize(FM); - - //Draw the rectangles - if(y<0 || y2<0) { - tft.fillRect(0,1,tftWidth,22,bruceConfig.bgColor); - tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle - tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle - tft.drawRect(107,2,50,20,TFT_WHITE); // DEL Rectangle - tft.drawRect(159,2,74,20,TFT_WHITE); // SPACE Rectangle - tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle - - - if(x==0 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(7,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("OK", 18, 4); - - - if(x==1 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(55,2,50,20,TFT_WHITE); } - else if(caps) { tft.fillRect(55,2,50,20,TFT_DARKGREY); tft.setTextColor(TFT_WHITE, TFT_DARKGREY); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("CAP", 64, 4); - - - if(x==2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(107,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("DEL", 115, 4); - - if(x>2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(159,2,74,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("SPACE", 168, 4); - } - - tft.setTextSize(FP); - tft.setTextColor(TFT_WHITE, 0x5AAB); - tft.drawString(msg.substring(0,38), 3, 24); - - tft.setTextSize(FM); - - // reseta o quadrado do texto - if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,tftWidth-3,20,bruceConfig.bgColor); // mystring Rectangle - // escreve o texto - tft.setTextColor(TFT_WHITE); - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - tft.drawString(mytext.substring(0,38), 5, 34); - tft.drawString(mytext.substring(38,mytext.length()), 5, 42); - } - else { - tft.drawString(mytext, 5, 34); - } - } else { - tft.drawString(mytext, 5, 34); - } - //desenha o retangulo colorido - tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle - - - tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.setTextSize(FM); - - - for(i=0;i<4;i++) { - for(j=0;j<12;j++) { - //use last coordenate to paint only this letter - if(x2==j && y2==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,bruceConfig.bgColor);} - /* If selected, change font color and draw Rectangle*/ - if(x==j && y==i) { tft.setTextColor(bruceConfig.bgColor, ~bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,~bruceConfig.bgColor);} - - - /* Print the letters */ - if(!caps) tft.drawChar(keys[i][j][0], (j*_x+_xo), (i*_y+56)); - else tft.drawChar(keys[i][j][1], (j*_x+_xo), (i*_y+56)); - - /* Return colors to normal to print the other letters */ - if(x==j && y==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); } - } - } - // save actual key coordenate - x2=x; - y2=y; - redraw = false; - TouchFooter(); - } - - //cursor handler - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - cY=42; - cX=5+(mytext.length()-38)*LW; - } - else { - cY=34; - cX=5+mytext.length()*LW; - } - } else { - cY=34; - cX=5+mytext.length()*LW*2; - } - - int z=0; - if (touch.touched()) - { - - auto t = touch.getPointScaled(); - if(bruceConfig.rotation==3) { - t.y = (tftHeight+20)-t.y; - t.x = tftWidth-t.x; - } - if(bruceConfig.rotation==0) { - int tmp=t.x; - t.x = tftWidth-t.y; - t.y = tmp; - } - if(bruceConfig.rotation==2) { - int tmp=t.x; - t.x = t.y; - t.y = (tftHeight+20)-tmp; - } - if (box_list[48].contain(t.x, t.y)) { break; } // Ok - if (box_list[49].contain(t.x, t.y)) { caps=!caps; tft.fillRect(0,54,tftWidth,tftHeight-54,bruceConfig.bgColor); goto THIS_END; } // CAP - if (box_list[50].contain(t.x, t.y)) goto DEL; // DEL - if (box_list[51].contain(t.x, t.y)) { mytext += box_list[51].key; goto ADD; } // SPACE - for(k=0;k<48;k++){ - if (box_list[k].contain(t.x, t.y)) { - if(caps) mytext += box_list[k].key_sh; - else mytext += box_list[k].key; - } - } - wakeUpScreen(); - THIS_END: - redraw=true; - delay(200); - } - - if(false) { // gotos placeholder, need refactor sometime. - tft.setCursor(cX,cY); - if(caps) z=1; - else z=0; - if(x==0 && y==-1) break; - else if(x==1 && y==-1) caps=!caps; - else if(x==2 && y==-1 && mytext.length() > 0) { - DEL: - mytext.remove(mytext.length()-1); - int fS=FM; - if(mytext.length()>19) { tft.setTextSize(FP); fS=FP; } - else tft.setTextSize(FM); - tft.setCursor((cX-fS*LW),cY); - tft.setTextColor(bruceConfig.priColor,bruceConfig.bgColor); - tft.print(" "); - tft.setTextColor(TFT_WHITE, 0x5AAB); - tft.setCursor(cX-fS*LW,cY); - cX=tft.getCursorX(); - cY=tft.getCursorY(); - } - else if(x>2 && y==-1 && mytext.length()-1 && mytext.length()' },//10 - { '?', '/' },//11 - { '/', '/' } //12 - } - }; - int _x = tftWidth/12; - int _y = (tftHeight - 54)/4; - int _xo = _x/2-3; - -#if defined(HAS_TOUCH) - int k=0; - for(x2=0; x2<12;x2++) { - for(y2=0; y2<4; y2++) { - box_list[k].key=keys[y2][x2][0]; - box_list[k].key_sh=keys[y2][x2][1]; - box_list[k].color = ~bruceConfig.bgColor; - box_list[k].x=x2*_x; - box_list[k].y=y2*_y+54; - box_list[k].w=_x; - box_list[k].h=_y; - k++; - } - } - // OK - box_list[k].key=' '; - box_list[k].key_sh=' '; - box_list[k].color = ~bruceConfig.bgColor; - box_list[k].x=0; - box_list[k].y=0; - box_list[k].w=53; - box_list[k].h=22; - k++; - // CAP - box_list[k].key=' '; - box_list[k].key_sh=' '; - box_list[k].color = ~bruceConfig.bgColor; - box_list[k].x=55; - box_list[k].y=0; - box_list[k].w=50; - box_list[k].h=22; - k++; - // DEL - box_list[k].key=' '; - box_list[k].key_sh=' '; - box_list[k].color = ~bruceConfig.bgColor; - box_list[k].x=107; - box_list[k].y=0; - box_list[k].w=50; - box_list[k].h=22; - k++; - // SPACE - box_list[k].key=' '; - box_list[k].key_sh=' '; - box_list[k].color = ~bruceConfig.bgColor; - box_list[k].x=159; - box_list[k].y=0; - box_list[k].w=tftWidth-164; - box_list[k].h=22; - - k=0; - x2=0; - y2=0; -#endif - - int i=0; - int j=-1; - bool redraw=true; - int cX =0; - int cY =0; - tft.fillScreen(bruceConfig.bgColor); - KeyStroke.Clear(); - while(1) { - if(redraw) { - tft.setCursor(0,0); - tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.setTextSize(FM); - - //Draw the rectangles - if(y<0) { - tft.fillRect(0,1,tftWidth,22,bruceConfig.bgColor); - tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle - tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle - tft.drawRect(107,2,50,20,TFT_WHITE); // DEL Rectangle - tft.drawRect(159,2,74,20,TFT_WHITE); // SPACE Rectangle - tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle - - - if(x==0 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(7,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("OK", 18, 4); - - - if(x==1 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(55,2,50,20,TFT_WHITE); } - else if(caps) { tft.fillRect(55,2,50,20,TFT_DARKGREY); tft.setTextColor(TFT_WHITE, TFT_DARKGREY); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("CAP", 64, 4); - - - if(x==2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(107,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("DEL", 115, 4); - - if(x>2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(159,2,74,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("SPACE", 168, 4); - } - - tft.setTextSize(FP); - tft.setTextColor(TFT_WHITE, 0x5AAB); - tft.drawString(msg.substring(0,38), 3, 24); - - tft.setTextSize(FM); - - // reseta o quadrado do texto - if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,tftWidth-3,20,bruceConfig.bgColor); // mystring Rectangle - // escreve o texto - tft.setTextColor(TFT_WHITE); - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - tft.drawString(mytext.substring(0,38), 5, 34); - tft.drawString(mytext.substring(38,mytext.length()), 5, 42); - } - else { - tft.drawString(mytext, 5, 34); - } - } else { - tft.drawString(mytext, 5, 34); - } - //desenha o retangulo colorido - tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle - - - tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.setTextSize(FM); - - - for(i=0;i<4;i++) { - for(j=0;j<12;j++) { - //use last coordenate to paint only this letter - if(x2==j && y2==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,bruceConfig.bgColor);} - /* If selected, change font color and draw Rectangle*/ - if(x==j && y==i) { tft.setTextColor(bruceConfig.bgColor, ~bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,~bruceConfig.bgColor);} - - - /* Print the letters */ - if(!caps) tft.drawChar(keys[i][j][0], (j*_x+_xo), (i*_y+56)); - else tft.drawChar(keys[i][j][1], (j*_x+_xo), (i*_y+56)); - - /* Return colors to normal to print the other letters */ - if(x==j && y==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); } - } - } - // save actual key coordenate - x2=x; - y2=y; - redraw = false; - #if defined(HAS_TOUCH) - TouchFooter(); - #endif - } - - //cursor handler - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - cY=42; - cX=5+(mytext.length()-38)*LW; - } - else { - cY=34; - cX=5+mytext.length()*LW; - } - } else { - cY=34; - cX=5+mytext.length()*LW*2; - } - - if (KeyStroke.pressed) { - wakeUpScreen(); - tft.setCursor(cX,cY); - String keyStr = ""; - for (auto i : KeyStroke.word) { - if (keyStr != "") { - keyStr = keyStr + "+" + i; - } else { - keyStr += i; - } - } - - if(mytext.length() 0) { // delete 0x08 - // Handle backspace key - mytext.remove(mytext.length() - 1); - int fS=FM; - if(mytext.length()>19) { tft.setTextSize(FP); fS=FP; } - else tft.setTextSize(FM); - tft.setCursor((cX-fS*LW),cY); - tft.setTextColor(bruceConfig.priColor,bruceConfig.bgColor); - tft.print(" "); - tft.setTextColor(TFT_WHITE, 0x5AAB); - tft.setCursor(cX-fS*LW,cY); - cX=tft.getCursorX(); - cY=tft.getCursorY(); - if(mytext.length()==19) redraw = true; - if(mytext.length()==38) redraw = true; - } - if (KeyStroke.enter) { - break; - } - KeyStroke.Clear(); - } - if(check(SelPress)) break; - - delay(5); - - } - - //Resets screen when finished writing - tft.fillRect(0,0,tftWidth,tftHeight,bruceConfig.bgColor); - resetTftDisplay(); - - return mytext; -} - - /********************************************************************* ** Function: powerOff diff --git a/boards/lilygo-t-embed-cc1101/interface.cpp b/boards/lilygo-t-embed-cc1101/interface.cpp index d096a0e62..ea2493570 100644 --- a/boards/lilygo-t-embed-cc1101/interface.cpp +++ b/boards/lilygo-t-embed-cc1101/interface.cpp @@ -129,9 +129,6 @@ void _setBrightness(uint8_t brightval) { //RotaryEncoder encoder(ENCODER_INA, ENCODER_INB, RotaryEncoder::LatchMode::TWO03); RotaryEncoder *encoder = nullptr; -int _new_pos = 0; -int _last_pos = 0; -volatile int _last_dir = 0; IRAM_ATTR void checkPosition() { encoder->tick(); // just call tick() to check the state. } @@ -141,15 +138,8 @@ IRAM_ATTR void checkPosition() { ** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress **********************************************************************/ void InputHandler(void) { - checkPowerSaveTime(); - PrevPress = false; - NextPress = false; - SelPress = false; - AnyKeyPress = false; - EscPress = false; + static int _last_dir = 0; _last_dir = (int)encoder->getDirection(); - _last_pos = _new_pos; - _new_pos = encoder->getPosition(); if(_last_dir!=0 || digitalRead(SEL_BTN)==BTN_ACT) { if(!wakeUpScreen()) AnyKeyPress = true; else goto END; @@ -180,261 +170,6 @@ void InputHandler(void) { } } -/* Starts keyboard to type data */ -String keyboard(String mytext, int maxSize, String msg) { - String _mytext = mytext; - - resetTftDisplay(); - bool caps=false; - int x=0; - int y=-1; - int x2=0; - int y2=0; - char keys[4][12][2] = { //4 lines, with 12 characteres, low and high caps - { - { '1', '!' },//1 - { '2', '@' },//2 - { '3', '#' },//3 - { '4', '$' },//4 - { '5', '%' },//5 - { '6', '^' },//6 - { '7', '&' },//7 - { '8', '*' },//8 - { '9', '(' },//9 - { '0', ')' },//10 - { '-', '_' },//11 - { '=', '+' } //12 - }, - { - { 'q', 'Q' },//1 - { 'w', 'W' },//2 - { 'e', 'E' },//3 - { 'r', 'R' },//4 - { 't', 'T' },//5 - { 'y', 'Y' },//6 - { 'u', 'U' },//7 - { 'i', 'I' },//8 - { 'o', 'O' },//9 - { 'p', 'P' },//10 - { '[', '{' },//11 - { ']', '}' } //12 - }, - { - { 'a', 'A' },//1 - { 's', 'S' },//2 - { 'd', 'D' },//3 - { 'f', 'F' },//4 - { 'g', 'G' },//5 - { 'h', 'H' },//6 - { 'j', 'J' },//7 - { 'k', 'K' },//8 - { 'l', 'L' },//9 - { ';', ':' },//10 - { '"', '\'' },//11 - { '|', '\\' } //12 - }, - { - { '\\', '|' },//1 - { 'z', 'Z' },//2 - { 'x', 'X' },//3 - { 'c', 'C' },//4 - { 'v', 'V' },//5 - { 'b', 'B' },//6 - { 'n', 'N' },//7 - { 'm', 'M' },//8 - { ',', '<' },//9 - { '.', '>' },//10 - { '?', '/' },//11 - { '/', '/' } //12 - } - }; - int _x = tftWidth/12; - int _y = (tftHeight - 54)/4; - int _xo = _x/2-3; - - int i=0; - int j=-1; - bool redraw=true; - int cX =0; - int cY =0; - tft.fillScreen(bruceConfig.bgColor); - while(1) { - if(redraw) { - tft.setCursor(0,0); - tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.setTextSize(FM); - - //Draw the rectangles - if(y<0 || y2<0) { - tft.fillRect(0,1,tftWidth,22,bruceConfig.bgColor); - tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle - tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle - tft.drawRect(107,2,50,20,TFT_WHITE); // DEL Rectangle - tft.drawRect(159,2,74,20,TFT_WHITE); // SPACE Rectangle - tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle - - - if(x==0 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(7,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("OK", 18, 4); - - - if(x==1 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(55,2,50,20,TFT_WHITE); } - else if(caps) { tft.fillRect(55,2,50,20,TFT_DARKGREY); tft.setTextColor(TFT_WHITE, TFT_DARKGREY); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("CAP", 64, 4); - - - if(x==2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(107,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("DEL", 115, 4); - - if(x>2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(159,2,74,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("SPACE", 168, 4); - } - - tft.setTextSize(FP); - tft.setTextColor(TFT_WHITE, 0x5AAB); - tft.drawString(msg.substring(0,38), 3, 24); - - tft.setTextSize(FM); - - // reseta o quadrado do texto - if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,tftWidth-3,20,bruceConfig.bgColor); // mystring Rectangle - // escreve o texto - tft.setTextColor(TFT_WHITE); - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - tft.drawString(mytext.substring(0,38), 5, 34); - tft.drawString(mytext.substring(38,mytext.length()), 5, 42); - } - else { - tft.drawString(mytext, 5, 34); - } - } else { - tft.drawString(mytext, 5, 34); - } - //desenha o retangulo colorido - tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle - - - tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.setTextSize(FM); - - - for(i=0;i<4;i++) { - for(j=0;j<12;j++) { - //use last coordenate to paint only this letter - if(x2==j && y2==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,bruceConfig.bgColor);} - /* If selected, change font color and draw Rectangle*/ - if(x==j && y==i) { tft.setTextColor(bruceConfig.bgColor, ~bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,~bruceConfig.bgColor);} - - - /* Print the letters */ - if(!caps) tft.drawChar(keys[i][j][0], (j*_x+_xo), (i*_y+56)); - else tft.drawChar(keys[i][j][1], (j*_x+_xo), (i*_y+56)); - - /* Return colors to normal to print the other letters */ - if(x==j && y==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); } - } - } - // save actual key coordenate - x2=x; - y2=y; - redraw = false; - - } - - //cursor handler - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - cY=42; - cX=5+(mytext.length()-38)*LW; - } - else { - cY=34; - cX=5+mytext.length()*LW; - } - } else { - cY=34; - cX=5+mytext.length()*LW*2; - } - - int z=0; - - if(check(SelPress)) { - tft.setCursor(cX,cY); - if(caps) z=1; - else z=0; - if(x==0 && y==-1) break; - else if(x==1 && y==-1) caps=!caps; - else if(x==2 && y==-1 && mytext.length() > 0) { - DEL: - mytext.remove(mytext.length()-1); - int fS=FM; - if(mytext.length()>19) { tft.setTextSize(FP); fS=FP; } - else tft.setTextSize(FM); - tft.setCursor((cX-fS*LW),cY); - tft.setTextColor(bruceConfig.priColor,bruceConfig.bgColor); - tft.print(" "); - tft.setTextColor(TFT_WHITE, 0x5AAB); - tft.setCursor(cX-fS*LW,cY); - cX=tft.getCursorX(); - cY=tft.getCursorY(); - } - else if(x>2 && y==-1 && mytext.length()-1 && mytext.length()= 3 && y < 0) || x == 11) { y++; x = 0; } - else x++; - - if (y > 3) y = -1; - redraw = true; - } - /* UP Btn to move in Y axis (Downwards) */ - if(check(PrevPress)) { - #ifdef T_EMBED_1101 - if(digitalRead(BK_BTN) == BTN_ACT) { y--; } - else - #endif - if(x==0) { y--; x--; } - else x--; - - if(y<-1) { y=3; x=11; } - else if(y<0 && x<0) x=3; - else if (x<0) x=11; - - redraw = true; - } - - } - - //Resets screen when finished writing - tft.fillRect(0,0,tftWidth,tftHeight,bruceConfig.bgColor); - resetTftDisplay(); - - return mytext; -} - void powerOff() { #ifdef T_EMBED_1101 digitalWrite(PIN_POWER_ON,LOW); diff --git a/boards/m5stack-cardputer/interface.cpp b/boards/m5stack-cardputer/interface.cpp index 361ee9c93..8a417944f 100644 --- a/boards/m5stack-cardputer/interface.cpp +++ b/boards/m5stack-cardputer/interface.cpp @@ -67,15 +67,6 @@ void _setBrightness(uint8_t brightval) { ** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress **********************************************************************/ void InputHandler(void) { - checkPowerSaveTime(); - PrevPress = false; - NextPress = false; - SelPress = false; - AnyKeyPress = false; - EscPress = false; - NextPagePress = false; - PrevPagePress = false; - Keyboard.update(); if(Keyboard.isPressed() || digitalRead(0)==LOW) { if(!wakeUpScreen()) AnyKeyPress = true; @@ -111,252 +102,6 @@ void InputHandler(void) { } } - -/********************************************************************* -** Function: keyboard -** location: mykeyboard.cpp -** Starts keyboard to type data -**********************************************************************/ -String keyboard(String mytext, int maxSize, String msg) { - String _mytext = mytext; - - resetTftDisplay(); - bool caps=false; - int x=0; - int y=-1; - int x2=0; - int y2=0; - char keys[4][12][2] = { //4 lines, with 12 characteres, low and high caps - { - { '1', '!' },//1 - { '2', '@' },//2 - { '3', '#' },//3 - { '4', '$' },//4 - { '5', '%' },//5 - { '6', '^' },//6 - { '7', '&' },//7 - { '8', '*' },//8 - { '9', '(' },//9 - { '0', ')' },//10 - { '-', '_' },//11 - { '=', '+' } //12 - }, - { - { 'q', 'Q' },//1 - { 'w', 'W' },//2 - { 'e', 'E' },//3 - { 'r', 'R' },//4 - { 't', 'T' },//5 - { 'y', 'Y' },//6 - { 'u', 'U' },//7 - { 'i', 'I' },//8 - { 'o', 'O' },//9 - { 'p', 'P' },//10 - { '[', '{' },//11 - { ']', '}' } //12 - }, - { - { 'a', 'A' },//1 - { 's', 'S' },//2 - { 'd', 'D' },//3 - { 'f', 'F' },//4 - { 'g', 'G' },//5 - { 'h', 'H' },//6 - { 'j', 'J' },//7 - { 'k', 'K' },//8 - { 'l', 'L' },//9 - { ';', ':' },//10 - { '"', '\'' },//11 - { '|', '\\' } //12 - }, - { - { '\\', '|' },//1 - { 'z', 'Z' },//2 - { 'x', 'X' },//3 - { 'c', 'C' },//4 - { 'v', 'V' },//5 - { 'b', 'B' },//6 - { 'n', 'N' },//7 - { 'm', 'M' },//8 - { ',', '<' },//9 - { '.', '>' },//10 - { '?', '/' },//11 - { '/', '/' } //12 - } - }; - int _x = tftWidth/12; - int _y = (tftHeight - 54)/4; - int _xo = _x/2-3; - - int i=0; - int j=-1; - bool redraw=true; - - int cX =0; - int cY =0; - tft.fillScreen(bruceConfig.bgColor); - KeyStroke.Clear(); - while(1) { - if(redraw) { - tft.setCursor(0,0); - tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.setTextSize(FM); - - //Draw the rectangles - if(y<0) { - tft.fillRect(0,1,tftWidth,22,bruceConfig.bgColor); - tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle - tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle - tft.drawRect(107,2,50,20,TFT_WHITE); // DEL Rectangle - tft.drawRect(159,2,74,20,TFT_WHITE); // SPACE Rectangle - tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle - - - if(x==0 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(7,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("OK", 18, 4); - - - if(x==1 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(55,2,50,20,TFT_WHITE); } - else if(caps) { tft.fillRect(55,2,50,20,TFT_DARKGREY); tft.setTextColor(TFT_WHITE, TFT_DARKGREY); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("CAP", 64, 4); - - - if(x==2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(107,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("DEL", 115, 4); - - if(x>2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(159,2,74,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("SPACE", 168, 4); - } - - tft.setTextSize(FP); - tft.setTextColor(TFT_WHITE, 0x5AAB); - tft.drawString(msg.substring(0,38), 3, 24); - - tft.setTextSize(FM); - - // reseta o quadrado do texto - if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,tftWidth-3,20,bruceConfig.bgColor); // mystring Rectangle - // escreve o texto - tft.setTextColor(TFT_WHITE); - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - tft.drawString(mytext.substring(0,38), 5, 34); - tft.drawString(mytext.substring(38,mytext.length()), 5, 42); - } - else { - tft.drawString(mytext, 5, 34); - } - } else { - tft.drawString(mytext, 5, 34); - } - //desenha o retangulo colorido - tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle - - - tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.setTextSize(FM); - - for(i=0;i<4;i++) { - for(j=0;j<12;j++) { - //use last coordenate to paint only this letter - if(x2==j && y2==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,bruceConfig.bgColor);} - /* If selected, change font color and draw Rectangle*/ - if(x==j && y==i) { tft.setTextColor(bruceConfig.bgColor, ~bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,~bruceConfig.bgColor);} - - /* Print the letters */ - if(!caps) tft.drawChar(keys[i][j][0], (j*_x+_xo), (i*_y+56)); - else tft.drawChar(keys[i][j][1], (j*_x+_xo), (i*_y+56)); - - /* Return colors to normal to print the other letters */ - if(x==j && y==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); } - } - } - // save actual key coordenate - x2=x; - y2=y; - redraw = false; - #if defined(HAS_TOUCH) - TouchFooter(); - #endif - } - - //cursor handler - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - cY=42; - cX=5+(mytext.length()-38)*LW; - } - else { - cY=34; - cX=5+mytext.length()*LW; - } - } else { - cY=34; - cX=5+mytext.length()*LW*2; - } - - /* When Select a key in keyboard */ - if (KeyStroke.pressed) { - wakeUpScreen(); - tft.setCursor(cX,cY); - String keyStr = ""; - for (auto i : KeyStroke.word) { - if (keyStr != "") { - keyStr = keyStr + "+" + i; - } else { - keyStr += i; - } - } - - if(mytext.length() 0) { // delete 0x08 - // Handle backspace key - mytext.remove(mytext.length() - 1); - int fS=FM; - if(mytext.length()>19) { tft.setTextSize(FP); fS=FP; } - else tft.setTextSize(FM); - tft.setCursor((cX-fS*LW),cY); - tft.setTextColor(bruceConfig.priColor,bruceConfig.bgColor); - tft.print(" "); - tft.setTextColor(TFT_WHITE, 0x5AAB); - tft.setCursor(cX-fS*LW,cY); - cX=tft.getCursorX(); - cY=tft.getCursorY(); - if(mytext.length()==19) redraw = true; - if(mytext.length()==38) redraw = true; - } - if (KeyStroke.enter) { - break; - } - delay(200); - KeyStroke.Clear(); - } - - if(check(SelPress)) break; - } - - //Resets screen when finished writing - tft.fillRect(0,0,tftWidth,tftHeight,bruceConfig.bgColor); - resetTftDisplay(); - - return mytext; -} - - - /********************************************************************* ** Function: powerOff ** location: mykeyboard.cpp diff --git a/boards/m5stack-core/interface.cpp b/boards/m5stack-core/interface.cpp index d7548abcf..61b0cdad5 100644 --- a/boards/m5stack-core/interface.cpp +++ b/boards/m5stack-core/interface.cpp @@ -43,13 +43,6 @@ void _setBrightness(uint8_t brightval) { ** Handles the variables PrevPress, NextPress, check(SelPress), AnyKeyPress and EscPress **********************************************************************/ void InputHandler(void) { - checkPowerSaveTime(); - PrevPress = false; - NextPress = false; - SelPress = false; - AnyKeyPress = false; - EscPress = false; - if(M5.BtnA.isPressed() || M5.BtnB.isPressed() || M5.BtnC.isPressed()) { if(!wakeUpScreen()) AnyKeyPress = true; else goto END; @@ -71,265 +64,6 @@ void InputHandler(void) { } } - - -/********************************************************************* -** Function: keyboard -** location: mykeyboard.cpp -** Starts keyboard to type data -**********************************************************************/ -String keyboard(String mytext, int maxSize, String msg) { - String _mytext = mytext; - - resetTftDisplay(); - bool caps=false; - int x=0; - int y=-1; - int x2=0; - int y2=0; - char keys[4][12][2] = { //4 lines, with 12 characteres, low and high caps - { - { '1', '!' },//1 - { '2', '@' },//2 - { '3', '#' },//3 - { '4', '$' },//4 - { '5', '%' },//5 - { '6', '^' },//6 - { '7', '&' },//7 - { '8', '*' },//8 - { '9', '(' },//9 - { '0', ')' },//10 - { '-', '_' },//11 - { '=', '+' } //12 - }, - { - { 'q', 'Q' },//1 - { 'w', 'W' },//2 - { 'e', 'E' },//3 - { 'r', 'R' },//4 - { 't', 'T' },//5 - { 'y', 'Y' },//6 - { 'u', 'U' },//7 - { 'i', 'I' },//8 - { 'o', 'O' },//9 - { 'p', 'P' },//10 - { '[', '{' },//11 - { ']', '}' } //12 - }, - { - { 'a', 'A' },//1 - { 's', 'S' },//2 - { 'd', 'D' },//3 - { 'f', 'F' },//4 - { 'g', 'G' },//5 - { 'h', 'H' },//6 - { 'j', 'J' },//7 - { 'k', 'K' },//8 - { 'l', 'L' },//9 - { ';', ':' },//10 - { '"', '\'' },//11 - { '|', '\\' } //12 - }, - { - { '\\', '|' },//1 - { 'z', 'Z' },//2 - { 'x', 'X' },//3 - { 'c', 'C' },//4 - { 'v', 'V' },//5 - { 'b', 'B' },//6 - { 'n', 'N' },//7 - { 'm', 'M' },//8 - { ',', '<' },//9 - { '.', '>' },//10 - { '?', '/' },//11 - { '/', '/' } //12 - } - }; - int _x = tftWidth/12; - int _y = (tftHeight - 54)/4; - int _xo = _x/2-3; - - int i=0; - int j=-1; - bool redraw=true; - - int cX =0; - int cY =0; - tft.fillScreen(bruceConfig.bgColor); - while(1) { - if(redraw) { - tft.setCursor(0,0); - tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.setTextSize(FM); - - //Draw the rectangles - if(y<0 || y2<0) { - tft.fillRect(0,1,tftWidth,22,bruceConfig.bgColor); - tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle - tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle - tft.drawRect(107,2,50,20,TFT_WHITE); // DEL Rectangle - tft.drawRect(159,2,74,20,TFT_WHITE); // SPACE Rectangle - tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle - - - if(x==0 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(7,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("OK", 18, 4); - - - if(x==1 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(55,2,50,20,TFT_WHITE); } - else if(caps) { tft.fillRect(55,2,50,20,TFT_DARKGREY); tft.setTextColor(TFT_WHITE, TFT_DARKGREY); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("CAP", 64, 4); - - - if(x==2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(107,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("DEL", 115, 4); - - if(x>2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(159,2,74,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("SPACE", 168, 4); - } - - tft.setTextSize(FP); - tft.setTextColor(TFT_WHITE, 0x5AAB); - tft.drawString(msg.substring(0,38), 3, 24); - - tft.setTextSize(FM); - - // reseta o quadrado do texto - if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,tftWidth-3,20,bruceConfig.bgColor); // mystring Rectangle - // escreve o texto - tft.setTextColor(TFT_WHITE); - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - tft.drawString(mytext.substring(0,38), 5, 34); - tft.drawString(mytext.substring(38,mytext.length()), 5, 42); - } - else { - tft.drawString(mytext, 5, 34); - } - } else { - tft.drawString(mytext, 5, 34); - } - //desenha o retangulo colorido - tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle - - - tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.setTextSize(FM); - - - for(i=0;i<4;i++) { - for(j=0;j<12;j++) { - //use last coordenate to paint only this letter - if(x2==j && y2==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,bruceConfig.bgColor);} - /* If selected, change font color and draw Rectangle*/ - if(x==j && y==i) { tft.setTextColor(bruceConfig.bgColor, ~bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,~bruceConfig.bgColor);} - - - /* Print the letters */ - if(!caps) tft.drawChar(keys[i][j][0], (j*_x+_xo), (i*_y+56)); - else tft.drawChar(keys[i][j][1], (j*_x+_xo), (i*_y+56)); - - /* Return colors to normal to print the other letters */ - if(x==j && y==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); } - } - } - // save actual key coordenate - x2=x; - y2=y; - redraw = false; - #if defined(HAS_TOUCH) - TouchFooter(); - #endif - } - - //cursor handler - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - cY=42; - cX=5+(mytext.length()-38)*LW; - } - else { - cY=34; - cX=5+mytext.length()*LW; - } - } else { - cY=34; - cX=5+mytext.length()*LW*2; - } - - /* When Select a key in keyboard */ - - int z=0; - - if(check(SelPress)) { - tft.setCursor(cX,cY); - if(caps) z=1; - else z=0; - if(x==0 && y==-1) break; - else if(x==1 && y==-1) caps=!caps; - else if(x==2 && y==-1 && mytext.length() > 0) { - DEL: - mytext.remove(mytext.length()-1); - int fS=FM; - if(mytext.length()>19) { tft.setTextSize(FP); fS=FP; } - else tft.setTextSize(FM); - tft.setCursor((cX-fS*LW),cY); - tft.setTextColor(bruceConfig.priColor,bruceConfig.bgColor); - tft.print(" "); - tft.setTextColor(TFT_WHITE, 0x5AAB); - tft.setCursor(cX-fS*LW,cY); - cX=tft.getCursorX(); - cY=tft.getCursorY(); - } - else if(x>2 && y==-1 && mytext.length()-1 && mytext.length()3) x=0; - if(x>11) x=0; - else if (x<0) x=11; - redraw = true; - } - /* UP Btn to move in Y axis (Downwards) */ - if(check(PrevPress)) { - delay(200); - if(check(PrevPress)) { y--; delay(250); }// Long press - else y++; // short press - if(y>3) { y=-1; } - else if(y<-1) y=3; - redraw = true; - } - - } - - //Resets screen when finished writing - tft.fillRect(0,0,tftWidth,tftHeight,bruceConfig.bgColor); - resetTftDisplay(); - - return mytext; -} - - /********************************************************************* ** Function: powerOff ** location: mykeyboard.cpp diff --git a/boards/m5stack-core2/interface.cpp b/boards/m5stack-core2/interface.cpp index 618125313..b5abf1bae 100644 --- a/boards/m5stack-core2/interface.cpp +++ b/boards/m5stack-core2/interface.cpp @@ -1,5 +1,6 @@ #include "interface.h" #include "core/powerSave.h" +#include "core/utils.h" #include @@ -41,16 +42,8 @@ void _setBrightness(uint8_t brightval) { ** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress **********************************************************************/ void InputHandler(void) { - checkPowerSaveTime(); - PrevPress = false; - NextPress = false; - SelPress = false; - AnyKeyPress = false; - EscPress = false; - M5.update(); auto t = M5.Touch.getDetail(); - int terco=tftWidth/3; if (t.isPressed() || t.isHolding()) { if(bruceConfig.rotation==3) { @@ -67,15 +60,14 @@ void InputHandler(void) { t.x = t.y; t.y = (tftHeight+20)-tmp; } - - //if(t.y>(tftHeight)) { - if(!wakeUpScreen()) AnyKeyPress = true; - else goto END; - - if(t.x>terco*0 && t.xterco*1 && t.xterco*2 && t.xx <= x && x < (this->x + this->w) - && this->y <= y && y < (this->y + this->h); - } -}; - -static constexpr std::size_t box_count = 52; -static box_t box_list[box_count]; - -/********************************************************************* -** Function: keyboard -** location: mykeyboard.cpp -** Starts keyboard to type data -**********************************************************************/ -String keyboard(String mytext, int maxSize, String msg) { - String _mytext = mytext; - - resetTftDisplay(); - bool caps=false; - int x=0; - int y=-1; - int x2=0; - int y2=0; - char keys[4][12][2] = { //4 lines, with 12 characteres, low and high caps - { - { '1', '!' },//1 - { '2', '@' },//2 - { '3', '#' },//3 - { '4', '$' },//4 - { '5', '%' },//5 - { '6', '^' },//6 - { '7', '&' },//7 - { '8', '*' },//8 - { '9', '(' },//9 - { '0', ')' },//10 - { '-', '_' },//11 - { '=', '+' } //12 - }, - { - { 'q', 'Q' },//1 - { 'w', 'W' },//2 - { 'e', 'E' },//3 - { 'r', 'R' },//4 - { 't', 'T' },//5 - { 'y', 'Y' },//6 - { 'u', 'U' },//7 - { 'i', 'I' },//8 - { 'o', 'O' },//9 - { 'p', 'P' },//10 - { '[', '{' },//11 - { ']', '}' } //12 - }, - { - { 'a', 'A' },//1 - { 's', 'S' },//2 - { 'd', 'D' },//3 - { 'f', 'F' },//4 - { 'g', 'G' },//5 - { 'h', 'H' },//6 - { 'j', 'J' },//7 - { 'k', 'K' },//8 - { 'l', 'L' },//9 - { ';', ':' },//10 - { '"', '\'' },//11 - { '|', '\\' } //12 - }, - { - { '\\', '|' },//1 - { 'z', 'Z' },//2 - { 'x', 'X' },//3 - { 'c', 'C' },//4 - { 'v', 'V' },//5 - { 'b', 'B' },//6 - { 'n', 'N' },//7 - { 'm', 'M' },//8 - { ',', '<' },//9 - { '.', '>' },//10 - { '?', '/' },//11 - { '/', '/' } //12 - } - }; - int _x = tftWidth/12; - int _y = (tftHeight - 54)/4; - int _xo = _x/2-3; - - int k=0; - for(x2=0; x2<12;x2++) { - for(y2=0; y2<4; y2++) { - box_list[k].key=keys[y2][x2][0]; - box_list[k].key_sh=keys[y2][x2][1]; - box_list[k].color = ~bruceConfig.bgColor; - box_list[k].x=x2*_x; - box_list[k].y=y2*_y+54; - box_list[k].w=_x; - box_list[k].h=_y; - k++; - } - } - // OK - box_list[k].key=' '; - box_list[k].key_sh=' '; - box_list[k].color = ~bruceConfig.bgColor; - box_list[k].x=0; - box_list[k].y=0; - box_list[k].w=53; - box_list[k].h=22; - k++; - // CAP - box_list[k].key=' '; - box_list[k].key_sh=' '; - box_list[k].color = ~bruceConfig.bgColor; - box_list[k].x=55; - box_list[k].y=0; - box_list[k].w=50; - box_list[k].h=22; - k++; - // DEL - box_list[k].key=' '; - box_list[k].key_sh=' '; - box_list[k].color = ~bruceConfig.bgColor; - box_list[k].x=107; - box_list[k].y=0; - box_list[k].w=50; - box_list[k].h=22; - k++; - // SPACE - box_list[k].key=' '; - box_list[k].key_sh=' '; - box_list[k].color = ~bruceConfig.bgColor; - box_list[k].x=159; - box_list[k].y=0; - box_list[k].w=tftWidth-164; - box_list[k].h=22; - - k=0; - x2=0; - y2=0; - - - int i=0; - int j=-1; - bool redraw=true; - int cX =0; - int cY =0; - tft.fillScreen(bruceConfig.bgColor); - while(1) { - if(redraw) { - tft.setCursor(0,0); - tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.setTextSize(FM); - - //Draw the rectangles - if(y<0 || y2<0) { - tft.fillRect(0,1,tftWidth,22,bruceConfig.bgColor); - tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle - tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle - tft.drawRect(107,2,50,20,TFT_WHITE); // DEL Rectangle - tft.drawRect(159,2,74,20,TFT_WHITE); // SPACE Rectangle - tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle - - - if(x==0 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(7,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("OK", 18, 4); - - - if(x==1 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(55,2,50,20,TFT_WHITE); } - else if(caps) { tft.fillRect(55,2,50,20,TFT_DARKGREY); tft.setTextColor(TFT_WHITE, TFT_DARKGREY); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("CAP", 64, 4); - - - if(x==2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(107,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("DEL", 115, 4); - - if(x>2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(159,2,74,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("SPACE", 168, 4); - } - - tft.setTextSize(FP); - tft.setTextColor(TFT_WHITE, 0x5AAB); - tft.drawString(msg.substring(0,38), 3, 24); - - tft.setTextSize(FM); - - // reseta o quadrado do texto - if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,tftWidth-3,20,bruceConfig.bgColor); // mystring Rectangle - // escreve o texto - tft.setTextColor(TFT_WHITE); - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - tft.drawString(mytext.substring(0,38), 5, 34); - tft.drawString(mytext.substring(38,mytext.length()), 5, 42); - } - else { - tft.drawString(mytext, 5, 34); - } - } else { - tft.drawString(mytext, 5, 34); - } - //desenha o retangulo colorido - tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle - - - tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.setTextSize(FM); - - - for(i=0;i<4;i++) { - for(j=0;j<12;j++) { - //use last coordenate to paint only this letter - if(x2==j && y2==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,bruceConfig.bgColor);} - /* If selected, change font color and draw Rectangle*/ - if(x==j && y==i) { tft.setTextColor(bruceConfig.bgColor, ~bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,~bruceConfig.bgColor);} - - - /* Print the letters */ - if(!caps) tft.drawChar(keys[i][j][0], (j*_x+_xo), (i*_y+56)); - else tft.drawChar(keys[i][j][1], (j*_x+_xo), (i*_y+56)); - - /* Return colors to normal to print the other letters */ - if(x==j && y==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); } - } - } - // save actual key coordenate - x2=x; - y2=y; - redraw = false; - - TouchFooter(); - - } - - //cursor handler - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - cY=42; - cX=5+(mytext.length()-38)*LW; - } - else { - cY=34; - cX=5+mytext.length()*LW; - } - } else { - cY=34; - cX=5+mytext.length()*LW*2; - } - - /* When Select a key in keyboard */ - - int z=0; - - M5.update(); - auto t = M5.Touch.getDetail(); - if (t.isPressed() || t.isHolding()) - { - if(bruceConfig.rotation==0) { - int tmp=t.x; - t.x = tftWidth-t.y; - t.y = tmp; - } - if(bruceConfig.rotation==2) { - int tmp=t.x; - t.x = t.y; - t.y = (tftHeight+20)-tmp; - } - if(bruceConfig.rotation==3) { - t.x=tftWidth-t.x; - t.y=(tftHeight+20)-t.y; - } - if (box_list[48].contain(t.x, t.y)) { break; } // Ok - if (box_list[49].contain(t.x, t.y)) { caps=!caps; tft.fillRect(0,54,tftWidth,tftHeight-54,bruceConfig.bgColor); goto THIS_END; } // CAP - if (box_list[50].contain(t.x, t.y)) goto DEL; // DEL - if (box_list[51].contain(t.x, t.y)) { mytext += box_list[51].key; goto ADD; } // SPACE - for(k=0;k<48;k++){ - if (box_list[k].contain(t.x, t.y)) { - if(caps) mytext += box_list[k].key_sh; - else mytext += box_list[k].key; - } - } - wakeUpScreen(); - THIS_END: - redraw=true; - delay(200); - } - - if(false) { - tft.setCursor(cX,cY); - if(caps) z=1; - else z=0; - if(x==0 && y==-1) break; - else if(x==1 && y==-1) caps=!caps; - else if(x==2 && y==-1 && mytext.length() > 0) { - DEL: - mytext.remove(mytext.length()-1); - int fS=FM; - if(mytext.length()>19) { tft.setTextSize(FP); fS=FP; } - else tft.setTextSize(FM); - tft.setCursor((cX-fS*LW),cY); - tft.setTextColor(bruceConfig.priColor,bruceConfig.bgColor); - tft.print(" "); - tft.setTextColor(TFT_WHITE, 0x5AAB); - tft.setCursor(cX-fS*LW,cY); - cX=tft.getCursorX(); - cY=tft.getCursorY(); - } - else if(x>2 && y==-1 && mytext.length()-1 && mytext.length() @@ -41,16 +42,8 @@ void _setBrightness(uint8_t brightval) { ** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress **********************************************************************/ void InputHandler(void) { - checkPowerSaveTime(); - PrevPress = false; - NextPress = false; - SelPress = false; - AnyKeyPress = false; - EscPress = false; - M5.update(); auto t = M5.Touch.getDetail(); - int terco=tftWidth/3; if (t.isPressed() || t.isHolding()) { if(bruceConfig.rotation==3) { @@ -68,14 +61,14 @@ void InputHandler(void) { t.y = (tftHeight+20)-tmp; } - //if(t.y>(tftHeight)) { - if(!wakeUpScreen()) AnyKeyPress = true; - else goto END; + if(!wakeUpScreen()) AnyKeyPress = true; + else goto END; - if(t.x>terco*0 && t.xterco*1 && t.xterco*2 && t.xx <= x && x < (this->x + this->w) - && this->y <= y && y < (this->y + this->h); - } -}; - -static constexpr std::size_t box_count = 52; -static box_t box_list[box_count]; - -/********************************************************************* -** Function: keyboard -** location: mykeyboard.cpp -** Starts keyboard to type data -**********************************************************************/ -String keyboard(String mytext, int maxSize, String msg) { - String _mytext = mytext; - - resetTftDisplay(); - bool caps=false; - int x=0; - int y=-1; - int x2=0; - int y2=0; - char keys[4][12][2] = { //4 lines, with 12 characteres, low and high caps - { - { '1', '!' },//1 - { '2', '@' },//2 - { '3', '#' },//3 - { '4', '$' },//4 - { '5', '%' },//5 - { '6', '^' },//6 - { '7', '&' },//7 - { '8', '*' },//8 - { '9', '(' },//9 - { '0', ')' },//10 - { '-', '_' },//11 - { '=', '+' } //12 - }, - { - { 'q', 'Q' },//1 - { 'w', 'W' },//2 - { 'e', 'E' },//3 - { 'r', 'R' },//4 - { 't', 'T' },//5 - { 'y', 'Y' },//6 - { 'u', 'U' },//7 - { 'i', 'I' },//8 - { 'o', 'O' },//9 - { 'p', 'P' },//10 - { '[', '{' },//11 - { ']', '}' } //12 - }, - { - { 'a', 'A' },//1 - { 's', 'S' },//2 - { 'd', 'D' },//3 - { 'f', 'F' },//4 - { 'g', 'G' },//5 - { 'h', 'H' },//6 - { 'j', 'J' },//7 - { 'k', 'K' },//8 - { 'l', 'L' },//9 - { ';', ':' },//10 - { '"', '\'' },//11 - { '|', '\\' } //12 - }, - { - { '\\', '|' },//1 - { 'z', 'Z' },//2 - { 'x', 'X' },//3 - { 'c', 'C' },//4 - { 'v', 'V' },//5 - { 'b', 'B' },//6 - { 'n', 'N' },//7 - { 'm', 'M' },//8 - { ',', '<' },//9 - { '.', '>' },//10 - { '?', '/' },//11 - { '/', '/' } //12 - } - }; - int _x = tftWidth/12; - int _y = (tftHeight - 54)/4; - int _xo = _x/2-3; - - int k=0; - for(x2=0; x2<12;x2++) { - for(y2=0; y2<4; y2++) { - box_list[k].key=keys[y2][x2][0]; - box_list[k].key_sh=keys[y2][x2][1]; - box_list[k].color = ~bruceConfig.bgColor; - box_list[k].x=x2*_x; - box_list[k].y=y2*_y+54; - box_list[k].w=_x; - box_list[k].h=_y; - k++; - } - } - // OK - box_list[k].key=' '; - box_list[k].key_sh=' '; - box_list[k].color = ~bruceConfig.bgColor; - box_list[k].x=0; - box_list[k].y=0; - box_list[k].w=53; - box_list[k].h=22; - k++; - // CAP - box_list[k].key=' '; - box_list[k].key_sh=' '; - box_list[k].color = ~bruceConfig.bgColor; - box_list[k].x=55; - box_list[k].y=0; - box_list[k].w=50; - box_list[k].h=22; - k++; - // DEL - box_list[k].key=' '; - box_list[k].key_sh=' '; - box_list[k].color = ~bruceConfig.bgColor; - box_list[k].x=107; - box_list[k].y=0; - box_list[k].w=50; - box_list[k].h=22; - k++; - // SPACE - box_list[k].key=' '; - box_list[k].key_sh=' '; - box_list[k].color = ~bruceConfig.bgColor; - box_list[k].x=159; - box_list[k].y=0; - box_list[k].w=tftWidth-164; - box_list[k].h=22; - - k=0; - x2=0; - y2=0; - - - int i=0; - int j=-1; - bool redraw=true; - int cX =0; - int cY =0; - tft.fillScreen(bruceConfig.bgColor); - while(1) { - if(redraw) { - tft.setCursor(0,0); - tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.setTextSize(FM); - - //Draw the rectangles - if(y<0 || y2<0) { - tft.fillRect(0,1,tftWidth,22,bruceConfig.bgColor); - tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle - tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle - tft.drawRect(107,2,50,20,TFT_WHITE); // DEL Rectangle - tft.drawRect(159,2,74,20,TFT_WHITE); // SPACE Rectangle - tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle - - - if(x==0 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(7,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("OK", 18, 4); - - - if(x==1 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(55,2,50,20,TFT_WHITE); } - else if(caps) { tft.fillRect(55,2,50,20,TFT_DARKGREY); tft.setTextColor(TFT_WHITE, TFT_DARKGREY); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("CAP", 64, 4); - - - if(x==2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(107,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("DEL", 115, 4); - - if(x>2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(159,2,74,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("SPACE", 168, 4); - } - - tft.setTextSize(FP); - tft.setTextColor(TFT_WHITE, 0x5AAB); - tft.drawString(msg.substring(0,38), 3, 24); - - tft.setTextSize(FM); - - // reseta o quadrado do texto - if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,tftWidth-3,20,bruceConfig.bgColor); // mystring Rectangle - // escreve o texto - tft.setTextColor(TFT_WHITE); - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - tft.drawString(mytext.substring(0,38), 5, 34); - tft.drawString(mytext.substring(38,mytext.length()), 5, 42); - } - else { - tft.drawString(mytext, 5, 34); - } - } else { - tft.drawString(mytext, 5, 34); - } - //desenha o retangulo colorido - tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle - - - tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.setTextSize(FM); - - - for(i=0;i<4;i++) { - for(j=0;j<12;j++) { - //use last coordenate to paint only this letter - if(x2==j && y2==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,bruceConfig.bgColor);} - /* If selected, change font color and draw Rectangle*/ - if(x==j && y==i) { tft.setTextColor(bruceConfig.bgColor, ~bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,~bruceConfig.bgColor);} - - - /* Print the letters */ - if(!caps) tft.drawChar(keys[i][j][0], (j*_x+_xo), (i*_y+56)); - else tft.drawChar(keys[i][j][1], (j*_x+_xo), (i*_y+56)); - - /* Return colors to normal to print the other letters */ - if(x==j && y==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); } - } - } - // save actual key coordenate - x2=x; - y2=y; - redraw = false; - TouchFooter(); - } - - //cursor handler - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - cY=42; - cX=5+(mytext.length()-38)*LW; - } - else { - cY=34; - cX=5+mytext.length()*LW; - } - } else { - cY=34; - cX=5+mytext.length()*LW*2; - } - - int z=0; - - M5.update(); - auto t = M5.Touch.getDetail(); - if (t.isPressed() || t.isHolding()) - { - if(bruceConfig.rotation==0) { - int tmp=t.x; - t.x = tftWidth-t.y; - t.y = tmp; - } - if(bruceConfig.rotation==2) { - int tmp=t.x; - t.x = t.y; - t.y = (tftHeight+20)-tmp; - } - if(bruceConfig.rotation==3) { - t.x=tftWidth-t.x; - t.y=(tftHeight+20)-t.y; - } - if (box_list[48].contain(t.x, t.y)) { break; } // Ok - if (box_list[49].contain(t.x, t.y)) { caps=!caps; tft.fillRect(0,54,tftWidth,tftHeight-54,bruceConfig.bgColor); goto THIS_END; } // CAP - if (box_list[50].contain(t.x, t.y)) goto DEL; // DEL - if (box_list[51].contain(t.x, t.y)) { mytext += box_list[51].key; goto ADD; } // SPACE - for(k=0;k<48;k++){ - if (box_list[k].contain(t.x, t.y)) { - if(caps) mytext += box_list[k].key_sh; - else mytext += box_list[k].key; - } - } - wakeUpScreen(); - THIS_END: - redraw=true; - delay(200); - } - - if(false) { // action placeholder for gotos - tft.setCursor(cX,cY); - if(caps) z=1; - else z=0; - if(x==0 && y==-1) break; - else if(x==1 && y==-1) caps=!caps; - else if(x==2 && y==-1 && mytext.length() > 0) { - DEL: - mytext.remove(mytext.length()-1); - int fS=FM; - if(mytext.length()>19) { tft.setTextSize(FP); fS=FP; } - else tft.setTextSize(FM); - tft.setCursor((cX-fS*LW),cY); - tft.setTextColor(bruceConfig.priColor,bruceConfig.bgColor); - tft.print(" "); - tft.setTextColor(TFT_WHITE, 0x5AAB); - tft.setCursor(cX-fS*LW,cY); - cX=tft.getCursorX(); - cY=tft.getCursorY(); - } - else if(x>2 && y==-1 && mytext.length()-1 && mytext.length()' },//10 - { '?', '/' },//11 - { '/', '/' } //12 - } - }; - int _x = tftWidth/12; - int _y = (tftHeight - 54)/4; - int _xo = _x/2-3; - - int i=0; - int j=-1; - bool redraw=true; - int cX =0; - int cY =0; - tft.fillScreen(bruceConfig.bgColor); - while(1) { - if(redraw) { - tft.setCursor(0,0); - tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.setTextSize(FM); - - //Draw the rectangles - if(y<0 || y2<0) { - tft.fillRect(0,1,tftWidth,22,bruceConfig.bgColor); - tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle - tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle - tft.drawRect(107,2,50,20,TFT_WHITE); // DEL Rectangle - tft.drawRect(159,2,74,20,TFT_WHITE); // SPACE Rectangle - tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle - - - if(x==0 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(7,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("OK", 18, 4); - - - if(x==1 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(55,2,50,20,TFT_WHITE); } - else if(caps) { tft.fillRect(55,2,50,20,TFT_DARKGREY); tft.setTextColor(TFT_WHITE, TFT_DARKGREY); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("CAP", 64, 4); - - - if(x==2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(107,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("DEL", 115, 4); - - if(x>2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(159,2,74,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("SPACE", 168, 4); - } - - tft.setTextSize(FP); - tft.setTextColor(TFT_WHITE, 0x5AAB); - tft.drawString(msg.substring(0,38), 3, 24); - - tft.setTextSize(FM); - - // reseta o quadrado do texto - if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,tftWidth-3,20,bruceConfig.bgColor); // mystring Rectangle - // escreve o texto - tft.setTextColor(TFT_WHITE); - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - tft.drawString(mytext.substring(0,38), 5, 34); - tft.drawString(mytext.substring(38,mytext.length()), 5, 42); - } - else { - tft.drawString(mytext, 5, 34); - } - } else { - tft.drawString(mytext, 5, 34); - } - //desenha o retangulo colorido - tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle - - - tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.setTextSize(FM); - - - for(i=0;i<4;i++) { - for(j=0;j<12;j++) { - //use last coordenate to paint only this letter - if(x2==j && y2==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,bruceConfig.bgColor);} - /* If selected, change font color and draw Rectangle*/ - if(x==j && y==i) { tft.setTextColor(bruceConfig.bgColor, ~bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,~bruceConfig.bgColor);} - - - /* Print the letters */ - if(!caps) tft.drawChar(keys[i][j][0], (j*_x+_xo), (i*_y+56)); - else tft.drawChar(keys[i][j][1], (j*_x+_xo), (i*_y+56)); - - /* Return colors to normal to print the other letters */ - if(x==j && y==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); } - } - } - // save actual key coordenate - x2=x; - y2=y; - redraw = false; - #if defined(HAS_TOUCH) - TouchFooter(); - #endif - } - - //cursor handler - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - cY=42; - cX=5+(mytext.length()-38)*LW; - } - else { - cY=34; - cX=5+mytext.length()*LW; - } - } else { - cY=34; - cX=5+mytext.length()*LW*2; - } - - /* When Select a key in keyboard */ - int z=0; - - if(check(SelPress)) { - tft.setCursor(cX,cY); - if(caps) z=1; - else z=0; - if(x==0 && y==-1) break; - else if(x==1 && y==-1) caps=!caps; - else if(x==2 && y==-1 && mytext.length() > 0) { - DEL: - mytext.remove(mytext.length()-1); - int fS=FM; - if(mytext.length()>19) { tft.setTextSize(FP); fS=FP; } - else tft.setTextSize(FM); - tft.setCursor((cX-fS*LW),cY); - tft.setTextColor(bruceConfig.priColor,bruceConfig.bgColor); - tft.print(" "); - tft.setTextColor(TFT_WHITE, 0x5AAB); - tft.setCursor(cX-fS*LW,cY); - cX=tft.getCursorX(); - cY=tft.getCursorY(); - } - else if(x>2 && y==-1 && mytext.length()-1 && mytext.length()3) x=0; - if(x>11) x=0; - else if (x<0) x=11; - redraw = true; - } - /* UP Btn to move in Y axis (Downwards) */ - if(check(PrevPress)) { - delay(200); - if(check(PrevPress)) { y--; delay(250); }// Long press - else y++; // short press - if(y>3) { y=-1; } - else if(y<-1) y=3; - redraw = true; - } - } - - //Resets screen when finished writing - tft.fillRect(0,0,tftWidth,tftHeight,bruceConfig.bgColor); - resetTftDisplay(); - - return mytext; -} - void powerOff() { axp192.PowerOff(); } diff --git a/boards/m5stack-cplus2/interface.cpp b/boards/m5stack-cplus2/interface.cpp index 18110cce6..4aeb352eb 100644 --- a/boards/m5stack-cplus2/interface.cpp +++ b/boards/m5stack-cplus2/interface.cpp @@ -70,13 +70,6 @@ void _setBrightness(uint8_t brightval) { ** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress **********************************************************************/ void InputHandler(void) { - checkPowerSaveTime(); - PrevPress = false; - NextPress = false; - SelPress = false; - AnyKeyPress = false; - EscPress = false; - if(digitalRead(UP_BTN)==LOW || digitalRead(SEL_BTN)==LOW || digitalRead(DW_BTN)==LOW) { if(!wakeUpScreen()) AnyKeyPress = true; else goto END; @@ -98,258 +91,6 @@ void InputHandler(void) { } } -/********************************************************************* -** Function: keyboard -** location: mykeyboard.cpp -** Starts keyboard to type data -**********************************************************************/ -String keyboard(String mytext, int maxSize, String msg) { - String _mytext = mytext; - resetTftDisplay(); - bool caps=false; - int x=0; - int y=-1; - int x2=0; - int y2=0; - char keys[4][12][2] = { //4 lines, with 12 characteres, low and high caps - { - { '1', '!' },//1 - { '2', '@' },//2 - { '3', '#' },//3 - { '4', '$' },//4 - { '5', '%' },//5 - { '6', '^' },//6 - { '7', '&' },//7 - { '8', '*' },//8 - { '9', '(' },//9 - { '0', ')' },//10 - { '-', '_' },//11 - { '=', '+' } //12 - }, - { - { 'q', 'Q' },//1 - { 'w', 'W' },//2 - { 'e', 'E' },//3 - { 'r', 'R' },//4 - { 't', 'T' },//5 - { 'y', 'Y' },//6 - { 'u', 'U' },//7 - { 'i', 'I' },//8 - { 'o', 'O' },//9 - { 'p', 'P' },//10 - { '[', '{' },//11 - { ']', '}' } //12 - }, - { - { 'a', 'A' },//1 - { 's', 'S' },//2 - { 'd', 'D' },//3 - { 'f', 'F' },//4 - { 'g', 'G' },//5 - { 'h', 'H' },//6 - { 'j', 'J' },//7 - { 'k', 'K' },//8 - { 'l', 'L' },//9 - { ';', ':' },//10 - { '"', '\'' },//11 - { '|', '\\' } //12 - }, - { - { '\\', '|' },//1 - { 'z', 'Z' },//2 - { 'x', 'X' },//3 - { 'c', 'C' },//4 - { 'v', 'V' },//5 - { 'b', 'B' },//6 - { 'n', 'N' },//7 - { 'm', 'M' },//8 - { ',', '<' },//9 - { '.', '>' },//10 - { '?', '/' },//11 - { '/', '/' } //12 - } - }; - int _x = tftWidth/12; - int _y = (tftHeight - 54)/4; - int _xo = _x/2-3; - - int i=0; - int j=-1; - bool redraw=true; - int cX =0; - int cY =0; - tft.fillScreen(bruceConfig.bgColor); - while(1) { - if(redraw) { - tft.setCursor(0,0); - tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.setTextSize(FM); - - //Draw the rectangles - if(y<0 || y2<0) { - tft.fillRect(0,1,tftWidth,22,bruceConfig.bgColor); - tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle - tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle - tft.drawRect(107,2,50,20,TFT_WHITE); // DEL Rectangle - tft.drawRect(159,2,74,20,TFT_WHITE); // SPACE Rectangle - tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle - - - if(x==0 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(7,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("OK", 18, 4); - - - if(x==1 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(55,2,50,20,TFT_WHITE); } - else if(caps) { tft.fillRect(55,2,50,20,TFT_DARKGREY); tft.setTextColor(TFT_WHITE, TFT_DARKGREY); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("CAP", 64, 4); - - - if(x==2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(107,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("DEL", 115, 4); - - if(x>2 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(159,2,74,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.drawString("SPACE", 168, 4); - } - - tft.setTextSize(FP); - tft.setTextColor(TFT_WHITE, 0x5AAB); - tft.drawString(msg.substring(0,38), 3, 24); - - tft.setTextSize(FM); - - // reseta o quadrado do texto - if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,tftWidth-3,20,bruceConfig.bgColor); // mystring Rectangle - // escreve o texto - tft.setTextColor(TFT_WHITE); - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - tft.drawString(mytext.substring(0,38), 5, 34); - tft.drawString(mytext.substring(38,mytext.length()), 5, 42); - } - else { - tft.drawString(mytext, 5, 34); - } - } else { - tft.drawString(mytext, 5, 34); - } - //desenha o retangulo colorido - tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle - - - tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); - tft.setTextSize(FM); - - - for(i=0;i<4;i++) { - for(j=0;j<12;j++) { - //use last coordenate to paint only this letter - if(x2==j && y2==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,bruceConfig.bgColor);} - /* If selected, change font color and draw Rectangle*/ - if(x==j && y==i) { tft.setTextColor(bruceConfig.bgColor, ~bruceConfig.bgColor); tft.fillRect(j*_x,i*_y+54,_x,_y,~bruceConfig.bgColor);} - - - /* Print the letters */ - if(!caps) tft.drawChar(keys[i][j][0], (j*_x+_xo), (i*_y+56)); - else tft.drawChar(keys[i][j][1], (j*_x+_xo), (i*_y+56)); - - /* Return colors to normal to print the other letters */ - if(x==j && y==i) { tft.setTextColor(~bruceConfig.bgColor, bruceConfig.bgColor); } - } - } - // save actual key coordenate - x2=x; - y2=y; - redraw = false; - #if defined(HAS_TOUCH) - TouchFooter(); - #endif - } - - //cursor handler - if(mytext.length()>19) { - tft.setTextSize(FP); - if(mytext.length()>38) { - cY=42; - cX=5+(mytext.length()-38)*LW; - } - else { - cY=34; - cX=5+mytext.length()*LW; - } - } else { - cY=34; - cX=5+mytext.length()*LW*2; - } - - /* When Select a key in keyboard */ - int z=0; - - if(check(SelPress)) { - tft.setCursor(cX,cY); - if(caps) z=1; - else z=0; - if(x==0 && y==-1) break; - else if(x==1 && y==-1) caps=!caps; - else if(x==2 && y==-1 && mytext.length() > 0) { - DEL: - mytext.remove(mytext.length()-1); - int fS=FM; - if(mytext.length()>19) { tft.setTextSize(FP); fS=FP; } - else tft.setTextSize(FM); - tft.setCursor((cX-fS*LW),cY); - tft.setTextColor(bruceConfig.priColor,bruceConfig.bgColor); - tft.print(" "); - tft.setTextColor(TFT_WHITE, 0x5AAB); - tft.setCursor(cX-fS*LW,cY); - cX=tft.getCursorX(); - cY=tft.getCursorY(); - } - else if(x>2 && y==-1 && mytext.length()-1 && mytext.length()3) x=0; - if(x>11) x=0; - else if (x<0) x=11; - redraw = true; - } - /* UP Btn to move in Y axis (Downwards) */ - if(check(PrevPress)) { - delay(200); - if(check(PrevPress)) { y--; delay(250); }// Long press - else y++; // short press - if(y>3) { y=-1; } - else if(y<-1) y=3; - redraw = true; - } - } - - //Resets screen when finished writing - tft.fillRect(0,0,tftWidth,tftHeight,bruceConfig.bgColor); - resetTftDisplay(); - - return mytext; -} - /********************************************************************* ** Function: powerOff diff --git a/boards/pinouts/lilygo-t-embed-cc1101.h b/boards/pinouts/lilygo-t-embed-cc1101.h index d09eba9d7..d93832858 100644 --- a/boards/pinouts/lilygo-t-embed-cc1101.h +++ b/boards/pinouts/lilygo-t-embed-cc1101.h @@ -106,6 +106,7 @@ static const uint8_t RX = SERIAL_RX; #define BQ27220_I2C_SCL GROVE_SCL // Encoder +#define HAS_ENCODER #define ENCODER_INA 4 #define ENCODER_INB 5 #define ENCODER_KEY 0 diff --git a/boards/pinouts/lilygo-t-embed.h b/boards/pinouts/lilygo-t-embed.h index f8f75775c..c8adc840d 100644 --- a/boards/pinouts/lilygo-t-embed.h +++ b/boards/pinouts/lilygo-t-embed.h @@ -95,6 +95,7 @@ static const uint8_t SCL = GROVE_SCL; #define BAT_PIN 4 // Encoder +#define HAS_ENCODER #define ENCODER_INA 2 #define ENCODER_INB 1 #define ENCODER_KEY 0 diff --git a/boards/pinouts/m5stack-core.h b/boards/pinouts/m5stack-core.h index e2161ed9a..8c77ed6f8 100644 --- a/boards/pinouts/m5stack-core.h +++ b/boards/pinouts/m5stack-core.h @@ -3,6 +3,8 @@ #include +#define HAS_3_BUTTONS + static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/boards/pinouts/m5stack-cplus1_1.h b/boards/pinouts/m5stack-cplus1_1.h index 350924164..d35bf5054 100644 --- a/boards/pinouts/m5stack-cplus1_1.h +++ b/boards/pinouts/m5stack-cplus1_1.h @@ -3,6 +3,8 @@ #include +#define HAS_3_BUTTONS + static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/boards/pinouts/m5stack-cplus2.h b/boards/pinouts/m5stack-cplus2.h index 91808918d..7717387e0 100644 --- a/boards/pinouts/m5stack-cplus2.h +++ b/boards/pinouts/m5stack-cplus2.h @@ -3,6 +3,8 @@ #include +#define HAS_3_BUTTONS + static const uint8_t TX = 1; static const uint8_t RX = 3; diff --git a/boards/pinouts/smoochiee-board.h b/boards/pinouts/smoochiee-board.h index c950463ad..02382a26b 100644 --- a/boards/pinouts/smoochiee-board.h +++ b/boards/pinouts/smoochiee-board.h @@ -53,6 +53,7 @@ static const uint8_t ADC2 = 8; #define USB_as_HID 1 #define BTN_ALIAS '"OK"' +#define HAS_5_BUTTONS #define SEL_BTN 0 #define UP_BTN 40 #define DW_BTN 41 diff --git a/boards/smoochiee-board/interface.cpp b/boards/smoochiee-board/interface.cpp index 83714e3ae..d51053450 100644 --- a/boards/smoochiee-board/interface.cpp +++ b/boards/smoochiee-board/interface.cpp @@ -99,6 +99,8 @@ void InputHandler(void) { SelPress = false; AnyKeyPress = false; EscPress = false; + UpPress = false; + DownPress = false; if(digitalRead(SEL_BTN)==BTN_ACT || digitalRead(UP_BTN)==BTN_ACT || digitalRead(DW_BTN)==BTN_ACT || digitalRead(R_BTN)==BTN_ACT || digitalRead(L_BTN)==BTN_ACT) { if(!wakeUpScreen()) AnyKeyPress = true; @@ -107,12 +109,16 @@ void InputHandler(void) { if(digitalRead(L_BTN)==BTN_ACT) { PrevPress = true; } - if(digitalRead(DW_BTN)==BTN_ACT) { - EscPress = true; - } if(digitalRead(R_BTN)==BTN_ACT) { NextPress = true; } + if(digitalRead(UP_BTN)==BTN_ACT) { + UpPress = true; + } + if(digitalRead(DW_BTN)==BTN_ACT) { + DownPress = true; + EscPress = true; + } if(digitalRead(SEL_BTN)==BTN_ACT) { SelPress = true; } diff --git a/include/globals.h b/include/globals.h index 3aa41e8ff..e2724a06c 100644 --- a/include/globals.h +++ b/include/globals.h @@ -80,6 +80,47 @@ struct Option { : label(lbl), operation(op), selected(sel) {} }; +struct keyStroke { // DO NOT CHANGE IT!!!!! + bool pressed=false; + bool exit_key=false; + bool fn = false; + bool del = false; + bool enter = false; + uint8_t modifiers = 0; + std::vector word; + std::vector hid_keys; + std::vector modifier_keys; + + + // Clear function + void Clear() { + pressed = false; + exit_key = false; + fn = false; + del = false; + enter = false; + modifiers = 0; + word.clear(); + hid_keys.clear(); + modifier_keys.clear(); + } +}; + +struct TouchPoint { + bool pressed = false; + uint16_t x; + uint16_t y; + + // clear touch to better handle tasks + void Clear(void) { + pressed = false; + x=0; + y=0; + } +}; + +extern TouchPoint touchPoint; +extern keyStroke KeyStroke; extern std::vector