src/main.cpp

changeset 23
daf26b083899
parent 22
2f51221af82d
child 26
86f099bda525
equal deleted inserted replaced
22:2f51221af82d 23:daf26b083899
186 char buffer[MAX_BUFF+1]; 186 char buffer[MAX_BUFF+1];
187 } DSP; 187 } DSP;
188 188
189 static DSP table[] = 189 static DSP table[] =
190 { 190 {
191 { 0x00, 0xF, 0x0, 0, 0, 0x01, MAX_BUFF, 245, Mono19x27}, // main display 191 { 0x00, 0xF, 0x0, 0, 0, 0x01, MAX_BUFF, 245, Mono19x27}, // main display
192 { 0x0C, 0xF, 0x0,204, 38, 0x01, 3, 45, Mono15x22}, // channels display 192 { 0x0C, 0xF, 0x0,196, 34, 0x01, 3, 45, Mono15x22}, // channels display
193 // { 0x01, 0xF, 0x0, 0, 0, 0x80, MAX_BUFF, 0, Terminal6x8}, 193 { 0x0A, 0xF, 0x0, 0, 57, 0x08, 4, 0, Terminal6x8}, // flags + bits
194 // { 0x02, 0xF, 0x0, 0, 0, 0x80, MAX_BUFF, 0, Terminal6x8},
195 { 0x0A, 0xF, 0x0, 0, 57, 0x08, 4, 0, Terminal6x8}, // flags + bits
196 // { 0xFF, 0xF, 0x0, 0, 0, 0x80, MAX_BUFF, 0, Terminal6x8},
197 }; 194 };
198 195
199 // 9x10 196 // 9x10
200 const unsigned char icon_alarm[] __attribute__((aligned (2))) = 197 const unsigned char icon_alarm[] __attribute__((aligned (2))) =
201 { 198 {
226 }; 223 };
227 224
228 typedef struct _FLAG 225 typedef struct _FLAG
229 { 226 {
230 uint8_t flag; 227 uint8_t flag;
231 uint16_t zone;
232 uint8_t x; 228 uint8_t x;
233 uint8_t y; 229 uint8_t y;
230 bool reverse;
234 const char* msg; 231 const char* msg;
235 const unsigned char* icon; 232 const unsigned char* icon;
236 } FLAG; 233 } FLAG;
237 234
238 typedef struct _FRAME 235 typedef struct _FRAME
244 uint8_t y1; 241 uint8_t y1;
245 } FRAME; 242 } FRAME;
246 243
247 static const FLAG flags[] = 244 static const FLAG flags[] =
248 { 245 {
249 // flag, zone, x0, y0, msg, icon 246 // flag, zone, x0, y0, reverse, msg, icon
250 // right-side icons area 247 // right-side icons area
251 { 0x00, 0x02, 0, 0, NULL, icon_alarm}, // F1.0 248 { 0x00, 246, 0, false, NULL, icon_alarm}, // F1.0
252 { 0x01, 0x02, 0, 11, NULL, icon_curve}, // F1.1 249 { 0x01, 246, 11, false, NULL, icon_curve}, // F1.1
253 //{ 0x14, 0x02, 0, 0, "4W"}, // F2.4
254 //{ 0x15, 0x02, 0, 8, "OC"}, // F2.5
255 250
256 // F1.2 == Channel frame 251 // F1.2 == Channel frame
257 { 0x03, 0x04, 1, 2, "Channel"}, // F1.3 252 { 0x03, 197, 27, false, "Channel"}, // F1.3
258 // F1.7 == Alarm frame 253 // F1.7 == Alarm frame
259 254
260 // col 1 255
261 { 0x34, 0x10, 0, 0, "MON"}, // F4.4 256 { 0x34, 0, 28+8, false, "MON"}, // F4.4
262 { 0x33, 0x10, 0, 8, "VIEW"}, // F4.3 257 { 0x33, 0, 28+16, false, "VIEW"}, // F4.3
263 { 0x35, 0x10, 0, 16, "SCAN"}, // F4.5 258 { 0x35, 0, 28, true, "SCAN"}, // F4.5
264 259 { 0x36, 0, 28+25, true, "CONFIG"}, // F4.6
265 //col 2 260
266 { 0x32, 0x20, 0, 0, "*"}, // F4.2 261 { 0x32, 40, 52, false, "*"}, // F4.2
267 { 0x36, 0x20, 0, 8, "CONFIG"}, // F4.6 262 { 0x31, 50, 52, false, "ADRS"}, // F4.1
268 { 0x27, 0x20, 0, 16, "ERROR"}, // F3.7 263 { 0x30, 80, 52, false, "RMT"}, // F4.0
269 264 { 0x27, 104, 52, true, "ERROR"}, // F3.7
270 // col 3 265
271 { 0x41, 0x040, 0, 0, "ADRS"}, // F4.1 266 { 0x26, 140, 52, false, "EXT"}, // F3.6
272 { 0x40, 0x040, 0, 8, "RMT"}, // F4.0 267 { 0x25, 164, 52, false, "ONCE"}, // F3.5
273 268
274 // col 4 269 { 0x23, 104, 28+16, false, "MEM"}, // F3.3
275 { 0x26, 0x080, 0, 0, "EXT"}, // F3.6
276 { 0x25, 0x080, 0, 8, "ONCE"}, // F3.5
277
278 { 0x23, 0x080, 0, 16, "MEM"}, // F3.3
279 270
280 271
281 // col 5 272 // col 5
282 { 0x14, 0x100, 0, 0, "4W"}, // F2.4 273 { 0x14, 244, 22, false, "4W"}, // F2.4
283 { 0x15, 0x100, 0, 8, "OC"}, // F2.5 274 { 0x15, 244, 30, false, "OC"}, // F2.5
284 { 0x22, 0x100, 0, 16, "LAST"}, // F3.2 275 { 0x22, 129, 28+16, false, "LAST"}, // F3.2
285 { 0x21, 0x100, 0, 16, "MIN"}, // F3.1 276 { 0x21, 129, 28+16, false, "MIN"}, // F3.1
286 { 0x20, 0x100, 0, 16, "MAX"}, // F3.0 277 { 0x20, 129, 28+16, false, "MAX"}, // F3.0
287 { 0x17, 0x100, 0, 16, "AVG"}, // F2.7 278 { 0x17, 129, 28+16, false, "AVG"}, // F2.7
288 279
289 { 0x05, 0x08, 0, 0, "Alarm"}, // F1.5 280 { 0x05, 154+0, 17+10, false, "Alarm"}, // F1.5
290 { 0x06, 0x08, 0, 10, "H"}, // F1.6 281 { 0x06, 154+0, 17+20, false, "H"}, // F1.6
291 { 0x13, 0x08, 6, 10, "1"}, // F2.3 282 { 0x13, 154+6, 17+20, false, "1"}, // F2.3
292 { 0x10, 0x08, 12, 10, "2"}, // F2.0 283 { 0x10, 154+12, 17+20, false, "2"}, // F2.0
293 { 0x12, 0x08, 18, 10, "3"}, // F2.2 284 { 0x12, 154+18, 17+20, false, "3"}, // F2.2
294 { 0x11, 0x08, 24, 10, "4"}, // F2.1 285 { 0x11, 154+24, 17+20, false, "4"}, // F2.1
295 { 0x04, 0x08, 30, 10, "L"}, // F1.4 286 { 0x04, 154+30, 17+20, false, "L"}, // F1.4
296 287
297 }; 288 };
298 289
299 static const FRAME zones[] = 290 static const FRAME zones[] =
300 { // flag, x0, y0, x1, y1 291 { // flag, x0, y0, x1, y1
301 { 0x001, 0, 0, 245, 27}, // main display area 292 { 0x001, 0, 0, 245, 27}, // main display area
302 { 0x002, 246, 0, 255, 27}, // right notif area 293 { 0x002, 246, 0, 255, 27}, // right notif area
303 { 0x004, 203, 28, 255, 54}, // channels display area 294 { 0x004, 208, 35, 254, 62}, // channels display area
304 { 0x008, 160, 28, 202, 54}, // alarms area 295 { 0x008, 160, 28, 202, 54}, // alarms area
305 { 0x010, 0, 28, 32, 54}, // flags col1 296 { 0x010, 0, 28, 32, 54}, // flags col1
306 { 0x020, 33, 28, 70, 54}, // flags col2 297 { 0x020, 33, 28, 70, 54}, // flags col2
307 { 0x040, 71, 28, 103, 54}, // flags col3 298 { 0x040, 71, 28, 103, 54}, // flags col3
308 { 0x080, 104, 28, 128, 54}, // flags col4 299 { 0x080, 104, 28, 128, 54}, // flags col4
311 // { 0x8000, 0, 55, 255, 63}, // flags bits display area 302 // { 0x8000, 0, 55, 255, 63}, // flags bits display area
312 }; 303 };
313 304
314 static const FRAME frames[] = 305 static const FRAME frames[] =
315 { 306 {
316 { 0x02, 203, 35, 255, 54}, // F1.2 - channel frame 307 { 0x02, 194, 30, 243, 53}, // F1.2 - channel frame
317 { 0x07, 160, 28, 202, 54}, // F1.7 - alarm frame 308 { 0x07, 151, 30, 192, 46}, // F1.7 - alarm frame
318 }; 309 };
319 310
320 311
321 #ifdef DEBUG 312 #ifdef DEBUG
322 313
403 printf(" DSP_CS=%d\r\n", DSP_CS); 394 printf(" DSP_CS=%d\r\n", DSP_CS);
404 printf(" DSP_RST=%d\r\n", DSP_RST); 395 printf(" DSP_RST=%d\r\n", DSP_RST);
405 printf(" DSP_DC=%d\r\n", DSP_DC); 396 printf(" DSP_DC=%d\r\n", DSP_DC);
406 dsp = new SSD1322(20000000, DSP_MOSI, DSP_MISO, DSP_SCLK, DSP_CS, 397 dsp = new SSD1322(20000000, DSP_MOSI, DSP_MISO, DSP_SCLK, DSP_CS,
407 DSP_RST, DSP_DC, "SSD1322"); 398 DSP_RST, DSP_DC, "SSD1322");
408 //dsp.set_orientation(3); 399
409 printf(" configure DSP\r\n"); 400 printf(" configure DSP\r\n");
410 // myLCD.set_font((unsigned char*) Terminal6x8);
411 // myLCD.claim(stdout); // send stdout to the LCD display
412 // myLCD.claim(stderr); // send stderr to the LCD display
413 dsp->background(Black); // set background to black 401 dsp->background(Black); // set background to black
414 dsp->foreground(0xF); 402 dsp->foreground(0xF);
415 dsp->cls(); 403 dsp->cls();
416 404
417 cmd = 0xFF; 405 cmd = 0xFF;
450 } 438 }
451 439
452 void end_splashscreen(void) 440 void end_splashscreen(void)
453 { 441 {
454 printf("End of splash screen CB\r\n"); 442 printf("End of splash screen CB\r\n");
455 //dsp->cls();
456 splashscreen = false; 443 splashscreen = false;
457 } 444 }
458 445
459 void reset_irq(void) 446 void reset_irq(void)
460 { 447 {
505 pulse(0, false); 492 pulse(0, false);
506 Thread::wait(30); 493 Thread::wait(30);
507 } 494 }
508 } 495 }
509 496
510 void show(uint8_t cmd, const char *intxt, uint8_t nchar=0) { 497 void show(uint8_t cmd, const char *intxt, uint8_t nchar=0)
498 {
511 uint8_t i, len; 499 uint8_t i, len;
512 uint16_t bgcolor, fgcolor; 500 uint16_t bgcolor, fgcolor;
513 char *oldv; 501 char *oldv;
514 char *txt, *txtp; 502 char *txt, *txtp;
515 503
518 { 506 {
519 dsp->clrbuff(); 507 dsp->clrbuff();
520 } 508 }
521 else 509 else
522 { 510 {
523 txt = (char *)malloc(strlen(intxt)+1); 511 txt = (char *)malloc(strlen(intxt)+1);
524 strcpy(txt, intxt); 512 strcpy(txt, intxt);
525 txtp = txt; 513 txtp = txt;
526 514
527 pulse(1, true); 515 pulse(1, true);
528 516
529 len = MAX_BUFF; 517 len = MAX_BUFF;
530 518
531 for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) { 519 for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) {
532 if (table[i].cmd == cmd) { 520 if (table[i].cmd == cmd) {
533 bgcolor = table[i].bgcolor; 521 bgcolor = table[i].bgcolor;
534 fgcolor = table[i].color; 522 fgcolor = table[i].color;
535 dsp->background(bgcolor); 523 dsp->background(bgcolor);
536 dsp->foreground(fgcolor); 524 dsp->foreground(fgcolor);
537 dsp->set_font((unsigned char*) table[i].font); 525 dsp->set_font((unsigned char*) table[i].font);
538 oldv = table[i].buffer; 526 oldv = table[i].buffer;
539 527
540 dsp->locate(table[i].x0, table[i].y0); 528 dsp->locate(table[i].x0, table[i].y0);
541 529
542 if (table[i].fmt & 0x01 ) 530 if (table[i].fmt & 0x01 ) // ASCII text
543 { 531 {
544 if (strncmp(oldv, txt, table[i].maxsize) != 0) 532 if (strncmp(oldv, txt, table[i].maxsize) != 0)
545 { 533 {
546 // ascii 534 if (table[i].width > 0)
547 if (table[i].width > 0) 535 dsp->fillrect(table[i].x0,
548 dsp->fillrect(table[i].x0, 536 table[i].y0,
549 table[i].y0, 537 table[i].x0 + table[i].width,
550 table[i].x0 + table[i].width, 538 table[i].y0 + table[i].font[2],
551 table[i].y0 + table[i].font[2], 539 bgcolor);
552 bgcolor); 540 for (uint8_t k=0; ;k++)
553 for (uint8_t k=0; ;k++) 541 {
554 { 542 if (txtp[k] == 0x00)
555 if (txtp[k] == 0x00) 543 {
556 { 544 dsp->printf(txtp);
557 dsp->printf(txtp); 545 break;
558 break; 546 }
547 if (txtp[k] == 0x09)
548 { // \t is a special char for 'unselected' display value
549 txtp[k] = 0x00;
550 dsp->printf(txtp);
551
552 if (fgcolor == table[i].color)
553 fgcolor /= 2;
554 else
555 fgcolor = table[i].color;
556 dsp->foreground(fgcolor);
557 txtp = &(txtp[k+1]);
558 k = 0;
559 }
560 }
561 if (cmd == 0x00) // main area
562 must_refresh |= 0x01;
563 if (cmd == 0x0C) // channels area
564 must_refresh |= 0x04;
565 }
566 }
567 /*
568 if (table[i].fmt & 0x02 ) {
569 // hex
570 for (uint8_t j=0;; j++) {
571 if (txt[j] == 0x00)
572 break;
573 dsp->printf("%02X ", txt[j]);
574 }
575 for (uint8_t j=3*strlen(txt); j<table[i].maxsize; j++)
576 dsp->printf(" ");
577 }
578 */
579 if (table[i].fmt & 0x08 ) // flag indicators
580 {
581 // flags
582 for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++)
583 {
584 for (uint8_t k=0; k<8; k++)
585 {
586 if (1)
587 { //(txt[j] & (1 << k) ) != (oldv[j] & (1 << k))) {
588 for (uint8_t l=0;
589 l<(sizeof(flags)/sizeof(flags[0])); ++l)
590 {
591 if (flags[l].flag == ((j<<4) + k)) {
592 if (txtp[j] & (1 << k))
593 {
594 dsp->foreground(flags[l].reverse ? bgcolor : fgcolor);
595 dsp->background(flags[l].reverse ? fgcolor : bgcolor);
596 }
597 else
598 {
599 dsp->foreground(bgcolor);
600 dsp->background(bgcolor);
601 }
602 if (flags[l].msg != NULL)
603 { // a string
604 dsp->locate(flags[l].x, flags[l].y);
605 dsp->printf(flags[l].msg);}
606 else
607 { // an icon
608 Bitmap_s pic = {9, 10, 2, (char*) flags[l].icon};
609 dsp->Bitmap_BW(pic, flags[l].x, flags[l].y);
610 }
611 must_refresh = 1; //|= zones[m].flag;
612 break;
613 }
614 }
615 }
616 }
617 }
618
619 // draw frames (Alarm and Channel)
620 for (uint8_t l=0;
621 l<(sizeof(frames)/sizeof(frames[0])); ++l)
622 {
623 uint16_t color;
624 if (frames[l].flag & txt[0]) // frame flags are on the 1st byte only
625 color = fgcolor/6;
626 else
627 color = bgcolor;
628 dsp->hline(frames[l].x0+1, frames[l].x0+3, frames[l].y0, color);
629 dsp->hline(frames[l].x1-3, frames[l].x1-1, frames[l].y0, color);
630 dsp->hline(frames[l].x0+1, frames[l].x1-1, frames[l].y1, color);
631
632 dsp->vline(frames[l].x0, frames[l].y0+1, frames[l].y1-1, color);
633 dsp->vline(frames[l].x1, frames[l].y0+1, frames[l].y1-1, color);
634 }
635 }
636
637 for(uint8_t j=0; j<table[i].maxsize; j++)
638 oldv[j] = txt[j];
639 break;
559 } 640 }
560 if (txtp[k] == 0x09)
561 { // \t is a special char for 'unselected' display value
562 txtp[k] = 0x00;
563 dsp->printf(txtp);
564
565 if (fgcolor == table[i].color)
566 fgcolor /= 2;
567 else
568 fgcolor = table[i].color;
569 dsp->foreground(fgcolor);
570 txtp = &(txtp[k+1]);
571 k = 0;
572 }
573 }
574 if (cmd == 0x00) // main area
575 must_refresh |= 0x01;
576 if (cmd == 0x0C) // channels area
577 must_refresh |= 0x04;
578 } 641 }
579 } 642 free(txt);
580 /* 643 //dsp->copy_to_lcd();
581 if (table[i].fmt & 0x02 ) { 644 pulse(1, false);
582 // hex
583 for (uint8_t j=0;; j++) {
584 if (txt[j] == 0x00)
585 break;
586 dsp->printf("%02X ", txt[j]);
587 }
588 for (uint8_t j=3*strlen(txt); j<table[i].maxsize; j++)
589 dsp->printf(" ");
590 }
591 */
592 if (table[i].fmt & 0x08 )
593 {
594 // flags
595 for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++)
596 {
597 for (uint8_t k=0; k<8; k++)
598 {
599 if (1)
600 { //(txt[j] & (1 << k) ) != (oldv[j] & (1 << k))) {
601 if (txtp[j] & (1 << k))
602 dsp->foreground(fgcolor);
603 else
604 dsp->foreground(bgcolor);
605
606 /*
607 for (uint8_t l=0;
608 l<(sizeof(frames)/sizeof(frames[0])); ++l) {
609 if (frames[l].flag & ((j<<4) + k))
610 dsp->fillrect(frames[l].x0, frames[l].y0,
611 frames[l].x1, frames[l].y1,
612 fgcolor/8);
613 else
614 dsp->fillrect(frames[l].x0, frames[l].y0,
615 frames[l].x1, frames[l].y1,
616 bgcolor);
617
618 }
619 */
620
621 for (uint8_t l=0;
622 l<(sizeof(flags)/sizeof(flags[0])); ++l)
623 {
624 if (flags[l].flag == ((j<<4) + k)) {
625 for (uint8_t m=0; m<(sizeof(zones)/sizeof(zones[0])); m++)
626 {
627 if (flags[l].zone == zones[m].flag) {
628 if (flags[l].msg != NULL)
629 { // a string
630 dsp->locate(flags[l].x + zones[m].x0,
631 flags[l].y + zones[m].y0);
632 dsp->printf(flags[l].msg);}
633 else
634 { // an icon
635 Bitmap_s pic = {9, 10, 2, (char*) flags[l].icon};
636 dsp->Bitmap_BW(pic,
637 flags[l].x + zones[m].x0,
638 flags[l].y + zones[m].y0);
639 }
640 must_refresh |= zones[m].flag;
641 break;
642 }
643 }
644 break;
645 }
646 }
647 }
648 }
649 }
650 }
651
652 for(uint8_t j=0; j<table[i].maxsize; j++)
653 oldv[j] = txt[j];
654 break;
655 }
656 }
657 free(txt);
658 //dsp->copy_to_lcd();
659 pulse(1, false);
660 } 645 }
661 } 646 }
662 647
663 void test_dsp() 648 void test_dsp()
664 { 649 {

mercurial