39 } DSP; |
39 } DSP; |
40 |
40 |
41 static DSP table[] = |
41 static DSP table[] = |
42 { |
42 { |
43 { 0x00, 0xF, 0x0, 0, 0, 0x01, MAX_BUFF, 245, Mono19x27}, // main display |
43 { 0x00, 0xF, 0x0, 0, 0, 0x01, MAX_BUFF, 245, Mono19x27}, // main display |
44 { 0x0C, 0xF, 0x0,204, 38, 0x01, 3, 45, Mono15x22}, // channels display |
44 { 0x0C, 0xF, 0x0,204, 38, 0x01, 3, 45, Mono15x22}, // channels display |
45 { 0x01, 0xF, 0x0, 0, 0, 0x80, MAX_BUFF, 0, Terminal6x8}, |
45 // { 0x01, 0xF, 0x0, 0, 0, 0x80, MAX_BUFF, 0, Terminal6x8}, |
46 { 0x02, 0xF, 0x0, 0, 0, 0x80, MAX_BUFF, 0, Terminal6x8}, |
46 // { 0x02, 0xF, 0x0, 0, 0, 0x80, MAX_BUFF, 0, Terminal6x8}, |
47 { 0x0A, 0xF, 0x0, 0, 57, 0x0C, 4, 0, Terminal6x8}, // flags + bits |
47 { 0x0A, 0xF, 0x0, 0, 57, 0x0C, 4, 0, Terminal6x8}, // flags + bits |
48 { 0xFF, 0xF, 0x0, 0, 0, 0x80, MAX_BUFF, 0, Terminal6x8}, |
48 // { 0xFF, 0xF, 0x0, 0, 0, 0x80, MAX_BUFF, 0, Terminal6x8}, |
49 }; |
49 }; |
50 |
50 |
51 // 9x10 |
51 // 9x10 |
52 const unsigned char icon_alarm[] __attribute__((aligned (2))) = |
52 const unsigned char icon_alarm[] __attribute__((aligned (2))) = |
53 { |
53 { |
54 0x1c, 0x0, |
54 0x1c, 0x0, |
55 0x3e, 0x0, |
55 0x3e, 0x0, |
56 0x7f, 0x0, |
56 0x7f, 0x0, |
57 0x7f, 0x0, |
57 0x7f, 0x0, |
74 0xc0, 0x0, |
74 0xc0, 0x0, |
75 0x80, 0x0, |
75 0x80, 0x0, |
76 0x80, 0x0, |
76 0x80, 0x0, |
77 0xff, 0x80 |
77 0xff, 0x80 |
78 }; |
78 }; |
79 |
79 |
80 typedef struct _FLAG |
80 typedef struct _FLAG |
81 { |
81 { |
82 uint8_t flag; |
82 uint8_t flag; |
|
83 uint8_t zone; |
83 uint8_t x; |
84 uint8_t x; |
84 uint8_t y; |
85 uint8_t y; |
85 const char* msg; |
86 const char* msg; |
86 const unsigned char* icon; |
87 const unsigned char* icon; |
87 } FLAG; |
88 } FLAG; |
88 |
|
89 static const FLAG flags[] = |
|
90 { |
|
91 //{ 0x00, 160, 30, "Alarm"}, // for the 'alarm' box |
|
92 { 0x00, 246, 0, NULL, icon_alarm}, // F1.1 |
|
93 { 0x01, 246, 11, NULL, icon_curve}, // F1.2 |
|
94 { 0x03, 204, 30, "Channel"}, // F1.4 |
|
95 { 0x14, 68, 44, "4W"}, // F2.5 |
|
96 { 0x32, 40, 44, "*"}, // F4.3 |
|
97 { 0x33, 40, 44, "VIEW"}, // F4.4 |
|
98 { 0x34, 0, 30, "MON"}, // F4.5 |
|
99 { 0x35, 0, 44, "SCAN"}, // F4.6 |
|
100 { 0x36, 0, 44, "CONFIG"}, // F4.7 |
|
101 |
|
102 { 0xFF, 0, 0, "ADRS"}, |
|
103 { 0xFF, 0, 0, "RMT"}, |
|
104 { 0xFF, 0, 0, "ERROR"}, |
|
105 { 0xFF, 0, 0, "EXT"}, |
|
106 { 0xFF, 0, 0, "ONCE"}, |
|
107 { 0xFF, 0, 0, "AUTO"}, |
|
108 { 0xFF, 0, 0, "MEM"}, |
|
109 { 0xFF, 0, 0, "LAST"}, |
|
110 { 0xFF, 0, 0, "MIN"}, |
|
111 { 0xFF, 0, 0, "MAX"}, |
|
112 { 0xFF, 0, 0, "AVG"}, |
|
113 { 0xFF, 0, 0, "OC"}, |
|
114 |
|
115 { 0xFF, 0, 0, "H"}, |
|
116 { 0xFF, 0, 0, "1"}, |
|
117 { 0xFF, 0, 0, "2"}, |
|
118 { 0xFF, 0, 0, "3"}, |
|
119 { 0xFF, 0, 0, "4"}, |
|
120 { 0xFF, 0, 0, "L"}, |
|
121 |
|
122 }; |
|
123 |
89 |
124 typedef struct _FRAME |
90 typedef struct _FRAME |
125 { |
91 { |
126 uint8_t flag; |
92 uint8_t flag; |
127 uint8_t x0; |
93 uint8_t x0; |
128 uint8_t y0; |
94 uint8_t y0; |
129 uint8_t x1; |
95 uint8_t x1; |
130 uint8_t y1; |
96 uint8_t y1; |
131 } FRAME; |
97 } FRAME; |
132 |
98 |
|
99 static const FLAG flags[] = |
|
100 { |
|
101 // flag, zone, x0, y0, msg, icon |
|
102 // right-side icons area |
|
103 { 0x00, 0x02, 0, 0, NULL, icon_alarm}, // F1.1 |
|
104 { 0x01, 0x02, 0, 11, NULL, icon_curve}, // F1.2 |
|
105 { 0x14, 0x02, 0, 22, "4W"}, // F2.5 |
|
106 |
|
107 { 0x03, 0x04, 1, 2, "Channel"}, // F1.4 |
|
108 |
|
109 // col 1 |
|
110 { 0x34, 0x10, 0, 0, "MON"}, // F4.5 |
|
111 { 0x33, 0x10, 0, 8, "VIEW"}, // F4.4 |
|
112 { 0x35, 0x10, 0, 16, "SCAN"}, // F4.6 |
|
113 |
|
114 //col 2 |
|
115 { 0x32, 0x20, 0, 0, "*"}, // F4.3 |
|
116 { 0x36, 0x20, 0, 8, "CFG"}, // F4.7 |
|
117 { 0xFF, 0x20, 0, 16, "ERROR"}, |
|
118 |
|
119 /* |
|
120 { 0xFF, 0, 0, "ADRS"}, |
|
121 { 0xFF, 0, 0, "RMT"}, |
|
122 { 0xFF, 0, 0, "EXT"}, |
|
123 |
|
124 { 0xFF, 0, 0, "ONCE"}, |
|
125 { 0xFF, 0, 0, "AUTO"}, |
|
126 { 0xFF, 0, 0, "MEM"}, |
|
127 |
|
128 { 0xFF, 0, 0, "LAST"}, |
|
129 { 0xFF, 0, 0, "MIN"}, |
|
130 { 0xFF, 0, 0, "MAX"}, |
|
131 |
|
132 { 0xFF, 0, 0, "AVG"}, |
|
133 { 0xFF, 0, 0, "OC"}, |
|
134 */ |
|
135 |
|
136 { 0x05, 0x08, 0, 0, "Alarm"}, // F1.6 |
|
137 { 0x06, 0x08, 0, 10, "H"}, // F1.7 |
|
138 { 0x13, 0x08, 6, 10, "1"}, // F2.4 |
|
139 { 0x10, 0x08, 12, 10, "2"}, // F2.1 |
|
140 { 0x12, 0x08, 18, 10, "3"}, // F2.3 |
|
141 { 0x11, 0x08, 24, 10, "4"}, // F2.2 |
|
142 { 0x04, 0x08, 30, 10, "L"}, // F1.5 |
|
143 |
|
144 }; |
|
145 |
|
146 static const FRAME zones[] = |
|
147 { |
|
148 { 0x01, 0, 0, 245, 27}, // main display area |
|
149 { 0x02, 246, 0, 255, 27}, // right notif area |
|
150 { 0x04, 203, 28, 255, 54}, // channels display area |
|
151 { 0x08, 160, 28, 202, 54}, // alarms area |
|
152 { 0x10, 0, 28, 32, 54}, // flags col1 |
|
153 { 0x20, 33, 28, 70, 54}, // flags col2 |
|
154 { 0x40, 71, 28, 159, 54}, // flags col3 |
|
155 |
|
156 { 0x80, 0, 55, 255, 63}, // flags bits display area |
|
157 }; |
|
158 |
133 static const FRAME frames[] = |
159 static const FRAME frames[] = |
134 { |
160 { |
135 { 0x02, 203, 35, 248, 55}, // F1.3 |
161 { 0x02, 203, 35, 248, 55}, // F1.3 |
136 }; |
162 }; |
137 |
163 |
180 // myLCD.claim(stdout); // send stdout to the LCD display |
206 // myLCD.claim(stdout); // send stdout to the LCD display |
181 // myLCD.claim(stderr); // send stderr to the LCD display |
207 // myLCD.claim(stderr); // send stderr to the LCD display |
182 dsp.background(Black); // set background to black |
208 dsp.background(Black); // set background to black |
183 dsp.foreground(0xF); |
209 dsp.foreground(0xF); |
184 dsp.cls(); |
210 dsp.cls(); |
185 dsp.locate(0, 0); |
211 |
186 dsp.set_font(Mono19x27); |
|
187 |
|
188 cmd = 0xFF; |
212 cmd = 0xFF; |
189 curchar = 0; |
213 curchar = 0; |
190 nchars = 0; |
214 nchars = 0; |
191 |
215 |
192 for (uint8_t i=0; i<sizeof(table)/sizeof(table[0]); ++i) |
216 for (uint8_t i=0; i<sizeof(table)/sizeof(table[0]); ++i) |
193 memset(table[i].buffer, 0, MAX_BUFF+1); |
217 memset(table[i].buffer, 0, MAX_BUFF+1); |
194 |
218 |
|
219 dsp.locate(30, 10); |
|
220 dsp.set_font(Mono19x27); |
195 dsp.printf("HP34970A"); |
221 dsp.printf("HP34970A"); |
196 dsp.set_font(Terminal6x8); |
222 dsp.set_font(Terminal6x8); |
197 for(uint8_t i=0; i<4; i++) { |
223 dsp.locate(90, 40); |
198 dsp.locate(160, i*8); |
224 dsp.printf("David Douard"); |
199 dsp.printf("Lg %d", i+1); |
|
200 dsp.locate(208, (3-i)*8); |
|
201 dsp.printf("Lg %d", i+1); |
|
202 } |
|
203 dsp.copy_to_lcd(); |
225 dsp.copy_to_lcd(); |
204 wait(2); |
226 wait(2); |
205 dsp.cls(); |
227 dsp.cls(); |
206 |
|
207 test_dsp(); |
|
208 dsp.copy_to_lcd(); |
|
209 wait(2); |
|
210 dsp.cls(); |
|
211 |
|
212 } |
228 } |
213 |
229 |
214 void copy_to_lcd(void) { |
230 void copy_to_lcd(void) { |
|
231 uint8_t mask=1; |
|
232 |
215 while(1) { |
233 while(1) { |
216 pulse(0, true); |
234 pulse(0, true); |
217 if (must_refresh) { |
235 if (must_refresh & mask) { |
218 must_refresh = false; |
236 for(uint8_t i=0; i<sizeof(zones)/sizeof(zones[0]); i++) |
219 dsp.copy_to_lcd(); |
237 if (zones[i].flag == mask) { |
220 } |
238 dsp.copy_to_lcd(zones[i].x0/4, (zones[i].x1+3)/4, |
|
239 zones[i].y0, zones[i].y1); |
|
240 must_refresh &= ~mask; |
|
241 break; |
|
242 } |
|
243 } |
|
244 mask = mask << 1; |
|
245 if (mask == 0) { |
|
246 mask = 1; |
|
247 } |
|
248 |
221 pulse(0, false); |
249 pulse(0, false); |
222 Thread::wait(100); |
250 Thread::wait(10); |
223 } |
251 } |
224 } |
252 } |
225 |
253 |
226 void show(uint8_t cmd, char *txt, uint8_t nchar=0) { |
254 void show(uint8_t cmd, char *txt, uint8_t nchar=0) { |
227 uint8_t i, len; |
255 uint8_t i, len; |
228 uint16_t bgcolor, fgcolor; |
256 uint16_t bgcolor, fgcolor; |
229 char *oldv; |
257 char *oldv; |
230 |
258 |
231 pulse(1, true); |
259 pulse(1, true); |
232 |
260 |
233 must_refresh = false; |
|
234 |
|
235 len = MAX_BUFF; |
261 len = MAX_BUFF; |
236 |
262 |
237 for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) { |
263 for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) { |
238 if (table[i].cmd == cmd) { |
264 if (table[i].cmd == cmd) { |
239 bgcolor = table[i].bgcolor; |
265 bgcolor = table[i].bgcolor; |
240 fgcolor = table[i].color; |
266 fgcolor = table[i].color; |
241 dsp.background(bgcolor); |
267 dsp.background(bgcolor); |
242 dsp.foreground(fgcolor); |
268 dsp.foreground(fgcolor); |
243 dsp.locate(table[i].x0, table[i].y0); |
|
244 dsp.set_font((unsigned char*) table[i].font); |
269 dsp.set_font((unsigned char*) table[i].font); |
245 oldv = table[i].buffer; |
270 oldv = table[i].buffer; |
246 |
271 |
|
272 dsp.locate(table[i].x0, table[i].y0); |
247 |
273 |
248 if (table[i].fmt & 0x01 ) { |
274 if (table[i].fmt & 0x01 ) { |
249 // ascii |
275 // ascii |
250 if (table[i].width > 0) |
276 if (table[i].width > 0) |
251 dsp.fillrect(table[i].x0, table[i].y0, table[i].x0 + table[i].width, table[i].y0 + table[i].font[2], bgcolor); |
277 dsp.fillrect(table[i].x0, table[i].y0, table[i].x0 + table[i].width, table[i].y0 + table[i].font[2], bgcolor); |
298 dsp.printf("%d", (8-k)); |
329 dsp.printf("%d", (8-k)); |
299 } |
330 } |
300 } |
331 } |
301 dsp.foreground(fgcolor); |
332 dsp.foreground(fgcolor); |
302 dsp.printf("]"); |
333 dsp.printf("]"); |
|
334 must_refresh |= 0x80; |
303 } |
335 } |
304 |
336 |
305 if (table[i].fmt & 0x08 ) { |
337 if (table[i].fmt & 0x08 ) { |
306 // flags |
338 // flags |
307 for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++) { |
339 for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++) { |
308 for (uint8_t k=0; k<8; k++) { |
340 for (uint8_t k=0; k<8; k++) { |
309 if ((txt[j] & (1 << k) ) != (oldv[j] & (1 << k))) { |
341 if ((txt[j] & (1 << k) ) != (oldv[j] & (1 << k))) { |
310 |
342 |
311 if (txt[j] & (1 << k)) |
343 if (txt[j] & (1 << k)) |
312 dsp.foreground(fgcolor); |
344 dsp.foreground(fgcolor); |
313 else |
345 else |
314 dsp.foreground(bgcolor); |
346 dsp.foreground(bgcolor); |
315 |
347 |
|
348 /* |
316 for (uint8_t l=0; |
349 for (uint8_t l=0; |
317 l<(sizeof(frames)/sizeof(frames[0])); ++l) { |
350 l<(sizeof(frames)/sizeof(frames[0])); ++l) { |
318 if (frames[l].flag & ((j<<4) + k)) |
351 if (frames[l].flag & ((j<<4) + k)) |
319 dsp.rect(frames[l].x0, frames[l].y0, |
352 dsp.fillrect(frames[l].x0, frames[l].y0, |
320 frames[l].x1, frames[l].y1, |
353 frames[l].x1, frames[l].y1, |
321 fgcolor); |
354 fgcolor/8); |
322 else |
355 else |
323 dsp.rect(frames[l].x0, frames[l].y0, |
356 dsp.fillrect(frames[l].x0, frames[l].y0, |
324 frames[l].x1, frames[l].y1, |
357 frames[l].x1, frames[l].y1, |
325 bgcolor); |
358 bgcolor); |
326 |
359 |
327 } |
360 } |
328 |
361 */ |
|
362 |
329 for (uint8_t l=0; |
363 for (uint8_t l=0; |
330 l<(sizeof(flags)/sizeof(flags[0])); ++l) { |
364 l<(sizeof(flags)/sizeof(flags[0])); ++l) { |
331 if (flags[l].flag == ((j<<4) + k)) { |
365 if (flags[l].flag == ((j<<4) + k)) { |
332 if (flags[l].msg != NULL) { // a string |
366 for (uint8_t m=0; m<(sizeof(zones)/sizeof(zones[0])); m++) { |
333 dsp.locate(flags[l].x, flags[l].y); |
367 if (flags[l].zone == zones[m].flag) { |
334 dsp.printf(flags[l].msg);} |
368 if (flags[l].msg != NULL) { // a string |
335 else { // an icon |
369 dsp.locate(flags[l].x + zones[m].x0, |
336 Bitmap_s pic = {9, 10, 2, flags[l].icon}; |
370 flags[l].y + zones[m].y0); |
337 dsp.Bitmap_BW(pic, flags[l].x, flags[l].y); |
371 dsp.printf(flags[l].msg);} |
|
372 else { // an icon |
|
373 Bitmap_s pic = {9, 10, 2, flags[l].icon}; |
|
374 dsp.Bitmap_BW(pic, |
|
375 flags[l].x + zones[m].x0, |
|
376 flags[l].y + zones[m].y0); |
|
377 } |
|
378 must_refresh |= zones[m].flag; |
|
379 break; |
|
380 } |
338 } |
381 } |
339 //break; |
382 break; |
340 } |
383 } |
341 } |
384 } |
342 } |
385 } |
343 } |
386 } |
344 } |
387 } |
345 } |
388 } |
346 |
389 |
347 for(uint8_t j=0; j<table[i].maxsize; j++) |
390 for(uint8_t j=0; j<table[i].maxsize; j++) |
348 oldv[j] = txt[j]; |
391 oldv[j] = txt[j]; |
|
392 break; |
349 } |
393 } |
350 } |
394 } |
351 |
395 |
352 must_refresh = true; |
|
353 //dsp.copy_to_lcd(); |
396 //dsp.copy_to_lcd(); |
354 pulse(1, false); |
397 pulse(1, false); |
355 } |
398 } |
356 |
399 |
357 void test_dsp() |
400 void test_dsp() |
358 { |
401 { |
|
402 const FRAME *z; |
359 show(0x00, "8g8g8g8g8g8g8", 13); // main dsp |
403 show(0x00, "8g8g8g8g8g8g8", 13); // main dsp |
360 show(0x0C, "888", 3); // channel dsp |
404 show(0x0C, "888", 3); // channel dsp |
361 show(0x0A, "\xFF\xFF\xFF\xFF", 4); // all flags |
405 show(0x0A, "\xFF\xFF\xFF\xFF", 4); // all flags |
|
406 dsp.copy_to_lcd(); |
|
407 wait(3); |
|
408 dsp.cls(); |
|
409 |
|
410 |
|
411 for (uint8_t i=0; i<(sizeof(zones)/sizeof(zones[0])); i++) |
|
412 { |
|
413 z = &zones[i]; |
|
414 dsp.fillrect(z->x0, z->y0, z->x1, z->y1, 4+i); |
|
415 dsp.locate(z->x0+1, z->y0+1); |
|
416 dsp.printf("%d", i); |
|
417 } |
|
418 for (uint8_t i=0; i<(sizeof(zones)/sizeof(zones[0])); i++) |
|
419 { |
|
420 z = &zones[i]; |
|
421 pc.printf("Zone %d [%x]: %d, %d, %d, %d\n", i, z->flag, |
|
422 z->x0, z->y0, z->x1, z->y1); |
|
423 must_refresh = z->flag; |
|
424 wait(1); |
|
425 } |
|
426 pc.printf("Done\n"); |
|
427 wait(2); |
|
428 pc.printf("Copy ALL\n"); |
|
429 dsp.copy_to_lcd(); |
|
430 wait(2); |
|
431 dsp.cls(); |
362 } |
432 } |
363 |
433 |
364 |
434 |
365 void loop() { // run over and over |
435 void loop() { // run over and over |
366 while(1){ |
436 while(1){ |
367 if (hp.cmd_available()) |
437 if (hp.cmd_available()) |
368 { |
438 { |
369 HPSerial::CMD cmd; |
439 HPSerial::CMD cmd; |
370 if (hp.pop(cmd)) |
440 if (hp.pop(cmd)) |
371 { |
441 {/* |
372 pc.printf("CMD[%s:%d %d/%d/%d/%d/%d/%d/%d] %X\n", (cmd.direction==HPSerial::Rx)?"Rx":"Tx", cmd.id, |
442 pc.printf("CMD[%s:%d %d/%d/%d/%d/%d/%d/%d] %X\n", (cmd.direction==HPSerial::Rx)?"Rx":"Tx", cmd.id, |
373 hp.nerrors(0), |
443 hp.nerrors(0), |
374 hp.nerrors(1), |
444 hp.nerrors(1), |
375 hp.nerrors(2), |
445 hp.nerrors(2), |
376 hp.nerrors(3), |
446 hp.nerrors(3), |
377 hp.nerrors(4), |
447 hp.nerrors(4), |
378 hp.nerrors(5), |
448 hp.nerrors(5), |
379 hp.nerrors(6), |
449 hp.nerrors(6), |
380 cmd.cmd); |
450 cmd.cmd); |
381 |
451 */ |
382 if (cmd.direction == HPSerial::Rx) { |
452 if (cmd.direction == HPSerial::Rx) { |
383 if ((cmd.cmd == 0x00) || (cmd.cmd == 0x0C)) |
453 // if ((cmd.cmd == 0x00) || (cmd.cmd == 0x0C)) |
384 pc.printf(" data=%s\n", cmd.value); |
454 // pc.printf(" data=%s\n", cmd.value); |
385 show(cmd.cmd, cmd.value, cmd.size); |
455 show(cmd.cmd, cmd.value, cmd.size); |
386 |
456 |
387 } |
457 } |
388 } |
458 } |
389 } |
459 } |
390 Thread::wait(0.01); |
460 Thread::wait(0.01); |
391 } |
461 } |
392 } |
462 } |
393 |
463 |
394 int main() |
464 int main() |
395 { |
465 { |
396 setup(); |
466 setup(); |
|
467 |
397 tdsp.start(copy_to_lcd); |
468 tdsp.start(copy_to_lcd); |
|
469 |
|
470 test_dsp(); |
|
471 wait(5); |
|
472 dsp.cls(); |
|
473 |
398 tloop.start(loop); |
474 tloop.start(loop); |
399 while(1); |
475 while(1); |
400 //loop(); |
476 //loop(); |
401 } |
477 } |