src/main.cpp

changeset 21
9ffa9d727d80
parent 19
a52d60613cf7
child 22
2f51221af82d
--- a/src/main.cpp	Tue Dec 05 00:59:57 2017 +0100
+++ b/src/main.cpp	Mon Nov 05 23:18:37 2018 +0100
@@ -1,8 +1,8 @@
 #include "stdio.h"
 
-#include "mbed.h"
-#include "rtos.h"
-#include "string"
+#include <mbed.h>
+#include <rtos.h>
+#include <string>
 
 #include "Terminal6x8.h"
 #include "Mono19x27.h"
@@ -61,12 +61,12 @@
 // USBTX PA_2
 // USBRX PA_3
 // display
-#define DSP_MOSI PB_15
+#define DSP_MOSI PB_15 // blue
 #define DSP_MISO NC
-#define DSP_SCLK PB_13
-#define DSP_CS   PB_12
-#define DSP_RST  PB_5
-#define DSP_DC   PB_4
+#define DSP_SCLK PB_13 // yellow
+#define DSP_CS   PB_12 // green
+#define DSP_RST  PB_5 // green
+#define DSP_DC   PB_4 // red
 
 // UART for RX (CPU->DP)
 #define HP_RX PC_11 // serial3 RX
@@ -248,48 +248,48 @@
   {
     // flag, zone, x0, y0, msg, icon
     // right-side icons area
-    { 0x00, 0x02, 0, 0,  NULL, icon_alarm}, // F1.1
-    { 0x01, 0x02, 0, 11, NULL, icon_curve}, // F1.2
-
-
-    { 0x03, 0x04, 1, 2, "Channel"}, // F1.4
+    { 0x00, 0x02, 0, 0,  NULL, icon_alarm}, // F1.0
+    { 0x01, 0x02, 0, 11, NULL, icon_curve}, // F1.1
+    // F1.2 == Channel frame
+    { 0x03, 0x04, 1, 2, "Channel"},  // F1.3
+	// F1.7 == Alarm frame
 
     // col 1
-    { 0x34, 0x10, 0,  0,  "MON"},     // F4.5
-    { 0x33, 0x10, 0,  8,  "VIEW"},    // F4.4
-    { 0x35, 0x10, 0,  16, "SCAN"},   // F4.6
+    { 0x34, 0x10, 0,  0,  "MON"},    // F4.4
+    { 0x33, 0x10, 0,  8,  "VIEW"},   // F4.3
+    { 0x35, 0x10, 0,  16, "SCAN"},   // F4.5
 
     //col 2
-    { 0x32, 0x20, 0, 0,  "*"},      // F4.3
-    { 0x36, 0x20, 0, 8,  "CFG"},    // F4.7
-    { 0x27, 0x20, 0, 16, "ERR"},  // F3.8
+    { 0x32, 0x20, 0, 0,   "*"},      // F4.2
+    { 0x36, 0x20, 0, 8,   "CFG"},    // F4.6
+    { 0x27, 0x20, 0, 16,  "ERR"},    // F3.7
 
     // col 3
-    { 0x41, 0x040, 0, 0, "ADRS"}, // F4.2
-    { 0x40, 0x040, 0, 8,  "RMT"},  // F4.1
+    { 0x41, 0x040, 0, 0,  "ADRS"},   // F4.1
+    { 0x40, 0x040, 0, 8,  "RMT"},    // F4.0
 
     // col 4
-    { 0x26, 0x080, 0, 0,  "EXT"},  // F3.7
-    { 0x25, 0x080, 0, 8,  "ONCE"}, // F3.6
+    { 0x26, 0x080, 0, 0,  "EXT"},    // F3.6
+    { 0x25, 0x080, 0, 8,  "ONCE"},   // F3.5
 
-    { 0xFF, 0x080, 0, 16,  "MEM"},
+    { 0x23, 0x080, 0, 16, "MEM"},    // F3.3
 
 
     // col 5
-    { 0x14, 0x100, 0, 0,  "4W"},    // F2.5
-    { 0x15, 0x100, 0, 8,  "OC"},    // F2.6
-    { 0xFF, 0x100, 0, 16, "LST"},   // F3.8? Nope
-    { 0xFF, 0x100, 0, 16, "MIN"},
-    { 0xFF, 0x100, 0, 16, "MAX"},
-    { 0xFF, 0x100, 0, 16, "AVG"},
+    { 0x14, 0x100, 0, 0,  "4W"},     // F2.4
+    { 0x15, 0x100, 0, 8,  "OC"},     // F2.5
+    { 0x22, 0x100, 0, 16, "LST"},    // F3.2
+    { 0x21, 0x100, 0, 16, "MIN"},    // F3.1
+    { 0x20, 0x100, 0, 16, "MAX"},    // F3.0
+    { 0x17, 0x100, 0, 16, "AVG"},    // F2.7
 
-    { 0x05, 0x08, 0,   0,  "Alarm"}, // F1.6
-    { 0x06, 0x08, 0,  10,  "H"}, // F1.7
-    { 0x13, 0x08, 6,  10,  "1"}, // F2.4
-    { 0x10, 0x08, 12, 10,  "2"}, // F2.1
-    { 0x12, 0x08, 18, 10,  "3"}, // F2.3
-    { 0x11, 0x08, 24, 10,  "4"}, // F2.2
-    { 0x04, 0x08, 30, 10,  "L"}, // F1.5
+    { 0x05, 0x08, 0,   0, "Alarm"},  // F1.5
+    { 0x06, 0x08, 0,  10, "H"},      // F1.6
+    { 0x13, 0x08, 6,  10, "1"},      // F2.3
+    { 0x10, 0x08, 12, 10, "2"},      // F2.0
+    { 0x12, 0x08, 18, 10, "3"},      // F2.2
+    { 0x11, 0x08, 24, 10, "4"},      // F2.1
+    { 0x04, 0x08, 30, 10, "L"},      // F1.4
 
   };
 
