Fix display of flags and improve dimm char handling draft

Sat, 07 Nov 2020 19:22:04 +0100

author
David Douard <david.douard@sdf3.org>
date
Sat, 07 Nov 2020 19:22:04 +0100
changeset 46
a4a007b3c42e
parent 45
2da50a3d4e9f
child 47
11c57010e4f9

Fix display of flags and improve dimm char handling

src/display.cpp file | annotate | diff | comparison | revisions
src/display.h file | annotate | diff | comparison | revisions
--- a/src/display.cpp	Sat Nov 07 19:20:39 2020 +0100
+++ b/src/display.cpp	Sat Nov 07 19:22:04 2020 +0100
@@ -42,42 +42,42 @@
 	// dimm the char number of the currently displayed string of the main area;
 	// do this by printing a modifed version of the last displayed string
 	// but only alphanumeric chars should be counted (not the punctuation)
-	static char txt[64];
 	char c;
 	uint8_t len, i, j;
 	// for which we need to look for the entry in the table
 	for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) {
 		if (table[i].cmd == 0x00) {
-			::printf("DIMM CHAR %d\n", n);
-			::printf("repl  '%s'\n", table[i].buffer);
+
+			background(table[i].bgcolor);
+			foreground(table[i].color / 2);  // dimmed
+			set_font((unsigned char*) table[i].font);
+			locate(table[i].x0, table[i].y0);
+
 			len = strlen(table[i].buffer);
 			if (n >= len)
 				break;  // nothing to do
-			strncpy(txt, table[i].buffer, table[i].maxsize);
-			// look for the actual position of the char in the string (only alphanum)
-			// XXX very poor implementation...
-			for (j=0; (j<len)&&(j<=n); j++)
+			//::printf("DIMM CHAR %d\n", n);
+			//::printf("  in (len=%d) '%s'\n", len, table[i].buffer);
+
+			for (j=0; (j<len); j++)
 			{
-				c = txt[j];
-				if ((c == ',') || (c == '.') || (c == ';') || (c == ':') || (c == ' '))
+				// advae the location up to the char to dimm
+				c = table[i].buffer[j];
+				if ((c == ',') || (c == '.') || (c == ';') || (c == ':'))
+					// it's a "zero" width char, skip it
 					n++;
+				if (n == 0)
+				{
+					//::printf("  Found at pos %d char '%c'\n", j, c);
+					// found it
+					character(c);
+					break;
+				}
+				// otherwise, just advance the char_x
+				//::printf("  move %d for '%c' [%X]\n", , c, c);
+				char_width(c, true);
+				n--;
 			}
-			// now move the end of the string for char n to steps on the right
-			// so we can insert our 2 '\t' characters before and after the
-			// character to dimm
-			for (j=len; j>n; j--)
-			{
-				txt[j+2] = txt[j];
-			}
-			txt[n+2] = '\t';
-			txt[n+1] = txt[n];
-			txt[n] = '\t';
-			txt[len+2] = 0x00; // make sure the string will be terminated
-
-			::printf("with  '%s'\n", txt);
-			// now display this string
-			show(0x00, txt, 0);
-			break;
 		}
 	}
 }
@@ -103,6 +103,7 @@
 	}
 	else
 	{
+		pixel_buffer_mutex.lock();
 		for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) {
 			if (table[i].cmd == cmd) {
 				strcpy(txt, intxt);
@@ -120,7 +121,7 @@
 				if (table[i].fmt & FMT_ASCII)  // ASCII text
 				{
 					// check if the string has changed since last time
-					if (strncmp(oldv, txt, table[i].maxsize) != 0)
+					if (true) //(strncmp(oldv, txt, table[i].maxsize) != 0)
 					{
 						// clear the text area
 						if (table[i].width > 0)
@@ -173,6 +174,7 @@
 				{
 					uint8_t nbyte;
 					uint8_t nbit;
+					uint16_t color;
 					// flags
 					for (uint8_t l=0; l<(sizeof(flags)/sizeof(flags[0])); ++l)
 					{
@@ -203,8 +205,9 @@
 					// draw frames (Alarm and Channel)
 					for (uint8_t l=0; l<(sizeof(frames)/sizeof(frames[0])); ++l)
 					{
-						uint16_t color;
-						if (intxt[0] & (1 << frames[l].flag)) // frame flags are on the 1st byte only
+						nbyte = frames[l].flag / 8;
+						nbit = frames[l].flag % 8;
+						if (intxt[nbyte] & (1 << nbit))
 							color = fgcolor/6;
 						else
 							color = bgcolor;
@@ -223,6 +226,8 @@
 				break;
 			}
 		}
+		pixel_buffer_mutex.unlock();
+
 		//free(txt);
 		//this->copy_to_lcd();
 	}
--- a/src/display.h	Sat Nov 07 19:20:39 2020 +0100
+++ b/src/display.h	Sat Nov 07 19:22:04 2020 +0100
@@ -123,12 +123,12 @@
     { 0x0f, 129, 28+16, false, "AVG"},         // F2.7  00 80 00 00
 
     { 0x05, 154+0,  17+10, false, "Alarm"},    // F1.5  20 00 00 00
-    { 0x06, 154+0,  17+20, false, "H"},        // F1.6  40 00 00 00
-    { 0x0b, 154+6,  17+20, false, "1"},        // F2.3  00 08 00 00
-    { 0x08, 154+12, 17+20, false, "2"},        // F2.0  00 01 00 00
-    { 0x0a, 154+18, 17+20, false, "3"},        // F2.2  00 04 00 00
+    { 0x08, 154+0,  17+20, false, "H"},        // F1.6  40 00 00 00
+    { 0x07, 154+6,  17+20, false, "1"},        // F2.3  00 08 00 00
+    { 0x06, 154+12, 17+20, false, "2"},        // F2.0  00 01 00 00
+    { 0x04, 154+18, 17+20, false, "3"},        // F2.2  00 04 00 00
     { 0x09, 154+24, 17+20, false, "4"},        // F2.1  00 02 00 00
-    { 0x04, 154+30, 17+20, false, "L"},        // F1.4  00 10 00 00
+    { 0x0a, 154+30, 17+20, false, "L"},        // F1.4  00 10 00 00
 
 	{ 0x80, 224, 54, true, "SHIFT"},   // not an actual command, managed by the front panel
 };
@@ -151,7 +151,7 @@
 static const FRAME frames[] =
 {
     { 0x02, 194, 30, 243, 53}, // F1.2 - channel frame
-    { 0x07, 151, 30, 192, 46}, // F1.7 - alarm frame
+    { 0x0b, 151, 30, 192, 46}, // F1.7 - alarm frame
 };
 
 

mercurial