246 |
246 |
247 static const FLAG flags[] = |
247 static const FLAG flags[] = |
248 { |
248 { |
249 // flag, zone, x0, y0, msg, icon |
249 // flag, zone, x0, y0, msg, icon |
250 // right-side icons area |
250 // right-side icons area |
251 { 0x00, 0x02, 0, 0, NULL, icon_alarm}, // F1.1 |
251 { 0x00, 0x02, 0, 0, NULL, icon_alarm}, // F1.0 |
252 { 0x01, 0x02, 0, 11, NULL, icon_curve}, // F1.2 |
252 { 0x01, 0x02, 0, 11, NULL, icon_curve}, // F1.1 |
253 |
253 // F1.2 == Channel frame |
254 |
254 { 0x03, 0x04, 1, 2, "Channel"}, // F1.3 |
255 { 0x03, 0x04, 1, 2, "Channel"}, // F1.4 |
255 // F1.7 == Alarm frame |
256 |
256 |
257 // col 1 |
257 // col 1 |
258 { 0x34, 0x10, 0, 0, "MON"}, // F4.5 |
258 { 0x34, 0x10, 0, 0, "MON"}, // F4.4 |
259 { 0x33, 0x10, 0, 8, "VIEW"}, // F4.4 |
259 { 0x33, 0x10, 0, 8, "VIEW"}, // F4.3 |
260 { 0x35, 0x10, 0, 16, "SCAN"}, // F4.6 |
260 { 0x35, 0x10, 0, 16, "SCAN"}, // F4.5 |
261 |
261 |
262 //col 2 |
262 //col 2 |
263 { 0x32, 0x20, 0, 0, "*"}, // F4.3 |
263 { 0x32, 0x20, 0, 0, "*"}, // F4.2 |
264 { 0x36, 0x20, 0, 8, "CFG"}, // F4.7 |
264 { 0x36, 0x20, 0, 8, "CFG"}, // F4.6 |
265 { 0x27, 0x20, 0, 16, "ERR"}, // F3.8 |
265 { 0x27, 0x20, 0, 16, "ERR"}, // F3.7 |
266 |
266 |
267 // col 3 |
267 // col 3 |
268 { 0x41, 0x040, 0, 0, "ADRS"}, // F4.2 |
268 { 0x41, 0x040, 0, 0, "ADRS"}, // F4.1 |
269 { 0x40, 0x040, 0, 8, "RMT"}, // F4.1 |
269 { 0x40, 0x040, 0, 8, "RMT"}, // F4.0 |
270 |
270 |
271 // col 4 |
271 // col 4 |
272 { 0x26, 0x080, 0, 0, "EXT"}, // F3.7 |
272 { 0x26, 0x080, 0, 0, "EXT"}, // F3.6 |
273 { 0x25, 0x080, 0, 8, "ONCE"}, // F3.6 |
273 { 0x25, 0x080, 0, 8, "ONCE"}, // F3.5 |
274 |
274 |
275 { 0xFF, 0x080, 0, 16, "MEM"}, |
275 { 0x23, 0x080, 0, 16, "MEM"}, // F3.3 |
276 |
276 |
277 |
277 |
278 // col 5 |
278 // col 5 |
279 { 0x14, 0x100, 0, 0, "4W"}, // F2.5 |
279 { 0x14, 0x100, 0, 0, "4W"}, // F2.4 |
280 { 0x15, 0x100, 0, 8, "OC"}, // F2.6 |
280 { 0x15, 0x100, 0, 8, "OC"}, // F2.5 |
281 { 0xFF, 0x100, 0, 16, "LST"}, // F3.8? Nope |
281 { 0x22, 0x100, 0, 16, "LST"}, // F3.2 |
282 { 0xFF, 0x100, 0, 16, "MIN"}, |
282 { 0x21, 0x100, 0, 16, "MIN"}, // F3.1 |
283 { 0xFF, 0x100, 0, 16, "MAX"}, |
283 { 0x20, 0x100, 0, 16, "MAX"}, // F3.0 |
284 { 0xFF, 0x100, 0, 16, "AVG"}, |
284 { 0x17, 0x100, 0, 16, "AVG"}, // F2.7 |
285 |
285 |
286 { 0x05, 0x08, 0, 0, "Alarm"}, // F1.6 |
286 { 0x05, 0x08, 0, 0, "Alarm"}, // F1.5 |
287 { 0x06, 0x08, 0, 10, "H"}, // F1.7 |
287 { 0x06, 0x08, 0, 10, "H"}, // F1.6 |
288 { 0x13, 0x08, 6, 10, "1"}, // F2.4 |
288 { 0x13, 0x08, 6, 10, "1"}, // F2.3 |
289 { 0x10, 0x08, 12, 10, "2"}, // F2.1 |
289 { 0x10, 0x08, 12, 10, "2"}, // F2.0 |
290 { 0x12, 0x08, 18, 10, "3"}, // F2.3 |
290 { 0x12, 0x08, 18, 10, "3"}, // F2.2 |
291 { 0x11, 0x08, 24, 10, "4"}, // F2.2 |
291 { 0x11, 0x08, 24, 10, "4"}, // F2.1 |
292 { 0x04, 0x08, 30, 10, "L"}, // F1.5 |
292 { 0x04, 0x08, 30, 10, "L"}, // F1.4 |
293 |
293 |
294 }; |
294 }; |
295 |
295 |
296 static const FRAME zones[] = |
296 static const FRAME zones[] = |
297 { |
297 { |
350 |
350 |
351 void setup() { |
351 void setup() { |
352 #ifdef HAVE_PC |
352 #ifdef HAVE_PC |
353 pc.baud (115200); |
353 pc.baud (115200); |
354 #endif |
354 #endif |
355 |
355 |
356 printf("\n\nSETUP\n"); |
356 printf("\n\nSETUP\n"); |
357 printf(" System Core Clock = %.3f MHZ\r\n", |
357 printf(" System Core Clock = %.3f MHZ\r\n", |
358 (float)SystemCoreClock/1000000); |
358 (float)SystemCoreClock/1000000); |
359 |
359 |
360 //printf("Attaching Led 1: %d\n", LED1); |
360 //printf("Attaching Led 1: %d\n", LED1); |
361 //blinker.attach(callback(timeout_h), 0.5f); |
361 //blinker.attach(callback(timeout_h), 0.5f); |
362 |
362 |
363 hp = NULL; |
363 hp = NULL; |
364 printf("Setup HP communication pins\n"); |
364 printf("Setup HP communication pins\r\n"); |
365 printf(" HP_RX=%d\n", HP_RX); |
365 printf(" HP_RX=%d\r\n", HP_RX); |
366 DigitalIn(HP_RX).mode(PullDown); |
366 DigitalIn(HP_RX).mode(PullDown); |
367 printf(" HP_TX=%d\n", HP_TX); |
367 printf(" HP_TX=%d\r\n", HP_TX); |
368 DigitalOut(HP_TX).write(1); |
368 DigitalOut(HP_TX).write(1); |
369 printf(" HP_RST=%d\n", HP_RST); |
369 printf(" HP_RST=%d\r\n", HP_RST); |
370 DigitalIn(HP_RST).mode(PullDown); |
370 DigitalIn(HP_RST).mode(PullDown); |
371 |
371 |
372 printf(" setup QEI pins\n"); |
372 printf(" setup QEI pins\r\n"); |
373 printf(" ENC1=%d\n", KP_ENC1); |
373 printf(" ENC1=%d\r\n", KP_ENC1); |
374 DigitalIn(KP_ENC1).mode(PullUp); |
374 DigitalIn(KP_ENC1).mode(PullUp); |
375 printf(" ENC2=%d\n", KP_ENC2); |
375 printf(" ENC2=%d\r\n", KP_ENC2); |
376 DigitalIn(KP_ENC2).mode(PullUp); |
376 DigitalIn(KP_ENC2).mode(PullUp); |
377 qenc.attach(&qei_cb); |
377 qenc.attach(&qei_cb); |
378 |
378 |
379 printf(" setup Keypad\n"); |
379 printf(" setup Keypad\r\n"); |
380 cur_keycode.keyevent = KEY_NONE; |
380 cur_keycode.keyevent = KEY_NONE; |
381 uint8_t nrows = sizeof(kp_rows)/sizeof(kp_rows[0]); |
381 uint8_t nrows = sizeof(kp_rows)/sizeof(kp_rows[0]); |
382 uint8_t ncols = sizeof(kp_colums)/sizeof(kp_colums[0]); |
382 uint8_t ncols = sizeof(kp_colums)/sizeof(kp_colums[0]); |
383 |
383 |
384 kpad = new Keypad(nrows, kp_in, ncols, kp_out); |
384 kpad = new Keypad(nrows, kp_in, ncols, kp_out); |
385 printf(" attach Keypad callbacks\n"); |
385 printf(" attach Keypad callbacks\r\n"); |
386 kpad->attach(&kp_cb, &kr_cb); |
386 kpad->attach(&kp_cb, &kr_cb); |
387 printf(" start Keypad\n"); |
387 printf(" start Keypad\r\n"); |
388 kpad->start(); |
388 kpad->start(); |
389 |
389 |
390 printf("Setup OLED display\n"); |
390 printf("Setup OLED display\r\n"); |
391 splashscreen = true; |
391 splashscreen = true; |
392 // init the LCD |
392 // init the LCD |
393 printf(" DSP_MOSI=%d\n", DSP_MOSI); |
393 printf(" DSP_MOSI=%d\r\n", DSP_MOSI); |
394 printf(" DSP_MISO=%d\n", DSP_MISO); |
394 printf(" DSP_MISO=%d\r\n", DSP_MISO); |
395 printf(" DSP_SCLK=%d\n", DSP_SCLK); |
395 printf(" DSP_SCLK=%d\r\n", DSP_SCLK); |
396 printf(" DSP_CS=%d\n", DSP_CS); |
396 printf(" DSP_CS=%d\r\n", DSP_CS); |
397 printf(" DSP_RST=%d\n", DSP_RST); |
397 printf(" DSP_RST=%d\r\n", DSP_RST); |
398 printf(" DSP_DC=%d\n", DSP_DC); |
398 printf(" DSP_DC=%d\r\n", DSP_DC); |
399 dsp = new SSD1322(20000000, DSP_MOSI, DSP_MISO, DSP_SCLK, DSP_CS, |
399 dsp = new SSD1322(20000000, DSP_MOSI, DSP_MISO, DSP_SCLK, DSP_CS, |
400 DSP_RST, DSP_DC, "SSD1322"); |
400 DSP_RST, DSP_DC, "SSD1322"); |
401 //dsp.set_orientation(3); |
401 //dsp.set_orientation(3); |
402 printf(" configure DSP\n"); |
402 printf(" configure DSP\r\n"); |
403 // myLCD.set_font((unsigned char*) Terminal6x8); |
403 // myLCD.set_font((unsigned char*) Terminal6x8); |
404 // myLCD.claim(stdout); // send stdout to the LCD display |
404 // myLCD.claim(stdout); // send stdout to the LCD display |
405 // myLCD.claim(stderr); // send stderr to the LCD display |
405 // myLCD.claim(stderr); // send stderr to the LCD display |
406 dsp->background(Black); // set background to black |
406 dsp->background(Black); // set background to black |
407 dsp->foreground(0xF); |
407 dsp->foreground(0xF); |
412 nchars = 0; |
412 nchars = 0; |
413 |
413 |
414 for (uint8_t i=0; i<sizeof(table)/sizeof(table[0]); ++i) |
414 for (uint8_t i=0; i<sizeof(table)/sizeof(table[0]); ++i) |
415 memset(table[i].buffer, 0, MAX_BUFF+1); |
415 memset(table[i].buffer, 0, MAX_BUFF+1); |
416 |
416 |
417 printf(" display splash screen\n"); |
417 printf(" display splash screen\r\n"); |
418 dsp->locate(30, 10); |
418 dsp->locate(30, 10); |
419 dsp->set_font((unsigned char*)Mono19x27); |
419 dsp->set_font((unsigned char*)Mono19x27); |
420 dsp->printf("HP34970A"); |
420 dsp->printf("HP34970A"); |
421 dsp->set_font((unsigned char*)Terminal6x8); |
421 dsp->set_font((unsigned char*)Terminal6x8); |
422 dsp->locate(90, 40); |
422 dsp->locate(90, 40); |
423 dsp->printf("David Douard"); |
423 dsp->printf("David Douard"); |
424 dsp->copy_to_lcd(); |
424 dsp->copy_to_lcd(); |
425 |
425 |
426 printf("Starting LCD thread\n"); |
426 printf("Starting LCD thread\r\n"); |
427 tdsp.start(©_to_lcd); |
427 tdsp.start(©_to_lcd); |
428 |
428 |
429 printf("Starting Event thread\n"); |
429 //printf("Starting Event thread\r\n"); |
430 tloop.start(&loop); |
430 //tloop.start(&loop); |
431 |
431 |
432 printf("Attaching timers\n"); |
432 printf("Attaching timers\r\n"); |
433 splashscreen_timer.attach(callback(&end_splashscreen), 2); |
433 splashscreen_timer.attach(callback(&end_splashscreen), 2); |
434 rst.fall(&reset_irq); |
434 rst.fall(&reset_irq); |
435 |
435 |
436 printf("SETUP DONE\n"); |
436 printf("SETUP DONE\r\n"); |
437 } |
437 } |
438 |
438 |
439 void end_splashscreen(void) |
439 void end_splashscreen(void) |
440 { |
440 { |
441 printf("End of splash screen\n"); |
441 printf("End of splash screen\r\n"); |
442 splashscreen = false; |
442 splashscreen = false; |
443 } |
443 } |
444 |
444 |
445 void reset_irq(void) |
445 void reset_irq(void) |
446 { |
446 { |
447 rst_delay.attach(callback(&reset), 0.1); |
447 rst_delay.attach(callback(&reset), 0.1); |
448 } |
448 } |
449 |
449 |
450 void reset(void) |
450 void reset(void) |
451 { |
451 { |
452 if (DigitalIn(HP_RST).read() == 0) { |
452 if (DigitalIn(HP_RST).read() == 0) { |
453 if (hp == NULL) { |
453 if (hp == NULL) { |
454 printf("setup HP communication handler\n"); |
454 printf("setup HP communication handler\r\n"); |
455 hp = new HPSerial(HP_TX, HP_RX); |
455 hp = new HPSerial(HP_TX, HP_RX); |
456 } |
456 } |
457 |
457 |
458 printf("!! RST !! (gstate=%d, state=%d)\n", |
458 printf("!! RST !! (gstate=%d, state=%d)\r\n", |
459 hp->gstate(), hp->state()); |
459 hp->gstate(), hp->state()); |
460 //printf("Value is ... %X\n", hp->search()); |
460 //printf("Value is ... %X\n", hp->search()); |
461 hp->startup(); |
461 hp->startup(); |
462 } |
462 } |
463 } |
463 } |
686 { // run over and over |
686 { // run over and over |
687 unsigned int err[8]; |
687 unsigned int err[8]; |
688 for (uint8_t i=0; i<8; i++) |
688 for (uint8_t i=0; i<8; i++) |
689 err[i] = 0; |
689 err[i] = 0; |
690 int p, pp; |
690 int p, pp; |
691 p=0; |
691 p = 0; |
692 pp=0; |
692 pp = 0; |
693 while(1) { |
693 while(1) { |
694 if (knob != 0) |
694 if (knob != 0) |
695 { |
695 { |
696 if (hp != NULL) { |
696 if (hp != NULL) |
697 printf("Sending keycode %X\n", knob); |
697 { |
698 hp->sendkey(knob); |
698 printf("Sending keycode %X\r\n", knob); |
699 printf(" DONE\n"); |
699 hp->sendkey(knob); |
|
700 printf(" DONE\r\n"); |
|
701 } |
|
702 knob = 0; |
700 } |
703 } |
701 knob = 0; |
|
702 } |
|
703 |
704 |
704 if (cur_keycode.keyevent != KEY_NONE) |
705 if (cur_keycode.keyevent != KEY_NONE) |
705 { |
706 { |
706 printf("Keycode %dx%d: %s\n", |
707 printf("Keycode %dx%d: %s\r\n", |
707 cur_keycode.row, cur_keycode.col, |
708 cur_keycode.row, cur_keycode.col, |
708 cur_keycode.keyevent==KEY_PRESSED?"pressed":"released"); |
709 cur_keycode.keyevent==KEY_PRESSED?"pressed":"released"); |
709 cur_keycode.keyevent = KEY_NONE; |
710 cur_keycode.keyevent = KEY_NONE; |
710 } |
711 } |
711 |
712 |
712 p = qenc.getPulses(); |
713 p = qenc.getPulses(); |
713 if (p != pp) { |
714 if (p != pp) |
714 printf("Pulses = %d\n", p); |
715 { |
|
716 printf("Pulses = %d\r\n", p); |
715 pp = p; |
717 pp = p; |
716 } |
718 } |
|
719 |
717 if ((hp != NULL) && (hp->cmd_available())) |
720 if ((hp != NULL) && (hp->cmd_available())) |
718 { |
721 { |
719 led = 1; |
722 HPSerial::CMD cmd; |
720 HPSerial::CMD cmd; |
723 if (hp->pop(cmd)) |
721 if (hp->pop(cmd)) |
724 { |
722 { |
725 led = 1; |
723 for (uint8_t i=0; i<7; i++) |
726 for (uint8_t i=0; i<7; i++) |
724 if (hp->nerrors(i) > err[i]) { |
727 if (hp->nerrors(i) > err[i]) { |
725 printf("ERR: %d/%d/%d/%d/%d/%d/%d\n", |
728 printf("ERR: %d/%d/%d/%d/%d/%d/%d\r\n", |
726 hp->nerrors(0), |
729 hp->nerrors(0), |
727 hp->nerrors(1), |
730 hp->nerrors(1), |
728 hp->nerrors(2), |
731 hp->nerrors(2), |
729 hp->nerrors(3), |
732 hp->nerrors(3), |
730 hp->nerrors(4), |
733 hp->nerrors(4), |
731 hp->nerrors(5), |
734 hp->nerrors(5), |
732 hp->nerrors(6) |
735 hp->nerrors(6) |
733 ); |
736 ); |
734 break; |
737 break; |
735 } |
738 } |
736 for (uint8_t i=0; i<7; i++) |
739 for (uint8_t i=0; i<7; i++) |
737 err[i] = hp->nerrors(i); |
740 err[i] = hp->nerrors(i); |
738 printf("CMD[%d] %02X", (int)cmd.id, cmd.cmd); |
741 |
739 |
742 printf("CMD[%d] %02X", (int)cmd.id, cmd.cmd); |
740 if ((cmd.cmd == 0x00) || (cmd.cmd == 0x0C)) |
743 |
741 printf(": '%s'\n", cmd.value); |
744 if ((cmd.cmd == 0x00) || (cmd.cmd == 0x0C)) |
742 else { |
745 printf(": '%s'\r\n", cmd.value); |
743 printf(":"); |
746 else { |
744 for (uint8_t i=0; i<cmd.size; i++) |
747 printf(":"); |
745 printf("%02x ", cmd.value[i]); |
748 for (uint8_t i=0; i<cmd.size; i++) |
746 printf("\n"); |
749 printf("%02x ", cmd.value[i]); |
747 } |
750 printf("\r\n"); |
748 show(cmd.cmd, cmd.value, cmd.size); |
751 } |
749 } |
752 show(cmd.cmd, cmd.value, cmd.size); |
750 else |
753 led = 0; |
751 printf("\n"); |
754 } |
752 |
755 } |
753 show(cmd.cmd, cmd.value, cmd.size); |
756 //else |
754 |
|
755 led = 0; |
|
756 } |
|
757 else |
|
758 Thread::wait(1); |
757 Thread::wait(1); |
759 } |
758 } |
760 } |
759 } |
761 |
760 |
762 void qei_cb(int dir) |
761 void qei_cb(int dir) |