Skip to content

Commit

Permalink
More preparations for the alternative smeter
Browse files Browse the repository at this point in the history
  • Loading branch information
stdevPavelmc committed Nov 11, 2017
1 parent 47df9bf commit 14e9ffe
Show file tree
Hide file tree
Showing 2 changed files with 247 additions and 98 deletions.
335 changes: 239 additions & 96 deletions fa-smeter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,120 12,263 @@

// do you have SMETER?
#ifdef SMETER
// defining the chars for the Smeter
/** As per the LCD datasheet:

// declaration for the special chars in the SMETER bar
/**************************************
* As per the LCD datasheet:
*
* Each char is a matrix of 8x8
* but internally they are:
* > 5 bits per line (lower 5 bits)
* > 7 lines
* > the underscore line
***/

byte half[8] = {
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B00000
};

byte full[8] = {
B11011,
B11011,
B11011,
B11011,
B11011,
B11011,
B11011,
B00000
};


// show the bar graph for the RX or TX modes
void showBarGraph() {
// we are working on a 2x16 and we have 13 bars to show (0-13)
// as we are on a double line we have 0-24 in value
unsigned long ave = 0, i;
volatile static byte barMax = 26;
byte fb, hb;

// pack for average
for (i=0; i<BARGRAPH_SAMPLES; i ) ave = pep[i];
// reduce to mean
ave /= BARGRAPH_SAMPLES;

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

// scale it down to 0-24 from word
byte actual = map(ave, 0, 1023, 0, 26);

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

// check for the bar redraw
if (barReDraw) {
barMax = 0;
// always show at least a half bar
if (actual == 0) actual = 1;
}

// growing bar: print the difference
if (actual > barMax) {
// reset barMax to a even number to avoid half bars loose
if (barMax % 2) barMax = -1;

// how many bars
fb = (actual - barMax) / 2;
hb = (actual - barMax) % 2;
*
**************************************/
#ifdef SMETER_ALT
// Alternative SMeter, low resolution and more code size
byte bar[8] = {
B11111,
B11111,
B11111,
B10001,
B11111,
B11111,
B11111
};

byte s1[8] = {
B11111,
B10011,
B11011,
B11011,
B11011,
B10001,
B11111
};

byte s3[8] = {
B11111,
B10001,
B11101,
B10001,
B11101,
B10001,
B11111
};

byte s5[8] = {
B11111,
B10001,
B10111,
B10001,
B11101,
B10001,
B11111
};

byte s7[8] = {
B11111,
B10001,
B11101,
B11011,
B11011,
B11011,
B11111
};

byte s9[8] = {
B11111,
B10001,
B10101,
B10001,
B11101,
B11101,
B11111
};

#else
// Default SMEter, high resolution small code size
byte half[8] = {
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B00000
};

byte full[8] = {
B11011,
B11011,
B11011,
B11011,
B11011,
B11011,
B11011,
B00000
};
#endif


// bar show function two alternatives upon smeter type
#ifdef SMETER_ALT
// Alternative "1-3-5-7-9- 20"
void showBarGraph() {
// we are working on a 2x16 and we have 13 bars to show (0-12)
unsigned long ave = 0, i;
volatile static byte barMax = 0;

// find the average
for (i=0; i<BARGRAPH_SAMPLES; i ) ave = pep[i];
ave /= BARGRAPH_SAMPLES;

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

// scale it down to 0-12 from word
byte local = map(ave, 0, 1023, 0, 12);

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

// if we get a barReDraw = true; then reset to redrawn the entire bar
if (barReDraw) {
barMax = 0;
// forcing the write of one line
if (local == 0) local = 1;
}

// LCD position
lcd.setCursor(3 (barMax/2), 1);
// growing bar: print the difference
if (local > barMax) {
// LCD position & print the bars
lcd.setCursor(3 barMax, 1);

// write it
for (i = barMax; i <= local; i ) {
switch (i) {
case 0:
lcd.write(byte(1));
break;
case 2:
lcd.write(byte(2));
break;
case 4:
lcd.write(byte(3));
break;
case 6:
lcd.write(byte(4));
break;
case 8:
lcd.write(byte(5));
break;
default:
lcd.write(byte(0));
break;
}
}

// second part of the erase, preparing for the blanking
if (barReDraw) barMax = 12;
}

// full bars
if (fb > 0)
for (word i = 0; i < fb; i )
lcd.write(byte(0)); // full bar
// shrinking bar: erase the old ones print spaces to erase just the diff
if (barMax > local) {
lcd.setCursor(3 barMax, 1);
spaces(barMax - local);
}

// half bars
// must be always just one half bar
if (hb > 0)
lcd.write(byte(1)); // half bar
// put the var for the next iteration
barMax = local;
//reset the redraw flag
barReDraw = false;
}
#else
// default smeter "|||||||||||||||||||"
void showBarGraph() {
// we are working on a 2x16 and we have 13 bars to show (0-13)
// as we are on a double line we have 0-24 in value
unsigned long ave = 0, i;
volatile static byte barMax = 26;
byte fb, hb;

// pack for average
for (i=0; i<BARGRAPH_SAMPLES; i ) ave = pep[i];
// reduce to mean
ave /= BARGRAPH_SAMPLES;

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

// scale it down to 0-24 from word
byte actual = map(ave, 0, 1023, 0, 26);

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

// check for the bar redraw
if (barReDraw) {
barMax = 0;
// always show at least a half bar
if (actual == 0) actual = 1;
}

// growing bar: print the difference
if (actual > barMax) {
// reset barMax to a even number to avoid half bars loose
if (barMax % 2) barMax = -1;

// shrinking bar: erase the old ones
// just print spaces to erase just the diff
if (barMax > actual) {
// base position, lower value
fb = actual / 2; // base position
hb = actual % 2;
// how many bars
fb = (actual - barMax) / 2;
hb = (actual - barMax) % 2;

// fail safe we always want a single bar even if zero
if (actual = 0) hb = 1;
// LCD position
lcd.setCursor(3 (barMax/2), 1);

// LCD position
lcd.setCursor(3 fb, 1);
// full bars
if (fb > 0)
for (word i = 0; i < fb; i )
lcd.write(byte(0)); // full bar

// half bars
if (hb > 0) {
// half bars
// must be always just one half bar
lcd.write(byte(1)); // half bar
if (hb > 0)
lcd.write(byte(1)); // half bar
}

// erase the next resting bars
spaces(((barMax 1) - actual) / 2);
}
// shrinking bar: erase the old ones
// just print spaces to erase just the diff
if (barMax > actual) {
// base position, lower value
fb = actual / 2; // base position
hb = actual % 2;

// put the var for the next iteration
barMax = actual;
// fail safe we always want a single bar even if zero
if (actual = 0) hb = 1;

// reset the bar redraw flag
barReDraw = false;
}
// LCD position
lcd.setCursor(3 fb, 1);

// half bars
if (hb > 0) {
// must be always just one half bar
lcd.write(byte(1)); // half bar
}

// erase the next resting bars
spaces(((barMax 1) - actual) / 2);
}

// put the var for the next iteration
barMax = actual;

// reset the bar redraw flag
barReDraw = false;
}
#endif


// take a sample an inject it on the array
Expand Down
10 changes: 8 additions & 2 deletions z-end.ino
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 32,14 @@ void setup() {
#ifdef LCD
#ifdef SMETER
// LCD init, create the custom chars first
lcd.createChar(0, full);
lcd.createChar(1, half);
// depending on the selected smeter type
#if SMETER_ALT

#else
// default
lcd.createChar(0, full);
lcd.createChar(1, half);
#endif
#endif // smeter

// now load the library
Expand Down

0 comments on commit 14e9ffe

Please sign in to comment.