|
11 | 11 |
|
12 | 12 |
|
13 | 13 | #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 | | - |
76 | 14 | #ifdef ABUT |
77 | 15 | // check some values don't go below zero |
78 | 16 | void belowZero(long *value) { |
|
544 | 482 | } |
545 | 483 |
|
546 | 484 |
|
547 | | - // do you have SMETER |
| 485 | + // do you have SMETER? |
548 | 486 | #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 | + |
549 | 519 | // show the bar graph for the RX or TX modes |
550 | 520 | void showBarGraph() { |
551 | 521 | // 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 |
552 | 523 | unsigned long ave = 0, i; |
553 | | - volatile static byte barMax = 0; |
| 524 | + volatile static byte barMax = 24; |
| 525 | + byte fb, hb; |
554 | 526 |
|
555 | | - // find the average |
| 527 | + // pack for average |
556 | 528 | for (i=0; i<BARGRAPH_SAMPLES; i++) ave += pep[i]; |
| 529 | + // reduce to mean |
557 | 530 | ave /= BARGRAPH_SAMPLES; |
558 | 531 |
|
559 | 532 | // set the smeter reading on the global scope for CAT readings |
560 | 533 | sMeter = ave; |
561 | 534 |
|
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); |
564 | 537 |
|
565 | 538 | // printing only the needed part of the bar, if growing or shrinking |
566 | 539 | // if the same no action is required, remember we have to minimize the |
567 | 540 | // writes to the LCD to minimize QRM |
568 | 541 |
|
569 | | - // if we get a barReDraw = true; then reset to redrawn the entire bar |
| 542 | + // check for the bar redraw |
570 | 543 | if (barReDraw) { |
571 | 544 | barMax = 0; |
572 | | - // forcing the write of one line |
| 545 | + // always show at least a half bar |
573 | 546 | if (local == 0) local = 1; |
574 | 547 | } |
575 | 548 |
|
576 | 549 | // growing bar: print the difference |
577 | 550 | 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 |
607 | 567 | } |
608 | 568 |
|
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 |
610 | 571 | 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); |
613 | 590 | } |
614 | 591 |
|
615 | 592 | // put the var for the next iteration |
616 | 593 | barMax = local; |
617 | | - //reset the redraw flag |
| 594 | + |
| 595 | + // reset the bar redraw flag |
618 | 596 | barReDraw = false; |
619 | 597 | } |
620 | 598 |
|
|
0 commit comments