This repository was archived by the owner on Feb 19, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmenu_handler.ino
More file actions
229 lines (170 loc) · 5.84 KB
/
menu_handler.ino
File metadata and controls
229 lines (170 loc) · 5.84 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
void menuUpdate(unsigned char encoderAction) { //main menu navigation updater
//called on by rotary encoder actions
//parameter 0: no action from encoder
//parameter 1: encoder click
//parameter 2: encoder CW rotation
//parameter 3: encoder CCW rotation
//unsigned int verifiedMenuPos;
if (encoderAction == 0) {
//no action
} else { //triggered by action
if (encoderAction == 1) { //encoder click button
//code below takes menu position to the next sub branch
if (menuPos % 10 == 0) { //if menu selection is at XX0 (zero at the end)
menuPos = menuPos / 10; //go back up one level of menu (we use zero as the 'return' menu selection)
} else {
menuPos = menuPos * 10 + 1; //else, go further in one level of menu from the current selection
}
menuPos = menuVerifyPos(menuPos);
menuAction(menuPos); //click execution
updateMenuDisplay(menuPos);
} else if (encoderAction == 2) { //encoder CW rotation
if (menuPos % 10 == 9) { //if current selection is at XX9
//do nothing
} else {
menuPos ++;
}
menuPos = menuVerifyPos(menuPos);
updateMenuDisplay(menuPos);
} else if (encoderAction == 3) { //encoder CCW rotation
if (menuPos % 10 == 0) { //if current selection is at XX0
//do nothing
} else {
menuPos --;
}
menuPos = menuVerifyPos(menuPos);
updateMenuDisplay(menuPos);
}
lastMenuPos = menuPos;
Serial.print("menuPos = ");
Serial.println(menuPos);
}
}
void subMenu1Update(unsigned char encoderAction) { //sub menu type 1 updater: number selection 1 - 255
//called on by rotary encoder actions with a parameter to indicate:
//parameter 0: no action from encoder
//parameter 1: encoder click
//parameter 2: encoder CW rotation
//parameter 3: encoder CCW rotation
if (encoderAction == 0) {
// no action
} else {
if (encoderAction == 1) { //encoder click
subMenuClick++;
//Serial.print("subMenu1Update: click++; click = ");
//Serial.println(subMenuClick);
if(subMenuClick == 1) { //single click to exit sub menu
lcd.clear();
menuAction(menuPos); //calls menuAction with last main menu tree position
}
} else if (encoderAction == 2) { //CW rotation
if (subMenuPos >= 255) {
subMenuPos = 1;
} else {
subMenuPos++;
}
} else if (encoderAction == 3) { //CCW rotation
if (subMenuPos <= 1) {
subMenuPos = 255;
} else {
subMenuPos--;
}
}
//update 4th row of LCD to display sub menu position
lcd.setCursor(0,3);
lcd.print(" ");
lcd.setCursor(0,3);
lcd.print(subMenuPos);
}
}
void subMenu2Update(unsigned char encoderAction){ //sub menu type 2, yes-no selection
//called on by rotary encoder actions
//parameter 0: no action from encoder
//parameter 1: encoder click
//parameter 2: encoder CW rotation
//parameter 3: encoder CCW rotation
if (encoderAction == 1) { //encoder click
subMenuClick++;
if(subMenuClick == 1) { //single click to exit sub menu
lcd.clear();
menuAction(menuPos); //calls menuAction with last main menu tree position
}
} else { //encoder rotation
if (encoderAction != 0) {
if (subMenuPos != 1) { //flip subMenuPos between 0 and 1
subMenuPos = 1;
} else {
subMenuPos = 0;
}
}
//update 4th row of LCD to display sub menu position
lcd.setCursor(0,3);
lcd.print(" ");
lcd.setCursor(0,3);
if (subMenuPos == 1) {
lcd.print("YES");
} else if (subMenuPos == 0) {
lcd.print("NO");
}
}
}
void subMenu3Update(unsigned char encoderAction) { //sub menu type 3 updater: time setting
//called on by rotary encoder actions with a parameter to indicate:
//parameter 0: no action from encoder
//parameter 1: encoder click
//parameter 2: encoder CW rotation
//parameter 3: encoder CCW rotation
if (encoderAction == 0) {
// no action
} else {
if (encoderAction == 1) { //encoder click
subMenuClick++;
if(subMenuClick == 1) { //first click to finish setting hour, move on to set minutes
subMenuPos = 0; //reset subMenuPos to be used for setting minute
} else if(subMenuClick == 2) { //second click to record minute, exit menu
//:::code to set hour and minute to global variables:::
lcd.clear();
menuAction(menuPos); //calls menuAction with last main menu tree position
}
} else if (encoderAction == 2) { //CW rotation
if (subMenuClick == 0) { //setting hour
if (subMenuPos >= 24) { //scrolling end limits
subMenuPos = 0;
} else {
subMenuPos++;
}
setHour = subMenuPos;
} else if (subMenuClick == 1) { //setting minute
if (subMenuPos >= 59) { //scrolling end limits
subMenuPos = 0;
} else {
subMenuPos++;
}
setMinute = subMenuPos;
}
} else if (encoderAction == 3) { //CCW rotation
if (subMenuClick == 0) { //setting hour
if (subMenuPos <= 0) { //scrolling end limits
subMenuPos = 24;
} else {
subMenuPos--;
}
setHour = subMenuPos;
} else if (subMenuClick == 1) { //setting minute
if (subMenuPos <= 0) { //scrolling end limits
subMenuPos = 59;
} else {
subMenuPos--;
}
setMinute = subMenuPos;
}
}
//update 4th row of LCD to display sub menu position
lcd.setCursor(0,3);
lcd.print(" ");
lcd.setCursor(0,3);
lcd.print(setHour);
lcd.print(":");
lcd.print(setMinute);
}
}