10 #include "BufferedSerial.h" |
10 #include "BufferedSerial.h" |
11 |
11 |
12 #include "SPI8.h" |
12 #include "SPI8.h" |
13 #include "ILI9341.h" |
13 #include "ILI9341.h" |
14 |
14 |
15 Serial pc(USBTX, USBRX); |
15 //Serial pc(USBTX, USBRX); |
16 BufferedSerial hp(PA_0, PA_1, 32); // serial4 |
16 BufferedSerial hp(NC, PA_1, 64, 0); // serial4 |
17 |
17 |
18 ILI9341 tft(SPI_8, 24000000, PA_7, PA_6, PA_5, PA_4, PB_6, PC_7, "myLCD"); // Spi 8bit, 24MHz, mosi, miso, sclk, cs, reset, dc |
18 ILI9341 tft(SPI_8, 24000000, PA_7, PA_6, PA_5, PA_4, PB_6, PC_7, "myLCD"); // Spi 8bit, 24MHz, mosi, miso, sclk, cs, reset, dc |
19 //ILI9341 tft(SPI_8, 24000000, PA_7, PA_6, PA_5, PA_4, PB_6, PB_5, "myLCD"); |
19 //ILI9341 tft(SPI_8, 24000000, PA_7, PA_6, PA_5, PA_4, PB_6, PB_5, "myLCD"); |
20 |
20 |
21 #define MAX_BUFF 13 |
21 #define MAX_BUFF 16 |
22 uint8_t curchar; |
22 uint8_t curchar; |
23 uint8_t cmd; |
23 uint8_t cmd; |
24 uint8_t nchars; |
24 uint8_t nchars; |
25 char buffer[MAX_BUFF+1]; |
25 char buffer[MAX_BUFF+1]; |
26 |
26 |
28 { |
28 { |
29 uint8_t cmd; |
29 uint8_t cmd; |
30 uint16_t color; |
30 uint16_t color; |
31 uint16_t bgcolor; |
31 uint16_t bgcolor; |
32 uint8_t y0; |
32 uint8_t y0; |
33 uint8_t fmt; // 0=>ascii, 1=>hex, 2=>bits |
33 uint8_t fmt; // 0=>ascii, 1=>hex, 2=>bits, 3=>flags |
34 uint8_t maxsize; |
34 uint8_t maxsize; |
35 const unsigned char* font; |
35 const unsigned char* font; |
36 char buffer[MAX_BUFF+1]; |
36 char buffer[MAX_BUFF+1]; |
37 } DSP; |
37 } DSP; |
38 |
38 |
39 static DSP table[] = |
39 static DSP table[] = |
40 { |
40 { |
41 { 0x00, Yellow, Red, 5, 0, MAX_BUFF, Arial28x28}, |
41 { 0x00, Blue, Black, 5, 0, MAX_BUFF, Arial28x28}, |
42 { 0x0C, Red, Blue, 40, 0, 3, Arial28x28}, |
42 { 0x0C, Blue, Black, 40, 0, 3, Arial28x28}, |
43 { 0x01, Blue, Yellow, 75, 1, MAX_BUFF, Arial12x12}, |
43 { 0x01, Green, Black, 95, 1, MAX_BUFF, Arial12x12}, |
44 { 0x02, Blue, Yellow, 110, 1, MAX_BUFF, Arial12x12}, |
44 { 0x02, Green, Black, 110, 1, MAX_BUFF, Arial12x12}, |
45 { 0x0A, Blue, Yellow, 145, 2, 4, Arial12x12}, |
45 { 0x0A, Blue, Yellow, 145, 2, 4, Arial12x12}, |
|
46 { 0x0A, Yellow, Black, 70 , 3, 4, Arial12x12}, |
46 { 0xFF, Red, Black, 210, 0, MAX_BUFF, Arial12x12}, |
47 { 0xFF, Red, Black, 210, 0, MAX_BUFF, Arial12x12}, |
47 }; |
48 }; |
|
49 |
|
50 typedef struct _FLAG |
|
51 { |
|
52 uint8_t flag; |
|
53 uint8_t x; |
|
54 uint8_t y; |
|
55 const char* msg; |
|
56 } FLAG; |
|
57 |
|
58 static const FLAG flags[] = |
|
59 { |
|
60 { 0x00, 0, 70, "Alarm"}, // F1.1 |
|
61 { 0x01, 40, 70, "Mx+B"}, // F1.2 |
|
62 { 0x03, 40, 70, "Channels"}, // F1.4 |
|
63 { 0x14, 70, 70, "4W"}, // F2.5 |
|
64 { 0x33, 90, 70, "VIEW"}, |
|
65 { 0x34, 120, 70, "MON"}, |
|
66 { 0x36, 150, 70, "CONFIG"}, |
|
67 }; |
48 #define DEBUG |
68 #define DEBUG |
49 #ifdef DEBUG |
69 #ifdef DEBUG |
50 #define DBGPIN PC_0 |
70 #define DBGPIN PC_0 |
51 |
71 |
52 DigitalOut dbgpin(DBGPIN); |
72 DigitalOut dbgpin(DBGPIN); |
102 fgcolor = table[i].color; |
122 fgcolor = table[i].color; |
103 tft.background(bgcolor); |
123 tft.background(bgcolor); |
104 tft.foreground(fgcolor); |
124 tft.foreground(fgcolor); |
105 tft.locate(0, table[i].y0); |
125 tft.locate(0, table[i].y0); |
106 tft.set_font((unsigned char*) table[i].font); |
126 tft.set_font((unsigned char*) table[i].font); |
107 break; |
127 oldv = table[i].buffer; |
|
128 |
|
129 switch (table[i].fmt) { |
|
130 case 0: //ascii |
|
131 tft.printf(txt); |
|
132 for (uint8_t j=strlen(txt); j<table[i].maxsize; j++) |
|
133 tft.printf(" "); |
|
134 break; |
|
135 case 1: // hex |
|
136 for (uint8_t j=0;; j++) { |
|
137 if (txt[j] == 0x00) |
|
138 break; |
|
139 tft.printf("%02X ", txt[j]); |
|
140 } |
|
141 for (uint8_t j=3*strlen(txt); j<table[i].maxsize; j++) |
|
142 tft.printf(" "); |
|
143 break; |
|
144 case 2: // binary |
|
145 tft.foreground(fgcolor); |
|
146 tft.printf(" ["); |
|
147 for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++) { |
|
148 if (j>0) { |
|
149 tft.foreground(fgcolor); |
|
150 tft.printf(" | "); |
|
151 } |
|
152 for (uint8_t k=0; k<8; k++) { |
|
153 if (txt[j] & (1 << (7-k))) |
|
154 tft.foreground(fgcolor); |
|
155 else |
|
156 tft.foreground(bgcolor); |
|
157 tft.printf("%d", (8-k)); |
|
158 } |
|
159 } |
|
160 tft.foreground(fgcolor); |
|
161 tft.printf("]"); |
|
162 break; |
|
163 case 3: // flags |
|
164 for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++) { |
|
165 for (uint8_t k=0; k<8; k++) { |
|
166 if ((txt[j] & (1 << k) ) != (oldv[j] & (1 << k))) { |
|
167 |
|
168 if (txt[j] & (1 << k)) |
|
169 tft.foreground(fgcolor); |
|
170 else |
|
171 tft.foreground(bgcolor); |
|
172 for (uint8_t l=0; |
|
173 l<(sizeof(flags)/sizeof(flags[0])); ++l) { |
|
174 if (flags[l].flag == ((j<<4) + k)) { |
|
175 tft.locate(flags[l].x, flags[l].y); |
|
176 tft.printf(flags[l].msg); |
|
177 break; |
|
178 } |
|
179 } |
|
180 } |
|
181 } |
|
182 oldv[j] = txt[j]; |
|
183 } |
|
184 break; |
|
185 } |
|
186 |
108 } |
187 } |
109 } |
188 } |
110 |
189 |
111 switch (table[i].fmt) { |
|
112 case 0: //ascii |
|
113 tft.printf(txt); |
|
114 for (uint8_t j=nchar; j<table[i].maxsize; j++) |
|
115 tft.printf(" "); |
|
116 break; |
|
117 case 1: // hex |
|
118 for (uint8_t j=0; j<nchar; j++) |
|
119 tft.printf("%02X ", txt[j]); |
|
120 for (uint8_t j=nchar; j<table[i].maxsize; j++) |
|
121 tft.printf(" "); |
|
122 break; |
|
123 case 2: // binary |
|
124 for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++) { |
|
125 //tft.setCursor(x0+w*i, y0+10); |
|
126 for (uint8_t k=0; k<8; k++) { |
|
127 if (txt[j] & (1 << (7-k))) |
|
128 tft.foreground(fgcolor); |
|
129 else |
|
130 tft.foreground(bgcolor); |
|
131 tft.printf("%d", (8-k)); |
|
132 } |
|
133 } |
|
134 break; |
|
135 } |
|
136 } |
190 } |
137 |
191 |
138 |
192 |
139 void loop() { // run over and over |
193 void loop() { // run over and over |
140 if (hp.readable()) { |
194 if (hp.readable()) { |
141 uint8_t val = hp.getc(); |
195 uint8_t val = hp.getc(); |
142 DebugPulse(); |
196 DebugPulse(3); |
143 // 0xFF: idle |
197 // 0xFF: idle |
144 // 0xFE: frame finished |
198 // 0xFE: frame finished |
145 // 0x66: Start of transmission received |
199 // 0x66: Start of transmission received |
146 if (cmd == 0xFF) { |
200 if (cmd == 0xFF) { |
147 if ((val == 0x66) || (val == 0x99)) { |
201 if ((val == 0x66) || (val == 0x99)) { |
162 cmd = 0xFF; |
216 cmd = 0xFF; |
163 } else if (val == 0x00){ |
217 } else if (val == 0x00){ |
164 // probably an ACK for a keypad related event |
218 // probably an ACK for a keypad related event |
165 } else { |
219 } else { |
166 // display "junk" byte |
220 // display "junk" byte |
167 //DebugPulse(); |
221 DebugPulse(); |
168 go_msg(); |
222 show(0xFF, "", 5); |
169 tft.printf("%02X=> %02x", cmd, val); |
223 tft.printf("%02X=> %02x", cmd, val); |
170 } |
224 } |
171 |
225 |
172 } else if (cmd == 0x66) { // waiting for the display command |
226 } else if (cmd == 0x66) { // waiting for the display command |
173 if ((val == 0x0C) || (val == 0x00) || val == 0x01 || val == 0x02 || val == 0x0A) { |
227 if ((val == 0x0C) || (val == 0x00) || (val == 0x01) || (val == 0x02) || (val == 0x0A)) { |
174 cmd = val; |
228 cmd = val; |
175 nchars = 0; |
229 nchars = 0; |
176 } else { |
230 } else { |
177 cmd = 0xFE; |
231 cmd = 0xFE; |
178 // display unknown cmd byte |
232 // display unknown cmd byte |
179 //DebugPulse(); |
233 DebugPulse(); |
180 go_msg(); |
234 show(0xFF, "", 10); |
181 tft.printf("%02X-> %02x", cmd, val); |
235 tft.printf("%02X-> %02x", cmd, val); |
182 } |
236 } |
183 |
237 |
184 } else if (cmd == 0x99) { // waiting for a 0x00, it's the DP that sent a keypress event |
238 } else if (cmd == 0x99) { // waiting for a 0x00, it's the DP that sent a keypress event |
185 if (val != 0x00) { |
239 if (val != 0x00) { |
186 go_msg(); |
240 show(0xFF, "", 0); |
187 tft.printf("%02X kp %02X", cmd, val); |
241 tft.printf("%02X kp %02X", cmd, val); |
188 } |
242 } |
189 cmd =0xFF; |
243 cmd = 0xFF; |
190 |
244 |
191 } else if (nchars == 0) { // waiting for the number of chars to display |
245 } else if (nchars == 0) { // waiting for the number of chars to display |
192 if (val>MAX_BUFF) { |
246 if (val>MAX_BUFF) { |
193 // display warning |
247 // display warning |
194 //dsp(); |
248 //dsp(); |
195 //tft << cmd << " got len " << val; |
249 //tft << cmd << " got len " << val; |
196 //DebugPulse(); |
250 //DebugPulse(); |
197 go_msg(); |
251 show(0xFF, "", 0); |
198 tft.printf("%02X len %d", cmd, val); |
252 tft.printf("%02X len %d", cmd, val); |
199 cmd = 0xFE; // weird |
253 cmd = 0xFE; // weird |
200 } else { |
254 } else { |
201 nchars = val; |
255 nchars = val; |
202 curchar = 0; |
256 curchar = 0; |