Skip to content

Commit 47df9bf

Browse files
committed
Preparations for an alternative SMeter graphics
1 parent 6e7b6b0 commit 47df9bf

File tree

3 files changed

+176
-155
lines changed

3 files changed

+176
-155
lines changed

arduino-arcs.ino

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,13 @@ struct userData u;
299299
#endif // smeter
300300
#endif // nolcd
301301

302+
// You have two alternatives for the SMeter graphics
303+
// The default is a simple bar with 24 points (high) resolution
304+
// The alternative is a low resolution one with 12 points
305+
// but numbers in the 1-3-5-7-9-+20
306+
//
307+
// If you want the alternative just uncomment this code below
308+
#define SMETER_ALT True
302309

303310
// run mode constants
304311
#define MODE_LSB 0

fa-lcd.ino

Lines changed: 0 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -475,159 +475,4 @@
475475
spaces(11);
476476
}
477477

478-
479-
// do you have SMETER?
480-
#ifdef SMETER
481-
// defining the chars for the Smeter
482-
/** As per the LCD datasheet:
483-
* Each char is a matrix of 8x8
484-
* but internally they are:
485-
* > 5 bits per line (lower 5 bits)
486-
* > 7 lines
487-
* > the underscore line
488-
***/
489-
490-
byte half[8] = {
491-
B11000,
492-
B11000,
493-
B11000,
494-
B11000,
495-
B11000,
496-
B11000,
497-
B11000,
498-
B00000
499-
};
500-
501-
byte full[8] = {
502-
B11011,
503-
B11011,
504-
B11011,
505-
B11011,
506-
B11011,
507-
B11011,
508-
B11011,
509-
B00000
510-
};
511-
512-
513-
// show the bar graph for the RX or TX modes
514-
void showBarGraph() {
515-
// we are working on a 2x16 and we have 13 bars to show (0-14)
516-
// as we are on a double line we have 0-24 in value
517-
unsigned long ave = 0, i;
518-
volatile static byte barMax = 28;
519-
byte fb, hb;
520-
521-
// pack for average
522-
for (i=0; i<BARGRAPH_SAMPLES; i++) ave += pep[i];
523-
// reduce to mean
524-
ave /= BARGRAPH_SAMPLES;
525-
526-
// set the smeter reading on the global scope for CAT readings
527-
sMeter = ave;
528-
529-
// scale it down to 0-24 from word
530-
byte local = map(ave, 0, 1023, 0, 28);
531-
532-
// printing only the needed part of the bar, if growing or shrinking
533-
// if the same no action is required, remember we have to minimize the
534-
// writes to the LCD to minimize QRM
535-
536-
// check for the bar redraw
537-
if (barReDraw) {
538-
barMax = 0;
539-
// always show at least a half bar
540-
if (local == 0) local = 1;
541-
}
542-
543-
// growing bar: print the difference
544-
if (local > barMax) {
545-
// how many bars
546-
fb = (local - barMax) / 2;
547-
hb = (local - barMax) % 2;
548-
549-
// LCD position
550-
lcd.setCursor(3 + (barMax/2), 1);
551-
552-
// full bars
553-
if (fb > 0)
554-
for (word i = 0; i < fb; i++)
555-
lcd.write(byte(0)); // full bar
556-
557-
// half bars
558-
// must be always just one half bar
559-
if (hb > 0)
560-
lcd.write(byte(1)); // half bar
561-
}
562-
563-
// shrinking bar: erase the old ones
564-
// just print spaces to erase just the diff
565-
if (barMax > local) {
566-
// base position, lower value
567-
fb = local / 2; // base position
568-
hb = local % 2;
569-
570-
// fail safe we always want a single bar even if zero
571-
if (local = 0) hb = 1;
572-
573-
// LCD position
574-
lcd.setCursor(3 + fb, 1);
575-
576-
// half bars
577-
if (hb > 0) {
578-
// must be always just one half bar
579-
lcd.write(byte(1)); // half bar
580-
}
581-
582-
// erase the next resting bars
583-
spaces(((barMax + 1) - local) / 2);
584-
}
585-
586-
// put the var for the next iteration
587-
barMax = local;
588-
589-
// reset the bar redraw flag
590-
barReDraw = false;
591-
}
592-
593-
594-
// take a sample an inject it on the array
595-
void takeSample() {
596-
// reference is 5v
597-
word val;
598-
byte adcPin = 1;
599-
600-
// check if TX
601-
if (tx) adcPin = 0;
602-
// take sample
603-
val = analogRead(adcPin);
604-
605-
// push it in the array
606-
for (byte i = 0; i < BARGRAPH_SAMPLES - 1; i++) pep[i] = pep[i + 1];
607-
pep[BARGRAPH_SAMPLES - 1] = val;
608-
}
609-
610-
611-
// smeter reading, this take a sample of the smeter/txpower each time; an will
612-
// rise a flag when they have rotated the array of measurements 2/3 times to
613-
// have a moving average
614-
void smeter() {
615-
// static smeter array counter
616-
volatile static byte smeterCount = 0;
617-
618-
// no matter what, I must keep taking samples
619-
takeSample();
620-
621-
// it has rotated already?
622-
if (smeterCount > (BARGRAPH_SAMPLES * 2 / 3)) {
623-
// rise the flag about the need to show the bar graph and reset the count
624-
smeterOk = true;
625-
smeterCount = 0;
626-
} else {
627-
// just increment it
628-
smeterCount += 1;
629-
}
630-
}
631-
#endif
632-
633478
#endif // lcd

