attempt to update display by bloc draft

Fri, 23 Sep 2016 21:12:43 +0200

author
David Douard <david.douard@logilab.fr>
date
Fri, 23 Sep 2016 21:12:43 +0200
changeset 7
5cf4034ba4e0
parent 6
8cb67d7afd79
child 8
55021f3f1929

attempt to update display by bloc

lib/unigraphic/SSD1322.cpp file | annotate | diff | comparison | revisions
src/main.cpp file | annotate | diff | comparison | revisions
--- a/lib/unigraphic/SSD1322.cpp	Wed Sep 21 20:09:21 2016 +0200
+++ b/lib/unigraphic/SSD1322.cpp	Fri Sep 23 21:12:43 2016 +0200
@@ -377,6 +377,10 @@
 {
   unsigned char x, y;
 
+  if (to_col>0x3F)
+    to_col = 0x3F;
+  if (to_row>0x3F)
+    to_row = 0x3F;
   set_row_address(from_row, to_row);
   set_column_address(from_col, to_col);
 
--- a/src/main.cpp	Wed Sep 21 20:09:21 2016 +0200
+++ b/src/main.cpp	Fri Sep 23 21:12:43 2016 +0200
@@ -16,7 +16,7 @@
 
 #define DEBUG
 
-SSD1322 dsp(SPI_8, 20000000, PB_15, PB_14, PB_13, PB_12, D11, D12, "SSD1322", 256, 64); 
+SSD1322 dsp(SPI_8, 20000000, PB_15, PB_14, PB_13, PB_12, D11, D12, "SSD1322", 256, 64);
 
 
 uint8_t curchar;
@@ -41,15 +41,15 @@
 static DSP table[] =
 {
   { 0x00, 0xF,   0x0,  0,  0, 0x01, MAX_BUFF, 245, Mono19x27}, // main display
-  { 0x0C, 0xF,   0x0,204, 38, 0x01, 3,        45, Mono15x22}, // channels display
-  { 0x01, 0xF,   0x0,  0,  0, 0x80, MAX_BUFF, 0, Terminal6x8}, 
-  { 0x02, 0xF,   0x0,  0,  0, 0x80, MAX_BUFF, 0, Terminal6x8},
+  { 0x0C, 0xF,   0x0,204, 38, 0x01, 3,        45,  Mono15x22}, // channels display
+  //  { 0x01, 0xF,   0x0,  0,  0, 0x80, MAX_BUFF, 0, Terminal6x8},
+  //  { 0x02, 0xF,   0x0,  0,  0, 0x80, MAX_BUFF, 0, Terminal6x8},
   { 0x0A, 0xF,   0x0,  0, 57, 0x0C, 4,        0, Terminal6x8}, // flags + bits
-  { 0xFF, 0xF,   0x0,  0,  0, 0x80, MAX_BUFF, 0, Terminal6x8},
+  //  { 0xFF, 0xF,   0x0,  0,  0, 0x80, MAX_BUFF, 0, Terminal6x8},
 };
 
 // 9x10
-const unsigned char icon_alarm[] __attribute__((aligned (2))) = 
+const unsigned char icon_alarm[] __attribute__((aligned (2))) =
 {
   0x1c, 0x0,
   0x3e, 0x0,
@@ -63,7 +63,7 @@
   0x10, 0x0
 };
 
-const unsigned char icon_curve[] __attribute__((aligned (2))) = 
+const unsigned char icon_curve[] __attribute__((aligned (2))) =
 {
   0x80, 0x0,
   0x80, 0x0,
@@ -76,51 +76,17 @@
   0x80, 0x0,
   0xff, 0x80
  };
- 
+
 typedef struct _FLAG
 {
   uint8_t flag;
+  uint8_t zone;
   uint8_t x;
   uint8_t y;
   const char* msg;
   const unsigned char* icon;
 } FLAG;
 
-static const FLAG flags[] =
-  {
-    //{ 0x00, 160, 30, "Alarm"},  // for the 'alarm' box
-    { 0x00, 246, 0,  NULL, icon_alarm}, // F1.1
-    { 0x01, 246, 11, NULL, icon_curve}, // F1.2
-    { 0x03, 204, 30, "Channel"}, // F1.4
-    { 0x14, 68, 44,  "4W"},      // F2.5
-    { 0x32, 40, 44,  "*"},       // F4.3
-    { 0x33, 40, 44,  "VIEW"},    // F4.4
-    { 0x34, 0,  30,  "MON"},     // F4.5
-    { 0x35, 0,  44,  "SCAN"},    // F4.6
-    { 0x36, 0,  44,  "CONFIG"},  // F4.7
-    
-    { 0xFF, 0, 0,  "ADRS"},
-    { 0xFF, 0, 0,  "RMT"},
-    { 0xFF, 0, 0,  "ERROR"},
-    { 0xFF, 0, 0,  "EXT"},
-    { 0xFF, 0, 0,  "ONCE"},
-    { 0xFF, 0, 0,  "AUTO"},
-    { 0xFF, 0, 0,  "MEM"},
-    { 0xFF, 0, 0,  "LAST"},
-    { 0xFF, 0, 0,  "MIN"},
-    { 0xFF, 0, 0,  "MAX"},
-    { 0xFF, 0, 0,  "AVG"},
-    { 0xFF, 0, 0,  "OC"},
-
-    { 0xFF, 0, 0,  "H"},
-    { 0xFF, 0, 0,  "1"},
-    { 0xFF, 0, 0,  "2"},
-    { 0xFF, 0, 0,  "3"},
-    { 0xFF, 0, 0,  "4"},
-    { 0xFF, 0, 0,  "L"},
-    
-  };
-
 typedef struct _FRAME
 {
   uint8_t flag;
@@ -130,6 +96,66 @@
   uint8_t y1;
 } FRAME;
 
+static const FLAG flags[] =
+  {
+    // 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
+    { 0x14, 0x02, 0, 22,  "4W"},    // F2.5
+
+    { 0x03, 0x04, 1, 2, "Channel"}, // F1.4
+
+    // col 1
+    { 0x34, 0x10, 0,  0,  "MON"},     // F4.5
+    { 0x33, 0x10, 0,  8,  "VIEW"},    // F4.4
+    { 0x35, 0x10, 0,  16,  "SCAN"},   // F4.6
+
+    //col 2
+    { 0x32, 0x20, 0, 0,  "*"},      // F4.3
+    { 0x36, 0x20, 0, 8,  "CFG"},    // F4.7
+    { 0xFF, 0x20, 0, 16,  "ERROR"},
+
+    /*
+    { 0xFF, 0, 0,  "ADRS"},
+    { 0xFF, 0, 0,  "RMT"},
+    { 0xFF, 0, 0,  "EXT"},
+
+    { 0xFF, 0, 0,  "ONCE"},
+    { 0xFF, 0, 0,  "AUTO"},
+    { 0xFF, 0, 0,  "MEM"},
+
+    { 0xFF, 0, 0,  "LAST"},
+    { 0xFF, 0, 0,  "MIN"},
+    { 0xFF, 0, 0,  "MAX"},
+
+    { 0xFF, 0, 0,  "AVG"},
+    { 0xFF, 0, 0,  "OC"},
+    */
+
+    { 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
+
+  };
+
+static const FRAME zones[] =
+  {
+    { 0x01, 0,   0, 245, 27}, // main display area
+    { 0x02, 246, 0, 255, 27}, // right notif area
+    { 0x04, 203, 28, 255, 54}, // channels display area
+    { 0x08, 160, 28, 202, 54}, // alarms area
+    { 0x10, 0,  28, 32,  54}, // flags col1
+    { 0x20, 33, 28, 70,  54}, // flags col2
+    { 0x40, 71, 28, 159, 54}, // flags col3
+
+    { 0x80, 0, 55, 255, 63}, // flags bits display area
+  };
+
 static const FRAME frames[] =
   {
     { 0x02, 203, 35, 248, 55}, // F1.3
@@ -142,18 +168,18 @@
 DigitalOut dbgpin(DBGPIN);
 inline void pulse(uint8_t count=1, bool stayup=false)
 {
-  dbgpin = 0; 
+  dbgpin = 0;
   wait_us(2);
   while (count--)
   {
     dbgpin = 1;
     wait_us(2);
-    dbgpin = 0; 
+    dbgpin = 0;
     wait_us(2);
  }
   if (stayup)
     dbgpin = 1;
-    
+
 }
 #else
 inline void pulse(uint8_t count=1, bool stayup=false)
@@ -162,7 +188,7 @@
 
 
 HPSerial hp;
-volatile bool must_refresh;
+volatile uint8_t must_refresh;
 Thread tdsp, tloop;
 
 void copy_to_lcd(void);
@@ -182,44 +208,46 @@
     dsp.background(Black);    // set background to black
     dsp.foreground(0xF);
     dsp.cls();
-    dsp.locate(0, 0);
-    dsp.set_font(Mono19x27);
-    
+
     cmd = 0xFF;
     curchar = 0;
     nchars = 0;
 
     for (uint8_t i=0; i<sizeof(table)/sizeof(table[0]); ++i)
       memset(table[i].buffer, 0, MAX_BUFF+1);
-      
+
+    dsp.locate(30, 10);
+    dsp.set_font(Mono19x27);
     dsp.printf("HP34970A");
     dsp.set_font(Terminal6x8);
-    for(uint8_t i=0; i<4;  i++) {
-      dsp.locate(160, i*8);
-      dsp.printf("Lg %d", i+1);
-      dsp.locate(208, (3-i)*8);
-      dsp.printf("Lg %d", i+1);
-    }
+    dsp.locate(90, 40);
+    dsp.printf("David Douard");
     dsp.copy_to_lcd();
     wait(2);
     dsp.cls();
-    
-    test_dsp();
-    dsp.copy_to_lcd();
-    wait(2);
-    dsp.cls();
-    
 }
 
 void copy_to_lcd(void) {
+  uint8_t mask=1;
+
   while(1) {
     pulse(0, true);
-    if (must_refresh) {
-      must_refresh = false;
-      dsp.copy_to_lcd();
+    if (must_refresh & mask) {
+      for(uint8_t i=0; i<sizeof(zones)/sizeof(zones[0]); i++)
+	if (zones[i].flag == mask) {
+	  dsp.copy_to_lcd(zones[i].x0/4, (zones[i].x1+3)/4,
+			  zones[i].y0,   zones[i].y1);
+	  must_refresh &= ~mask;
+	  break;
+	}
     }
+    mask = mask << 1;
+    if (mask == 0) {
+      mask = 1;
+    }
+
     pulse(0, false);
-    Thread::wait(100);
+    Thread::wait(10);
   }
 }
 
@@ -229,9 +257,7 @@
   char *oldv;
 
   pulse(1, true);
-  
-  must_refresh = false;
-  
+
   len = MAX_BUFF;
 
   for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) {
@@ -240,10 +266,10 @@
       fgcolor = table[i].color;
       dsp.background(bgcolor);
       dsp.foreground(fgcolor);
-      dsp.locate(table[i].x0, table[i].y0);
       dsp.set_font((unsigned char*) table[i].font);
       oldv = table[i].buffer;
-      
+
+      dsp.locate(table[i].x0, table[i].y0);
 
       if (table[i].fmt & 0x01 ) {
 	// ascii
@@ -258,7 +284,7 @@
 	  if (txt[k] == 0x09) { // \t is a special char for 'unselected' display value
 	    txt[k] = 0x00;
 	    dsp.printf(txt);
-	    
+
 	    if (fgcolor == table[i].color)
 	      fgcolor /= 2;
 	    else
@@ -268,8 +294,13 @@
 	    k = 0;
 	  }
 	}
+	if (cmd == 0x00) // main area
+	  must_refresh |= 0x01;
+	if (cmd == 0x0C) // channels area
+	  must_refresh |= 0x04;
       }
-	
+
+      /*
       if (table[i].fmt & 0x02 ) {
       // hex
 	for (uint8_t j=0;; j++) {
@@ -280,7 +311,7 @@
 	for (uint8_t j=3*strlen(txt); j<table[i].maxsize; j++)
 	  dsp.printf(" ");
       }
-      
+      */
       if (table[i].fmt & 0x04 ) {
       // binary
 	dsp.foreground(fgcolor);
@@ -300,6 +331,7 @@
 	}
 	dsp.foreground(fgcolor);
 	dsp.printf("]");
+	must_refresh |= 0x80;
       }
 
       if (table[i].fmt & 0x08 ) {
@@ -307,58 +339,96 @@
 	for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++) {
 	  for (uint8_t k=0; k<8; k++) {
 	    if ((txt[j] & (1 << k) ) != (oldv[j] & (1 << k))) {
-	 
+
 	      if (txt[j] & (1 << k))
 		dsp.foreground(fgcolor);
 	      else
 		dsp.foreground(bgcolor);
 
+	      /*
 	      for (uint8_t l=0;
 		   l<(sizeof(frames)/sizeof(frames[0])); ++l) {
 		if (frames[l].flag & ((j<<4) + k))
-		  dsp.rect(frames[l].x0, frames[l].y0,
-			   frames[l].x1, frames[l].y1,
-			   fgcolor); 
+		  dsp.fillrect(frames[l].x0, frames[l].y0,
+			       frames[l].x1, frames[l].y1,
+			       fgcolor/8);
 		else
-		  dsp.rect(frames[l].x0, frames[l].y0,
-			   frames[l].x1, frames[l].y1,
-			   bgcolor); 
-		
+		  dsp.fillrect(frames[l].x0, frames[l].y0,
+			       frames[l].x1, frames[l].y1,
+			       bgcolor);
+
 	      }
-	      
+	      */
+
 	      for (uint8_t l=0;
 		   l<(sizeof(flags)/sizeof(flags[0])); ++l) {
 		if (flags[l].flag == ((j<<4) + k)) {
-		  if (flags[l].msg != NULL) { // a string
-		    dsp.locate(flags[l].x, flags[l].y);
-		    dsp.printf(flags[l].msg);}
-		  else { // an icon
-		    Bitmap_s pic = {9, 10, 2, flags[l].icon};
-		    dsp.Bitmap_BW(pic, flags[l].x, flags[l].y);
+		  for (uint8_t m=0; m<(sizeof(zones)/sizeof(zones[0])); m++) {
+		    if (flags[l].zone == zones[m].flag) {
+		      if (flags[l].msg != NULL) { // a string
+			dsp.locate(flags[l].x + zones[m].x0,
+				   flags[l].y + zones[m].y0);
+			dsp.printf(flags[l].msg);}
+		      else { // an icon
+			Bitmap_s pic = {9, 10, 2, flags[l].icon};
+			dsp.Bitmap_BW(pic,
+				      flags[l].x + zones[m].x0,
+				      flags[l].y + zones[m].y0);
+		      }
+		      must_refresh |= zones[m].flag;
+		      break;
+		    }
 		  }
-		  //break;
+		  break;
 		}
-	      }	      
+	      }
 	    }
 	  }
 	}
       }
