Skip to content

Commit 8f97bd2

Browse files
committed
testing new smeter
1 parent 3c61d32 commit 8f97bd2

File tree

3 files changed

+84
-110
lines changed

3 files changed

+84
-110
lines changed

fa-lcd.ino

Lines changed: 80 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -11,68 +11,6 @@
1111

1212

1313
#ifdef LCD
14-
// defining the chars for the Smeter
15-
byte bar[8] = {
16-
B11111,
17-
B11111,
18-
B11111,
19-
B10001,
20-
B11111,
21-
B11111,
22-
B11111
23-
};
24-
25-
byte s1[8] = {
26-
B11111,
27-
B10011,
28-
B11011,
29-
B11011,
30-
B11011,
31-
B10001,
32-
B11111
33-
};
34-
35-
byte s3[8] = {
36-
B11111,
37-
B10001,
38-
B11101,
39-
B10001,
40-
B11101,
41-
B10001,
42-
B11111
43-
};
44-
45-
byte s5[8] = {
46-
B11111,
47-
B10001,
48-
B10111,
49-
B10001,
50-
B11101,
51-
B10001,
52-
B11111
53-
};
54-
55-
byte s7[8] = {
56-
B11111,
57-
B10001,
58-
B11101,
59-
B11011,
60-
B11011,
61-
B11011,
62-
B11111
63-
};
64-
65-
byte s9[8] = {
66-
B11111,
67-
B10001,
68-
B10101,
69-
B10001,
70-
B11101,
71-
B11101,
72-
B11111
73-
};
74-
75-
7614
#ifdef ABUT
7715
// check some values don't go below zero
7816
void belowZero(long *value) {
@@ -544,77 +482,117 @@
544482
}
545483

546484

547-
// do you have SMETER
485+
// do you have SMETER?
548486
#ifdef SMETER
487+
// defining the chars for the Smeter
488+
/** As per the LCD datasheet:
489+
* Each char is a matrix of 8x8
490+
* but internally they are:
491+
* > 5 bits per line (lower 5 bits)
492+
* > 7 lines
493+
* > the underscore line
494+
***/
495+
496+
byte half[8] = {
497+
B11000,
498+
B11000,
499+
B11000,
500+
B11000,
501+
B11000,
502+
B11000,
503+
B11000,
504+
B00000
505+
};
506+
507+
byte full[8] = {
508+
B11011,
509+
B11011,
510+
B11011,
511+
B11011,
512+
B11011,
513+
B11011,
514+
B11011,
515+
B00000
516+
};
517+
518+
549519
// show the bar graph for the RX or TX modes
550520
void showBarGraph() {
551521
// we are working on a 2x16 and we have 13 bars to show (0-12)
522+
// as we are on a double line we have 0-24 in value
552523
unsigned long ave = 0, i;
553-
volatile static byte barMax = 0;
524+
volatile static byte barMax = 24;
525+
byte fb, hb;
554526

555-
// find the average
527+
// pack for average
556528
for (i=0; i<BARGRAPH_SAMPLES; i++) ave += pep[i];
529+
// reduce to mean
557530
ave /= BARGRAPH_SAMPLES;
558531

559532
// set the smeter reading on the global scope for CAT readings
560533
sMeter = ave;
561534

562-
// scale it down to 0-12 from word
563-
byte local = map(ave, 0, 1023, 0, 12);
535+
// scale it down to 0-24 from word
536+
byte local = map(ave, 0, 1023, 0, 24);
564537

565538
// printing only the needed part of the bar, if growing or shrinking
566539
// if the same no action is required, remember we have to minimize the
567540
// writes to the LCD to minimize QRM
568541

569-
// if we get a barReDraw = true; then reset to redrawn the entire bar
542+
// check for the bar redraw
570543
if (barReDraw) {
571544
barMax = 0;
572-
// forcing the write of one line
545+
// always show at least a half bar
573546
if (local == 0) local = 1;
574547
}
575548

576549
// growing bar: print the difference
577550
if (local > barMax) {
578-
// LCD position & print the bars
579-
lcd.setCursor(3 + barMax, 1);
580-
581-
// write it
582-
for (i = barMax; i <= local; i++) {
583-
switch (i) {
584-
case 0:
585-
lcd.write(byte(1));
586-
break;
587-
case 2:
588-
lcd.write(byte(2));
589-
break;
590-
case 4:
591-
lcd.write(byte(3));
592-
break;
593-
case 6:
594-
lcd.write(byte(4));
595-
break;
596-
case 8:
597-
lcd.write(byte(5));
598-
break;
599-
default:
600-
lcd.write(byte(0));
601-
break;
602-
}
603-
}
604-
605-
// second part of the erase, preparing for the blanking
606-
if (barReDraw) barMax = 12;
551+
// how many bars
552+
fb = (local - barMax) / 2;
553+
hb = (local - barMax) % 2;
554+
555+
// LCD position
556+
lcd.setCursor(3 + (barMax/2), 1);
557+
558+
// full bars
559+
if (fb > 0)
560+
for (word i = 0; i < fb; i++)
561+
lcd.write(byte(0)); // full bar
562+
563+
// half bars
564+
// must be always just one half bar
565+
if (hb > 0)
566+
lcd.write(byte(1)); // half bar
607567
}
608568

609-
// shrinking bar: erase the old ones print spaces to erase just the diff
569+
// shrinking bar: erase the old ones
570+
// just print spaces to erase just the diff
610571
if (barMax > local) {
611-
lcd.setCursor(3 + barMax, 1);
612-
spaces(barMax - local);
572+
// base position, lower value
573+
fb = local / 2; // base position
574+
hb = local % 2;
575+
576+
// fail safe we always want a single bar even if zero
577+
if (local = 0) hb = 1;
578+
579+
// LCD position
580+
lcd.setCursor(3 + fb, 1);
581+
582+
// half bars
583+
if (hb > 0) {
584+
// must be always just one half bar
585+
lcd.write(byte(1)); // half bar
586+
}
587+
588+
// erase the next resting bars
589+
spaces(((barMax + 1) - local) / 2);
613590
}
614591

615592
// put the var for the next iteration
616593
barMax = local;
617-
//reset the redraw flag
594+
595+
// reset the bar redraw flag
618596
barReDraw = false;
619597
}
620598

fc_cat.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@
8181

8282
// get the s meter status to CAT
8383
byte catGetSMeter() {
84-
// returns a byte in wich the s-meter is scaled to 4 bits (15)
85-
// it's scaled already this our code
84+
// returns a byte in wich the s-meter is scaled to 4 bits (1023 > 15)
8685
#ifdef SMETER
8786
return sMeter >> 6 ;
8887
#else

z-end.ino

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,10 @@ void setup() {
3232
#ifdef LCD
3333
#ifdef SMETER
3434
// LCD init, create the custom chars first
35-
lcd.createChar(0, bar);
36-
lcd.createChar(1, s1);
37-
lcd.createChar(2, s3);
38-
lcd.createChar(3, s5);
39-
lcd.createChar(4, s7);
40-
lcd.createChar(5, s9);
35+
lcd.createChar(0, full);
36+
lcd.createChar(1, half);
4137
#endif // smeter
38+
4239
// now load the library
4340
lcd.begin(16, 2);
4441
lcd.clear();

0 commit comments

Comments
 (0)