src/display.cpp

changeset 44
b3c3d54d2c7c
parent 37
07e8ca2bdf6d
child 46
a4a007b3c42e
equal deleted inserted replaced
43:c850674a3101 44:b3c3d54d2c7c
21 set_font((unsigned char*)Mono19x27); 21 set_font((unsigned char*)Mono19x27);
22 this->printf("HP34970A"); 22 this->printf("HP34970A");
23 set_font((unsigned char*)Terminal6x8); 23 set_font((unsigned char*)Terminal6x8);
24 locate(90, 40); 24 locate(90, 40);
25 this->printf("David Douard"); 25 this->printf("David Douard");
26 locate(0, 52);
27 this->printf("Clock = %ld ", SystemCoreClock);
28
29 RCC_OscInitTypeDef cfg;
30 HAL_RCC_GetOscConfig(&cfg);
31 if (cfg.HSEState == RCC_HSE_BYPASS)
32 this->printf("HSE:EXT ");
33 else if (cfg.HSEState == RCC_HSE_ON)
34 this->printf("HSE:XTAL ");
35 else
36 this->printf("HSE:OFF ");
37
38 if (cfg.HSIState == RCC_HSI_ON)
39 this->printf("HSI:ON ");
40 else
41 this->printf("HSI:OFF ");
42
43 copy_to_lcd(); 26 copy_to_lcd();
44 } 27 }
45 28
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 copy_to_lcd();
38 }
39
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 static char txt[64];
46 char c;
47 uint8_t len, i, j;
48 // for which we need to look for the entry in the table
49 for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) {
50 if (table[i].cmd == 0x00) {
51 ::printf("DIMM CHAR %d\n", n);
52 ::printf("repl '%s'\n", table[i].buffer);
53 len = strlen(table[i].buffer);
54 if (n >= len)
55 break; // nothing to do
56 strncpy(txt, table[i].buffer, table[i].maxsize);
57 // look for the actual position of the char in the string (only alphanum)
58 // XXX very poor implementation...
59 for (j=0; (j<len)&&(j<=n); j++)
60 {
61 c = txt[j];
62 if ((c == ',') || (c == '.') || (c == ';') || (c == ':') || (c == ' '))
63 n++;
64 }
65 // now move the end of the string for char n to steps on the right
66 // so we can insert our 2 '\t' characters before and after the
67 // character to dimm
68 for (j=len; j>n; j--)
69 {
70 txt[j+2] = txt[j];
71 }
72 txt[n+2] = '\t';
73 txt[n+1] = txt[n];
74 txt[n] = '\t';
75 txt[len+2] = 0x00; // make sure the string will be terminated
76
77 ::printf("with '%s'\n", txt);
78 // now display this string
79 show(0x00, txt, 0);
80 break;
81 }
82 }
83 }
46 84
47 void Display::show(uint8_t cmd, const char *intxt, uint8_t nchar=0) 85 void Display::show(uint8_t cmd, const char *intxt, uint8_t nchar=0)
48 { 86 {
49 uint8_t i; 87 uint8_t i;
50 // uint8_t len; 88 // uint8_t len;
51 uint16_t bgcolor, fgcolor; 89 uint16_t bgcolor, fgcolor;
52 char *oldv; 90 char *oldv;
53 // char *txt; 91 // char *txt;
54 char *txtp; 92 char *txtp;
55 static char txt[256]; 93 static char txt[64];
56 94
57 95
58 if (cmd == 0xFF) // cls 96 if (cmd == 0xFF) // cls
59 { 97 {
60 clrbuff(); 98 clrbuff();
61 } 99 }
100 else if (cmd == 0x0D)
101 { // dimm a character of the main area
102 dimm_char(intxt[0]);
103 }
62 else 104 else
63 { 105 {
64 //txt = (char *)malloc(strlen(intxt)+1);
65 strcpy(txt, intxt);
66 txtp = txt;
67
68 for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) { 106 for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) {
69 if (table[i].cmd == cmd) { 107 if (table[i].cmd == cmd) {
108 strcpy(txt, intxt);
109 txtp = txt;
110
70 bgcolor = table[i].bgcolor; 111 bgcolor = table[i].bgcolor;
71 fgcolor = table[i].color; 112 fgcolor = table[i].color;
72 background(bgcolor); 113 background(bgcolor);
73 foreground(fgcolor); 114 foreground(fgcolor);
74 set_font((unsigned char*) table[i].font); 115 set_font((unsigned char*) table[i].font);
75 oldv = table[i].buffer; 116 oldv = table[i].buffer;
76 117
77 locate(table[i].x0, table[i].y0); 118 locate(table[i].x0, table[i].y0);
78 119
79 if (table[i].fmt & 0x01) // ASCII text 120 if (table[i].fmt & FMT_ASCII) // ASCII text
80 { 121 {
122 // check if the string has changed since last time
81 if (strncmp(oldv, txt, table[i].maxsize) != 0) 123 if (strncmp(oldv, txt, table[i].maxsize) != 0)
82 { 124 {
125 // clear the text area
83 if (table[i].width > 0) 126 if (table[i].width > 0)
84 fillrect(table[i].x0, 127 fillrect(table[i].x0,
85 table[i].y0, 128 table[i].y0,
86 table[i].x0 + table[i].width, 129 table[i].x0 + table[i].width,
87 table[i].y0 + table[i].font[2], 130 table[i].y0 + table[i].font[2] - 1,
88 bgcolor); 131 bgcolor);
132 // draw chars by portions of string separated by \t (highlight)
89 for (uint8_t k=0; ;k++) 133 for (uint8_t k=0; ;k++)
90 { 134 {
91 if (txtp[k] == 0x00) 135 if (txtp[k] == 0x00)
92 { 136 { // end of string, display it
93 this->printf(txtp); 137 this->printf(txtp);
94 break; 138 break;
95 } 139 }
96 if (txtp[k] == 0x09) 140 if (txtp[k] == 0x09)
97 { // \t is a special char for 'unselected' display value 141 { // \t is a special char for 'unselected' display value
142 // first disply the beginning of the string
98 txtp[k] = 0x00; 143 txtp[k] = 0x00;
99 this->printf(txtp); 144 this->printf(txtp);
100 145
146 // swap the fg color (dimm/bright)
101 if (fgcolor == table[i].color) 147 if (fgcolor == table[i].color)
102 fgcolor /= 2; 148 fgcolor /= 2;
103 else 149 else
104 fgcolor = table[i].color; 150 fgcolor = table[i].color;
105 foreground(fgcolor); 151 foreground(fgcolor);
152 // continue on the next with part of the string
106 txtp = &(txtp[k+1]); 153 txtp = &(txtp[k+1]);
107 k = 0; 154 k = 0;
108 } 155 }
109 } 156 }
110 if (cmd == 0x00) // main area 157 must_refresh = 1;
111 must_refresh |= 0x01;
112 if (cmd == 0x0C) // channels area
113 must_refresh |= 0x04;
114 } 158 }
115 } 159 }
116 /* 160 /*
117 if (table[i].fmt & 0x02 ) { 161 if (table[i].fmt & FMT_HEX ) {
118 // hex 162 // hex
119 for (uint8_t j=0;; j++) { 163 for (uint8_t j=0;; j++) {
120 if (txt[j] == 0x00) 164 if (txt[j] == 0x00)
121 break; 165 break;
122 this->printf("%02X ", txt[j]); 166 this->printf("%02X ", txt[j]);
123 } 167 }
124 for (uint8_t j=3*strlen(txt); j<table[i].maxsize; j++) 168 for (uint8_t j=3*strlen(txt); j<table[i].maxsize; j++)
125 this->printf(" "); 169 this->printf(" ");
126 } 170 }
127 */ 171 */
128 if (table[i].fmt & 0x08 ) // flag indicators 172 if (table[i].fmt & FMT_FLAGS ) // flag indicators
129 { 173 {
174 uint8_t nbyte;
175 uint8_t nbit;
130 // flags 176 // flags
131 for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++) 177 for (uint8_t l=0; l<(sizeof(flags)/sizeof(flags[0])); ++l)
132 { 178 {
133 for (uint8_t k=0; k<8; k++) 179 nbyte = flags[l].flag / 8;
134 { 180 nbit = flags[l].flag % 8;
135 if (1) 181
136 { //(txt[j] & (1 << k) ) != (oldv[j] & (1 << k))) { 182 if (intxt[nbyte] & (1 << nbit))
137 for (uint8_t l=0; 183 { // draw the flag, possibly reversed fg/bg
138 l<(sizeof(flags)/sizeof(flags[0])); ++l) 184 foreground(flags[l].reverse ? bgcolor : fgcolor);
139 { 185 background(flags[l].reverse ? fgcolor : bgcolor);
140 if (flags[l].flag == ((j<<4) + k)) {
141 if (txtp[j] & (1 << k))
142 {
143 foreground(flags[l].reverse ? bgcolor : fgcolor);
144 background(flags[l].reverse ? fgcolor : bgcolor);
145 }
146 else
147 {
148 foreground(bgcolor);
149 background(bgcolor);
150 }
151 if (flags[l].msg != NULL)
152 { // a string
153 locate(flags[l].x, flags[l].y);
154 this->printf(flags[l].msg);}
155 else
156 { // an icon
157 Bitmap_s pic = {9, 10, 2, (char*) flags[l].icon};
158 Bitmap_BW(pic, flags[l].x, flags[l].y);
159 }
160 must_refresh = 1; //|= zones[m].flag;
161 break;
162 }
163 }
164 }
165 } 186 }
187 else
188 { // erase the flag
189 foreground(bgcolor);
190 background(bgcolor);
191 }
192 if (flags[l].msg != NULL)
193 { // flag is a string
194 locate(flags[l].x, flags[l].y);
195 this->printf(flags[l].msg);}
196 else
197 { // flag is an icon
198 Bitmap_s pic = {9, 10, 2, (char*) flags[l].icon};
199 Bitmap_BW(pic, flags[l].x, flags[l].y);
200 }
166 } 201 }
167 202
168 // draw frames (Alarm and Channel) 203 // draw frames (Alarm and Channel)
169 for (uint8_t l=0; 204 for (uint8_t l=0; l<(sizeof(frames)/sizeof(frames[0])); ++l)
170 l<(sizeof(frames)/sizeof(frames[0])); ++l)
171 { 205 {
172 uint16_t color; 206 uint16_t color;
173 if (frames[l].flag & txt[0]) // frame flags are on the 1st byte only 207 if (intxt[0] & (1 << frames[l].flag)) // frame flags are on the 1st byte only
174 color = fgcolor/6; 208 color = fgcolor/6;
175 else 209 else
176 color = bgcolor; 210 color = bgcolor;
177 hline(frames[l].x0+1, frames[l].x0+3, frames[l].y0, color); 211 hline(frames[l].x0+1, frames[l].x0+3, frames[l].y0, color);
178 hline(frames[l].x1-3, frames[l].x1-1, frames[l].y0, color); 212 hline(frames[l].x1-3, frames[l].x1-1, frames[l].y0, color);
179 hline(frames[l].x0+1, frames[l].x1-1, frames[l].y1, color); 213 hline(frames[l].x0+1, frames[l].x1-1, frames[l].y1, color);
180 214
181 vline(frames[l].x0, frames[l].y0+1, frames[l].y1-1, color); 215 vline(frames[l].x0, frames[l].y0+1, frames[l].y1-1, color);
182 vline(frames[l].x1, frames[l].y0+1, frames[l].y1-1, color); 216 vline(frames[l].x1, frames[l].y0+1, frames[l].y1-1, color);
183 } 217 }
218 must_refresh = 1; //|= zones[m].flag;
184 } 219 }
185 220
186 for(uint8_t j=0; j<table[i].maxsize; j++) 221 for(uint8_t j=0; j<table[i].maxsize; j++)
187 oldv[j] = txt[j]; 222 oldv[j] = txt[j];
188 break; 223 break;
189 } 224 }
190 } 225 }
191 //free(txt); 226 //free(txt);
192 //this->copy_to_lcd(); 227 //this->copy_to_lcd();
193 } 228 }
229 }
230
231
232 void Display::set_flag(uint8_t flag, bool show=true)
233 {
234 uint8_t i;
235 uint8_t bgcolor = 0x00, fgcolor = 0xFF;
236
237 for (uint8_t l=0; l<(sizeof(flags)/sizeof(flags[0])); ++l)
238 {
239 if (flag == flags[l].flag)
240 {
241
242 if (show)
243 {
244 foreground(flags[l].reverse ? bgcolor : fgcolor);
245 background(flags[l].reverse ? fgcolor : bgcolor);
246 }
247 else
248 {
249 foreground(bgcolor);
250 background(bgcolor);
251 }
252 if (flags[l].msg != NULL)
253 { // flag is a string
254 locate(flags[l].x, flags[l].y);
255 set_font((unsigned char*)Terminal6x8);
256 this->printf(flags[l].msg);}
257 else
258 { // flag is an icon
259 Bitmap_s pic = {9, 10, 2, (char*) flags[l].icon};
260 Bitmap_BW(pic, flags[l].x, flags[l].y);
261 }
262 }
263 }
264
265 // draw frames (Alarm and Channel)
266 for (uint8_t l=0; l<(sizeof(frames)/sizeof(frames[0])); ++l)
267 {
268 if (flag == frames[l].flag)
269 {
270 uint16_t color;
271 if (show)
272 color = fgcolor/6;
273 else
274 color = bgcolor;
275 hline(frames[l].x0+1, frames[l].x0+3, frames[l].y0, color);
276 hline(frames[l].x1-3, frames[l].x1-1, frames[l].y0, color);
277 hline(frames[l].x0+1, frames[l].x1-1, frames[l].y1, color);
278
279 vline(frames[l].x0, frames[l].y0+1, frames[l].y1-1, color);
280 vline(frames[l].x1, frames[l].y0+1, frames[l].y1-1, color);
281 }
282 }
283 must_refresh = 1;
194 } 284 }
195 285
196 286
197 void Display::test_dsp() 287 void Display::test_dsp()
198 { 288 {

mercurial