-      
+
       for(uint8_t j=0; j<table[i].maxsize; j++)
 	oldv[j] = txt[j];
+      break;
     }
   }
 
-  must_refresh = true;
   //dsp.copy_to_lcd();
   pulse(1, false);
 }
 
 void test_dsp()
 {
+  const FRAME *z;
   show(0x00, "8g8g8g8g8g8g8", 13); // main dsp
   show(0x0C, "888", 3); // channel dsp
   show(0x0A, "\xFF\xFF\xFF\xFF", 4); // all flags
+  dsp.copy_to_lcd();
+  wait(3);
+  dsp.cls();
+  
+
+  for (uint8_t i=0; i<(sizeof(zones)/sizeof(zones[0])); i++)
+    {
+      z = &zones[i];
+      dsp.fillrect(z->x0, z->y0, z->x1, z->y1, 4+i);
+      dsp.locate(z->x0+1, z->y0+1);
+      dsp.printf("%d", i);
+    }
+  for (uint8_t i=0; i<(sizeof(zones)/sizeof(zones[0])); i++)
+    {
+      z = &zones[i];
+      pc.printf("Zone %d [%x]: %d, %d, %d, %d\n", i, z->flag,
+		z->x0, z->y0, z->x1, z->y1);
+      must_refresh = z->flag;      
+      wait(1);
+    }
+  pc.printf("Done\n");
+  wait(2);
+  pc.printf("Copy ALL\n");
+  dsp.copy_to_lcd();
+  wait(2);  
+  dsp.cls();
 }
 
 