@@ -310,8 +310,8 @@
 
 static const FRAME frames[] =
   {
-    { 0x02, 203, 35, 255, 54}, // F1.3 - channel frame
-    { 0x07, 160, 28, 202, 54}, // F1.8 - alarm frame
+    { 0x02, 203, 35, 255, 54}, // F1.2 - channel frame
+    { 0x07, 160, 28, 202, 54}, // F1.7 - alarm frame
   };
 
 
@@ -352,54 +352,54 @@
 #ifdef HAVE_PC
   pc.baud (115200);
 #endif
-  
+
   printf("\n\nSETUP\n");
   printf("  System Core Clock = %.3f MHZ\r\n",
   	 (float)SystemCoreClock/1000000);
-  
+
   //printf("Attaching Led 1: %d\n", LED1);
   //blinker.attach(callback(timeout_h), 0.5f);
-  
+
   hp = NULL;
-  printf("Setup HP communication pins\n");
-  printf("     HP_RX=%d\n", HP_RX);
+  printf("Setup HP communication pins\r\n");
+  printf("     HP_RX=%d\r\n", HP_RX);
   DigitalIn(HP_RX).mode(PullDown);
-  printf("     HP_TX=%d\n", HP_TX);
+  printf("     HP_TX=%d\r\n", HP_TX);
   DigitalOut(HP_TX).write(1);
-  printf("     HP_RST=%d\n", HP_RST);
+  printf("     HP_RST=%d\r\n", HP_RST);
   DigitalIn(HP_RST).mode(PullDown);
-  
-  printf("  setup QEI pins\n");
-  printf("     ENC1=%d\n", KP_ENC1);
+
+  printf("  setup QEI pins\r\n");
+  printf("     ENC1=%d\r\n", KP_ENC1);
   DigitalIn(KP_ENC1).mode(PullUp);
-  printf("     ENC2=%d\n", KP_ENC2);
+  printf("     ENC2=%d\r\n", KP_ENC2);
   DigitalIn(KP_ENC2).mode(PullUp);
   qenc.attach(&qei_cb);
 
-  printf("  setup Keypad\n");
+  printf("  setup Keypad\r\n");
   cur_keycode.keyevent = KEY_NONE;
   uint8_t nrows = sizeof(kp_rows)/sizeof(kp_rows[0]);
   uint8_t ncols = sizeof(kp_colums)/sizeof(kp_colums[0]);
 
   kpad = new Keypad(nrows, kp_in, ncols, kp_out);
