Skip to content

Commit

Permalink
Interface Updates
Browse files Browse the repository at this point in the history
Removed keyboard function from interface.cpp, all devices are now usinf the same function, easy to maintain

Remapped TouchArea for touchscreen devices.. now it is possible to use the touch area to escape some functions, go up/down/left/right and selec
  • Loading branch information
bmorcelli committed Jan 3, 2025
1 parent 754b464 commit dca5b16
Show file tree
Hide file tree
Showing 26 changed files with 387 additions and 2,873 deletions.
374 changes: 7 additions & 367 deletions boards/CYD-2432S028/interface.cpp

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions boards/ESP-General/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ void _setBrightness(uint8_t brightval) { }
**********************************************************************/
void InputHandler(void) { }

/*********************************************************************
** Function: keyboard
** location: mykeyboard.cpp
** Starts keyboard to type data
**********************************************************************/
String keyboard(String mytext, int maxSize, String msg) { }


/*********************************************************************
** Function: powerOff
** location: mykeyboard.cpp
Expand Down
308 changes: 0 additions & 308 deletions boards/lilygo-t-deck/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,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;


char keyValue = 0;
// 0 - UP
// 1 - Down
Expand Down Expand Up @@ -176,306 +168,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;

#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()<maxSize && !KeyStroke.enter && !KeyStroke.del) {
mytext += keyStr;
if(mytext.length()!=20 && mytext.length()!=20) tft.print(keyStr.c_str());
cX=tft.getCursorX();
cY=tft.getCursorY();
if(mytext.length()==20) redraw = true;
if(mytext.length()==39) redraw = true;
}
if (KeyStroke.del && 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
Expand Down
Loading

0 comments on commit dca5b16

Please sign in to comment.