Sat, 07 Nov 2020 19:23:21 +0100
Attempt to improve the detection of packet collisions (not fixed yet)
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
1 | #include "stdio.h" |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
2 | #include <mbed.h> |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
3 | #include <rtos.h> |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
4 | #include "display.h" |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
5 | |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
6 | |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
7 | Display::Display(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
8 | const char* name) |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
9 | : SSD1322(Hz, mosi, miso, sclk, CS, reset, DC, name) |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
10 | { |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
11 | must_refresh = 0; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
12 | } |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
13 | |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
14 | Display::~Display() |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
15 | { |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
16 | } |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
17 | |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
18 | void Display::show_splashscreen() |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
19 | { |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
20 | locate(30, 10); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
21 | set_font((unsigned char*)Mono19x27); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
22 | this->printf("HP34970A"); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
23 | set_font((unsigned char*)Terminal6x8); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
24 | locate(90, 40); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
25 | this->printf("David Douard"); |
44 | 26 | copy_to_lcd(); |
27 | } | |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
28 | |
44 | 29 | void Display::show_byescreen() |
30 | { | |
31 | cls(); | |
32 | background(0x00); | |
33 | foreground(0xFF); | |
34 | locate(30, 10); | |
35 | set_font((unsigned char*)Mono19x27); | |
36 | this->printf("Bye..."); | |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
37 | copy_to_lcd(); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
38 | } |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
39 | |
44 | 40 | void Display::dimm_char(uint8_t n) |
41 | { | |
42 | // dimm the char number of the currently displayed string of the main area; | |
43 | // do this by printing a modifed version of the last displayed string | |
44 | // but only alphanumeric chars should be counted (not the punctuation) | |
45 | char c; | |
46 | uint8_t len, i, j; | |
47 | // for which we need to look for the entry in the table | |
48 | for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) { | |
49 | if (table[i].cmd == 0x00) { | |
46
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
50 | |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
51 | background(table[i].bgcolor); |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
52 | foreground(table[i].color / 2); // dimmed |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
53 | set_font((unsigned char*) table[i].font); |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
54 | locate(table[i].x0, table[i].y0); |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
55 | |
44 | 56 | len = strlen(table[i].buffer); |
57 | if (n >= len) | |
58 | break; // nothing to do | |
46
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
59 | //::printf("DIMM CHAR %d\n", n); |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
60 | //::printf(" in (len=%d) '%s'\n", len, table[i].buffer); |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
61 | |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
62 | for (j=0; (j<len); j++) |
44 | 63 | { |
46
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
64 | // advae the location up to the char to dimm |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
65 | c = table[i].buffer[j]; |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
66 | if ((c == ',') || (c == '.') || (c == ';') || (c == ':')) |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
67 | // it's a "zero" width char, skip it |
44 | 68 | n++; |
46
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
69 | if (n == 0) |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
70 | { |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
71 | //::printf(" Found at pos %d char '%c'\n", j, c); |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
72 | // found it |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
73 | character(c); |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
74 | break; |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
75 | } |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
76 | // otherwise, just advance the char_x |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
77 | //::printf(" move %d for '%c' [%X]\n", , c, c); |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
78 | char_width(c, true); |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
79 | n--; |
44 | 80 | } |
81 | } | |
82 | } | |
83 | } | |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
84 | |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
85 | void Display::show(uint8_t cmd, const char *intxt, uint8_t nchar=0) |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
86 | { |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
87 | uint8_t i; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
88 | // uint8_t len; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
89 | uint16_t bgcolor, fgcolor; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
90 | char *oldv; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
91 | // char *txt; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
92 | char *txtp; |
44 | 93 | static char txt[64]; |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
94 | |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
95 | |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
96 | if (cmd == 0xFF) // cls |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
97 | { |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
98 | clrbuff(); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
99 | } |
44 | 100 | else if (cmd == 0x0D) |
101 | { // dimm a character of the main area | |
102 | dimm_char(intxt[0]); | |
103 | } | |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
104 | else |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
105 | { |
46
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
106 | pixel_buffer_mutex.lock(); |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
107 | for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) { |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
108 | if (table[i].cmd == cmd) { |
44 | 109 | strcpy(txt, intxt); |
110 | txtp = txt; | |
111 | ||
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
112 | bgcolor = table[i].bgcolor; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
113 | fgcolor = table[i].color; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
114 | background(bgcolor); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
115 | foreground(fgcolor); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
116 | set_font((unsigned char*) table[i].font); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
117 | oldv = table[i].buffer; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
118 | |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
119 | locate(table[i].x0, table[i].y0); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
120 | |
44 | 121 | if (table[i].fmt & FMT_ASCII) // ASCII text |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
122 | { |
44 | 123 | // check if the string has changed since last time |
46
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
124 | if (true) //(strncmp(oldv, txt, table[i].maxsize) != 0) |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
125 | { |
44 | 126 | // clear the text area |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
127 | if (table[i].width > 0) |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
128 | fillrect(table[i].x0, |
44 | 129 | table[i].y0, |
130 | table[i].x0 + table[i].width, | |
131 | table[i].y0 + table[i].font[2] - 1, | |
132 | bgcolor); | |
133 | // draw chars by portions of string separated by \t (highlight) | |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
134 | for (uint8_t k=0; ;k++) |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
135 | { |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
136 | if (txtp[k] == 0x00) |
44 | 137 | { // end of string, display it |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
138 | this->printf(txtp); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
139 | break; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
140 | } |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
141 | if (txtp[k] == 0x09) |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
142 | { // \t is a special char for 'unselected' display value |
44 | 143 | // first disply the beginning of the string |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
144 | txtp[k] = 0x00; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
145 | this->printf(txtp); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
146 | |
44 | 147 | // swap the fg color (dimm/bright) |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
148 | if (fgcolor == table[i].color) |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
149 | fgcolor /= 2; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
150 | else |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
151 | fgcolor = table[i].color; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
152 | foreground(fgcolor); |
44 | 153 | // continue on the next with part of the string |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
154 | txtp = &(txtp[k+1]); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
155 | k = 0; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
156 | } |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
157 | } |
44 | 158 | must_refresh = 1; |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
159 | } |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
160 | } |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
161 | /* |
44 | 162 | if (table[i].fmt & FMT_HEX ) { |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
163 | // hex |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
164 | for (uint8_t j=0;; j++) { |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
165 | if (txt[j] == 0x00) |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
166 | break; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
167 | this->printf("%02X ", txt[j]); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
168 | } |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
169 | for (uint8_t j=3*strlen(txt); j<table[i].maxsize; j++) |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
170 | this->printf(" "); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
171 | } |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
172 | */ |
44 | 173 | if (table[i].fmt & FMT_FLAGS ) // flag indicators |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
174 | { |
44 | 175 | uint8_t nbyte; |
176 | uint8_t nbit; | |
46
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
177 | uint16_t color; |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
178 | // flags |
44 | 179 | for (uint8_t l=0; l<(sizeof(flags)/sizeof(flags[0])); ++l) |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
180 | { |
44 | 181 | nbyte = flags[l].flag / 8; |
182 | nbit = flags[l].flag % 8; | |
183 | ||
184 | if (intxt[nbyte] & (1 << nbit)) | |
185 | { // draw the flag, possibly reversed fg/bg | |
186 | foreground(flags[l].reverse ? bgcolor : fgcolor); | |
187 | background(flags[l].reverse ? fgcolor : bgcolor); | |
188 | } | |
189 | else | |
190 | { // erase the flag | |
191 | foreground(bgcolor); | |
192 | background(bgcolor); | |
193 | } | |
194 | if (flags[l].msg != NULL) | |
195 | { // flag is a string | |
196 | locate(flags[l].x, flags[l].y); | |
197 | this->printf(flags[l].msg);} | |
198 | else | |
199 | { // flag is an icon | |
200 | Bitmap_s pic = {9, 10, 2, (char*) flags[l].icon}; | |
201 | Bitmap_BW(pic, flags[l].x, flags[l].y); | |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
202 | } |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
203 | } |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
204 | |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
205 | // draw frames (Alarm and Channel) |
44 | 206 | for (uint8_t l=0; l<(sizeof(frames)/sizeof(frames[0])); ++l) |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
207 | { |
46
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
208 | nbyte = frames[l].flag / 8; |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
209 | nbit = frames[l].flag % 8; |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
210 | if (intxt[nbyte] & (1 << nbit)) |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
211 | color = fgcolor/6; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
212 | else |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
213 | color = bgcolor; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
214 | hline(frames[l].x0+1, frames[l].x0+3, frames[l].y0, color); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
215 | hline(frames[l].x1-3, frames[l].x1-1, frames[l].y0, color); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
216 | hline(frames[l].x0+1, frames[l].x1-1, frames[l].y1, color); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
217 | |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
218 | vline(frames[l].x0, frames[l].y0+1, frames[l].y1-1, color); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
219 | vline(frames[l].x1, frames[l].y0+1, frames[l].y1-1, color); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
220 | } |
44 | 221 | must_refresh = 1; //|= zones[m].flag; |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
222 | } |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
223 | |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
224 | for(uint8_t j=0; j<table[i].maxsize; j++) |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
225 | oldv[j] = txt[j]; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
226 | break; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
227 | } |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
228 | } |
46
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
229 | pixel_buffer_mutex.unlock(); |
a4a007b3c42e
Fix display of flags and improve dimm char handling
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
230 | |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
231 | //free(txt); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
232 | //this->copy_to_lcd(); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
233 | } |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
234 | } |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
235 | |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
236 | |
44 | 237 | void Display::set_flag(uint8_t flag, bool show=true) |
238 | { | |
239 | uint8_t i; | |
240 | uint8_t bgcolor = 0x00, fgcolor = 0xFF; | |
241 | ||
242 | for (uint8_t l=0; l<(sizeof(flags)/sizeof(flags[0])); ++l) | |
243 | { | |
244 | if (flag == flags[l].flag) | |
245 | { | |
246 | ||
247 | if (show) | |
248 | { | |
249 | foreground(flags[l].reverse ? bgcolor : fgcolor); | |
250 | background(flags[l].reverse ? fgcolor : bgcolor); | |
251 | } | |
252 | else | |
253 | { | |
254 | foreground(bgcolor); | |
255 | background(bgcolor); | |
256 | } | |
257 | if (flags[l].msg != NULL) | |
258 | { // flag is a string | |
259 | locate(flags[l].x, flags[l].y); | |
260 | set_font((unsigned char*)Terminal6x8); | |
261 | this->printf(flags[l].msg);} | |
262 | else | |
263 | { // flag is an icon | |
264 | Bitmap_s pic = {9, 10, 2, (char*) flags[l].icon}; | |
265 | Bitmap_BW(pic, flags[l].x, flags[l].y); | |
266 | } | |
267 | } | |
268 | } | |
269 | ||
270 | // draw frames (Alarm and Channel) | |
271 | for (uint8_t l=0; l<(sizeof(frames)/sizeof(frames[0])); ++l) | |
272 | { | |
273 | if (flag == frames[l].flag) | |
274 | { | |
275 | uint16_t color; | |
276 | if (show) | |
277 | color = fgcolor/6; | |
278 | else | |
279 | color = bgcolor; | |
280 | hline(frames[l].x0+1, frames[l].x0+3, frames[l].y0, color); | |
281 | hline(frames[l].x1-3, frames[l].x1-1, frames[l].y0, color); | |
282 | hline(frames[l].x0+1, frames[l].x1-1, frames[l].y1, color); | |
283 | ||
284 | vline(frames[l].x0, frames[l].y0+1, frames[l].y1-1, color); | |
285 | vline(frames[l].x1, frames[l].y0+1, frames[l].y1-1, color); | |
286 | } | |
287 | } | |
288 | must_refresh = 1; | |
289 | } | |
290 | ||
291 | ||
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
292 | void Display::test_dsp() |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
293 | { |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
294 | const FRAME *z; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
295 | printf("TEST DSP\r\n"); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
296 | cls(); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
297 | printf("TEST DSP #2\r\n"); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
298 | show(0x00, "8g8g8g8g8g8g8", 13); // main dsp |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
299 | show(0x0C, "888", 3); // channel dsp |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
300 | show(0x0A, "\xFF\xFF\xFF\xFF", 4); // all flags |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
301 | copy_to_lcd(); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
302 | ThisThread::sleep_for(3ms); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
303 | cls(); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
304 | printf("TEST DSP #3\r\n"); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
305 | |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
306 | for (uint8_t i=0; i<(sizeof(zones)/sizeof(zones[0])); i++) |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
307 | { |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
308 | z = &zones[i]; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
309 | fillrect(z->x0, z->y0, z->x1, z->y1, 4+i); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
310 | locate(z->x0+1, z->y0+1); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
311 | this->printf("%d", i); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
312 | } |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
313 | |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
314 | /* |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
315 | for (uint8_t i=0; i<(sizeof(zones)/sizeof(zones[0])); i++) |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
316 | { |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
317 | z = &zones[i]; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
318 | printf("Zone %d [%x]: %d, %d, %d, %d\n", i, z->flag, |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
319 | z->x0, z->y0, z->x1, z->y1); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
320 | must_refresh = z->flag; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
321 | wait(1); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
322 | } |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
323 | printf("Done\n"); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
324 | wait(2); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
325 | printf("Copy ALL\n"); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
326 | copy_to_lcd(); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
327 | */ |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
328 | ThisThread::sleep_for(2ms); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
329 | cls(); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
330 | printf("TEST DSP DONE\r\n"); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
331 | } |