-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathz-end.ino
340 lines (287 loc) · 8.98 KB
/
z-end.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
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
/******************************************************************************
*
* This file is part of the Arduino-Arcs project, see
* https://github.com/pavelmc/arduino-arcs
*
* Copyright (C) 2016...2017 Pavel Milanes (CO7WT) <[email protected]>
*
* This program is free software under the GNU GPL v3.0
*
* ***************************************************************************/
// main setup function
void setup() {
// set the defult values, before restoring theEEPROM ones
setDefaultVals();
#ifdef CAT_CONTROL
// CAT Library setup
cat.addCATPtt(catGoPtt);
cat.addCATAB(catGoToggleVFOs);
cat.addCATFSet(catSetFreq);
cat.addCATMSet(catSetMode);
cat.addCATGetFreq(catGetFreq);
cat.addCATGetMode(catGetMode);
cat.addCATSMeter(catGetSMeter);
cat.addCATTXStatus(catGetTXStatus);
// now we activate the library
cat.begin(38400, SERIAL_8N2);
#endif
#ifdef LCD
#ifdef SMETER
// LCD init, create the custom chars first
// depending on the selected smeter type
#ifdef SMETER_ALT
lcd.createChar(0, bar);
lcd.createChar(1, s1);
lcd.createChar(2, s3);
lcd.createChar(3, s5);
lcd.createChar(4, s7);
lcd.createChar(5, s9);
#else
// default
lcd.createChar(0, full);
lcd.createChar(1, half);
#endif
#endif // smeter
// now load the library
lcd.begin(16, 2);
lcd.clear();
#endif // nolcd
#ifdef ABUT
// analog buttons setup
abm.init(KEYS_PIN, 3, 20);
abm.add(bvfoab);
abm.add(bmode);
abm.add(brit);
abm.add(bsplit);
// how many memories this chip supports
#ifdef MEMORIES
memCount = (EEPROM.length() - MEMSTART) / sizeof(mmem);
// self limiting the mem amount to 100 (0-99)
// we have only two chars on the LCD and 100 mems are a lot
if (memCount > 99) memCount = 99;
#endif
#endif
#ifdef ROTARY
// buttons debounce & PTT
pinMode(btnPush, INPUT_PULLUP);
dbBtnPush.attach(btnPush);
dbBtnPush.interval(debounceInterval);
// pin mode of the PTT
pinMode(inPTT, INPUT_PULLUP);
dbPTT.attach(inPTT);
dbPTT.interval(debounceInterval);
// default awake mode is RX
#endif // ROTARY
// set PTT at the start to LOW aka RX
pinMode(PTT, OUTPUT);
digitalWrite(PTT, 0);
// I2C init
Wire.begin();
// check the EEPROM to know if I need to initialize it
if (checkInitEEPROM()) {
// just if it's already ok
loadEEPROMConfig();
} else {
#ifdef LCD
// full init, LCD banner
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Init EEPROM"));
lcd.setCursor(0, 1);
lcd.print(F("Please wait"));
#endif // nolcd
// init eeprom.
saveEEPROM();
#ifdef MEMORIES
wipeMEM();
#endif
// make a smart delay
smartDelay();
#ifdef LCD
lcd.clear();
#endif // nolcd
}
#ifdef LCD
// Welcome screen
lcd.clear();
lcd.print(F(" Aduino Arcs "));
lcd.setCursor(0, 1);
lcd.print(F("Fv: "));
lcd.print(FMW_VER);
lcd.print(F(" Mfv: "));
lcd.print(EEP_VER);
#endif // nolcd
// A software controlling the CAT via USB will reset the sketch upon
// connection, so we need turn the cat.check() when running the welcome
// banners (use case: Fldigi)
// make a smart delay
smartDelay();
#ifdef LCD
lcd.setCursor(0, 0);
lcd.print(F(" by Pavel CO7WT "));
#endif // nolcd
// make a smart delay
smartDelay();
#ifdef LCD
lcd.clear();
#endif // nolcd
#ifdef ROTARY // check for SETUP mode
// if you have no analog buttons then
// there is no meaning for the setup mode
#ifdef ABUT
// Check for setup mode
if (digitalRead(btnPush) == LOW) {
// sound signal
beep();
delay(50);
beop();
// rise the flag of setup mode for every body to see it.
runMode = false;
// beep signal to the user
tone(4, 800, 250);
delay(250);
#ifdef CAT_CONTROL
// CAT is disabled in SETUP mode
cat.enabled = false;
#endif
#ifdef LCD
// we are in the setup mode
lcd.setCursor(0, 0);
lcd.print(F(" You are in the "));
lcd.setCursor(0, 1);
lcd.print(F(" SETUP MODE "));
delay(2000);
lcd.clear();
// show setup mode
showConfig();
#endif // lcd
}
#endif // abut
#endif // rotary
// setting up VFO A as principal.
activeVFO = true;
ptrVFO = &u.a;
ptrMode = &u.aMode;
// init the wire lib
Wire.begin();
// start the VFOa and it's mode
updateAllFreq();
// reset the Si5351 for the forst time
Si5351_resets();
}
// forever loop
void loop() {
#ifdef ROTARY
// encoder check
encoderState = encoder.process();
if (encoderState == DIR_CW) encoderMoved(+1);
if (encoderState == DIR_CCW) encoderMoved(-1);
#endif // rotary
// LCD update check in normal mode
if (update and runMode) {
#ifdef LCD
// update and reset the flag
updateLcd();
#endif // nolcd
update = false;
}
#ifdef ROTARY
// check Hardware PTT and make the RX/TX changes
if (dbPTT.update()) {
// state changed
if (dbPTT.fell()) {
// line asserted (PTT Closed) going to TX
going2TX();
// clear the memory scan flag if active
#ifdef MEMORIES
#ifdef MEM_SCAN
mscan = false;
#endif
#endif
} else {
// line left open, going to RX
going2RX();
}
// update flag
update = true;
}
// debouce for the push
dbBtnPush.update();
tbool = dbBtnPush.fell();
if (runMode) {
// we are in normal mode
// step (push button)
if (tbool) {
// beep
beep();
// VFO step change
changeStep();
update = true;
}
#ifdef SMETER
// Second line of the LCD, I must show the bargraph only if not rit nor steps
if ((!ritActive and showStepCounter == 0) and smeterOk)
showBarGraph();
#endif
}
#ifdef ABUT // no setup mode if no analog buttons to change it
if (!runMode) {
// setup mode
// Push button is step in Config mode
if (tbool) {
// change the step and show it on the LCD
changeStep();
#ifdef LCD
showStep();
#endif // nolcd
}
}
#endif // abut
#endif // rotary
// timed actions, it ticks every 1/4 second (250 msecs)
if ((millis() - lastMilis) >= TICK_INTERVAL) {
// Reset the last reading to keep track
lastMilis = millis();
#ifdef SMETER
// I must sample the input for the bar graph
smeter();
#endif
// time counter for VFO remember after power off
if (qcounter < SAVE_INTERVAL) {
qcounter += 1;
} else {
// the saveEEPROM has already a mechanism to change only the parts
// that has changed, to protect the EEPROM of wear out
saveEEPROM();
qcounter = 0;
}
// step show time show the first time
if (showStepCounter >= STEP_SHOW_TIME) {
#ifdef LCD
showStep();
#endif // nolcd
}
// decrement timer
if (showStepCounter > 0) {
showStepCounter -= 1;
#ifdef SMETER
// flag to redraw the bar graph only if zero
if (showStepCounter == 0) barReDraw = true;
#endif
}
}
#ifdef CAT_CONTROL
// CAT check
cat.check();
#endif
#ifdef ABUT
// analog buttons check
abm.check();
#endif
#ifdef MEMORIES
#ifdef MEM_SCAN
// memory scan timming check
checkMemScan();
#endif
#endif
}