Merge pull request #1054 from gemarcano/long_press_serial

Cleanups for SERIAL_MONITOR interface, and support "long press" with SERIAL_MONITOR
This commit is contained in:
sanni 2024-12-23 18:57:19 +01:00 committed by GitHub
commit 560aea88cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -267,11 +267,6 @@ boolean holdEventPast2 = false; // whether or not the hold event happened a
boolean longholdEventPast2 = false; // whether or not the long hold event happened already boolean longholdEventPast2 = false; // whether or not the long hold event happened already
#endif #endif
#ifdef ENABLE_SERIAL
// For incoming serial data
int incomingByte;
#endif
// Variables for the menu // Variables for the menu
int choice = 0; int choice = 0;
// Temporary array that holds the menu option read out of progmem // Temporary array that holds the menu option read out of progmem
@ -2954,11 +2949,11 @@ byte questionBox_Serial(const __FlashStringHelper* question __attribute__((unuse
while (Serial.available() == 0) { while (Serial.available() == 0) {
} }
// Read the incoming byte: // Read the incoming byte (can't be -1, as there must be data available)
incomingByte = Serial.read() - 48; char incomingByte = Serial.read();
// Page up (u) // Page up (u)
if (incomingByte == 69) { if (incomingByte == 'u') {
if (currPage > 1) { if (currPage > 1) {
lastPage = currPage; lastPage = currPage;
currPage--; currPage--;
@ -2968,7 +2963,7 @@ byte questionBox_Serial(const __FlashStringHelper* question __attribute__((unuse
} }
// Page down (d) // Page down (d)
else if (incomingByte == 52) { else if (incomingByte == 'd') {
if (numPages > currPage) { if (numPages > currPage) {
lastPage = currPage; lastPage = currPage;
currPage++; currPage++;
@ -2976,14 +2971,14 @@ byte questionBox_Serial(const __FlashStringHelper* question __attribute__((unuse
} }
// Execute choice // Execute choice
else if ((incomingByte >= 0) && (incomingByte < 7)) { else if ((incomingByte >= '0') && (incomingByte < '7')) {
numPages = 0; numPages = 0;
} }
// Print the received byte for validation e.g. in case of a different keyboard mapping // Print the received byte for validation e.g. in case of a different keyboard mapping
//Serial.println(incomingByte); //Serial.println(incomingByte);
//Serial.println(FS(FSTRING_EMPTY)); //Serial.println(FS(FSTRING_EMPTY));
return incomingByte; return incomingByte - '0';
} }
#endif #endif
@ -3197,23 +3192,29 @@ void checkUpdater() {
uint8_t checkButton() { uint8_t checkButton() {
while (Serial.available() == 0) { while (Serial.available() == 0) {
} }
incomingByte = Serial.read() - 48; // read() can't return -1 since there's data available.
char incomingByte = Serial.read();
//Next //Next
if (incomingByte == 52) { if (incomingByte == 'd') {
return 1; return 1;
} }
//Previous //Previous
else if (incomingByte == 69) { else if (incomingByte == 'u') {
return 2; return 2;
} }
//Selection //Selection
else if ((incomingByte == 240) || (incomingByte == -16) || (incomingByte == 0)) { else if ((incomingByte == ' ') || (incomingByte == '0')) {
return 3; return 3;
} }
//Long Press (simulate)
else if ((incomingByte == 'l') || (incomingByte == 'L')) {
return 4;
}
return 0; return 0;
} }
@ -3223,37 +3224,8 @@ void wait_serial() {
} }
while (Serial.available() == 0) { while (Serial.available() == 0) {
} }
incomingByte = Serial.read() - 48; // Result is ignored, so don't even bother putting it in a variable
/* if ((incomingByte == 53) && (fileName[0] != '\0')) { Serial.read();
// Open file on sd card
sd.chdir(folder);
if (myFile.open(fileName, O_READ)) {
// Get rom size from file
fileSize = myFile.fileSize();
// Send filesize
char tempStr[16];
sprintf(tempStr, "%d", fileSize);
Serial.write(tempStr);
// Wait for ok
while (Serial.available() == 0) {
}
// Send file
for (unsigned long currByte = 0; currByte < fileSize; currByte++) {
// Blink led
if (currByte % 1024 == 0)
blinkLED();
Serial.write(myFile.read());
}
// Close the file:
myFile.close();
}
else {
print_FatalError(open_file_STR);
}
}*/
} }
#endif #endif