-  printf("  attach Keypad callbacks\n");
+  printf("  attach Keypad callbacks\r\n");
   kpad->attach(&kp_cb, &kr_cb);
-  printf("  start Keypad\n");
-  kpad->start();  
-  
-  printf("Setup OLED display\n");
+  printf("  start Keypad\r\n");
+  kpad->start();
+
+  printf("Setup OLED display\r\n");
   splashscreen = true;
   // init the LCD
-  printf("     DSP_MOSI=%d\n", DSP_MOSI);
-  printf("     DSP_MISO=%d\n", DSP_MISO);
-  printf("     DSP_SCLK=%d\n", DSP_SCLK);
-  printf("     DSP_CS=%d\n", DSP_CS);
-  printf("     DSP_RST=%d\n", DSP_RST);
-  printf("     DSP_DC=%d\n", DSP_DC);
+  printf("     DSP_MOSI=%d\r\n", DSP_MOSI);
+  printf("     DSP_MISO=%d\r\n", DSP_MISO);
+  printf("     DSP_SCLK=%d\r\n", DSP_SCLK);
+  printf("     DSP_CS=%d\r\n", DSP_CS);
+  printf("     DSP_RST=%d\r\n", DSP_RST);
+  printf("     DSP_DC=%d\r\n", DSP_DC);
   dsp = new SSD1322(20000000, DSP_MOSI, DSP_MISO, DSP_SCLK, DSP_CS,
 		    DSP_RST, DSP_DC, "SSD1322");
   //dsp.set_orientation(3);
-  printf("  configure DSP\n");
+  printf("  configure DSP\r\n");
   // myLCD.set_font((unsigned char*) Terminal6x8);
   // myLCD.claim(stdout);      // send stdout to the LCD display
   // myLCD.claim(stderr);      // send stderr to the LCD display
@@ -414,7 +414,7 @@
   for (uint8_t i=0; i<sizeof(table)/sizeof(table[0]); ++i)
     memset(table[i].buffer, 0, MAX_BUFF+1);
 
-  printf("  display splash screen\n");
+  printf("  display splash screen\r\n");
   dsp->locate(30, 10);
   dsp->set_font((unsigned char*)Mono19x27);
   dsp->printf("HP34970A");
@@ -423,39 +423,39 @@
   dsp->printf("David Douard");
   dsp->copy_to_lcd();
 
-  printf("Starting LCD thread\n");
+  printf("Starting LCD thread\r\n");
   tdsp.start(&copy_to_lcd);
 
-  printf("Starting Event thread\n");
-  tloop.start(&loop);
-  
-  printf("Attaching timers\n");
+  //printf("Starting Event thread\r\n");
+  //tloop.start(&loop);
+
+  printf("Attaching timers\r\n");
   splashscreen_timer.attach(callback(&end_splashscreen), 2);
   rst.fall(&reset_irq);
