-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cpp
More file actions
358 lines (314 loc) · 12.6 KB
/
Menu.cpp
File metadata and controls
358 lines (314 loc) · 12.6 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
#ifndef BEENHERE
#include "SDT.h"
#endif
/*
const char *topMenus[] = { "Bearing", "CW Options", "RF Set", "VFO Select",
"EEPROM", "AGC", "Spectrum Options",
"Noise Floor", "Mic Gain", "Mic Comp",
"EQ Rec Set", "EQ Xmt Set", "Calibrate" };
int (*functionPtr[])() = { &BearingMaps, &CWOptions, &RFOptions, &VFOSelect,
&EEPROMOptions, &AGCOptions, &SpectrumOptions,
&ButtonSetNoiseFloor, &MicGainSet, &MicOptions,
&EqualizerRecOptions, &EqualizerXmtOptions, &IQOptions
};
*/
/*****
Purpose: void ShowMenu()
Parameter list:
char *menuItem pointers to the menu
int where 0 is a primary menu, 1 is a secondary menu
Return value;
void
*****/
void ShowMenu(const char *menu[], int where) {
tft.setFontScale((enum RA8875tsize)1);
if (menuStatus == NO_MENUS_ACTIVE) // No menu selected??
NoActiveMenu();
if (where == PRIMARY_MENU) { // Should print on left edge of top line
tft.fillRect(PRIMARY_MENU_X, MENUS_Y, 300, CHAR_HEIGHT, RA8875_BLUE); // Top-left of display
tft.setCursor(5, 0);
tft.setTextColor(RA8875_WHITE);
tft.print(*menu); // Primary Menu
} else {
tft.fillRect(SECONDARY_MENU_X, MENUS_Y, 300, CHAR_HEIGHT, RA8875_GREEN); // Right of primary display
tft.setCursor(35, 0);
tft.setTextColor(RA8875_WHITE);
tft.print(*menu); // Secondary Menu
}
return;
}
/*****
Purpose: To present the encoder-driven menu display
Argument List;
void
Return value: index number for the selected menu
const char *secondaryChoices[][8] = {
{ "WPM", "Key Type", "CW Filter", "Paddle Flip", "Sidetone Vol", "Xmit Delay", "Cancel" }, // CW Options
{ "Power level", "Gain", "Cancel" }, // RF
{ "VFO A", "VFO B", "Split", "Cancel" }, // VFO
{ "Save Current", "Set Defaults", "Get Favorite", "Set Favorite", "EEPROM-->SD", "SD-->EEPROM", "SD Dump", "Cancel" }, // EEPROM
{ "Off", "Long", "Slow", "Medium", "Fast", "Cancel" }, // AGC
{ "20 dB/unit", "10 dB/unit", " 5 dB/unit", " 2 dB/unit", " 1 dB/unit", "Cancel" }, // Spectrum
{ "Set floor", "Cancel" }, // Noise
{ "Set Mic Gain", "Cancel" }, // Mic gain
{ "On", "Off", "Set Threshold", "Set Ratio", "Set Attack", "Set Decay", "Cancel" }, // Mic Compression
{ "On", "Off", "EQSet", "Cancel" }, // Receiver equalizer
{ "On", "Off", "EQSet", "Cancel" }, // Transmiiter equilizer
{ "Freq Cal", "CW PA Cal", "Rec Cal", "Xmit Cal", "SSB PA Cal", "Cancel" }, // Calibrate
{ "Set Prefix", "Cancel" } // Bearing
};
*****/
int DrawMenuDisplay() {
int i;
menuStatus = 0; // No primary or secondary menu set
// mainMenuIndex = 0;
secondaryMenuIndex = 0;
tft.writeTo(L2); // Clear layer 2. KF5N July 31, 2023
tft.clearMemory();
tft.writeTo(L1);
tft.fillRect(1, SPECTRUM_TOP_Y + 1, 513, 379, RA8875_BLACK); // Show Menu box
tft.drawRect(1, SPECTRUM_TOP_Y + 1, 513, 378, RA8875_YELLOW);
tft.setFontScale((enum RA8875tsize)1);
tft.setTextColor(RA8875_WHITE);
for (i = 0; i < TOP_MENU_COUNT; i++) { // Show primary menu list
tft.setCursor(10, i * 25 + 115);
tft.print(topMenus[i]);
}
tft.setTextColor(RA8875_GREEN); // show currently active menu
tft.setCursor(10, mainMenuIndex * 25 + 115);
tft.print(topMenus[mainMenuIndex]);
tft.setTextColor(DARKGREY);
for (i = 0; i < secondaryMenuCounts[mainMenuIndex]; i++) { // Show secondary choices
tft.setCursor(300, i * 25 + 115);
tft.print(secondaryChoices[mainMenuIndex][i]);
}
menuStatus = PRIMARY_MENU_ACTIVE;
return 0;
}
static void unselectPrimaryMenuIndex(int index) {
tft.setTextColor(RA8875_WHITE); // Yep. Repaint the old choice
tft.setCursor(10, index * 25 + 115);
tft.print(topMenus[index]);
}
void selectPrimaryMenuIndex(int index) {
tft.setTextColor(RA8875_GREEN);
tft.setCursor(10, index * 25 + 115);
tft.print(topMenus[index]);
tft.fillRect(SECONDARY_MENU_X, SPECTRUM_TOP_Y + 5, 260, 279, RA8875_BLACK); // Erase secondary menu list
tft.setTextColor(DARKGREY);
for (int i = 0; i < secondaryMenuCounts[index]; i++) { // Have we read the last entry in secondary menu?
tft.setCursor(300, i * 25 + 115);
tft.print(secondaryChoices[index][i]);
}
tft.setCursor(300, 115);
tft.print(secondaryChoices[index][0]);
}
void selectSecondaryMenuIndex(int index) {
tft.setTextColor(RA8875_GREEN); // Highlight the first menu option
tft.setCursor(300, (index*25)+115);
tft.print(secondaryChoices[mainMenuIndex][index]);
}
void unselectSecondaryMenuIndex(int index) {
tft.setTextColor(DARKGREY); // Yep. Repaint the old choice
tft.setCursor(300, index * 25 + 115);
tft.print(secondaryChoices[mainMenuIndex][index]);
}
/*****
Purpose: To select the primary menu
Argument List:
void
Return value: index number for the selected primary menu
*****/
int SetPrimaryMenuIndex() {
//int i;
//int resultIndex;
int val;
//i = 0;
//resultIndex = 0;
// mainMenuIndex = 0;
#ifdef G0ORX_FRONTPANEL_2
calibrateFlag=1;
#endif
while (true) {
#ifdef G0ORX_FRONTPANEL_2
if(touchPrimaryMenuIndex>=0) {
unselectPrimaryMenuIndex(mainMenuIndex);
mainMenuIndex = touchPrimaryMenuIndex;
touchPrimaryMenuIndex = -1;
if (mainMenuIndex >= TOP_MENU_COUNT) { // Did they go past the end of the primary menu list?
mainMenuIndex = TOP_MENU_COUNT - 1; // Yep. Set to start of the list.
}
selectPrimaryMenuIndex(mainMenuIndex);
} else if(touchSecondaryMenuIndex>=0) {
break;
}
#endif
if (filterEncoderMove != 0) { // Did they move the encoder?
unselectPrimaryMenuIndex(mainMenuIndex);
mainMenuIndex += filterEncoderMove; // Change the menu index to the new value
if (mainMenuIndex >= TOP_MENU_COUNT) { // Did they go past the end of the primary menu list?
mainMenuIndex = 0; // Yep. Set to start of the list.
} else {
if (mainMenuIndex < 0) { // Did they go past the start of the list?
mainMenuIndex = TOP_MENU_COUNT - 1; // Yep. Set to end of the list.
}
}
selectPrimaryMenuIndex(mainMenuIndex);
filterEncoderMove = 0;
}
val = ReadSelectedPushButton(); // Read the ladder value
MyDelay(150L);
if (val != -1 && val < (EEPROMData.switchValues[0] + WIGGLE_ROOM)) { // Did they press Select?
val = ProcessButtonPress(val); // Use ladder value to get menu choice
if (val > -1) { // Valid choice?
if (val == MENU_OPTION_SELECT) { // They made a choice
// tft.setTextColor(RA8875_WHITE);
break;
}
MyDelay(50L);
}
}
} // End while True
#ifdef G0ORX_FRONTPANEL_2
calibrateFlag=0;
#endif
tft.setTextColor(RA8875_WHITE);
return mainMenuIndex;
}
/*****
Purpose: To select the secondary menu
Argument List;
void
Return value: index number for the selected primary menu
*****/
int SetSecondaryMenuIndex()
{
int i = 0;
int secondaryMenuCount = 0;
int oldIndex = 0;
int val;
/*
while (true) { // How many secondary menu options?
if (strcmp(secondaryChoices[mainMenuIndex][i], "Cancel") != 0) { // Have we read the last entry in secondary menu?
i++; // Nope.
} else {
secondaryMenuCount = i + 1; // Add 1 because index starts with 0
break;
}
}
*/
secondaryMenuCount = secondaryMenuCounts[mainMenuIndex];
secondaryMenuIndex = 0; // Change the menu index to the new value
filterEncoderMove = 0;
//tft.setTextColor(RA8875_GREEN); // Highlight the first menu option
//tft.setCursor(300, 115);
//tft.print(secondaryChoices[mainMenuIndex][0]);
selectSecondaryMenuIndex(0);
i = 0;
oldIndex = 0;
#ifdef G0ORX_FRONTPANEL_2
calibrateFlag=1;
#endif
while (true) {
#ifdef G0ORX_FRONTPANEL_2
if(touchSecondaryMenuIndex>=0) {
unselectSecondaryMenuIndex(oldIndex);
oldIndex = touchSecondaryMenuIndex;
touchSecondaryMenuIndex = -1;
if (oldIndex >= secondaryMenuCount) { // Did they go past the end of the primary menu list?
oldIndex = secondaryMenuCount - 1; // Yep. Set last in the list.
}
selectSecondaryMenuIndex(oldIndex);
}
#endif
if (filterEncoderMove != 0) { // Did they move the encoder?
//tft.fillRect(SECONDARY_MENU_X, MENUS_Y, EACH_MENU_WIDTH + 30, CHAR_HEIGHT, RA8875_BLACK);
//tft.setTextColor(DARKGREY); // Yep. Repaint the old choice
//tft.setCursor(300, oldIndex * 25 + 115);
//tft.print(secondaryChoices[mainMenuIndex][oldIndex]);
unselectSecondaryMenuIndex(oldIndex);
i += filterEncoderMove; // Change the menu index to the new value
if (i == secondaryMenuCount) { // Did they go past the end of the primary menu list?
i = 0; // Yep. Set to start of the list.
} else {
if (i < 0) { // Did they go past the start of the list?
i = secondaryMenuCount - 1; // Yep. Set to end of the list.
}
}
oldIndex = i;
selectSecondaryMenuIndex(i);
//tft.setTextColor(RA8875_GREEN);
//tft.setCursor(300, i * 25 + 115);
//tft.print(secondaryChoices[mainMenuIndex][i]);
filterEncoderMove = 0;
}
val = ReadSelectedPushButton(); // Read the ladder value
MyDelay(200L);
if (val != -1 && val < (EEPROMData.switchValues[0] + WIGGLE_ROOM)) {
val = ProcessButtonPress(val); // Use ladder value to get menu choice
if (val > -1) { // Valid choice?
if (val == MENU_OPTION_SELECT) { // They made a choice
tft.setTextColor(RA8875_WHITE);
secondaryMenuIndex = oldIndex;
break;
}
MyDelay(50L);
}
}
} // End while True
#ifdef G0ORX_FRONTPANEL_2
calibrateFlag=0;
#endif
return secondaryMenuIndex;
}
/*****
Purpose: To select the secondary menu
Argument List;
char *choice[] // The options
int count // Options in the list
int menuDefault // The default or current choice
Return value: // index number of option
*****/
int SecondarySubmenuString(char *options[], int count, int menuDefault)
{
int i = menuDefault;
int val;
#ifdef G0ORX_FRONTPANEL_2
calibrateFlag=1;
#endif
while (true) {
tft.fillRect(SECONDARY_MENU_X, MENUS_Y, EACH_MENU_WIDTH, CHAR_HEIGHT + 1, RA8875_MAGENTA); // Erase menu choices
tft.setCursor(SECONDARY_MENU_X, MENUS_Y);
tft.setTextColor(RA8875_BLACK, RA8875_MAGENTA);
tft.print(options[i]);
i += filterEncoderMove; // Change the menu index to the new value
if (i == count) { // Did they go past the end of the primary menu list?
i = 0; // Yep. Set to start of the list.
} else {
if (i < 0) { // Did they go past the start of the list?
i = count - 1; // Yep. Set to end of the list.
}
}
filterEncoderMove = 0;
val = ReadSelectedPushButton(); // Read the ladder value
MyDelay(200L);
if (val != -1 && val < (EEPROMData.switchValues[0] + WIGGLE_ROOM)) {
val = ProcessButtonPress(val); // Use ladder value to get menu choice
if (val > -1) { // Valid choice?
if (val == MENU_OPTION_SELECT) { // They made a choice
keyType = i;
break;
}
MyDelay(50L);
}
}
}
#ifdef G0ORX_FRONTPANEL_2
calibrateFlag=0;
#endif
tft.setTextColor(RA8875_WHITE, RA8875_BLACK);
return keyType;
}
void RenderBearing()
{
}