|
12 | 12 |
|
13 | 13 | // do you have SMETER?
|
14 | 14 | #ifdef SMETER
|
15 |
| - // defining the chars for the Smeter |
16 |
| - /** As per the LCD datasheet: |
| 15 | + |
| 16 | + // declaration for the special chars in the SMETER bar |
| 17 | + /************************************** |
| 18 | + * As per the LCD datasheet: |
| 19 | + * |
17 | 20 | * Each char is a matrix of 8x8
|
18 | 21 | * but internally they are:
|
19 | 22 | * > 5 bits per line (lower 5 bits)
|
20 | 23 | * > 7 lines
|
21 | 24 | * > 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; |
| 25 | + * |
| 26 | + **************************************/ |
| 27 | + #ifdef SMETER_ALT |
| 28 | + // Alternative SMeter, low resolution and more code size |
| 29 | + byte bar[8] = { |
| 30 | + B11111, |
| 31 | + B11111, |
| 32 | + B11111, |
| 33 | + B10001, |
| 34 | + B11111, |
| 35 | + B11111, |
| 36 | + B11111 |
| 37 | + }; |
| 38 | + |
| 39 | + byte s1[8] = { |
| 40 | + B11111, |
| 41 | + B10011, |
| 42 | + B11011, |
| 43 | + B11011, |
| 44 | + B11011, |
| 45 | + B10001, |
| 46 | + B11111 |
| 47 | + }; |
| 48 | + |
| 49 | + byte s3[8] = { |
| 50 | + B11111, |
| 51 | + B10001, |
| 52 | + B11101, |
| 53 | + B10001, |
| 54 | + B11101, |
| 55 | + B10001, |
| 56 | + B11111 |
| 57 | + }; |
| 58 | + |
| 59 | + byte s5[8] = { |
| 60 | + B11111, |
| 61 | + B10001, |
| 62 | + B10111, |
| 63 | + B10001, |
| 64 | + B11101, |
| 65 | + B10001, |
| 66 | + B11111 |
| 67 | + }; |
| 68 | + |
| 69 | + byte s7[8] = { |
| 70 | + B11111, |
| 71 | + B10001, |
| 72 | + B11101, |
| 73 | + B11011, |
| 74 | + B11011, |
| 75 | + B11011, |
| 76 | + B11111 |
| 77 | + }; |
| 78 | + |
| 79 | + byte s9[8] = { |
| 80 | + B11111, |
| 81 | + B10001, |
| 82 | + B10101, |
| 83 | + B10001, |
| 84 | + B11101, |
| 85 | + B11101, |
| 86 | + B11111 |
| 87 | + }; |
| 88 | + |
| 89 | + #else |
| 90 | + // Default SMEter, high resolution small code size |
| 91 | + byte half[8] = { |
| 92 | + B11000, |
| 93 | + B11000, |
| 94 | + B11000, |
| 95 | + B11000, |
| 96 | + B11000, |
| 97 | + B11000, |
| 98 | + B11000, |
| 99 | + B00000 |
| 100 | + }; |
| 101 | + |
| 102 | + byte full[8] = { |
| 103 | + B11011, |
| 104 | + B11011, |
| 105 | + B11011, |
| 106 | + B11011, |
| 107 | + B11011, |
| 108 | + B11011, |
| 109 | + B11011, |
| 110 | + B00000 |
| 111 | + }; |
| 112 | + #endif |
| 113 | + |
| 114 | + |
| 115 | + // bar show function two alternatives upon smeter type |
| 116 | + #ifdef SMETER_ALT |
| 117 | + // Alternative "1-3-5-7-9-+20" |
| 118 | + void showBarGraph() { |
| 119 | + // we are working on a 2x16 and we have 13 bars to show (0-12) |
| 120 | + unsigned long ave = 0, i; |
| 121 | + volatile static byte barMax = 0; |
| 122 | + |
| 123 | + // find the average |
| 124 | + for (i=0; i<BARGRAPH_SAMPLES; i++) ave += pep[i]; |
| 125 | + ave /= BARGRAPH_SAMPLES; |
| 126 | + |
| 127 | + // set the smeter reading on the global scope for CAT readings |
| 128 | + sMeter = ave; |
| 129 | + |
| 130 | + // scale it down to 0-12 from word |
| 131 | + byte local = map(ave, 0, 1023, 0, 12); |
| 132 | + |
| 133 | + // printing only the needed part of the bar, if growing or shrinking |
| 134 | + // if the same no action is required, remember we have to minimize the |
| 135 | + // writes to the LCD to minimize QRM |
| 136 | + |
| 137 | + // if we get a barReDraw = true; then reset to redrawn the entire bar |
| 138 | + if (barReDraw) { |
| 139 | + barMax = 0; |
| 140 | + // forcing the write of one line |
| 141 | + if (local == 0) local = 1; |
| 142 | + } |
85 | 143 |
|
86 |
| - // LCD position |
87 |
| - lcd.setCursor(3 + (barMax/2), 1); |
| 144 | + // growing bar: print the difference |
| 145 | + if (local > barMax) { |
| 146 | + // LCD position & print the bars |
| 147 | + lcd.setCursor(3 + barMax, 1); |
| 148 | + |
| 149 | + // write it |
| 150 | + for (i = barMax; i <= local; i++) { |
| 151 | + switch (i) { |
| 152 | + case 0: |
| 153 | + lcd.write(byte(1)); |
| 154 | + break; |
| 155 | + case 2: |
| 156 | + lcd.write(byte(2)); |
| 157 | + break; |
| 158 | + case 4: |
| 159 | + lcd.write(byte(3)); |
| 160 | + break; |
| 161 | + case 6: |
| 162 | + lcd.write(byte(4)); |
| 163 | + break; |
| 164 | + case 8: |
| 165 | + lcd.write(byte(5)); |
| 166 | + break; |
| 167 | + default: |
| 168 | + lcd.write(byte(0)); |
| 169 | + break; |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | + // second part of the erase, preparing for the blanking |
| 174 | + if (barReDraw) barMax = 12; |
| 175 | + } |
88 | 176 |
|
89 |
| - // full bars |
90 |
| - if (fb > 0) |
91 |
| - for (word i = 0; i < fb; i++) |
92 |
| - lcd.write(byte(0)); // full bar |
| 177 | + // shrinking bar: erase the old ones print spaces to erase just the diff |
| 178 | + if (barMax > local) { |
| 179 | + lcd.setCursor(3 + barMax, 1); |
| 180 | + spaces(barMax - local); |
| 181 | + } |
93 | 182 |
|
94 |
| - // half bars |
95 |
| - // must be always just one half bar |
96 |
| - if (hb > 0) |
97 |
| - lcd.write(byte(1)); // half bar |
| 183 | + // put the var for the next iteration |
| 184 | + barMax = local; |
| 185 | + //reset the redraw flag |
| 186 | + barReDraw = false; |
98 | 187 | }
|
| 188 | + #else |
| 189 | + // default smeter "|||||||||||||||||||" |
| 190 | + void showBarGraph() { |
| 191 | + // we are working on a 2x16 and we have 13 bars to show (0-13) |
| 192 | + // as we are on a double line we have 0-24 in value |
| 193 | + unsigned long ave = 0, i; |
| 194 | + volatile static byte barMax = 26; |
| 195 | + byte fb, hb; |
| 196 | + |
| 197 | + // pack for average |
| 198 | + for (i=0; i<BARGRAPH_SAMPLES; i++) ave += pep[i]; |
| 199 | + // reduce to mean |
| 200 | + ave /= BARGRAPH_SAMPLES; |
| 201 | + |
| 202 | + // set the smeter reading on the global scope for CAT readings |
| 203 | + sMeter = ave; |
| 204 | + |
| 205 | + // scale it down to 0-24 from word |
| 206 | + byte actual = map(ave, 0, 1023, 0, 26); |
| 207 | + |
| 208 | + // printing only the needed part of the bar, if growing or shrinking |
| 209 | + // if the same no action is required, remember we have to minimize the |
| 210 | + // writes to the LCD to minimize QRM |
| 211 | + |
| 212 | + // check for the bar redraw |
| 213 | + if (barReDraw) { |
| 214 | + barMax = 0; |
| 215 | + // always show at least a half bar |
| 216 | + if (actual == 0) actual = 1; |
| 217 | + } |
| 218 | + |
| 219 | + // growing bar: print the difference |
| 220 | + if (actual > barMax) { |
| 221 | + // reset barMax to a even number to avoid half bars loose |
| 222 | + if (barMax % 2) barMax += -1; |
99 | 223 |
|
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; |
| 224 | + // how many bars |
| 225 | + fb = (actual - barMax) / 2; |
| 226 | + hb = (actual - barMax) % 2; |
106 | 227 |
|
107 |
| - // fail safe we always want a single bar even if zero |
108 |
| - if (actual = 0) hb = 1; |
| 228 | + // LCD position |
| 229 | + lcd.setCursor(3 + (barMax/2), 1); |
109 | 230 |
|
110 |
| - // LCD position |
111 |
| - lcd.setCursor(3 + fb, 1); |
| 231 | + // full bars |
| 232 | + if (fb > 0) |
| 233 | + for (word i = 0; i < fb; i++) |
| 234 | + lcd.write(byte(0)); // full bar |
112 | 235 |
|
113 |
| - // half bars |
114 |
| - if (hb > 0) { |
| 236 | + // half bars |
115 | 237 | // must be always just one half bar
|
116 |
| - lcd.write(byte(1)); // half bar |
| 238 | + if (hb > 0) |
| 239 | + lcd.write(byte(1)); // half bar |
117 | 240 | }
|
118 | 241 |
|
119 |
| - // erase the next resting bars |
120 |
| - spaces(((barMax + 1) - actual) / 2); |
121 |
| - } |
| 242 | + // shrinking bar: erase the old ones |
| 243 | + // just print spaces to erase just the diff |
| 244 | + if (barMax > actual) { |
| 245 | + // base position, lower value |
| 246 | + fb = actual / 2; // base position |
| 247 | + hb = actual % 2; |
122 | 248 |
|
123 |
| - // put the var for the next iteration |
124 |
| - barMax = actual; |
| 249 | + // fail safe we always want a single bar even if zero |
| 250 | + if (actual = 0) hb = 1; |
125 | 251 |
|
126 |
| - // reset the bar redraw flag |
127 |
| - barReDraw = false; |
128 |
| - } |
| 252 | + // LCD position |
| 253 | + lcd.setCursor(3 + fb, 1); |
| 254 | + |
| 255 | + // half bars |
| 256 | + if (hb > 0) { |
| 257 | + // must be always just one half bar |
| 258 | + lcd.write(byte(1)); // half bar |
| 259 | + } |
| 260 | + |
| 261 | + // erase the next resting bars |
| 262 | + spaces(((barMax + 1) - actual) / 2); |
| 263 | + } |
| 264 | + |
| 265 | + // put the var for the next iteration |
| 266 | + barMax = actual; |
| 267 | + |
| 268 | + // reset the bar redraw flag |
| 269 | + barReDraw = false; |
| 270 | + } |
| 271 | + #endif |
129 | 272 |
|
130 | 273 |
|
131 | 274 | // take a sample an inject it on the array
|
|
0 commit comments