-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.cpp
More file actions
executable file
·150 lines (122 loc) · 2.53 KB
/
Copy pathmenu.cpp
File metadata and controls
executable file
·150 lines (122 loc) · 2.53 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "menu.h"
#ifndef menu_cpp
#define menu_cpp
/*
class menu{
private:
int items = 0;
String title;
public:
int index = 0;
String menuItems[];
menu();
void defineMenuItems(String* Items, int numberOfItems);
void defineTitle(String title);
int len() const;
void next();
void back();
void printMenu();
}
*/
/*
* Main user interface
*/
void menu::ui(){
if(items == 0)
return;
printMenu();
while(true){
delay(25);
char key = keypad.getKey();
//wait for key until pressed
if(!key)
continue;
//keypressed actions
switch (key) {
case '2':
previous();
printMenu();
break;
case '8':
next();
printMenu();
break;
case '5':
cls();
(menuProgs[index])();
if(!loop){
return;
}
printMenu();
break;
case '4':
return;
}
}
}
/*
* Constructors
*/
menu::menu() {
//define colors
defaultColor = ST7735_WHITE;
color = ST7735_YELLOW;
titleColor = ST7735_GREEN;
lcd.setTextColor(defaultColor);
title = "=======Main Menu=======";
loop = true;
}
/*
* Definer Functions
*/
void menu::defineMenuItems(String* Items, int numberOfItems){
for (int i = 0; i < min(numberOfItems, MAX_ITEMS); i++){
menuItems[i] = Items[i];
items = i+1;
}
}
void menu::defineMenuProgs(void (*Programs[])(), int numberOfProgs){
for (int i = 0; i < min(numberOfProgs, MAX_ITEMS); i++){
menuProgs[i] = Programs[i];
items = i+1;
}
}
void menu::defineTitle(String text){
title = text;
}
void menu::defineCursorColor(int colorInput){
color = colorInput;
}
/*
* Utility Functions
*/
void menu::printMenu() {
//prep screen
cls();
//print title
lcd.setTextColor(titleColor);
lcd.println(title);
//print menu
for(int i = 0; i < min(items, SCR_HEIGHT_IN_CHARS-2); i++)
{
if( i == index ){
lcd.setTextColor(color);
} else {
lcd.setTextColor(defaultColor);
}
lcd.print(">");
lcd.println(menuItems[i]);
}
//restore to default color
lcd.setTextColor(defaultColor);
//print useful info
lcd.setCursor(0, CHARH*(SCR_HEIGHT_IN_CHARS-1));
lcd.print("2:UP,8:DWN,5:SEL,4:BACK");
}
void menu::next(){
index = (index+1)%items;
}
void menu::previous(){
index = (items + index - 1) % items;
}
#endif