-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.cpp
More file actions
448 lines (392 loc) · 13.6 KB
/
Button.cpp
File metadata and controls
448 lines (392 loc) · 13.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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
#ifndef BEENHERE
#include "SDT.h"
#endif
/*****
Purpose: Determine which UI button was pressed
Parameter list:
int valPin the ADC value from analogRead()
Return value;
int -1 if not valid push button, index of push button if valid
*****/
int ProcessButtonPress(int valPin) {
#if defined(G0ORX_FRONTPANEL) || defined(G0ORX_FRONTPANEL_2)
return valPin;
#else
int switchIndex;
if (valPin == BOGUS_PIN_READ) { // Not valid press
return -1;
}
if (valPin == MENU_OPTION_SELECT && menuStatus == NO_MENUS_ACTIVE) {
NoActiveMenu();
return -1;
}
for (switchIndex = 0; switchIndex < NUMBER_OF_SWITCHES; switchIndex++) {
if (abs(valPin - EEPROMData.switchValues[switchIndex]) < WIGGLE_ROOM) // ...because ADC does return exact values every time
{
return switchIndex;
}
}
return -1; // Really should never do this
#endif
}
/*****
Purpose: Check for UI button press. If pressed, return the ADC value
Parameter list:
int vsl the value from analogRead in loop()\
Return value;
int -1 if not valid push button, ADC value if valid
*****/
int ReadSelectedPushButton() {
#if defined(G0ORX_FRONTPANEL) || defined(G0ORX_FRONTPANEL_2)
__disable_irq();
#ifdef G0ORX_FRONTPANEL_2
getKeypad();
#endif
int i=G0ORXButtonPressed;
G0ORXButtonPressed=-1;
__enable_irq();
return i;
#else
minPinRead = 0;
int buttonReadOld = 1023;
while (abs(minPinRead - buttonReadOld) > 3) { // do averaging to smooth out the button response
minPinRead = analogRead(BUSY_ANALOG_PIN);
buttonRead = .1 * minPinRead + (1 - .1) * buttonReadOld; // See expected values in next function.
buttonReadOld = buttonRead;
}
if (buttonRead > EEPROMData.switchValues[0] + WIGGLE_ROOM) { //AFP 10-29-22 per Jack Wilson
return -1;
}
minPinRead = buttonRead;
MyDelay(100L);
return minPinRead;
#endif
}
/*****
Purpose: Function is designed to route program control to the proper execution point in response to
a button press.
Parameter list:
int vsl the value from analogRead in loop()
Return value;
void
*****/
void ExecuteButtonPress(int val)
{
switch (val) {
case MAIN_MENU_UP: // 11/16/23 JJP
tft.setFontScale((enum RA8875tsize) 1);
DrawMenuDisplay(); // Draw selection box and primary menu
SetPrimaryMenuIndex(); // Scroll through primary indexes and select one
SetSecondaryMenuIndex(); // Use the primary index selection to redraw the secondary menu and set its index
secondaryMenuChoiceMade = functionPtr[mainMenuIndex]();
tft.fillRect(1, SPECTRUM_TOP_Y + 1, 513, 379, RA8875_BLACK); // Erase Menu box
DrawSpectrumDisplayContainer();
EraseMenus();
break;
case BAND_UP: // 2 Now calls ProcessIQData and Encoders calls
EraseMenus();
if(currentBand < 5) digitalWrite(bandswitchPins[currentBand], LOW); // Added if so unused GPOs will not be touched. KF5N October 16, 2023.
ButtonBandIncrease();
if(currentBand < 5) digitalWrite(bandswitchPins[currentBand], HIGH);
BandInformation();
NCOFreq = 0L;
DrawBandWidthIndicatorBar(); // AFP 10-20-22
SetFreq();
ShowSpectrum();
break;
case ZOOM: // 3
menuStatus = PRIMARY_MENU_ACTIVE;
EraseMenus();
ButtonZoom();
break;
case MAIN_MENU_DN: // 4
ButtonMenuDecrease();
if (menuStatus != NO_MENUS_ACTIVE) { // Doing primary menu
ShowMenu(&topMenus[mainMenuIndex], PRIMARY_MENU);
}
break;
case BAND_DN: // 5
EraseMenus();
ShowSpectrum(); //Now calls ProcessIQData and Encoders calls
if(currentBand < 5) digitalWrite(bandswitchPins[currentBand], LOW);
ButtonBandDecrease();
if(currentBand < 5) digitalWrite(bandswitchPins[currentBand], HIGH);
BandInformation();
NCOFreq = 0L;
DrawBandWidthIndicatorBar(); //AFP 10-20-22
break;
case FILTER: // 6
EraseMenus();
ButtonFilter();
break;
case DEMODULATION: // 7
EraseMenus();
ButtonDemodMode();
break;
case SET_MODE: // 8
ButtonMode();
ShowSpectrumdBScale();
break;
case NOISE_REDUCTION: // 9
ButtonNR();
break;
case NOTCH_FILTER: // 10
ButtonNotchFilter();
UpdateNotchField();
break;
case NOISE_FLOOR: // 11
ButtonSetNoiseFloor();
break;
case FINE_TUNE_INCREMENT: // 12
UpdateIncrementField();
break;
case DECODER_TOGGLE: // 13
decoderFlag = !decoderFlag;
UpdateDecoderField();
break;
case MAIN_TUNE_INCREMENT: // 14
ButtonFreqIncrement();
UpdateEEPROMSyncIndicator(0);
break;
case RESET_TUNING: // 15 AFP 10-11-22
ResetTuning(); // AFP 10-11-22
break; // AFP 10-11-22
case UNUSED_1: // 16
#ifdef G0ORX_VFO
// Copy VFOA to VFOB
currentFreqB = currentFreqA;
currentBandB = currentBandA;
if(activeVFO == VFO_A) {
ShowFrequency();
} else {
NCOFreq = 0L;
centerFreq = TxRxFreq = currentFreqB;
SetBand(); // KF5N July 12, 2023
SetBandRelay(HIGH); // Required when switching VFOs. KF5N July 12, 2023
SetFreq();
RedrawDisplayScreen();
BandInformation();
ShowBandwidth();
FilterBandwidth();
tft.fillRect(FREQUENCY_X_SPLIT, FREQUENCY_Y - 12, VFOB_PIXEL_LENGTH, FREQUENCY_PIXEL_HI, RA8875_BLACK); // delete old digit
tft.fillRect(FREQUENCY_X, FREQUENCY_Y - 12, VFOA_PIXEL_LENGTH, FREQUENCY_PIXEL_HI, RA8875_BLACK); // delete old digit tft.setFontScale( (enum RA8875tsize) 0);
ShowFrequency();
// Draw or not draw CW filter graphics to audio spectrum area. KF5N July 30, 2023
tft.writeTo(L2);
tft.clearMemory();
if (xmtMode == CW_MODE) BandInformation();
DrawBandWidthIndicatorBar();
DrawFrequencyBarValue();
}
#else
if (calOnFlag == 0) {
ButtonFrequencyEntry();
}
#endif
break;
case BEARING: // 17 // AFP 10-11-22
#ifdef G0ORX_VFO
// Copy VFOB to VFOA
currentFreqA = currentFreqB;
currentBandA = currentBandB;
if(activeVFO == VFO_B) {
// just need to update display
ShowFrequency();
} else {
NCOFreq = 0L;
centerFreq = TxRxFreq = currentFreqA;
SetBand(); // KF5N July 12, 2023
SetBandRelay(HIGH); // Required when switching VFOs. KF5N July 12, 2023
SetFreq();
RedrawDisplayScreen();
BandInformation();
ShowBandwidth();
FilterBandwidth();
tft.fillRect(FREQUENCY_X_SPLIT, FREQUENCY_Y - 12, VFOB_PIXEL_LENGTH, FREQUENCY_PIXEL_HI, RA8875_BLACK); // delete old digit
tft.fillRect(FREQUENCY_X, FREQUENCY_Y - 12, VFOA_PIXEL_LENGTH, FREQUENCY_PIXEL_HI, RA8875_BLACK); // delete old digit tft.setFontScale( (enum RA8875tsize) 0);
ShowFrequency();
// Draw or not draw CW filter graphics to audio spectrum area. KF5N July 30, 2023
tft.writeTo(L2);
tft.clearMemory();
if (xmtMode == CW_MODE) BandInformation();
DrawBandWidthIndicatorBar();
DrawFrequencyBarValue();
}
#else
int buttonIndex, doneViewing, valPin;
float retVal;
tft.clearScreen(RA8875_BLACK);
DrawKeyboard();
CaptureKeystrokes();
retVal = BearingHeading(keyboardBuffer);
if (retVal != -1.0) { // We have valid country
bmpDraw((char *)myMapFiles[selectedMapIndex].mapNames, IMAGE_CORNER_X, IMAGE_CORNER_Y);
doneViewing = false;
} else {
tft.setTextColor(RA8875_RED);
tft.setCursor(380 - (17 * tft.getFontWidth(0)) / 2, 240); // Center message
tft.print("Country not found");
tft.setTextColor(RA8875_WHITE);
}
while (true) {
valPin = ReadSelectedPushButton(); // Poll UI push buttons
MyDelay(100L);
if (valPin != BOGUS_PIN_READ) { // If a button was pushed...
buttonIndex = ProcessButtonPress(valPin); // Winner, winner...chicken dinner!
switch (buttonIndex) {
case BEARING: // Pressed puchbutton 18
doneViewing = true;
break;
default:
break;
}
}
if (doneViewing == true) {
//tft.clearMemory(); // Need to clear overlay too
//tft.writeTo(L2);
//tft.fillWindow();
break;
}
}
RedrawDisplayScreen();
ShowFrequency();
DrawFrequencyBarValue();
#endif
break;
#if (defined(G0ORX_FRONTPANEL) || defined(G0ORX_FRONTPANEL_2))
case 18: // 18 - Encoder 1 SW (Volume)
switch(volumeFunction) {
case AUDIO_VOLUME:
volumeFunction=AGC_GAIN;
break;
case AGC_GAIN:
volumeFunction=MIC_GAIN;
break;
case MIC_GAIN:
volumeFunction=SIDETONE_VOLUME;
break;
case SIDETONE_VOLUME:
volumeFunction=NOISE_FLOOR_LEVEL;
break;
case NOISE_FLOOR_LEVEL:
volumeFunction=SQUELCH_LEVEL;
break;
case SQUELCH_LEVEL:
volumeFunction=AUDIO_VOLUME;
break;
}
volumeChangeFlag = true;
break;
case 19: // 19 - Encoder 2 SW (Filter/Menu)
// Temp use to step through AGC
AGCMode++;
if(AGCMode>4) {
AGCMode = 0;
}
AGCLoadValues();
EEPROMData.AGCMode = AGCMode; // Store in EEPROM and...
EEPROM.put(EEPROM_BASE_ADDRESS, EEPROMData); // ...save it
UpdateAGCField();
break;
case 20: // 20 - Encoder 3 SW (Center Tune)
// switch between VFO-A and VFO-B
if (activeVFO == VFO_A) {
centerFreq = TxRxFreq = currentFreqB;
activeVFO = VFO_B;
currentBand = currentBandB;
tft.fillRect(FILTER_PARAMETERS_X + 180, FILTER_PARAMETERS_Y, 150, 20, RA8875_BLACK); // Erase split message
splitOn = 0;
} else { // Must be VFO-B
centerFreq = TxRxFreq = currentFreqA;
activeVFO = VFO_A;
currentBand = currentBandA;
tft.fillRect(FILTER_PARAMETERS_X + 180, FILTER_PARAMETERS_Y, 150, 20, RA8875_BLACK); // Erase split message
splitOn = 0;
}
bands[currentBand].freq = TxRxFreq;
SetBand(); // KF5N July 12, 2023
SetBandRelay(HIGH); // Required when switching VFOs. KF5N July 12, 2023
SetFreq();
RedrawDisplayScreen();
BandInformation();
ShowBandwidth();
FilterBandwidth();
EEPROMData.activeVFO = activeVFO;
tft.fillRect(FREQUENCY_X_SPLIT, FREQUENCY_Y - 12, VFOB_PIXEL_LENGTH, FREQUENCY_PIXEL_HI, RA8875_BLACK); // delete old digit
tft.fillRect(FREQUENCY_X, FREQUENCY_Y - 12, VFOA_PIXEL_LENGTH, FREQUENCY_PIXEL_HI, RA8875_BLACK); // delete old digit tft.setFontScale( (enum RA8875tsize) 0);
ShowFrequency();
// Draw or not draw CW filter graphics to audio spectrum area. KF5N July 30, 2023
tft.writeTo(L2);
tft.clearMemory();
if(xmtMode == CW_MODE) BandInformation();
DrawBandWidthIndicatorBar();
DrawFrequencyBarValue();
break;
case 21: // 21 - Encoder 4 SW (Fine Tune)
// swap VFO A and B
long tempFreq = currentFreqA;
int tempBand = currentBandA;
currentFreqA = currentFreqB;
currentBandA = currentBandB;
currentFreqB = tempFreq;
currentBandB = tempBand;
if (activeVFO == VFO_A) {
centerFreq = TxRxFreq = currentFreqA;
currentBand = currentBandA;
} else { // must be VFO-B
centerFreq = TxRxFreq = currentFreqB;
currentBand = currentBandB;
}
bands[currentBand].freq = TxRxFreq;
SetBand(); // KF5N July 12, 2023
SetBandRelay(HIGH); // Required when switching VFOs. KF5N July 12, 2023
SetFreq();
RedrawDisplayScreen();
BandInformation();
ShowBandwidth();
FilterBandwidth();
EEPROMData.activeVFO = activeVFO;
tft.fillRect(FREQUENCY_X_SPLIT, FREQUENCY_Y - 12, VFOB_PIXEL_LENGTH, FREQUENCY_PIXEL_HI, RA8875_BLACK); // delete old digit
tft.fillRect(FREQUENCY_X, FREQUENCY_Y - 12, VFOA_PIXEL_LENGTH, FREQUENCY_PIXEL_HI, RA8875_BLACK); // delete old digit tft.setFontScale( (enum RA8875tsize) 0);
ShowFrequency();
// Draw or not draw CW filter graphics to audio spectrum area. KF5N July 30, 2023
tft.writeTo(L2);
tft.clearMemory();
if(xmtMode == CW_MODE) BandInformation();
DrawBandWidthIndicatorBar();
DrawFrequencyBarValue();
break;
#endif
}
}
/*****
Purpose: To process a band decrease button push
Parameter list:
void
Return value:
void
*****/
void ButtonFreqIncrement() {
tuneIndex--;
if (tuneIndex < 0)
tuneIndex = MAX_FREQ_INDEX - 1;
freqIncrement = incrementValues[tuneIndex];
//UpdateEEPROMSyncIndicator(0); // JJP 7/25/23
DisplayIncrementField();
}
/*****
Purpose: Error message if Select button pressed with no Menu active
Parameter list:
void
Return value;
void
*****/
void NoActiveMenu() {
tft.setFontScale((enum RA8875tsize)1);
tft.setTextColor(RA8875_RED);
tft.setCursor(10, 0);
tft.print("No menu selected");
menuStatus = NO_MENUS_ACTIVE;
mainMenuIndex = 0;
secondaryMenuIndex = 0;
}