-
Notifications
You must be signed in to change notification settings - Fork 5
/
fb-rotary.ino
99 lines (83 loc) · 2.78 KB
/
fb-rotary.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
/******************************************************************************
*
* 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
*
* ***************************************************************************/
#ifdef ROTARY
// the encoder has moved
void encoderMoved(int dir) {
// check if in memory
#ifdef MEMORIES
if (!vfoMode) {
// we are in mem mode, move it
int tmem = mem + dir;
// limits check
if (tmem < 0) tmem = memCount;
if (tmem > (int)memCount) tmem = 0;
// update the mem setting
mem = word(tmem);
loadMEM(mem);
updateAllFreq();
// update flag and return
update = true;
return;
}
#endif
// check the run mode
if (runMode) {
// update freq
updateFreq(dir);
update = true;
}
#ifdef LCD // no meaning if no lcd
#ifdef ABUT // no meaning if no Analog buttons
if (!runMode) {
// update the values in the setup mode
updateSetupValues(dir);
}
#endif // abut
#endif // nolcd
}
// change the steps
void changeStep() {
// calculating the next step
if (step < 7) {
// simply increment
step += 1;
} else {
// default start mode is 2 (100Hz)
step = 2;
// in setup mode and just specific modes it's allowed to go to 1 hz
boolean am = false;
am = am or (config == CONFIG_USB) or (config == CONFIG_PPM);
if (!runMode and am) step = 1;
}
// if in normal mode reset the counter to show the change in the LCD
if (runMode) showStepCounter = STEP_SHOW_TIME;
}
// update freq procedure
void updateFreq(int dir) {
long freq = *ptrVFO;
if (ritActive) {
// we fix the steps to 10 Hz in rit mode
freq += 100 * dir;
// check we don't exceed the MAX_RIT
if (abs(tvfo - freq) > MAX_RIT) return;
} else {
// otherwise we use the default step on the environment
freq += getStep() * dir;
// check we don't exceed the limits
if(freq > F_MAX) freq = F_MIN;
if(freq < F_MIN) freq = F_MAX;
}
// apply the change
*ptrVFO = freq;
// update the output freq
setFreqVFO();
}
#endif // rotary