-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrailWave.cpp
executable file
·141 lines (123 loc) · 3.37 KB
/
TrailWave.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
#include "TrailWave.h"
void TrailRadio::init(U8G2_OLED* display) {
u8g2 = display;
mode = 0;
period = 100;
locked = false;
interfreq = IF;
cal = XT_CAL_F;
freq = FREQ_MIN;
vfo_is_A = true;
interfreqold = 0;
freqA = FREQ_MIN;
freqB = FREQ_MIN;
freqAdjustStep = 2;
step = 2;
rit_enabled = false;
pttButtonState = false;
setstep(false);
initPrefs();
memPresets();
displaySplashScreen();
delay(2000);
initialized = true;
}
void TrailRadio::update() {
if (freqold != freq || rit_enabled) {
tunegen();
freqold = freq;
displayUpdate();
}
if (interfreqold != interfreq) {
tunegen();
interfreqold = interfreq;
displayUpdate();
}
if (xo != x) {
xo = x;
displayUpdate();
}
if (rit_changed) {
displayUpdate();
rit_changed = false;
}
// Check if the SAVE_SETTINGS_PIN is LOW or POWER_DETECTION_PIN is LOW
if (digitalRead(SAVE_SETTINGS_PIN) == LOW || digitalRead(POWER_DETECTION_PIN) == LOW) {
prefsSave();
Serial.println("Save button pressed.");
}
// Check if the SAVE_SETTINGS_PIN is LOW or POWER_DETECTION_PIN is LOW
if (digitalRead(FACTORY_RESET_PIN) == LOW) {
prefsWipe();
Serial.println("Factory Wipe button pressed.");
}
//prefsSave();
handlePTT();
sgnalread();
}
void TrailRadio::changeMode() {
mode = (mode + 1) % 4;
displayUpdate();
}
void TrailRadio::sgnalread() {
smval = analogRead(ADC_PIN);
x = map(smval, 0, S_GAIN, 1, 14);
if (x > 14) x = 14;
}
void TrailRadio::tunegen() {
long tone_offset = 0;
if (mode == 0) tone_offset = 1500; // USB mode: +1.5 kHz.
if (mode == 1) tone_offset = -1500; // LSB mode: -1.5 kHz.
if (mode == 2) tone_offset = 700; // CW mode: +700 Hz for CW tone.
if (mode == 3) tone_offset = 1500; // DIG mode: +1.5 kHz.
if (!pttButtonState) {
if (rit_enabled && !split_mode) {
//si5351.set_freq((freq + rit_offset + tone_offset + (interfreq * 1000ULL)) * 100ULL, SI5351_CLK0);
} else {
//si5351.set_freq((freq + tone_offset + (interfreq * 1000ULL)) * 100ULL, SI5351_CLK0);
}
} else { // Transmit mode
if (split_mode) {
//si5351.set_freq((freqB + tone_offset + (interfreq * 1000ULL)) * 100ULL, SI5351_CLK0);
} else {
//si5351.set_freq((freqA + tone_offset + (interfreq * 1000ULL)) * 100ULL, SI5351_CLK0);
}
}
}
void TrailRadio::handlePTT() {
// Check if the RX_TX_PIN is LOW on the pcf8575
if (digitalRead(RX_TX_PIN) == LOW) {
pttButtonState = 1;
digitalWrite(RX_TX_LED_PIN, HIGH);
digitalWrite(TXRX_FILTER_RELAY_PIN, HIGH);
digitalWrite(TXRX_RELAY_PIN, HIGH);
// Handle split mode for VFOs
if (split_mode && vfo_is_A) {
swapVFOs();
}
// If push-to-talk is not active, handle frequency offset adjustments
if (!pushToTalk) {
freq += (rit_offset > 0) ? -rit_offset : rit_offset;
pushToTalk = true;
displayUpdate();
}
} else {
// RX_TX_PIN is HIGH, handle release of PTT
pttButtonState = 0;
digitalWrite(RX_TX_LED_PIN, LOW);
digitalWrite(TXRX_FILTER_RELAY_PIN, LOW);
digitalWrite(TXRX_RELAY_PIN, LOW);
// Swap VFOs back if needed in split mode
if (split_mode && !vfo_is_A) {
swapVFOs();
}
// Reset push-to-talk and adjust frequency if RIT is enabled
if (pushToTalk) {
if (rit_enabled) {
freq += rit_offset;
}
displayUpdate();
pushToTalk = false;
}
}
}