@@ -368,22 +438,22 @@
     {
       HPSerial::CMD cmd;
       if (hp.pop(cmd))
-	{
+	{/*
 	  pc.printf("CMD[%s:%d %d/%d/%d/%d/%d/%d/%d] %X\n", (cmd.direction==HPSerial::Rx)?"Rx":"Tx", cmd.id,
-		    hp.nerrors(0), 
-		    hp.nerrors(1), 
-		    hp.nerrors(2), 
-		    hp.nerrors(3), 
-		    hp.nerrors(4), 
-		    hp.nerrors(5), 
-		    hp.nerrors(6), 
+		    hp.nerrors(0),
+		    hp.nerrors(1),
+		    hp.nerrors(2),
+		    hp.nerrors(3),
+		    hp.nerrors(4),
+		    hp.nerrors(5),
+		    hp.nerrors(6),
 		    cmd.cmd);
-
+	 */
 	  if (cmd.direction == HPSerial::Rx) {
-	    if ((cmd.cmd == 0x00) || (cmd.cmd == 0x0C))
-	      pc.printf("  data=%s\n", cmd.value);
+	    //  if ((cmd.cmd == 0x00) || (cmd.cmd == 0x0C))
+	    //  pc.printf("  data=%s\n", cmd.value);
 	    show(cmd.cmd, cmd.value, cmd.size);
-	    
+
 	  }
 	}
     }
@@ -394,7 +464,13 @@
 int main()
 {
   setup();
+
   tdsp.start(copy_to_lcd);
+
+  test_dsp();
+  wait(5);
+  dsp.cls();
+
   tloop.start(loop);
   while(1);
   //loop();

mercurial