src/main.cpp

changeset 34
94ab7ff42a1b
parent 32
bc1d6ecbb0cc
child 35
b2dca6b935bb
equal deleted inserted replaced
33:167010858b8d 34:94ab7ff42a1b
54 //volatile keycode_t cur_keycode; 54 //volatile keycode_t cur_keycode;
55 55
56 #define KEY_BUF_SIZE 10 56 #define KEY_BUF_SIZE 10
57 CircularBuffer<keycode_t, KEY_BUF_SIZE> key_buf; 57 CircularBuffer<keycode_t, KEY_BUF_SIZE> key_buf;
58 58
59 PinName kp_rows[] = { 59 #define KP_NROWS 4
60 #define KP_NCOLS 5
61 DigitalIn kp_rows[KP_NROWS] = {
60 KP_R0, 62 KP_R0,
61 KP_R1, 63 KP_R1,
62 KP_R2, 64 KP_R2,
63 KP_R3 65 KP_R3
64 }; 66 };
65 67
66 PinName kp_colums[] = { 68 DigitalOut kp_columns[KP_NCOLS] = {
67 KP_C0, KP_C1, 69 KP_C0, KP_C1,
68 KP_C2, KP_C3, 70 KP_C2, KP_C3,
69 KP_C4 71 KP_C4
70 }; 72 };
71 73
72 DigitalIn kp_in[] = { 74 /* mapping (RxC)
73 KP_R0, 75 0x2 0x00: View
74 KP_R1, 76 0x1 0x01: Mon
75 KP_R2, 77 3x3 0x02: Sto/Rcl
76 KP_R3 78 0x0 0x03: Scan
79 1x2 0x04: Alarm
80 1x1 0x05: Mx+B
81 1x0 0x06: Measure
82 2x0 0x07: Interval
83 3x2 0x08: Card Reset
84 3x1 0x09: Close
85 3x0 0x0A: Open
86 0x3 0x0B: Read
87 2x3 0x0C: Shift
88 1x3 0x0D: Write
89 0x4 0x0E: Left
90 1x4 0x0F: Right
91 2x2 0x10: Advanced
92 2x1 0x11: Step
93 */
94
95 uint8_t kp_mapping[KP_NROWS][KP_NCOLS] = { // [row][column]
96 {0x03, 0x01, 0x00, 0x0B, 0x0E},
97 {0x06, 0x05, 0x04, 0x0D, 0x0F},
98 {0x07, 0x11, 0x10, 0x0C, 0xFF},
99 {0x0A, 0x09, 0x08, 0x02, 0xFF}
77 }; 100 };
78 101
79 DigitalOut kp_out[] = {
80 KP_C0, KP_C1,
81 KP_C2, KP_C3,
82 KP_C4
83 };
84
85 uint8_t kp_nrows = sizeof(kp_in)/sizeof(kp_in[0]);
86 uint8_t kp_ncols = sizeof(kp_out)/sizeof(kp_out[0]);
87 102
88 void kp_cb(uint8_t row, uint8_t col); 103 void kp_cb(uint8_t row, uint8_t col);
89 void kr_cb(uint8_t row, uint8_t col); 104 void kr_cb(uint8_t row, uint8_t col);
90 105
91 Keypad *kpad; 106 Keypad *kpad;
153 typedef struct _FLAG 168 typedef struct _FLAG
154 { 169 {
155 uint8_t flag; 170 uint8_t flag;
156 uint8_t x; 171 uint8_t x;
157 uint8_t y; 172 uint8_t y;
158 bool reverse; 173 bool reverse;
159 const char* msg; 174 const char* msg;
160 const unsigned char* icon; 175 const unsigned char* icon;
161 } FLAG; 176 } FLAG;
162 177
163 typedef struct _FRAME 178 typedef struct _FRAME
171 186
172 static const FLAG flags[] = 187 static const FLAG flags[] =
173 { 188 {
174 // flag, zone, x0, y0, reverse, msg, icon 189 // flag, zone, x0, y0, reverse, msg, icon
175 // right-side icons area 190 // right-side icons area
176 { 0x00, 246, 0, false, NULL, icon_alarm}, // F1.0 191 { 0x00, 246, 0, false, NULL, icon_alarm}, // F1.0
177 { 0x01, 246, 11, false, NULL, icon_curve}, // F1.1 192 { 0x01, 246, 11, false, NULL, icon_curve}, // F1.1
178 193
179 // F1.2 == Channel frame 194 // F1.2 == Channel frame
180 { 0x03, 197, 27, false, "Channel"}, // F1.3 195 { 0x03, 197, 27, false, "Channel"}, // F1.3
181 // F1.7 == Alarm frame 196 // F1.7 == Alarm frame
182 197
183 { 0x34, 0, 28+8, false, "MON"}, // F4.4 198 { 0x34, 0, 28+8, false, "MON"}, // F4.4
184 { 0x33, 0, 28+16, false, "VIEW"}, // F4.3 199 { 0x33, 0, 28+16, false, "VIEW"}, // F4.3
185 { 0x35, 0, 28, true, "SCAN"}, // F4.5 200 { 0x35, 0, 28, true, "SCAN"}, // F4.5
186 { 0x36, 0, 28+25, true, "CONFIG"}, // F4.6 201 { 0x36, 0, 28+25, true, "CONFIG"}, // F4.6
278 */ 293 */
279 294
280 void setup() { 295 void setup() {
281 #if defined(HAVE_PC) 296 #if defined(HAVE_PC)
282 #if defined(TARGET_NUCLEO_F446RE) 297 #if defined(TARGET_NUCLEO_F446RE)
283 pc.set_baud(115200); 298 pc.set_baud(115200);
284 #endif 299 #endif
285 300
286 /* 301 /*
287 #if defined(TARGET_HP34970_FP_F303RD) 302 #if defined(TARGET_HP34970_FP_F303RD)
288 pc.init(); 303 pc.init();
291 */ 306 */
292 #endif 307 #endif
293 308
294 printf("\n\nSETUP\n"); 309 printf("\n\nSETUP\n");
295 printf(" System Core Clock = %.3f MHZ\r\n", 310 printf(" System Core Clock = %.3f MHZ\r\n",
296 (float)SystemCoreClock/1000000); 311 (float)SystemCoreClock/1000000);
297 312
298 /* 313 /*
299 #if defined(HAS_LED) 314 #if defined(HAS_LED)
300 printf("Attaching Led 1: %d\n", LED1); 315 printf("Attaching Led 1: %d\n", LED1);
301 blinker.attach(callback(timeout_h), 0.5f); 316 blinker.attach(callback(timeout_h), 0.5f);
327 DigitalIn(KP_ENC2).mode(PullDown); 342 DigitalIn(KP_ENC2).mode(PullDown);
328 qenc.attach(&qei_cb); 343 qenc.attach(&qei_cb);
329 344
330 printf(" setup Keypad\r\n"); 345 printf(" setup Keypad\r\n");
331 //cur_keycode.keyevent = KEY_NONE; 346 //cur_keycode.keyevent = KEY_NONE;
332 uint8_t nrows = sizeof(kp_rows)/sizeof(kp_rows[0]); 347
333 uint8_t ncols = sizeof(kp_colums)/sizeof(kp_colums[0]); 348 kpad = new Keypad(KP_NROWS, kp_rows, KP_NCOLS, kp_columns);
334
335 kpad = new Keypad(nrows, kp_in, ncols, kp_out);
336 printf(" attach Keypad callbacks\r\n"); 349 printf(" attach Keypad callbacks\r\n");
337 kpad->attach(&kp_cb, &kr_cb); 350 kpad->attach(&kp_cb, &kr_cb);
338 printf(" start Keypad\r\n"); 351 printf(" start Keypad\r\n");
339 kpad->start(); 352 kpad->start();
340 353
345 printf(" DSP_SCLK=%d\r\n", DSP_SCLK); 358 printf(" DSP_SCLK=%d\r\n", DSP_SCLK);
346 printf(" DSP_CS=%d\r\n", DSP_CS); 359 printf(" DSP_CS=%d\r\n", DSP_CS);
347 printf(" DSP_RST=%d\r\n", DSP_RST); 360 printf(" DSP_RST=%d\r\n", DSP_RST);
348 printf(" DSP_DC=%d\r\n", DSP_DC); 361 printf(" DSP_DC=%d\r\n", DSP_DC);
349 dsp = new SSD1322(20000000, DSP_MOSI, DSP_MISO, DSP_SCLK, DSP_CS, 362 dsp = new SSD1322(20000000, DSP_MOSI, DSP_MISO, DSP_SCLK, DSP_CS,
350 DSP_RST, DSP_DC, "SSD1322"); 363 DSP_RST, DSP_DC, "SSD1322");
351 364
352 printf(" configure DSP\r\n"); 365 printf(" configure DSP\r\n");
353 dsp->background(Black); // set background to black 366 dsp->background(Black); // set background to black
354 dsp->foreground(0xF); 367 dsp->foreground(0xF);
355 dsp->cls(); 368 dsp->cls();
372 dsp->printf("Clock = %d ", SystemCoreClock); 385 dsp->printf("Clock = %d ", SystemCoreClock);
373 386
374 RCC_OscInitTypeDef cfg; 387 RCC_OscInitTypeDef cfg;
375 HAL_RCC_GetOscConfig(&cfg); 388 HAL_RCC_GetOscConfig(&cfg);
376 if (cfg.HSEState == RCC_HSE_BYPASS) 389 if (cfg.HSEState == RCC_HSE_BYPASS)
377 dsp->printf("HSE:EXT "); 390 dsp->printf("HSE:EXT ");
378 else if (cfg.HSEState == RCC_HSE_ON) 391 else if (cfg.HSEState == RCC_HSE_ON)
379 dsp->printf("HSE:XTAL "); 392 dsp->printf("HSE:XTAL ");
380 else 393 else
381 dsp->printf("HSE:OFF "); 394 dsp->printf("HSE:OFF ");
382 395
383 if (cfg.HSIState == RCC_HSI_ON) 396 if (cfg.HSIState == RCC_HSI_ON)
384 dsp->printf("HSI:ON "); 397 dsp->printf("HSI:ON ");
385 else 398 else
386 dsp->printf("HSI:OFF "); 399 dsp->printf("HSI:OFF ");
387 400
388 dsp->copy_to_lcd(); 401 dsp->copy_to_lcd();
389 402
390 printf("Starting LCD thread\r\n"); 403 printf("Starting LCD thread\r\n");
391 tdsp.start(&copy_to_lcd); 404 tdsp.start(&copy_to_lcd);
408 printf("SETUP DONE\r\n"); 421 printf("SETUP DONE\r\n");
409 } 422 }
410 423
411 void end_splashscreen(void) 424 void end_splashscreen(void)
412 { 425 {
413 // print is forbidden here because we are in an ISR context here 426 // print is forbidden here because we are in an ISR context here
414 //printf("End of splash screen CB\r\n"); 427 //printf("End of splash screen CB\r\n");
415 splashscreen = false; 428 splashscreen = false;
416 } 429 }
417 430
418 void reset_irq(void) 431 void reset_irq(void)
419 { 432 {
427 printf("setup HP communication handler\r\n"); 440 printf("setup HP communication handler\r\n");
428 hp = new HPSerial(HP_TX, HP_RX); 441 hp = new HPSerial(HP_TX, HP_RX);
429 } 442 }
430 443
431 printf("!! RST !! (gstate=%d, state=%d)\r\n", 444 printf("!! RST !! (gstate=%d, state=%d)\r\n",
432 hp->gstate(), hp->state()); 445 hp->gstate(), hp->state());
433 //printf("Value is ... %X\n", hp->search()); 446 //printf("Value is ... %X\n", hp->search());
434 hp->startup(); 447 hp->startup();
435 } 448 }
436 } 449 }
437 450
447 } 460 }
448 461
449 /* 462 /*
450 if (must_refresh & mask) { 463 if (must_refresh & mask) {
451 for(uint8_t i=0; i<sizeof(zones)/sizeof(zones[0]); i++) 464 for(uint8_t i=0; i<sizeof(zones)/sizeof(zones[0]); i++)
452 if (zones[i].flag == mask) { 465 if (zones[i].flag == mask) {
453 dsp->copy_to_lcd(zones[i].x0/4, (zones[i].x1+3)/4, 466 dsp->copy_to_lcd(zones[i].x0/4, (zones[i].x1+3)/4,
454 zones[i].y0, zones[i].y1); 467 zones[i].y0, zones[i].y1);
455 must_refresh &= ~mask; 468 must_refresh &= ~mask;
456 break; 469 break;
457 } 470 }
458 } 471 }
459 mask = mask << 1; 472 mask = mask << 1;
460 if (mask == 0) { 473 if (mask == 0) {
461 mask = 1; 474 mask = 1;
462 } 475 }
463 */ 476 */
464 pulse(0, false); 477 pulse(0, false);
465 478
466 ThisThread::sleep_for(30); 479 ThisThread::sleep_for(30);
467 } 480 }
468 } 481 }
469 482
470 void show(uint8_t cmd, const char *intxt, uint8_t nchar=0) 483 void show(uint8_t cmd, const char *intxt, uint8_t nchar=0)
471 { 484 {
478 static char txt[256]; 491 static char txt[256];
479 492
480 493
481 if (cmd == 0xFF) // cls 494 if (cmd == 0xFF) // cls
482 { 495 {
483 dsp->clrbuff(); 496 dsp->clrbuff();
484 } 497 }
485 else 498 else
486 { 499 {
487 //txt = (char *)malloc(strlen(intxt)+1); 500 //txt = (char *)malloc(strlen(intxt)+1);
488 strcpy(txt, intxt); 501 strcpy(txt, intxt);
489 txtp = txt; 502 txtp = txt;
490 503
491 pulse(1, true); 504 pulse(1, true);
492 505
493 // len = MAX_BUFF; 506 // len = MAX_BUFF;
494 507
495 for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) { 508 for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) {
496 if (table[i].cmd == cmd) { 509 if (table[i].cmd == cmd) {
497 bgcolor = table[i].bgcolor; 510 bgcolor = table[i].bgcolor;
498 fgcolor = table[i].color; 511 fgcolor = table[i].color;
499 dsp->background(bgcolor); 512 dsp->background(bgcolor);
500 dsp->foreground(fgcolor); 513 dsp->foreground(fgcolor);
501 dsp->set_font((unsigned char*) table[i].font); 514 dsp->set_font((unsigned char*) table[i].font);
502 oldv = table[i].buffer; 515 oldv = table[i].buffer;
503 516
504 dsp->locate(table[i].x0, table[i].y0); 517 dsp->locate(table[i].x0, table[i].y0);
505 518
506 if (table[i].fmt & 0x01) // ASCII text 519 if (table[i].fmt & 0x01) // ASCII text
507 { 520 {
508 if (strncmp(oldv, txt, table[i].maxsize) != 0) 521 if (strncmp(oldv, txt, table[i].maxsize) != 0)
509 { 522 {
510 if (table[i].width > 0) 523 if (table[i].width > 0)
511 dsp->fillrect(table[i].x0, 524 dsp->fillrect(table[i].x0,
512 table[i].y0, 525 table[i].y0,
513 table[i].x0 + table[i].width, 526 table[i].x0 + table[i].width,
514 table[i].y0 + table[i].font[2], 527 table[i].y0 + table[i].font[2],
515 bgcolor); 528 bgcolor);
516 for (uint8_t k=0; ;k++) 529 for (uint8_t k=0; ;k++)
517 { 530 {
518 if (txtp[k] == 0x00) 531 if (txtp[k] == 0x00)
519 { 532 {
520 dsp->printf(txtp); 533 dsp->printf(txtp);
521 break; 534 break;
522 } 535 }
523 if (txtp[k] == 0x09) 536 if (txtp[k] == 0x09)
524 { // \t is a special char for 'unselected' display value 537 { // \t is a special char for 'unselected' display value
525 txtp[k] = 0x00; 538 txtp[k] = 0x00;
526 dsp->printf(txtp); 539 dsp->printf(txtp);
527 540
528 if (fgcolor == table[i].color) 541 if (fgcolor == table[i].color)
529 fgcolor /= 2; 542 fgcolor /= 2;
530 else 543 else
531 fgcolor = table[i].color; 544 fgcolor = table[i].color;
532 dsp->foreground(fgcolor); 545 dsp->foreground(fgcolor);
533 txtp = &(txtp[k+1]); 546 txtp = &(txtp[k+1]);
534 k = 0; 547 k = 0;
535 } 548 }
536 } 549 }
537 if (cmd == 0x00) // main area 550 if (cmd == 0x00) // main area
538 must_refresh |= 0x01; 551 must_refresh |= 0x01;
539 if (cmd == 0x0C) // channels area 552 if (cmd == 0x0C) // channels area
540 must_refresh |= 0x04; 553 must_refresh |= 0x04;
541 } 554 }
542 } 555 }
543 /* 556 /*
544 if (table[i].fmt & 0x02 ) { 557 if (table[i].fmt & 0x02 ) {
545 // hex 558 // hex
546 for (uint8_t j=0;; j++) { 559 for (uint8_t j=0;; j++) {
547 if (txt[j] == 0x00) 560 if (txt[j] == 0x00)
548 break; 561 break;
549 dsp->printf("%02X ", txt[j]); 562 dsp->printf("%02X ", txt[j]);
550 } 563 }
551 for (uint8_t j=3*strlen(txt); j<table[i].maxsize; j++) 564 for (uint8_t j=3*strlen(txt); j<table[i].maxsize; j++)
552 dsp->printf(" "); 565 dsp->printf(" ");
553 } 566 }
554 */ 567 */
555 if (table[i].fmt & 0x08 ) // flag indicators 568 if (table[i].fmt & 0x08 ) // flag indicators
556 { 569 {
557 // flags 570 // flags
558 for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++) 571 for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++)
559 { 572 {
560 for (uint8_t k=0; k<8; k++) 573 for (uint8_t k=0; k<8; k++)
561 { 574 {
562 if (1) 575 if (1)
563 { //(txt[j] & (1 << k) ) != (oldv[j] & (1 << k))) { 576 { //(txt[j] & (1 << k) ) != (oldv[j] & (1 << k))) {
564 for (uint8_t l=0; 577 for (uint8_t l=0;
565 l<(sizeof(flags)/sizeof(flags[0])); ++l) 578 l<(sizeof(flags)/sizeof(flags[0])); ++l)
566 { 579 {
567 if (flags[l].flag == ((j<<4) + k)) { 580 if (flags[l].flag == ((j<<4) + k)) {
568 if (txtp[j] & (1 << k)) 581 if (txtp[j] & (1 << k))
569 { 582 {
570 dsp->foreground(flags[l].reverse ? bgcolor : fgcolor); 583 dsp->foreground(flags[l].reverse ? bgcolor : fgcolor);
571 dsp->background(flags[l].reverse ? fgcolor : bgcolor); 584 dsp->background(flags[l].reverse ? fgcolor : bgcolor);
572 } 585 }
573 else 586 else
574 { 587 {
575 dsp->foreground(bgcolor); 588 dsp->foreground(bgcolor);
576 dsp->background(bgcolor); 589 dsp->background(bgcolor);
577 } 590 }
578 if (flags[l].msg != NULL) 591 if (flags[l].msg != NULL)
579 { // a string 592 { // a string
580 dsp->locate(flags[l].x, flags[l].y); 593 dsp->locate(flags[l].x, flags[l].y);
581 dsp->printf(flags[l].msg);} 594 dsp->printf(flags[l].msg);}
582 else 595 else
583 { // an icon 596 { // an icon
584 Bitmap_s pic = {9, 10, 2, (char*) flags[l].icon}; 597 Bitmap_s pic = {9, 10, 2, (char*) flags[l].icon};
585 dsp->Bitmap_BW(pic, flags[l].x, flags[l].y); 598 dsp->Bitmap_BW(pic, flags[l].x, flags[l].y);
586 } 599 }
587 must_refresh = 1; //|= zones[m].flag; 600 must_refresh = 1; //|= zones[m].flag;
588 break; 601 break;
589 } 602 }
590 } 603 }
591 } 604 }
592 } 605 }
593 } 606 }
594 607
595 // draw frames (Alarm and Channel) 608 // draw frames (Alarm and Channel)
596 for (uint8_t l=0; 609 for (uint8_t l=0;
597 l<(sizeof(frames)/sizeof(frames[0])); ++l) 610 l<(sizeof(frames)/sizeof(frames[0])); ++l)
598 { 611 {
599 uint16_t color; 612 uint16_t color;
600 if (frames[l].flag & txt[0]) // frame flags are on the 1st byte only 613 if (frames[l].flag & txt[0]) // frame flags are on the 1st byte only
601 color = fgcolor/6; 614 color = fgcolor/6;
602 else 615 else
603 color = bgcolor; 616 color = bgcolor;
604 dsp->hline(frames[l].x0+1, frames[l].x0+3, frames[l].y0, color); 617 dsp->hline(frames[l].x0+1, frames[l].x0+3, frames[l].y0, color);
605 dsp->hline(frames[l].x1-3, frames[l].x1-1, frames[l].y0, color); 618 dsp->hline(frames[l].x1-3, frames[l].x1-1, frames[l].y0, color);
606 dsp->hline(frames[l].x0+1, frames[l].x1-1, frames[l].y1, color); 619 dsp->hline(frames[l].x0+1, frames[l].x1-1, frames[l].y1, color);
607 620
608 dsp->vline(frames[l].x0, frames[l].y0+1, frames[l].y1-1, color); 621 dsp->vline(frames[l].x0, frames[l].y0+1, frames[l].y1-1, color);
609 dsp->vline(frames[l].x1, frames[l].y0+1, frames[l].y1-1, color); 622 dsp->vline(frames[l].x1, frames[l].y0+1, frames[l].y1-1, color);
610 } 623 }
611 } 624 }
612 625
613 for(uint8_t j=0; j<table[i].maxsize; j++) 626 for(uint8_t j=0; j<table[i].maxsize; j++)
614 oldv[j] = txt[j]; 627 oldv[j] = txt[j];
615 break; 628 break;
616 } 629 }
617 } 630 }
618 //free(txt); 631 //free(txt);
619 //dsp->copy_to_lcd(); 632 //dsp->copy_to_lcd();
620 pulse(1, false); 633 pulse(1, false);
621 } 634 }
622 } 635 }
623 636
624 void test_dsp() 637 void test_dsp()
625 { 638 {
646 /* 659 /*
647 for (uint8_t i=0; i<(sizeof(zones)/sizeof(zones[0])); i++) 660 for (uint8_t i=0; i<(sizeof(zones)/sizeof(zones[0])); i++)
648 { 661 {
649 z = &zones[i]; 662 z = &zones[i];
650 printf("Zone %d [%x]: %d, %d, %d, %d\n", i, z->flag, 663 printf("Zone %d [%x]: %d, %d, %d, %d\n", i, z->flag,
651 z->x0, z->y0, z->x1, z->y1); 664 z->x0, z->y0, z->x1, z->y1);
652 must_refresh = z->flag; 665 must_refresh = z->flag;
653 wait(1); 666 wait(1);
654 } 667 }
655 printf("Done\n"); 668 printf("Done\n");
656 wait(2); 669 wait(2);
663 } 676 }
664 677
665 678
666 void loop() 679 void loop()
667 { // run over and over 680 { // run over and over
668 keycode_t key; 681 keycode_t key;
669 682
670 unsigned int err[8]; 683 unsigned int err[8];
671 for (uint8_t i=0; i<8; i++) 684 for (uint8_t i=0; i<8; i++)
672 err[i] = 0; 685 err[i] = 0;
673 int p, pp; // rot encoder pulse counters 686 int p, pp; // rot encoder pulse counters
675 pp = 0; 688 pp = 0;
676 689
677 while(1) { 690 while(1) {
678 p = qenc.getPulses(); 691 p = qenc.getPulses();
679 if (p != pp) 692 if (p != pp)
693 {
694 dsp->locate(0, 0);
695 dsp->printf("Pulses = %d ", p);
696 dsp->copy_to_lcd();
697 pp = p;
698 }
699
700 if (knob != 0)
701 {
702 if (hp != NULL)
703 {
704 printf("Sending keycode %X\r\n", knob);
705 hp->sendkey(knob);
706 printf(" DONE\r\n");
707 }
708 else
709 {
710 dsp->locate(70, 0);
711 dsp->printf("Knob = %X ", knob);
712 dsp->copy_to_lcd();
713 }
714 knob = 0;
715 }
716
717 if (!key_buf.empty()) //cur_keycode.keyevent != KEY_NONE)
680 { 718 {
681 dsp->locate(0, 0); 719 key_buf.pop(key);
682 dsp->printf("Pulses = %d ", p); 720 printf("Keycode %dx%d: %s\r\n",
683 dsp->copy_to_lcd(); 721 key.row, key.col, key.keyevent==KEY_PRESSED?"pressed":"released");
684 pp = p; 722 if (hp != NULL) {
685 } 723 hp->sendkey(kp_mapping[key.row][key.col]);
686
687 if (knob != 0)
688 {
689 if (hp != NULL)
690 {
691 printf("Sending keycode %X\r\n", knob);
692 hp->sendkey(knob);
693 printf(" DONE\r\n");
694 } 724 }
695 else 725 else
696 { 726 {
697 dsp->locate(70, 0); 727 dsp->locate(140, 0);
698 dsp->printf("Knob = %X ", knob); 728 dsp->printf("KC: %dx%d[%X] %s",
699 dsp->copy_to_lcd(); 729 key.row, key.col, kp_mapping[key.row][key.col],
730 key.keyevent==KEY_PRESSED?"PRE":"REL");
731 dsp->copy_to_lcd();
700 } 732 }
701 knob = 0; 733 // cur_keycode.keyevent = KEY_NONE;
702 } 734 }
703
704 if (!key_buf.empty()) //cur_keycode.keyevent != KEY_NONE)
705 {
706 key_buf.pop(key);
707 printf("Keycode %dx%d: %s\r\n",
708 key.row, key.col, key.keyevent==KEY_PRESSED?"pressed":"released");
709 if (hp != NULL) {
710 }
711 else
712 {
713 dsp->locate(140, 0);
714 dsp->printf("KC: %dx%d: %s",
715 key.row, key.col,key.keyevent==KEY_PRESSED?"PRE":"REL");
716 dsp->copy_to_lcd();
717 }
718 // cur_keycode.keyevent = KEY_NONE;
719 }
720 735
721 736
722 if ((hp != NULL) && (hp->cmd_available())) 737 if ((hp != NULL) && (hp->cmd_available()))
723 { 738 {
724 HPSerial::CMD cmd; 739 HPSerial::CMD cmd;
725 if (hp->pop(cmd)) 740 if (hp->pop(cmd))
726 { 741 {
727 #if defined(HAS_LED) 742 #if defined(HAS_LED)
728 led = 1; 743 led = 1;
729 #endif 744 #endif
730 for (uint8_t i=0; i<7; i++) 745 for (uint8_t i=0; i<7; i++)
731 if (hp->nerrors(i) > err[i]) { 746 if (hp->nerrors(i) > err[i]) {
732 printf("ERR: %d/%d/%d/%d/%d/%d/%d\r\n", 747 printf("ERR: %d/%d/%d/%d/%d/%d/%d\r\n",
733 hp->nerrors(0), 748 hp->nerrors(0),
734 hp->nerrors(1), 749 hp->nerrors(1),
735 hp->nerrors(2), 750 hp->nerrors(2),
736 hp->nerrors(3), 751 hp->nerrors(3),
737 hp->nerrors(4), 752 hp->nerrors(4),
738 hp->nerrors(5), 753 hp->nerrors(5),
739 hp->nerrors(6) 754 hp->nerrors(6)
740 ); 755 );
741 break; 756 break;
742 } 757 }
743 for (uint8_t i=0; i<7; i++) 758 for (uint8_t i=0; i<7; i++)
744 err[i] = hp->nerrors(i); 759 err[i] = hp->nerrors(i);
745 760
746 printf("CMD[%d] %02X", (int)cmd.id, cmd.cmd); 761 printf("CMD[%d] %02X", (int)cmd.id, cmd.cmd);
747 762
748 if ((cmd.cmd == 0x00) || (cmd.cmd == 0x0C)) 763 if ((cmd.cmd == 0x00) || (cmd.cmd == 0x0C))
749 printf(": '%s'\r\n", cmd.value); 764 printf(": '%s'\r\n", cmd.value);
750 else { 765 else {
751 printf(":"); 766 printf(":");
752 for (uint8_t i=0; i<cmd.size; i++) 767 for (uint8_t i=0; i<cmd.size; i++)
753 printf("%02x ", cmd.value[i]); 768 printf("%02x ", cmd.value[i]);
754 printf("\r\n"); 769 printf("\r\n");
755 } 770 }
756 show(cmd.cmd, cmd.value, cmd.size); 771 show(cmd.cmd, cmd.value, cmd.size);
757 #if defined(HAS_LED) 772 #if defined(HAS_LED)
758 led = 0; 773 led = 0;
759 #endif 774 #endif
760 } 775 }
761 } 776 }
762 //else 777 //else
763 ThisThread::sleep_for(1); 778 ThisThread::sleep_for(1);
764 } 779 }
765 } 780 }
766 781
767 void qei_cb(int dir) 782 void qei_cb(int dir)
768 { 783 {
769 if(dir == 1) // turn right 784 if(dir == 1) // turn right
770 knob = 0x80; 785 knob = 0x80;
771 else // turn left 786 else // turn left
772 knob = 0x83; 787 knob = 0x81; // 83?
773 } 788 }
774 789
775 void kp_cb(uint8_t row, uint8_t col) 790 void kp_cb(uint8_t row, uint8_t col)
776 { 791 {
777 keycode_t key; 792 keycode_t key;
778 key.row = row; 793 key.row = row;
779 key.col = col; 794 key.col = col;
780 key.keyevent = KEY_PRESSED; 795 key.keyevent = KEY_PRESSED;
781 if(!key_buf.full()) 796 if(!key_buf.full())
782 key_buf.push(key); 797 key_buf.push(key);
783 } 798 }
784 799
785 void kr_cb(uint8_t row, uint8_t col) 800 void kr_cb(uint8_t row, uint8_t col)
786 { 801 {
787 keycode_t key; 802 keycode_t key;
788 key.row = row; 803 key.row = row;
789 key.col = col; 804 key.col = col;
790 key.keyevent = KEY_RELEASED; 805 key.keyevent = KEY_RELEASED;
791 if(!key_buf.full()) 806 if(!key_buf.full())
792 key_buf.push(key); 807 key_buf.push(key);
793 } 808 }
794 809
795 int main() 810 int main()
796 { 811 {
797 setup(); 812 setup();
798 printf("Main loop (noop)\r\n"); 813 printf("Main loop (noop)\r\n");
799 while(1) 814 while(1)
800 { 815 {
801 timeout_h(); 816 timeout_h();
802 ThisThread::sleep_for(1); 817 ThisThread::sleep_for(1);
803 } 818 }
804 } 819 }

mercurial