Skip to content

Commit

Permalink
Task control and var handling
Browse files Browse the repository at this point in the history
Added a function to control the Input variables, now they "rearm" after read.

Fixed Restarts and some other changes

Fixed Keyboard to send Delete key and modifiers pr3y#594
  • Loading branch information
bmorcelli authored and whywilson committed Jan 4, 2025
1 parent 8030e7a commit c2cb4eb
Show file tree
Hide file tree
Showing 62 changed files with 535 additions and 521 deletions.
22 changes: 11 additions & 11 deletions boards/CYD-2432S028/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ static box_t box_list[box_count];

/*********************************************************************
** Function: InputHandler
** Handles the variables checkPrevPress, checkNextPress, checkSelPress, checkAnyKeyPress and checkEscPress
** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress
**********************************************************************/
void InputHandler(void) {
checkPowerSaveTime();
checkPrevPress = false;
checkNextPress = false;
checkSelPress = false;
checkAnyKeyPress = false;
checkEscPress = false;
PrevPress = false;
NextPress = false;
SelPress = false;
AnyKeyPress = false;
EscPress = false;

int terco=tftWidth/3;
if (touch.touched()) { //touch.tirqTouched() &&
Expand All @@ -139,16 +139,16 @@ void InputHandler(void) {
}

//if(t.y>(tftHeight)) {
if(!wakeUpScreen()) checkAnyKeyPress = true;
if(!wakeUpScreen()) AnyKeyPress = true;
else goto END;

if(t.x>terco*0 && t.x<terco*(1+0)) checkPrevPress = true;
if(t.x>terco*1 && t.x<terco*(1+1)) { checkSelPress = true; checkEscPress = true; }
if(t.x>terco*2 && t.x<terco*(1+2)) checkNextPress = true;
if(t.x>terco*0 && t.x<terco*(1+0)) PrevPress = true;
if(t.x>terco*1 && t.x<terco*(1+1)) { SelPress = true; EscPress = true; }
if(t.x>terco*2 && t.x<terco*(1+2)) NextPress = true;
//}
}
END:
if(checkAnyKeyPress) {
if(AnyKeyPress) {
long tmp=millis();
while((millis()-tmp)<200 && (touch.touched()));
}
Expand Down
2 changes: 1 addition & 1 deletion boards/ESP-General/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void _setBrightness(uint8_t brightval) { }

/*********************************************************************
** Function: InputHandler
** Handles the variables checkPrevPress, checkNextPress, checkSelPress, checkAnyKeyPress and checkEscPress
** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress
**********************************************************************/
void InputHandler(void) { }

Expand Down
24 changes: 12 additions & 12 deletions boards/_New-Device-Model/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,34 @@ void _setBrightness(uint8_t brightval) { }

/*********************************************************************
** Function: InputHandler
** Handles the variables checkPrevPress, checkNextPress, checkSelPress, checkAnyKeyPress and checkEscPress
** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress
**********************************************************************/
void InputHandler(void) {
checkPowerSaveTime();
checkPrevPress = false;
checkNextPress = false;
checkSelPress = false;
checkAnyKeyPress = false;
checkEscPress = false;
PrevPress = false;
NextPress = false;
SelPress = false;
AnyKeyPress = false;
EscPress = false;

if(false /*Conditions fot all inputs*/) {
if(!wakeUpScreen()) checkAnyKeyPress = true;
if(!wakeUpScreen()) AnyKeyPress = true;
else goto END;
}
if(false /*Conditions for previous btn*/) {
checkPrevPress = true;
PrevPress = true;
}
if(false /*Conditions for Next btn*/) {
checkNextPress = true;
NextPress = true;
}
if(false /*Conditions for Esc btn*/) {
checkEscPress = true;
EscPress = true;
}
if(false /*Conditions for Select btn*/) {
checkSelPress = true;
SelPress = true;
}
END:
if(checkAnyKeyPress) {
if(AnyKeyPress) {
long tmp=millis();
while((millis()-tmp)<200 && false /*Conditions fot all inputs*/);
}
Expand Down
101 changes: 41 additions & 60 deletions boards/lilygo-t-deck/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ void _setBrightness(uint8_t brightval) {

/*********************************************************************
** Function: InputHandler
** Handles the variables checkPrevPress, checkNextPress, checkSelPress, checkAnyKeyPress and checkEscPress
** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress
**********************************************************************/
void InputHandler(void) {
checkPowerSaveTime();
checkPrevPress = false;
checkNextPress = false;
checkSelPress = false;
checkAnyKeyPress = false;
checkEscPress = false;
PrevPress = false;
NextPress = false;
SelPress = false;
AnyKeyPress = false;
EscPress = false;


char keyValue = 0;
Expand All @@ -139,27 +139,38 @@ void InputHandler(void) {
if(xx==1 && yy==1) {
ISR_rst();
} else {
if(!wakeUpScreen()) checkAnyKeyPress = true;
if(!wakeUpScreen()) AnyKeyPress = true;
else goto END;
}
delay(50);
// Print "bot - xx - yy", 1 is normal value for xx and yy 0 and 2 means movement on the axis
//Serial.print(bot); Serial.print("-"); Serial.print(xx); Serial.print("-"); Serial.println(yy);
if (xx < 1 || yy < 1) { ISR_rst(); checkPrevPress = true; } // left , Up
else if (xx > 1 || yy > 1 ) { ISR_rst(); checkNextPress = true; } // right, Down
if (xx < 1 || yy < 1) { ISR_rst(); PrevPress = true; } // left , Up
else if (xx > 1 || yy > 1 ) { ISR_rst(); NextPress = true; } // right, Down
}

Wire.requestFrom(LILYGO_KB_SLAVE_ADDRESS, 1);
while (Wire.available() > 0) {
keyValue = Wire.read();
}
if(digitalRead(SEL_BTN)==BTN_ACT || keyValue==0x0D) {
if(!wakeUpScreen()) { checkSelPress = true; checkAnyKeyPress = true; }
if (keyValue!=(char)0x00) {
KeyStroke.Clear();
KeyStroke.hid_keys.push_back(keyValue);
if(keyValue==' ') KeyStroke.exit_key=true; // key pressed to try to exit
if (keyValue==(char)0x08) KeyStroke.del=true;
if (keyValue==(char)0x0D) KeyStroke.enter=true;
if (digitalRead(SEL_BTN)==BTN_ACT) KeyStroke.fn=true;
KeyStroke.word.push_back(keyValue);
KeyStroke.pressed=true;
} else KeyStroke.pressed=false;

if(digitalRead(SEL_BTN)==BTN_ACT || KeyStroke.enter) {
if(!wakeUpScreen()) { SelPress = true; AnyKeyPress = true; }
else goto END;
}
if(keyValue==0x08) { checkEscPress = true; checkAnyKeyPress = true; }
if(keyValue==0x08) { EscPress = true; AnyKeyPress = true; }
END:
if(checkAnyKeyPress) {
if(AnyKeyPress) {
long tmp=millis();
while((millis()-tmp)<200 && (digitalRead(SEL_BTN)==BTN_ACT));
}
Expand Down Expand Up @@ -302,6 +313,7 @@ String keyboard(String mytext, int maxSize, String msg) {
int cX =0;
int cY =0;
tft.fillScreen(bruceConfig.bgColor);
KeyStroke.Clear();
while(1) {
if(redraw) {
tft.setCursor(0,0);
Expand Down Expand Up @@ -409,29 +421,27 @@ String keyboard(String mytext, int maxSize, String msg) {
cX=5+mytext.length()*LW*2;
}

/* When Select a key in keyboard */
char keyValue = 0;
Wire.requestFrom(LILYGO_KB_SLAVE_ADDRESS, 1);
while (Wire.available() > 0) {
keyValue = Wire.read();
}
if (keyValue != (char)0x00) {
Serial.print("keyValue : ");
Serial.print(keyValue);
Serial.print(" -> Hex 0x");
Serial.println(keyValue,HEX);
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 && keyValue!=0x08 && keyValue!=0x0D) {
mytext += keyValue;
if(mytext.length()!=20 && mytext.length()!=20) tft.print(keyValue);
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 (keyValue==0x08 && mytext.length() > 0) { // delete 0x08
if (KeyStroke.del && mytext.length() > 0) { // delete 0x08
// Handle backspace key
mytext.remove(mytext.length() - 1);
int fS=FM;
Expand All @@ -447,11 +457,12 @@ String keyboard(String mytext, int maxSize, String msg) {
if(mytext.length()==19) redraw = true;
if(mytext.length()==38) redraw = true;
}
if (keyValue==0x0D) {
if (KeyStroke.enter) {
break;
}
KeyStroke.Clear();
}
if(checkSelPress) break;
if(check(SelPress)) break;

delay(5);

Expand Down Expand Up @@ -481,36 +492,6 @@ void powerOff() { }
**********************************************************************/
void checkReboot() { }


/*********************************************************************
** Function: _checkKeyPress
** location: mykeyboard.cpp
** returns the key from the keyboard
** ISSUES: Usb-HID and BLE-HID need HID Mapping
**********************************************************************/
keyStroke _getKeyPress() {
keyStroke key;
char keyValue = 0;
Wire.requestFrom(LILYGO_KB_SLAVE_ADDRESS, 1);
while (Wire.available() > 0) {
keyValue = Wire.read();
}
if (keyValue!=(char)0x00) {
wakeUpScreen();
//for (auto i : status.hid_keys) key.hid_keys.push_back(i);
key.hid_keys.push_back(keyValue);
if(keyValue==' ') key.exit_key=true; // key pressed to try to exit
//for (auto i : status.modifier_keys) key.modifier_keys.push_back(i);
if (keyValue==(char)0x08) key.del=true;
if (keyValue==(char)0x0D) key.enter=true;
if (digitalRead(SEL_BTN)==BTN_ACT) key.fn=true;
key.word.push_back(keyValue);
key.pressed=true;
} else key.pressed=false;

return key;
} // must return something that the keyboards won´t recognize by default

/*********************************************************************
** Function: _checkNextPagePress
** location: mykeyboard.cpp
Expand Down
32 changes: 16 additions & 16 deletions boards/lilygo-t-embed-cc1101/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,43 +138,43 @@ IRAM_ATTR void checkPosition() {

/*********************************************************************
** Function: InputHandler
** Handles the variables checkPrevPress, checkNextPress, checkSelPress, checkAnyKeyPress and checkEscPress
** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress
**********************************************************************/
void InputHandler(void) {
checkPowerSaveTime();
checkPrevPress = false;
checkNextPress = false;
checkSelPress = false;
checkAnyKeyPress = false;
checkEscPress = false;
PrevPress = false;
NextPress = false;
SelPress = false;
AnyKeyPress = false;
EscPress = false;
_last_dir = (int)encoder->getDirection();
_last_pos = _new_pos;
_new_pos = encoder->getPosition();
if(_last_dir!=0 || digitalRead(SEL_BTN)==BTN_ACT) {
if(!wakeUpScreen()) checkAnyKeyPress = true;
if(!wakeUpScreen()) AnyKeyPress = true;
else goto END;
}
if(_last_dir>0) {
_last_dir=0;
checkPrevPress = true;
PrevPress = true;
}
if(_last_dir<0) {
_last_dir=0;
checkNextPress = true;
NextPress = true;
}
if(digitalRead(SEL_BTN)==BTN_ACT) {
_last_dir=0;
checkSelPress = true;
SelPress = true;
}

#ifdef T_EMBED_1101
if(digitalRead(BK_BTN)==BTN_ACT) {
checkAnyKeyPress = true;
checkEscPress = true;
AnyKeyPress = true;
EscPress = true;
}
#endif
END:
if(checkAnyKeyPress) {
if(AnyKeyPress) {
long tmp=millis();
while((millis()-tmp)<200 && (digitalRead(SEL_BTN)==BTN_ACT));
}
Expand Down Expand Up @@ -365,7 +365,7 @@ String keyboard(String mytext, int maxSize, String msg) {

int z=0;

if(checkSelPress) {
if(check(SelPress)) {
tft.setCursor(cX,cY);
if(caps) z=1;
else z=0;
Expand Down Expand Up @@ -398,7 +398,7 @@ String keyboard(String mytext, int maxSize, String msg) {
}

/* Down Btn to move in X axis (to the right) */
if(checkNextPress)
if(check(NextPress))
{
#ifdef T_EMBED_1101
if(digitalRead(BK_BTN) == BTN_ACT) { y++; }
Expand All @@ -411,7 +411,7 @@ String keyboard(String mytext, int maxSize, String msg) {
redraw = true;
}
/* UP Btn to move in Y axis (Downwards) */
if(checkPrevPress) {
if(check(PrevPress)) {
#ifdef T_EMBED_1101
if(digitalRead(BK_BTN) == BTN_ACT) { y--; }
else
Expand Down
Loading

0 comments on commit c2cb4eb

Please sign in to comment.