Created
October 10, 2021 10:48
-
-
Save sweemeng/bca0842f4437bb6adcae5807b18fbd4f to your computer and use it in GitHub Desktop.
This is a demo with Arduino for Wio Terminal. This is the demo that assumes that you have the library and board set up on the Arduino IDE. I go look at ways to do it in platform.io later
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Keyboard.h" | |
#include"TFT_eSPI.h" | |
#define NOOP 0 | |
#define PRESS 1 | |
#define UP 2 | |
#define DOWN 3 | |
#define LEFT 4 | |
#define RIGHT 5 | |
#define MODE_NOOP 0 | |
#define MODE_YOUTUBE 1 | |
#define MODE_BROWSER 2 | |
#define MODE_GMEET 3 | |
TFT_eSPI tft; | |
char *youtubeMSGS[] = { "nothing", "play/pause", "invalid", "invalid", "FBwd", "FFwd" }; | |
char *browserMSGS[] = { "nothing", "reload", "Page Up", "Page Down", "Top", "Bottom" }; | |
char *gmeetMSGS[] = { "nothing", "mute/unmute", "invalid", "invalid", "invalid", "invalid"}; | |
char *modeMSGS[] = { "noop", "youtube", "browser", "gmeet" }; | |
int modeMSG; | |
int actionMSG; | |
int action; | |
int actionType; | |
bool refresh; | |
void youtubeAction(int action){ | |
switch(action){ | |
case PRESS: | |
Keyboard.write(' '); | |
break; | |
case LEFT: | |
Keyboard.write(KEY_LEFT_ARROW); | |
break; | |
case RIGHT: | |
Keyboard.write(KEY_RIGHT_ARROW); | |
break; | |
default: | |
break; | |
} | |
} | |
void browserAction(int action){ | |
switch(action){ | |
case PRESS: | |
Keyboard.press(KEY_LEFT_CTRL); | |
Keyboard.press('r'); | |
delay(100); | |
Keyboard.releaseAll(); | |
break; | |
case LEFT: | |
Keyboard.write(KEY_HOME); | |
break; | |
case RIGHT: | |
Keyboard.write(KEY_END); | |
break; | |
case UP: | |
Keyboard.write(KEY_PAGE_UP); | |
break; | |
case DOWN: | |
Keyboard.write(KEY_PAGE_DOWN); | |
break; | |
default: | |
break; | |
} | |
} | |
void googleMeetAction(int action){ | |
switch(action){ | |
case PRESS: | |
Keyboard.press(KEY_LEFT_CTRL); | |
Keyboard.press('d'); | |
delay(100); | |
Keyboard.releaseAll(); | |
break; | |
default: | |
break; | |
} | |
} | |
void actionSelector(int actionType, int action){ | |
switch(actionType){ | |
case MODE_YOUTUBE: | |
youtubeAction(action); | |
break; | |
case MODE_BROWSER: | |
browserAction(action); | |
break; | |
case MODE_GMEET: | |
googleMeetAction(action); | |
break; | |
default: | |
break; | |
} | |
} | |
void setMessage(int actionType, int action){ | |
tft.fillScreen(TFT_BLACK); | |
tft.drawString(modeMSGS[actionType], 70,80); | |
switch(actionType){ | |
case MODE_YOUTUBE: | |
tft.drawString(youtubeMSGS[action], 70,110); | |
break; | |
case MODE_BROWSER: | |
tft.drawString(browserMSGS[action], 70,110); | |
break; | |
case MODE_GMEET: | |
tft.drawString(gmeetMSGS[action], 70,110); | |
break; | |
default: | |
break; | |
} | |
} | |
void setup() { | |
pinMode(WIO_5S_UP, INPUT_PULLUP); | |
pinMode(WIO_5S_DOWN, INPUT_PULLUP); | |
pinMode(WIO_5S_LEFT, INPUT_PULLUP); | |
pinMode(WIO_5S_RIGHT, INPUT_PULLUP); | |
pinMode(WIO_5S_PRESS, INPUT_PULLUP); | |
pinMode(WIO_KEY_A, INPUT); | |
pinMode(WIO_KEY_B, INPUT); | |
pinMode(WIO_KEY_C, INPUT); | |
actionMSG = NOOP; | |
modeMSG = MODE_NOOP; | |
action = NOOP; | |
actionType = MODE_NOOP; | |
refresh = true; | |
Keyboard.begin(); | |
tft.begin(); | |
tft.setRotation(3); | |
} | |
void loop() { | |
if(digitalRead(WIO_KEY_A) == LOW) { | |
actionType = MODE_YOUTUBE; | |
modeMSG = MODE_YOUTUBE; | |
refresh = true; | |
} else if(digitalRead(WIO_KEY_B) == LOW) { | |
actionType = MODE_BROWSER; | |
modeMSG = MODE_BROWSER; | |
refresh = true; | |
} else if(digitalRead(WIO_KEY_C) == LOW) { | |
actionType = MODE_GMEET; | |
modeMSG = MODE_GMEET; | |
refresh = true; | |
} | |
if(digitalRead(WIO_5S_LEFT) == LOW){ | |
action = LEFT; | |
refresh = true; | |
} else if(digitalRead(WIO_5S_RIGHT) == LOW) { | |
action = RIGHT; | |
refresh = true; | |
} else if(digitalRead(WIO_5S_PRESS) == LOW) { | |
action = PRESS; | |
refresh = true; | |
} else if(digitalRead(WIO_5S_UP) == LOW) { | |
action = UP; | |
refresh = true; | |
} else if(digitalRead(WIO_5S_DOWN) == LOW) { | |
action = DOWN; | |
refresh = true; | |
} | |
if(action != NOOP && actionType != MODE_NOOP){ | |
actionSelector(actionType, action); | |
delay(200); | |
} | |
if(refresh){ | |
actionMSG = action; | |
setMessage(actionType, actionMSG); | |
} | |
refresh = false; | |
action = NOOP; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment