-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSSB_LCD_Display.cpp
280 lines (234 loc) · 6.96 KB
/
SSB_LCD_Display.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
#include "RadioControl.h"
#ifdef DISPLAY_LCD
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); //0x27 or 0x3F 0r 0x20 //1604 LCD/w I2C
//////////////////////////////////////////////////////////////////////
// //
// Display Routines //
// Display routines for 20x4 LCD //
// //
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// Display Layout 20x4 //
// 1111111111 //
// 01234567890123456789 //
// 0: A>xX.XXX.XXX xSB //
// 1: B>xX.XXX.XXX SPLIT //
// 2: RX S:123456789+++ //
// 3: CALL xxxx Hz vX.X //
//////////////////////////////////////////////////////////////////////
//************************displayBanner*****************************
// Sets up display line 3 - call sign, increment display and version
//
// Note - Does not use the input String (included for code compatibility
// with other display modules)
//
void displayBanner(String s) {
// Setup line 3 call and tuning increment
lcd.setCursor(0, 3);
lcd.print(CALLSIGN);
lcd.setCursor(12, 3);
lcd.print("Hz");
lcd.setCursor(16, 3);
lcd.print(F("v"));
lcd.print(VERSION);
}
//************************displaySmeter****************************
void displaySMeter(byte level) {
int i;
lcd.setCursor(6, 2);
lcd.print("S:");
for (i = 0; i < MAXSLEVELS; i++) {
if (level >= i) {
if (i < 9) {
lcd.print(i + 1);
} else {
lcd.print("+");
}
} else {
lcd.print(" ");
}
}
}
//************************displayVFOAB*******************************
// displayVFOAB(int VFO)
// Updates the display with flag for the currently active VFO - A or B
//
void displayVFOAB(int vfo) {
// Reset the active VFO flag
// Clear previous flag
lcd.setCursor(1,0);
lcd.print(F(" "));
lcd.setCursor(1,1);
lcd.print(F(" "));
// Set flag by currently active VFO
if (vfo == VFOA) {
lcd.setCursor(1, 0);
} else {
lcd.setCursor(1, 1);
}
lcd.print(F(">"));
}
//************************displayVFO*******************************
// displayVFO(vfo,freq)
// Updates the dispaly for the input vfo
// Displays the frequency subracting the bfo - sideband inversion
//
void displayVFO(int vfo, long freq) {
int row = 0;
if (vfo == VFOA) {
row = 0;
} else if (vfo == VFOB) {
row = 1;
}
// Update the frequency
lcd.setCursor(2, row);
if (freq < 10000000) {
lcd.print(" ");
}
lcd.print(int((freq / 1000000))); //millions
lcd.print(".");
lcd.print(((freq / 100000) % 10)); //hundredthousands
lcd.print(((freq / 10000) % 10)); //tenthousands
lcd.print(((freq / 1000) % 10)); //thousands
lcd.print(".");
lcd.print(((freq / 100) % 10)); //hundreds
lcd.print(((freq / 10) % 10)); //tens
lcd.print(((freq / 1) % 10)); //ones
}
//************************displayActVFO*******************************
// Updates the frequencey display for the current active VFO A or B
void displayActVFO(uint32_t freq) {
displayVFO(active_vfo, freq);
}
//************************displayActVFO*******************************
// Updates the frequencey display for the current alternate VFO A or B
extern void displayAltVFO(uint32_t freq) {
if (active_vfo == VFOA) {
displayVFO(VFOB, freq);
} else{
displayVFO(VFOA, freq);
}
}
//************************displayMode*******************************
//
// displaySideband(mode)
// Updates the current mode (sideband) indicator U or L
//
void displayMode(int mode) {
char sb = ' ';
if (mode == USB) {
sb = 'U';
} else if (mode == LSB) {
sb = 'L';
}
lcd.setCursor(13, 0);
lcd.print(sb);
}
void displayTxRx(int tx_rx) {
lcd.setCursor(0, 2);
if (tx_rx == RX) {
lcd.print(F("RX"));
} else {
lcd.print(F("TX"));
}
}
//************************displayIncr*******************************
//
// displayIncr(increment)
// Display the tuning increment
//
void displayIncr(unsigned long increment) {
String hertz = " "; // tune step display
#ifdef DEBUG
sprintf(debugmsg, "Increment: %ld", increment);
Serial.println(debugmsg);
#endif
if (increment == 10) {
hertz = F(" 10");
} else if (increment == 100) {
hertz = F(" 100");
} else if (increment == 1000) {
hertz = F(" 1K");
} else if (increment == 10000) {
hertz = F(" 10K");
} else if (increment == 100000) {
hertz = F("100K");
} else if (increment == 1000000) {
hertz = F(" 1M");
}
lcd.setCursor(7, 3);
lcd.print(hertz);
}
//************************displayTune*******************************
//
// displayTune(On)
// If On is TRUE displays TUNE message else clears it
//
void displayTune(bool On) {
lcd.setCursor(7, 2);
if (On == true) {
lcd.print(F("TUNE"));
} else {
lcd.print(F(" "));
}
}
void displayDebug(String msg) {
lcd.setCursor(7, 2);
lcd.print(msg);
}
//************************displaySplit*******************************
//
// displayTune(split)
// If split is TRUE displays SPLIT message else clears it
//
void displaySplit(boolean splt) {
lcd.setCursor(14, 1);
if (split == true) {
lcd.print(F("SPLIT"));
} else {
lcd.print(F(" "));
}
}
///////////////////////////////////////////////////////////////////////////
// displaySetup()
// Initialze and populate the display
///////////////////////////////////////////////////////////////////////////
void displaySetup(String banner,
uint32_t vfoActfreq, uint32_t vfoAltfreq,
uint32_t activeVFO,
int tx_rx,
int sideband,
boolean split,
uint32_t increment,
byte s_meter) {
lcd.init();
lcd.clear();
delay(100);
lcd.backlight();
// Setup fixed screeen elements
// Line 0 - VFO A
lcd.setCursor(0,0);
lcd.print(F("A"));
// Line 0 - sideband indicator
lcd.setCursor(14,0);
lcd.print(F("SB"));
// Line 1 VFO B
lcd.setCursor(0,1);
lcd.print(F("B"));
//
// Display the intitial values
//
displayBanner(banner);
displayActVFO(vfoActfreq);
displayAltVFO(vfoAltfreq);
displayVFOAB(activeVFO);
displayTxRx(tx_rx);
displayMode(sideband);
displaySplit(split);
displayIncr(increment);
#ifdef SMETER
displaySMeter(s_meter);
#endif
}
#endif