src/display.cpp

changeset 46
a4a007b3c42e
parent 44
b3c3d54d2c7c
child 51
d8042bff0e00
equal deleted inserted replaced
45:2da50a3d4e9f 46:a4a007b3c42e
40 void Display::dimm_char(uint8_t n) 40 void Display::dimm_char(uint8_t n)
41 { 41 {
42 // dimm the char number of the currently displayed string of the main area; 42 // dimm the char number of the currently displayed string of the main area;
43 // do this by printing a modifed version of the last displayed string 43 // do this by printing a modifed version of the last displayed string
44 // but only alphanumeric chars should be counted (not the punctuation) 44 // but only alphanumeric chars should be counted (not the punctuation)
45 static char txt[64];
46 char c; 45 char c;
47 uint8_t len, i, j; 46 uint8_t len, i, j;
48 // for which we need to look for the entry in the table 47 // for which we need to look for the entry in the table
49 for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) { 48 for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) {
50 if (table[i].cmd == 0x00) { 49 if (table[i].cmd == 0x00) {
51 ::printf("DIMM CHAR %d\n", n); 50
52 ::printf("repl '%s'\n", table[i].buffer); 51 background(table[i].bgcolor);
52 foreground(table[i].color / 2); // dimmed
53 set_font((unsigned char*) table[i].font);
54 locate(table[i].x0, table[i].y0);
55
53 len = strlen(table[i].buffer); 56 len = strlen(table[i].buffer);
54 if (n >= len) 57 if (n >= len)
55 break; // nothing to do 58 break; // nothing to do
56 strncpy(txt, table[i].buffer, table[i].maxsize); 59 //::printf("DIMM CHAR %d\n", n);
57 // look for the actual position of the char in the string (only alphanum) 60 //::printf(" in (len=%d) '%s'\n", len, table[i].buffer);
58 // XXX very poor implementation... 61
59 for (j=0; (j<len)&&(j<=n); j++) 62 for (j=0; (j<len); j++)
60 { 63 {
61 c = txt[j]; 64 // advae the location up to the char to dimm
62 if ((c == ',') || (c == '.') || (c == ';') || (c == ':') || (c == ' ')) 65 c = table[i].buffer[j];
66 if ((c == ',') || (c == '.') || (c == ';') || (c == ':'))
67 // it's a "zero" width char, skip it
63 n++; 68 n++;
64 } 69 if (n == 0)
65 // now move the end of the string for char n to steps on the right 70 {
66 // so we can insert our 2 '\t' characters before and after the 71 //::printf(" Found at pos %d char '%c'\n", j, c);
67 // character to dimm 72 // found it
68 for (j=len; j>n; j--) 73 character(c);
69 { 74 break;
70 txt[j+2] = txt[j]; 75 }
71 } 76 // otherwise, just advance the char_x
72 txt[n+2] = '\t'; 77 //::printf(" move %d for '%c' [%X]\n", , c, c);
73 txt[n+1] = txt[n]; 78 char_width(c, true);
74 txt[n] = '\t'; 79 n--;
75 txt[len+2] = 0x00; // make sure the string will be terminated 80 }
76
77 ::printf("with '%s'\n", txt);
78 // now display this string
79 show(0x00, txt, 0);
80 break;
81 } 81 }
82 } 82 }
83 } 83 }
84 84
85 void Display::show(uint8_t cmd, const char *intxt, uint8_t nchar=0) 85 void Display::show(uint8_t cmd, const char *intxt, uint8_t nchar=0)
101 { // dimm a character of the main area 101 { // dimm a character of the main area
102 dimm_char(intxt[0]); 102 dimm_char(intxt[0]);
103 } 103 }
104 else 104 else
105 { 105 {
106 pixel_buffer_mutex.lock();
106 for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) { 107 for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) {
107 if (table[i].cmd == cmd) { 108 if (table[i].cmd == cmd) {
108 strcpy(txt, intxt); 109 strcpy(txt, intxt);
109 txtp = txt; 110 txtp = txt;
110 111
118 locate(table[i].x0, table[i].y0); 119 locate(table[i].x0, table[i].y0);
119 120
120 if (table[i].fmt & FMT_ASCII) // ASCII text 121 if (table[i].fmt & FMT_ASCII) // ASCII text
121 { 122 {
122 // check if the string has changed since last time 123 // check if the string has changed since last time
123 if (strncmp(oldv, txt, table[i].maxsize) != 0) 124 if (true) //(strncmp(oldv, txt, table[i].maxsize) != 0)
124 { 125 {
125 // clear the text area 126 // clear the text area
126 if (table[i].width > 0) 127 if (table[i].width > 0)
127 fillrect(table[i].x0, 128 fillrect(table[i].x0,
128 table[i].y0, 129 table[i].y0,
171 */ 172 */
172 if (table[i].fmt & FMT_FLAGS ) // flag indicators 173 if (table[i].fmt & FMT_FLAGS ) // flag indicators
173 { 174 {
174 uint8_t nbyte; 175 uint8_t nbyte;
175 uint8_t nbit; 176 uint8_t nbit;
177 uint16_t color;
176 // flags 178 // flags
177 for (uint8_t l=0; l<(sizeof(flags)/sizeof(flags[0])); ++l) 179 for (uint8_t l=0; l<(sizeof(flags)/sizeof(flags[0])); ++l)
178 { 180 {
179 nbyte = flags[l].flag / 8; 181 nbyte = flags[l].flag / 8;
180 nbit = flags[l].flag % 8; 182 nbit = flags[l].flag % 8;
201 } 203 }
202 204
203 // draw frames (Alarm and Channel) 205 // draw frames (Alarm and Channel)
204 for (uint8_t l=0; l<(sizeof(frames)/sizeof(frames[0])); ++l) 206 for (uint8_t l=0; l<(sizeof(frames)/sizeof(frames[0])); ++l)
205 { 207 {
206 uint16_t color; 208 nbyte = frames[l].flag / 8;
207 if (intxt[0] & (1 << frames[l].flag)) // frame flags are on the 1st byte only 209 nbit = frames[l].flag % 8;
210 if (intxt[nbyte] & (1 << nbit))
208 color = fgcolor/6; 211 color = fgcolor/6;
209 else 212 else
210 color = bgcolor; 213 color = bgcolor;
211 hline(frames[l].x0+1, frames[l].x0+3, frames[l].y0, color); 214 hline(frames[l].x0+1, frames[l].x0+3, frames[l].y0, color);
212 hline(frames[l].x1-3, frames[l].x1-1, frames[l].y0, color); 215 hline(frames[l].x1-3, frames[l].x1-1, frames[l].y0, color);
221 for(uint8_t j=0; j<table[i].maxsize; j++) 224 for(uint8_t j=0; j<table[i].maxsize; j++)
222 oldv[j] = txt[j]; 225 oldv[j] = txt[j];
223 break; 226 break;
224 } 227 }
225 } 228 }
229 pixel_buffer_mutex.unlock();
230
226 //free(txt); 231 //free(txt);
227 //this->copy_to_lcd(); 232 //this->copy_to_lcd();
228 } 233 }
229 } 234 }
230 235

mercurial