-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.ino
76 lines (60 loc) · 2.18 KB
/
menu.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// The basic menu code
// If you add an app, this is where you will update the
// framework code to include it in the menu.
//
// Make the following updates:
// 1) Update maxApp to the total number of apps.
// 2) Update appName to add the title of the app.
// 3) in the main routine in GrumpyWatch, add a case to the switch statement to call your app routine.
const int maxApp = 11; // number of apps
String appName[maxApp] = {"Clock", "Jupiter", "Accel", "Battery", "Hall Sensor", "Set Time", "Motor", "Temp", "Scan Wifi", "Int Time", "Reset Steps"}; // app names
uint8_t modeMenu() {
int mSelect = 0; // The currently highlighted app
int16_t x, y, tx, ty;
boolean exitMenu = false; // used to stay in the menu until user selects app
setMenuDisplay(0); // display the list of Apps
while (!exitMenu) {
if (ttgo->getTouch(x, y)) { // If you have touched something...
while (ttgo->getTouch(tx, ty)) {} // wait until you stop touching
if (y >= 160) { // you want the menu list shifted up
mSelect += 1;
if (mSelect == maxApp) mSelect = 0;
setMenuDisplay(mSelect);
}
if (y <= 80) { // you want the menu list shifted down
mSelect -= 1;
if (mSelect < 0) mSelect = maxApp - 1;
setMenuDisplay(mSelect);
}
if (y > 80 && y < 160) { // You selected the middle
exitMenu = true;
}
}
}
//Return with mSelect containing the desired mode
ttgo->tft->fillScreen(TFT_BLACK);
return mSelect;
}
void setMenuDisplay(int mSel) {
int curSel = 0;
// Display mode header
ttgo->tft->fillScreen(TFT_BLUE);
ttgo->tft->fillRect(0, 80, 239, 80, TFT_BLACK);
// Display apps
if (mSel == 0) curSel = maxApp - 1;
else curSel = mSel - 1;
ttgo->tft->setTextSize(2);
ttgo->tft->setTextColor(TFT_GREEN);
ttgo->tft->setCursor(50, 30);
ttgo->tft->println(appName[curSel]);
ttgo->tft->setTextSize(3);
ttgo->tft->setTextColor(TFT_RED);
ttgo->tft->setCursor(40, 110);
ttgo->tft->println(appName[mSel]);
if (mSel == maxApp - 1) curSel = 0;
else curSel = mSel + 1;
ttgo->tft->setTextSize(2);
ttgo->tft->setTextColor(TFT_GREEN);
ttgo->tft->setCursor(50, 190);
ttgo->tft->print(appName[curSel]);
}