fa-smeter.ino

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/******************************************************************************
2+
*
3+
* This file is part of the Arduino-Arcs project, see
4+
* https://github.com/pavelmc/arduino-arcs
5+
*
6+
* Copyright (C) 2016...2017 Pavel Milanes (CO7WT) <pavelmc@gmail.com>
7+
*
8+
* This program is free software under the GNU GPL v3.0
9+
*
10+
* ***************************************************************************/
11+
12+
13+
// do you have SMETER?
14+
#ifdef SMETER
15+
// defining the chars for the Smeter
16+
/** As per the LCD datasheet:
17+
* Each char is a matrix of 8x8
18+
* but internally they are:
19+
* > 5 bits per line (lower 5 bits)
20+
* > 7 lines
21+
* > the underscore line
22+
***/
23+
24+
byte half[8] = {
25+
B11000,
26+
B11000,
27+
B11000,
28+
B11000,
29+
B11000,
30+
B11000,
31+
B11000,
32+
B00000
33+
};
34+
35+
byte full[8] = {
36+
B11011,
37+
B11011,
38+
B11011,
39+
B11011,
40+
B11011,
41+
B11011,
42+
B11011,
43+
B00000
44+
};
45+
46+
47+
// show the bar graph for the RX or TX modes
48+
void showBarGraph() {
49+
// we are working on a 2x16 and we have 13 bars to show (0-13)
50+
// as we are on a double line we have 0-24 in value
51+
unsigned long ave = 0, i;
52+
volatile static byte barMax = 26;
53+
byte fb, hb;
54+
55+
// pack for average
56+
for (i=0; i<BARGRAPH_SAMPLES; i++) ave += pep[i];
57+
// reduce to mean
58+
ave /= BARGRAPH_SAMPLES;
59+
60+
// set the smeter reading on the global scope for CAT readings
61+
sMeter = ave;
62+
63+
// scale it down to 0-24 from word
64+
byte actual = map(ave, 0, 1023, 0, 26);
65+
66+
// printing only the needed part of the bar, if growing or shrinking
67+
// if the same no action is required, remember we have to minimize the
68+
// writes to the LCD to minimize QRM
69+
70+
// check for the bar redraw
71+
if (barReDraw) {
72+
barMax = 0;
73+
// always show at least a half bar
74+
if (actual == 0) actual = 1;
75+
}
76+
77+
// growing bar: print the difference
78+
if (actual > barMax) {
79+
// reset barMax to a even number to avoid half bars loose
80+
if (barMax % 2) barMax += -1;
81+
82+
// how many bars
83+
fb = (actual - barMax) / 2;
84+
hb = (actual - barMax) % 2;
85+
86+
// LCD position
87+
lcd.setCursor(3 + (barMax/2), 1);
88+
89+
// full bars
90+
if (fb > 0)
91+
for (word i = 0; i < fb; i++)
92+
lcd.write(byte(0)); // full bar
93+
94+
// half bars
95+
// must be always just one half bar
96+
if (hb > 0)
97+
lcd.write(byte(1)); // half bar
98+
}
99+
100+
// shrinking bar: erase the old ones
101+
// just print spaces to erase just the diff
102+
if (barMax > actual) {
103+
// base position, lower value
104+
fb = actual / 2; // base position
105+
hb = actual % 2;
106+
107+
// fail safe we always want a single bar even if zero
108+
if (actual = 0) hb = 1;
109+
110+
// LCD position
111+
lcd.setCursor(3 + fb, 1);
112+
113+
// half bars
114+
if (hb > 0) {
115+
// must be always just one half bar
116+
lcd.write(byte(1)); // half bar
117+
}
118+
119+
// erase the next resting bars
120+
spaces(((barMax + 1) - actual) / 2);
121+
}
122+
123+
// put the var for the next iteration
124+
barMax = actual;
125+
126+
// reset the bar redraw flag
127+
barReDraw = false;
128+
}
129+
130+
131+
// take a sample an inject it on the array
132+
void takeSample() {
133+
// reference is 5v
134+
word val;
135+
byte adcPin = 1;
136+
137+
// check if TX
138+
if (tx) adcPin = 0;
139+
// take sample
140+
val = analogRead(adcPin);
141+
142+
// push it in the array
143+
for (byte i = 0; i < BARGRAPH_SAMPLES - 1; i++) pep[i] = pep[i + 1];
144+
pep[BARGRAPH_SAMPLES - 1] = val;
145+
}
146+
147+
148+
// smeter reading, this take a sample of the smeter/txpower each time; an will
149+
// rise a flag when they have rotated the array of measurements 2/3 times to
150+
// have a moving average
151+
void smeter() {
152+
// static smeter array counter
153+
volatile static byte smeterCount = 0;
154+
155+
// no matter what, I must keep taking samples
156+
takeSample();
157+
158+
// it has rotated already?
159+
if (smeterCount > (BARGRAPH_SAMPLES * 2 / 3)) {
160+
// rise the flag about the need to show the bar graph and reset the count
161+
smeterOk = true;
162+
smeterCount = 0;
163+
} else {
164+
// just increment it
165+
smeterCount += 1;
166+
}
167+
}
168+
169+
#endif

0 commit comments

Comments
 (0)