Skip to content

Commit

Permalink
added number keys as options menu shortcuts (pr3y#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
eadmaster committed Aug 4, 2024
1 parent 22e32d4 commit ad7468e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
18 changes: 17 additions & 1 deletion src/core/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "mykeyboard.h"
#include "wg.h" //for isConnectedWireguard to print wireguard lock
#include "settings.h" //for timeStr
#include "modules/others/webInterface.h" // for server

#if defined(CARDPUTER) || defined(STICK_C_PLUS2) //Battery Calculation
#include <driver/adc.h>
Expand Down Expand Up @@ -46,6 +47,9 @@ void initDisplay(int i) {
** Description: Display Red Stripe with information
***************************************************************************************/
void displayRedStripe(String text, uint16_t fgcolor, uint16_t bgcolor) {
// detect if not running in interactive mode -> show nothing onscreen and return immediately
if(server || isSleeping || isScreenOff) return; // webui is running

int size;
if(fgcolor==bgcolor && fgcolor==TFT_WHITE) fgcolor=TFT_BLACK;
if(text.length()*LW*FM<(tft.width()-2*FM*LW)) size = FM;
Expand Down Expand Up @@ -119,7 +123,19 @@ void loopOptions(const std::vector<std::pair<std::string, std::function<void()>>
}

#ifdef CARDPUTER
if(checkEscPress()) break;
if(checkEscPress()) break;
int pressed_number = checkNumberShortcutPress();
if(pressed_number>=0) {
if(index == pressed_number) {
// press 2 times the same number to confirm
options[index].second();
break;
}
// else only highlight the option
index = pressed_number;
if((index+1)>options.size()) index = options.size() - 1;
redraw = true;
}
#endif
}
delay(200);
Expand Down
18 changes: 15 additions & 3 deletions src/core/mykeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,31 @@ bool checkAnyKeyPress() {

}

#ifdef CARDPUTER
void checkShortcutPress(){
// some shortctus to quickly starts apps
#if defined (CARDPUTER)
// shortctus to quickly starts apps
Keyboard.update();
if(Keyboard.isKeyPressed('i')) otherIRcodes();
if(Keyboard.isKeyPressed('r') || Keyboard.isKeyPressed('s')) otherRFcodes();
if(Keyboard.isKeyPressed('b')) usb_setup(); // badusb
if(Keyboard.isKeyPressed('w')) loopOptionsWebUi();
// TODO: other boards
// TODO: other boards?
// TODO: user-configurable
}

int checkNumberShortcutPress() {
// shortctus to quickly select options
Keyboard.update();
char c;
for (c = '1'; c <= '9'; c++) {
if(Keyboard.isKeyPressed(c)) return(c - '1');
}
// else
return -1;
#endif
}


/* Starts keyboard to type data */
String keyboard(String mytext, int maxSize, String msg) {

Expand Down
3 changes: 3 additions & 0 deletions src/core/mykeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ bool checkSelPress();

bool checkEscPress();

#ifdef CARDPUTER
void checkShortcutPress();
int checkNumberShortcutPress();
#endif

bool checkAnyKeyPress();

Expand Down

0 comments on commit ad7468e

Please sign in to comment.