forked from reedbn/ubitxv6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu_main.cpp
192 lines (168 loc) · 5.25 KB
/
menu_main.cpp
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
#include "menu_main.h"
#include "menu_main_buttons.h"
#include <avr/pgmspace.h>
#include <Arduino.h>
#include "button.h"
#include "color_theme.h"
#include "menu_utils.h"
#include "morse.h"
#include "nano_gui.h"
#include "scratch_space.h"
#include "settings.h"
#include "tuner.h"//THRESHOLD_USB_LSB
#include "utils.h"
void drawMainMenu(void);
MenuReturn_e runMainMenu(const ButtonPress_e tuner_button,
const ButtonPress_e touch_button,
const Point touch_point,
const int16_t knob);
Menu_t mainMenu = {
drawMainMenu,
runMainMenu,
nullptr
};
Menu_t* const rootMenu = &mainMenu;
bool mainMenuSelecting = false;//Tracks if we're selecting buttons with knob, or adjusting frequency
int16_t mainMenuSelectedItemRaw = 0;//Allow negative only for easier checks on wrap around
void drawMainMenu(void)
{
displayClear(COLOR_BACKGROUND);
Button button;
Button* bp;
for(uint8_t i = 0; i < MAIN_MENU_NUM_BUTTONS; ++i){
memcpy_P(&bp, &(mainMenuButtons[i]), sizeof(bp));
extractAndDrawButton(&button,bp);
}
drawVersion();
drawCallsign();
ltoa(GetActiveVfoFreq(),b,10);
morseText(b);
}
void drawMainMenuIncrement()
{
//State variables
static uint32_t last_freq = 0;
static Vfo_e last_vfo = Vfo_e::VFO_A;
static VfoMode_e last_mode = VfoMode_e::VFO_MODE_LSB;
static bool last_split = false;
static bool last_rit = false;
static TuningMode_e last_tuning = TuningMode_e::TUNE_SSB;
Button button;
if((last_freq != GetActiveVfoFreq())
||(last_vfo != globalSettings.activeVfo)){
extractAndDrawButton(&button,&bVfoA);
extractAndDrawButton(&button,&bVfoB);
updateBandButtons(last_freq);
last_freq = GetActiveVfoFreq();
last_vfo = globalSettings.activeVfo;
//We set this here so that we're always hearing what's displayed
setFrequency(last_freq);
}
if(last_mode != GetActiveVfoMode()){
updateSidebandButtons();
last_mode = GetActiveVfoMode();
}
if(last_split != globalSettings.splitOn){
extractAndDrawButton(&button,&bVfoA);
extractAndDrawButton(&button,&bVfoB);
extractAndDrawButton(&button,&bSpl);
last_split = globalSettings.splitOn;
}
if(last_rit != globalSettings.ritOn){
extractAndDrawButton(&button,&bRit);
last_rit = globalSettings.ritOn;
}
if(last_tuning != globalSettings.tuningMode){
extractAndDrawButton(&button,&bCw);
last_tuning = globalSettings.tuningMode;
}
}
void mainMenuTune(int16_t knob)
{
if(0 == knob){
//Nothing to do - we're already set!
return;
}
const uint32_t current_freq = GetActiveVfoFreq();
const uint32_t new_freq = current_freq + (50 * knob);
SetActiveVfoFreq(new_freq);
autoSelectSidebandChanged(current_freq);
}
MenuReturn_e runMainMenu(const ButtonPress_e tuner_button,
const ButtonPress_e touch_button,
const Point touch_point,
const int16_t knob)
{
//Check tuner_button
if(ButtonPress_e::NotPressed != tuner_button){
switch(tuner_button){
default://Fallthrough intended
case ButtonPress_e::NotPressed:
{
//Nothing to do
break;
}
case ButtonPress_e::ShortPress:
{
if(mainMenuSelecting){
uint8_t menu_index = mainMenuSelectedItemRaw/MENU_KNOB_COUNTS_PER_ITEM;
Button button;
Button* bp;
memcpy_P(&bp,&(mainMenuButtons[menu_index]),sizeof(bp));
memcpy_P(&button,bp,sizeof(button));
endSelector(&button);
button.on_select();
}
else{
initSelector(&mainMenuSelectedItemRaw,
mainMenuButtons,
MAIN_MENU_NUM_BUTTONS,
MorsePlaybackType_e::PlayChar);
}
mainMenuSelecting = !mainMenuSelecting;
//Don't handle touch or knob on this run
return MenuReturn_e::StillActive;//main menu always returns StillActive
break;
}
case ButtonPress_e::LongPress:
{
if(!globalSettings.morseMenuOn){
globalSettings.morseMenuOn = true;//set before playing
morseLetter(2);
}
else{
morseLetter(4);
globalSettings.morseMenuOn = false;//unset after playing
}
SaveSettingsToEeprom();
//Don't handle touch or knob on this run
return MenuReturn_e::StillActive;//main menu always returns StillActive
break;
}
}//switch
}//tuner_button
else if(ButtonPress_e::NotPressed != touch_button){
//We treat long and short presses the same, so no need to have a switch
Button button;
if(findPressedButton(mainMenuButtons,MAIN_MENU_NUM_BUTTONS,&button,touch_point)){
button.on_select();
}
else{
//Touch detected, but not on our buttons, so ignore
}
}//touch_button
else{//Neither button input type found, so handle the knob
if(mainMenuSelecting){
adjustSelector(&mainMenuSelectedItemRaw,
knob,
mainMenuButtons,
MAIN_MENU_NUM_BUTTONS,
MorsePlaybackType_e::PlayChar);
}
else{
mainMenuTune(knob);
}
}
drawMainMenuIncrement();
return MenuReturn_e::StillActive;//main menu always returns StillActive
}