-  
-  printf("SETUP DONE\n");
+
+  printf("SETUP DONE\r\n");
 }
 
 void end_splashscreen(void)
 {
-  printf("End of splash screen\n");
+  printf("End of splash screen\r\n");
   splashscreen = false;
 }
 
 void reset_irq(void)
 {
-  rst_delay.attach(callback(&reset), 0.1);  
+  rst_delay.attach(callback(&reset), 0.1);
 }
 
 void reset(void)
 {
   if (DigitalIn(HP_RST).read() == 0) {
     if (hp == NULL) {
-      printf("setup HP communication handler\n");
+      printf("setup HP communication handler\r\n");
       hp = new HPSerial(HP_TX, HP_RX);
     }
-  
-    printf("!! RST !! (gstate=%d, state=%d)\n",
+
+    printf("!! RST !! (gstate=%d, state=%d)\r\n",
 	   hp->gstate(), hp->state());
     //printf("Value is ... %X\n", hp->search());
     hp->startup();
@@ -499,7 +499,7 @@
   char *oldv;
   char *txt;
 
-  
+
   txt = (char *)malloc(strlen(intxt)+1);
   strcpy(txt, intxt);
   pulse(1, true);
@@ -688,73 +688,72 @@
   for (uint8_t i=0; i<8; i++)
     err[i] = 0;
   int p, pp;
-  p=0;
-  pp=0;
+  p = 0;
+  pp = 0;
   while(1) {
     if (knob != 0)
-      {
-	if (hp != NULL) {
-	  printf("Sending keycode %X\n", knob);
-	  hp->sendkey(knob);
-	  printf("   DONE\n");
+	{
+	  if (hp != NULL)
+	  {
+		printf("Sending keycode %X\r\n", knob);
+		hp->sendkey(knob);
+		printf("   DONE\r\n");
+	  }
+	  knob = 0;
 	}
-	knob = 0;
-      }
 
     if (cur_keycode.keyevent != KEY_NONE)
-      {
-	printf("Keycode %dx%d: %s\n",
-	       cur_keycode.row, cur_keycode.col,
-	       cur_keycode.keyevent==KEY_PRESSED?"pressed":"released");
-	cur_keycode.keyevent = KEY_NONE;
-      }
+	{
+	  printf("Keycode %dx%d: %s\r\n",
+			 cur_keycode.row, cur_keycode.col,
+			 cur_keycode.keyevent==KEY_PRESSED?"pressed":"released");
+	  cur_keycode.keyevent = KEY_NONE;
+	}
 
     p = qenc.getPulses();
-    if (p != pp) {
-      printf("Pulses = %d\n", p);
+    if (p != pp)
+	{
+      printf("Pulses = %d\r\n", p);
       pp = p;
     }
+
     if ((hp != NULL) && (hp->cmd_available()))
       {
-        led = 1;
-	HPSerial::CMD cmd;
-	if (hp->pop(cmd))
-	  {
-            for (uint8_t i=0; i<7; i++)
-	      if (hp->nerrors(i) > err[i]) {
-    printf("ERR: %d/%d/%d/%d/%d/%d/%d\n",
-      hp->nerrors(0),
-      hp->nerrors(1),
-      hp->nerrors(2),
-      hp->nerrors(3),
-      hp->nerrors(4),
-      hp->nerrors(5),
-      hp->nerrors(6)
-      );
-    break;
-  }
-	    for (uint8_t i=0; i<7; i++)
-	      err[i] = hp->nerrors(i);
-	    printf("CMD[%d] %02X", (int)cmd.id, cmd.cmd);
+		HPSerial::CMD cmd;
+		if (hp->pop(cmd))
+    	  {
+			led = 1;
+    		for (uint8_t i=0; i<7; i++)
+    	      if (hp->nerrors(i) > err[i]) {
+    			  printf("ERR: %d/%d/%d/%d/%d/%d/%d\r\n",
+    					 hp->nerrors(0),
+    					 hp->nerrors(1),
+    					 hp->nerrors(2),
+    					 hp->nerrors(3),
+    					 hp->nerrors(4),
+    					 hp->nerrors(5),
+    					 hp->nerrors(6)
+    					 );
+    			  break;
+    		  }
+    	    for (uint8_t i=0; i<7; i++)
+    	      err[i] = hp->nerrors(i);
 
-	    if ((cmd.cmd == 0x00) || (cmd.cmd == 0x0C))
-	      printf(": '%s'\n", cmd.value);
-	    else {
-              printf(":");
-	      for (uint8_t i=0; i<cmd.size; i++)
-		printf("%02x ", cmd.value[i]);
-	      printf("\n");
-            }
-	    show(cmd.cmd, cmd.value, cmd.size);
-           }
-	  else
-	    printf("\n");
+    	    printf("CMD[%d] %02X", (int)cmd.id, cmd.cmd);
 
-	  show(cmd.cmd, cmd.value, cmd.size);
-
-	  led = 0;
-	}
-      else
+    	    if ((cmd.cmd == 0x00) || (cmd.cmd == 0x0C))
+    	      printf(": '%s'\r\n", cmd.value);
+    	    else {
+    		  printf(":");
+    	      for (uint8_t i=0; i<cmd.size; i++)
+    			  printf("%02x ", cmd.value[i]);
+    	      printf("\r\n");
+    		}
+    	    show(cmd.cmd, cmd.value, cmd.size);
+			led = 0;
+    	  }
+	  }
+	//else
 	Thread::wait(1);
   }
 }
@@ -784,7 +783,7 @@
 int main()
 {
   setup();
-  printf("Main loop (noop)\n");
+  printf("Main loop (noop)\r\n");
   while(1)
     wait(.1);
 }

mercurial