-
Notifications
You must be signed in to change notification settings - Fork 0
/
saveNsetup.ino
307 lines (267 loc) · 9.88 KB
/
saveNsetup.ino
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
void update_display()
{
save_frequency();
display_frequency();
set_band();
display_band();
display_sideband();
}
void set_vfo()
{
/* Serial.print("VFO : ");
Serial.println(vfo);
Serial.print("BFO : ");
Serial.println(bfo); */
#ifdef FIXED_BFO // eg in HFSig's bitx40 having fixed BFO osc
if (sideband == LSB)
vfo_tx = bfo - vfo; // + offset;
else
vfo_tx = vfo + bfo; // - offset; // USB generated by adding BFO so VFO ~19MHz for USB
#else
if (vfo < bfo)
vfo_tx = bfo - vfo + offset;
else
vfo_tx = vfo - bfo + offset;
#endif
/* Serial.print("VFO TX: ");
Serial.println(vfo_tx);*/
si5351.set_freq(((vfo_tx + if_offset)* SI5351_FREQ_MULT), SI5351_CLK0);
}
void save_frequency() // for temporarily saving in variables not in EEPROM
{
if (vfo_M_sel)
{
vfo_M = vfo;
bfo_M = bfo;
sb_M = sideband;
}
else if (vfo_A_sel)
{
vfo_A = vfo;
bfo_A = bfo;
sb_A = sideband;
}
else
{
vfo_B = vfo;
bfo_B = bfo;
sb_B = sideband;
}
}
void set_bfo()
{
// si5351.set_freq((bfo * SI5351_FREQ_MULT), SI5351_CLK1);
si5351.set_freq((bfo * SI5351_FREQ_MULT), SI5351_CLK2); //
}
void setup_vfo_screen() // sets up main screen for VFO etc display
{
tft.fillScreen(BLACK); // setup blank screen LIGHTGREY
// tft.fillRect(0, 0, 320, 121, BLUE); // top segment
tft.drawRect(0, 0, wd, ht, WHITE); // outer full border
tft.setTextSize(2);
tft.setTextColor(WHITE); //
/* tft.drawRect(smx, smy, smwd, smht, RED); // vert S meter
tft.fillRect(smx + 3, smy + 3, smwd - 4, smht - 5, YELLOW);
tft.setTextSize(2);
tft.setTextColor(RED);
tft.setCursor(smx + 5, smy + smht + 5); // print below s meter
tft.println("S");
*/
tft.drawRoundRect(vfox, vfoy, vfowd, vfoht, roundness, RED); // VFO A/B box outline
tft.fillRoundRect(vfox + 2, vfoy + 2, vfowd - 4, vfoht - 4, roundness - 4, GREEN); //VFO A/B box
tft.setCursor(vfox + 10, vfoy + 5);
tft.setTextSize(3);
tft.setTextColor(RED);
tft.print("VFO");
tft.drawRoundRect(memx, memy, memwd, memht, roundness, RED); // Mem box outline
tft.fillRoundRect(memx + 2, memy + 2, memwd - 4, memht - 4, roundness - 4, GREY); //Mem box
tft.setCursor(memx + 20, memy + 5);
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.print("MEM ");
display_mem();
tft.drawRoundRect(txrx, txry, txrwd, txrht, roundness, RED); // TxRx box outline
tft.fillRoundRect(txrx + 2, txry + 2, txrwd - 4, txrht - 4, roundness - 4, GREEN); //TxRx box
tft.setCursor(txrx + 10, txry + 5);
tft.setTextSize(3);
tft.setTextColor(BLUE);
tft.print("Rx");
tft.drawRoundRect(frqx, frqy, frqwd, frqht, roundness, WHITE); // freq box outline
// tft.fillRoundRect(frqx+2, frqy+2, frqwd-4, frqht-4, roundness-4, ORANGE); //freq box
tft.fillRoundRect(bandx, bandy, bandwd, bandht, roundness, WHITE); //band button outline
tft.fillRoundRect(bandx + 2, bandy + 2, bandwd - 4, bandht - 4, roundness - 4, GREY); //band
tft.fillRoundRect(stpx, stpy, stpwd, stpht, roundness, WHITE); // step button outline
tft.fillRoundRect(stpx + 2, stpy + 2, stpwd - 4, stpht - 4, roundness - 4, GREY); //step
tft.fillRoundRect(sbx, sby, sbwd, sbht, roundness, WHITE); // sideband button outline
tft.fillRoundRect(sbx + 2, sby + 2, sbwd - 4, sbht - 4, roundness - 4, GREEN); //sideband
tft.drawRoundRect(vmx, vmy, vmwd, vmht, roundness, RED); // VFO <> MEM button outline
tft.fillRoundRect(vmx + 2, vmy + 2, vmwd - 4, vmht - 4, roundness - 4, GREY); // V/M
tft.setTextSize(2);
tft.setTextColor(WHITE);
tft.setCursor(vmx + 10, vmy + 10);
tft.print("V> <M");
tft.drawRoundRect(bfox, bfoy, bfowd, bfoht, roundness, RED); //bfo button outline
tft.fillRoundRect(bfox + 2, bfoy + 2, bfowd - 4, bfoht - 4, roundness - 4, GREY); //bfo
tft.setTextSize(2);
tft.setTextColor(WHITE);
tft.setCursor(bfox + 16, bfoy + 10);
tft.print(bfo);
tft.drawRoundRect(svx, svy, svwd, svht, roundness, MAGENTA); // Save button outline
tft.fillRoundRect(svx + 2, svy + 2, svwd - 4, svht - 4, roundness - 4, RED); //Save
tft.setTextSize(2);
tft.setTextColor(WHITE);
tft.setCursor(svx + 10, svy + 10);
tft.print("SAVE");
// 5th row of buttons
tft.drawRoundRect(f1x, f1y, f1wd, f1ht, roundness, WHITE); // F1 button outline TxTimeOut
tft.fillRoundRect(f1x + 2, f1y + 2, f1wd - 4, f1ht - 4, roundness - 4, GREEN); //F1
tft.setTextSize(2);
tft.setTextColor(BLUE);
tft.setCursor(f1x +5, f1y + 8);
tft.print("TxTmO");
tft.drawRoundRect(f2x, f2y, f2wd, f2ht, roundness, GREEN); // F2 button outline
tft.fillRoundRect(f2x + 2, f2y + 2, f2wd - 4, f2ht - 4, roundness - 4, NAVY); //F2
tft.setTextSize(2);
tft.setTextColor(WHITE);
tft.setCursor(f2x + 20, f2y + 6);
tft.print("F2");
tft.drawRoundRect(f3x, f3y, f3wd, f3ht, roundness, GREEN); // F3 button outline
tft.fillRoundRect(f3x + 2, f3y + 2, f3wd - 4, f3ht - 4, roundness - 4, PURPLE); //F3
tft.setTextSize(2);
tft.setTextColor(WHITE);
tft.setCursor(f3x + 25, f3y + 6);
tft.print("F3");
tft.drawRoundRect(f4x, f4y, f4wd, f4ht, roundness, GREEN); // F4 button outline
tft.fillRoundRect(f4x + 2, f4y + 2, f4wd - 4, f4ht - 4, roundness - 4, GREENYELLOW); //F4
tft.setTextSize(2);
tft.setTextColor(MAROON);
tft.setCursor(f4x + 25, f4y + 6);
tft.print("F4");
tft.drawRect(botx, boty, botwd, botht, WHITE); // surrounding RECT
tft.fillRect(botx + 2, boty + 2, botwd - 4, botht - 4, BLACK); // bot strip
tft.setTextColor(WHITE, BLUE);
tft.setCursor(botwd, boty + 2);
tft.print(Ver);
} // end of setup_vfo_screen()
//---------------------------
/////// $$$ EEPROM related
void init_eprom() // write some info on EEPROM when initially loaded or when magic number changes
{
EEPROM.write(eprom_base_addr, magic_no); // check byte may be same as ver no at 0 address
display_mem_msg("InitEPrm");
//display_msg(60, "Init EEPROM");
ch_info = {vfo_A, bfo_LSB, LSB};
address = eprom_base_addr + 1 + sizeof(ch_info) * 1; // initial infos for VFO A
EEPROM_writeAnything(address, ch_info);
// ch_info={vfo_B, bfo_USB, USB}; //or
ch_info.s_vfo = vfo_B; // initial values of VFO B
ch_info.s_bfo = bfo_USB;
ch_info.s_sb = 2 ;
address = eprom_base_addr + 1 + sizeof(ch_info) * 2; // initial infos for VFO B
EEPROM_writeAnything(address, ch_info);
// Now store all 13 channels
for (int i = 1; i <= MAX_BANDS; i++) // starting from 1st entry in table of freq
{
ch_info.s_vfo = VFO_T[i];
if (VFO_T[i] < 10000000)
{
ch_info.s_bfo = bfo_LSB;
ch_info.s_sb = LSB;
}
else
{
ch_info.s_bfo = bfo_USB;
ch_info.s_sb = USB;
}
address = eprom_base_addr + 1 + sizeof(ch_info) * (i + 2); // first byte for magic no and first 2 infos for VFO A & B
EEPROM_writeAnything(address, ch_info);
}
vfo = 7100000;
for (int i = MAX_BANDS + 1; i <= 24; i++) // starting from
{
ch_info.s_vfo = vfo;
ch_info.s_bfo = bfo_LSB;
ch_info.s_sb = LSB;
address = eprom_base_addr + 1 + sizeof(ch_info) * (i + 2); // first byte for magic no and first 2 infos for VFO A & B
EEPROM_writeAnything(address, ch_info);
}
vfo = 14000000;
for (int i = 25; i <= 50; i++) // starting from 160m
{
ch_info.s_vfo = vfo;
ch_info.s_bfo = bfo_USB;
ch_info.s_sb = USB;
address = eprom_base_addr + 1 + sizeof(ch_info) * (i + 2); // first byte for magic no and first 2 infos for VFO A & B
EEPROM_writeAnything(address, ch_info);
}
vfo = 14200000;
for (int i = 51; i <= max_memory_ch; i++) // starting from 160m
{
ch_info.s_vfo = vfo;
ch_info.s_bfo = bfo_USB;
ch_info.s_sb = USB;
address = eprom_base_addr + 1 + sizeof(ch_info) * (i + 2); // first byte for magic no and first 2 infos for VFO A & B
EEPROM_writeAnything(address, ch_info);
}
//display_msg(60, " ");
// clear area
tft.drawRoundRect(memx, memy, memwd, memht, roundness, RED); // Mem box outline
tft.fillRoundRect(memx + 2, memy + 2, memwd - 4, memht - 4, roundness - 4, GREY); //Mem box
tft.setCursor(memx + 20, memy + 5);
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.print("MEM ");
display_mem();
}
void read_eprom() // should be called at powerup to retrieve stored values for vfos A and B
{
//display_msg(60, "Read EEPROM");
display_mem_msg("RdEPr");
address = eprom_base_addr + 1 + sizeof(ch_info) * 1; // first infos for VFO A
EEPROM_readAnything(address, ch_info);
vfo_A = ch_info.s_vfo ; // initial values of VFO A
bfo_A = ch_info.s_bfo;
sb_A = ch_info.s_sb;
address = eprom_base_addr + 1 + sizeof(ch_info) * 2; // second infos for VFO B
EEPROM_readAnything(address, ch_info);
vfo_B = ch_info.s_vfo ; // initial values of VFO B
bfo_B = ch_info.s_bfo;
sb_B = ch_info.s_sb;
memCh = 1;
read_ch(); // for 1st mem channel also
//display_msg(60, " ");
// clear area
tft.drawRoundRect(memx, memy, memwd, memht, roundness, RED); // Mem box outline
tft.fillRoundRect(memx + 2, memy + 2, memwd - 4, memht - 4, roundness - 4, GREY); //Mem box
tft.setCursor(memx + 20, memy + 5);
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.print("MEM ");
display_mem();
}
void read_ch() // read channel info from eeprom when ever mem ch no changed
{
address = eprom_base_addr + 1 + sizeof(ch_info) * (memCh + 2); // info for mem channel displayed
EEPROM_readAnything(address, ch_info);
vfo_M = ch_info.s_vfo ;
bfo_M = ch_info.s_bfo ;
sb_M = ch_info.s_sb;
}
void write_ch() // write memory channel into eeprom
{
ch_info = {vfo_M, bfo_M, sb_M};
address = eprom_base_addr + 1 + sizeof(ch_info) * (memCh + 2); // initial infos for VFO A
EEPROM_writeAnything(address, ch_info);
}
void write_vfo_A()
{
ch_info = {vfo_A, bfo_A, sb_A};
address = eprom_base_addr + 1 + sizeof(ch_info) * 1; // initial infos for VFO A
EEPROM_writeAnything(address, ch_info);
}
void write_vfo_B()
{
ch_info = {vfo_B, bfo_B, sb_B};
address = eprom_base_addr + 1 + sizeof(ch_info) * 2; // initial infos for VFO B
EEPROM_writeAnything(address, ch_info);
}