forked from afarhan/ubitxv6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.cpp
303 lines (241 loc) · 7.53 KB
/
setup.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
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
#include <Arduino.h>
#include <EEPROM.h>
#include "morse.h"
#include "ubitx.h"
#include "nano_gui.h"
/** Menus
* The Radio menus are accessed by tapping on the function button.
* - The main loop() constantly looks for a button press and calls doMenu() when it detects
* a function button press.
* - As the encoder is rotated, at every 10th pulse, the next or the previous menu
* item is displayed. Each menu item is controlled by it's own function.
* - Eache menu function may be called to display itself
* - Each of these menu routines is called with a button parameter.
* - The btn flag denotes if the menu itme was clicked on or not.
* - If the menu item is clicked on, then it is selected,
* - If the menu item is NOT clicked on, then the menu's prompt is to be displayed
*/
void setupExit(){
menuOn = 0;
}
//this is used by the si5351 routines in the ubitx_5351 file
extern int32_t calibration;
extern uint32_t si5351bx_vcoa;
void setupFreq(){
int knob = 0;
int32_t prev_calibration;
displayDialog("Set Frequency", "Push TUNE to Save");
//round off the the nearest khz
frequency = (frequency/1000l)* 1000l;
setFrequency(frequency);
displayRawText("You should have a", 20, 50, DISPLAY_CYAN, DISPLAY_NAVY);
displayRawText("signal exactly at ", 20, 75, DISPLAY_CYAN, DISPLAY_NAVY);
ltoa(frequency/1000l, c, 10);
strcat(c, " KHz");
displayRawText(c, 20, 100, DISPLAY_CYAN, DISPLAY_NAVY);
displayRawText("Rotate to zerobeat", 20, 180, DISPLAY_CYAN, DISPLAY_NAVY);
//keep clear of any previous button press
while (btnDown())
active_delay(100);
active_delay(100);
prev_calibration = calibration;
calibration = 0;
// ltoa(calibration/8750, c, 10);
// strcpy(b, c);
// strcat(b, "Hz");
// printLine2(b);
while (!btnDown())
{
knob = enc_read();
if (knob != 0)
calibration += knob * 875;
/* else if (knob < 0)
calibration -= 875; */
else
continue; //don't update the frequency or the display
si5351bx_setfreq(0, usbCarrier); //set back the cardrier oscillator anyway, cw tx switches it off
si5351_set_calibration(calibration);
setFrequency(frequency);
//displayRawText("Rotate to zerobeat", 20, 120, DISPLAY_CYAN, DISPLAY_NAVY);
ltoa(calibration, b, 10);
displayText(b, 100, 140, 100, 26, DISPLAY_CYAN, DISPLAY_NAVY, DISPLAY_WHITE);
}
EEPROM.put(MASTER_CAL, calibration);
initOscillators();
si5351_set_calibration(calibration);
setFrequency(frequency);
//debounce and delay
while(btnDown())
active_delay(50);
active_delay(100);
}
void setupBFO(){
int knob = 0;
unsigned long prevCarrier;
prevCarrier = usbCarrier;
displayDialog("Set BFO", "Press TUNE to Save");
usbCarrier = 11053000l;
si5351bx_setfreq(0, usbCarrier);
printCarrierFreq(usbCarrier);
while (!btnDown()){
knob = enc_read();
if (knob != 0)
usbCarrier -= 50 * knob;
else
continue; //don't update the frequency or the display
si5351bx_setfreq(0, usbCarrier);
setFrequency(frequency);
printCarrierFreq(usbCarrier);
active_delay(100);
}
EEPROM.put(USB_CAL, usbCarrier);
si5351bx_setfreq(0, usbCarrier);
setFrequency(frequency);
updateDisplay();
menuOn = 0;
}
void setupCwDelay(){
int knob = 0;
int prev_cw_delay;
displayDialog("Set CW T/R Delay", "Press tune to Save");
active_delay(500);
prev_cw_delay = cwDelayTime;
itoa(10 * (int)cwDelayTime, b, 10);
strcat(b, " msec");
displayText(b, 100, 100, 120, 26, DISPLAY_CYAN, DISPLAY_BLACK, DISPLAY_BLACK);
while (!btnDown()){
knob = enc_read();
if (knob < 0 && cwDelayTime > 10)
cwDelayTime -= 10;
else if (knob > 0 && cwDelayTime < 100)
cwDelayTime += 10;
else
continue; //don't update the frequency or the display
itoa(10 * (int)cwDelayTime, b, 10);
strcat(b, " msec");
displayText(b, 100, 100, 120, 26, DISPLAY_CYAN, DISPLAY_BLACK, DISPLAY_BLACK);
}
EEPROM.put(CW_DELAYTIME, cwDelayTime);
// cwDelayTime = getValueByKnob(10, 1000, 50, cwDelayTime, "CW Delay>", " msec");
active_delay(500);
menuOn = 0;
}
void setupKeyer(){
int tmp_key, knob;
displayDialog("Set CW Keyer", "Press tune to Save");
if (!Iambic_Key)
displayText("< Hand Key >", 100, 100, 120, 26, DISPLAY_CYAN, DISPLAY_BLACK, DISPLAY_BLACK);
else if (keyerControl & IAMBICB)
displayText("< Iambic A >", 100, 100, 120, 26, DISPLAY_CYAN, DISPLAY_BLACK, DISPLAY_BLACK);
else
displayText("< Iambic B >", 100, 100, 120, 26, DISPLAY_CYAN, DISPLAY_BLACK, DISPLAY_BLACK);
if (!Iambic_Key)
tmp_key = 0; //hand key
else if (keyerControl & IAMBICB)
tmp_key = 2; //Iambic B
else
tmp_key = 1;
while (!btnDown())
{
knob = enc_read();
if (knob == 0){
active_delay(50);
continue;
}
if (knob < 0 && tmp_key > 0)
tmp_key--;
if (knob > 0)
tmp_key++;
if (tmp_key > 2)
tmp_key = 0;
if (tmp_key == 0)
displayText("< Hand Key >", 100, 100, 120, 26, DISPLAY_CYAN, DISPLAY_BLACK, DISPLAY_BLACK);
else if (tmp_key == 1)
displayText("< Iambic A >", 100, 100, 120, 26, DISPLAY_CYAN, DISPLAY_BLACK, DISPLAY_BLACK);
else if (tmp_key == 2)
displayText("< Iambic B >", 100, 100, 120, 26, DISPLAY_CYAN, DISPLAY_BLACK, DISPLAY_BLACK);
}
active_delay(500);
if (tmp_key == 0)
Iambic_Key = false;
else if (tmp_key == 1){
Iambic_Key = true;
keyerControl &= ~IAMBICB;
}
else if (tmp_key == 2){
Iambic_Key = true;
keyerControl |= IAMBICB;
}
EEPROM.put(CW_KEY_TYPE, tmp_key);
menuOn = 0;
}
void drawSetupMenu(){
displayClear(DISPLAY_BLACK);
displayText("Setup", 10, 10, 300, 35, DISPLAY_WHITE, DISPLAY_NAVY, DISPLAY_WHITE);
displayRect(10,10,300,220, DISPLAY_WHITE);
displayRawText("Set Freq...", 30, 50, DISPLAY_WHITE, DISPLAY_NAVY);
displayRawText("Set BFO...", 30, 80, DISPLAY_WHITE, DISPLAY_NAVY);
displayRawText("CW Delay...", 30, 110, DISPLAY_WHITE, DISPLAY_NAVY);
displayRawText("CW Keyer...", 30, 140, DISPLAY_WHITE, DISPLAY_NAVY);
displayRawText("Touch Screen...", 30, 170, DISPLAY_WHITE, DISPLAY_NAVY);
displayRawText("Exit", 30, 200, DISPLAY_WHITE, DISPLAY_NAVY);
}
static int prevPuck = -1;
void movePuck(int i){
if (prevPuck >= 0)
displayRect(15, 49 + (prevPuck * 30), 290, 25, DISPLAY_NAVY);
displayRect(15, 49 + (i * 30), 290, 25, DISPLAY_WHITE);
prevPuck = i;
}
void doSetup2(){
int select=0, i,btnState;
drawSetupMenu();
movePuck(select);
//wait for the button to be raised up
while(btnDown())
active_delay(50);
active_delay(50); //debounce
menuOn = 2;
while (menuOn){
i = enc_read();
if (i > 0){
if (select + i < 60)
select += i;
movePuck(select/10);
}
if (i < 0 && select - i >= 0){
select += i; //caught ya, i is already -ve here, so you add it
movePuck(select/10);
}
if (!btnDown()){
active_delay(50);
continue;
}
//wait for the touch to lift off and debounce
while(btnDown()){
active_delay(50);
}
active_delay(300);
if (select < 10)
setupFreq();
else if (select < 20 )
setupBFO();
else if (select < 30 )
setupCwDelay();
else if (select < 40)
setupKeyer();
else if (select < 50)
setupTouch();
else
break; //exit setup was chosen
//setupExit();
//redraw
drawSetupMenu();
}
//debounce the button
while(btnDown())
active_delay(50);
active_delay(50);
checkCAT();
guiUpdate();
}