src/main.cpp

Thu, 08 Sep 2016 20:02:23 +0200

author
David Douard <david.douard@logilab.fr>
date
Thu, 08 Sep 2016 20:02:23 +0200
changeset 2
d0826e4a1ff7
parent 1
3021fc79cc3b
child 3
a3233abe730e
permissions
-rw-r--r--

several improvements

1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
1 #include "stdio.h"
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
2 #include "mbed.h"
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
3 #include "string"
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
4 #include "Arial12x12.h"
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
5 #include "Arial28x28.h"
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
6 //#include "Arial24x23.h"
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
7 //#include "Terminal6x8.h"
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
8 //#include "Arial43x48_numb.h"
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
9
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
10 #include "BufferedSerial.h"
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
11
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
12 #include "SPI8.h"
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
13 #include "ILI9341.h"
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
14
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
15 //Serial pc(USBTX, USBRX);
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
16 BufferedSerial hp(NC, PA_1, 64, 0); // serial4
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
17
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
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
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
19 //ILI9341 tft(SPI_8, 24000000, PA_7, PA_6, PA_5, PA_4, PB_6, PB_5, "myLCD");
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
20
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
21 #define MAX_BUFF 16
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
22 uint8_t curchar;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
23 uint8_t cmd;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
24 uint8_t nchars;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
25 char buffer[MAX_BUFF+1];
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
26
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
27 typedef struct _DSP
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
28 {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
29 uint8_t cmd;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
30 uint16_t color;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
31 uint16_t bgcolor;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
32 uint8_t y0;
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
33 uint8_t fmt; // 0=>ascii, 1=>hex, 2=>bits, 3=>flags
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
34 uint8_t maxsize;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
35 const unsigned char* font;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
36 char buffer[MAX_BUFF+1];
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
37 } DSP;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
38
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
39 static DSP table[] =
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
40 {
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
41 { 0x00, Blue, Black, 5, 0, MAX_BUFF, Arial28x28},
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
42 { 0x0C, Blue, Black, 40, 0, 3, Arial28x28},
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
43 { 0x01, Green, Black, 95, 1, MAX_BUFF, Arial12x12},
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
44 { 0x02, Green, Black, 110, 1, MAX_BUFF, Arial12x12},
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
45 { 0x0A, Blue, Yellow, 145, 2, 4, Arial12x12},
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
46 { 0x0A, Yellow, Black, 70 , 3, 4, Arial12x12},
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
47 { 0xFF, Red, Black, 210, 0, MAX_BUFF, Arial12x12},
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
48 };
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
49
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
50 typedef struct _FLAG
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
51 {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
52 uint8_t flag;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
53 uint8_t x;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
54 uint8_t y;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
55 const char* msg;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
56 } FLAG;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
57
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
58 static const FLAG flags[] =
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
59 {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
60 { 0x00, 0, 70, "Alarm"}, // F1.1
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
61 { 0x01, 40, 70, "Mx+B"}, // F1.2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
62 { 0x03, 40, 70, "Channels"}, // F1.4
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
63 { 0x14, 70, 70, "4W"}, // F2.5
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
64 { 0x33, 90, 70, "VIEW"},
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
65 { 0x34, 120, 70, "MON"},
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
66 { 0x36, 150, 70, "CONFIG"},
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
67 };
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
68 #define DEBUG
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
69 #ifdef DEBUG
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
70 #define DBGPIN PC_0
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
71
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
72 DigitalOut dbgpin(DBGPIN);
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
73 inline void DebugPulse(uint8_t count=1)
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
74 {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
75 while (count--)
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
76 {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
77 dbgpin = 1;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
78 dbgpin = 0;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
79 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
80 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
81 #else
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
82 inline void DebugPulse(uint8_t count=1)
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
83 {}
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
84 #endif
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
85
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
86 void setup() {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
87 // init the LCD
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
88
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
89 tft.set_orientation(3);
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
90 //pc.baud (115200);
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
91 //pc.printf("\n\nSystem Core Clock = %.3f MHZ\r\n",
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
92 // (float)SystemCoreClock/1000000);
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
93
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
94 hp.baud(187500);
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
95
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
96 // myLCD.set_font((unsigned char*) Terminal6x8);
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
97 // myLCD.claim(stdout); // send stdout to the LCD display
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
98 // myLCD.claim(stderr); // send stderr to the LCD display
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
99 tft.background(Black); // set background to black
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
100 tft.cls();
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
101
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
102 cmd = 0xFF;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
103 curchar = 0;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
104 nchars = 0;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
105 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
106
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
107 void go_msg() {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
108 tft.set_font((unsigned char*) Arial12x12);
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
109 tft.locate(0, 210);
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
110 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
111
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
112 void show(uint8_t cmd, char *txt, uint8_t nchar=0) {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
113 uint8_t i, len;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
114 uint16_t bgcolor, fgcolor;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
115 char *oldv;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
116
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
117 len = MAX_BUFF;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
118
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
119 for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
120 if (table[i].cmd == cmd) {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
121 bgcolor = table[i].bgcolor;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
122 fgcolor = table[i].color;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
123 tft.background(bgcolor);
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
124 tft.foreground(fgcolor);
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
125 tft.locate(0, table[i].y0);
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
126 tft.set_font((unsigned char*) table[i].font);
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
127 oldv = table[i].buffer;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
128
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
129 switch (table[i].fmt) {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
130 case 0: //ascii
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
131 tft.printf(txt);
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
132 for (uint8_t j=strlen(txt); j<table[i].maxsize; j++)
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
133 tft.printf(" ");
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
134 break;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
135 case 1: // hex
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
136 for (uint8_t j=0;; j++) {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
137 if (txt[j] == 0x00)
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
138 break;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
139 tft.printf("%02X ", txt[j]);
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
140 }
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
141 for (uint8_t j=3*strlen(txt); j<table[i].maxsize; j++)
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
142 tft.printf(" ");
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
143 break;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
144 case 2: // binary
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
145 tft.foreground(fgcolor);
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
146 tft.printf(" [");
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
147 for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++) {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
148 if (j>0) {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
149 tft.foreground(fgcolor);
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
150 tft.printf(" | ");
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
151 }
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
152 for (uint8_t k=0; k<8; k++) {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
153 if (txt[j] & (1 << (7-k)))
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
154 tft.foreground(fgcolor);
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
155 else
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
156 tft.foreground(bgcolor);
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
157 tft.printf("%d", (8-k));
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
158 }
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
159 }
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
160 tft.foreground(fgcolor);
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
161 tft.printf("]");
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
162 break;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
163 case 3: // flags
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
164 for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++) {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
165 for (uint8_t k=0; k<8; k++) {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
166 if ((txt[j] & (1 << k) ) != (oldv[j] & (1 << k))) {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
167
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
168 if (txt[j] & (1 << k))
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
169 tft.foreground(fgcolor);
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
170 else
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
171 tft.foreground(bgcolor);
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
172 for (uint8_t l=0;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
173 l<(sizeof(flags)/sizeof(flags[0])); ++l) {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
174 if (flags[l].flag == ((j<<4) + k)) {
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
175 tft.locate(flags[l].x, flags[l].y);
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
176 tft.printf(flags[l].msg);
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
177 break;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
178 }
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
179 }
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
180 }
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
181 }
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
182 oldv[j] = txt[j];
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
183 }
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
184 break;
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
185 }
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
186
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
187 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
188 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
189
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
190 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
191
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
192
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
193 void loop() { // run over and over
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
194 if (hp.readable()) {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
195 uint8_t val = hp.getc();
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
196 DebugPulse(3);
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
197 // 0xFF: idle
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
198 // 0xFE: frame finished
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
199 // 0x66: Start of transmission received
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
200 if (cmd == 0xFF) {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
201 if ((val == 0x66) || (val == 0x99)) {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
202 cmd = val;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
203 } else if ((val == 0x00) || (val == 0x55)){
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
204 // probably an ACK for a keypad related event
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
205 } else {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
206 // display "junk" byte
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
207 //DebugPulse();
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
208 show(0xFF, "", 0);
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
209 tft.printf("%02X:> %02x", cmd, val);
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
210 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
211
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
212 } else if (cmd == 0xFE ) {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
213 if ((val == 0x66) || (val == 0x99)) {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
214 cmd = val;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
215 } else if (val == 0x55) {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
216 cmd = 0xFF;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
217 } else if (val == 0x00){
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
218 // probably an ACK for a keypad related event
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
219 } else {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
220 // display "junk" byte
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
221 DebugPulse();
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
222 show(0xFF, "", 5);
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
223 tft.printf("%02X=> %02x", cmd, val);
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
224 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
225
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
226 } else if (cmd == 0x66) { // waiting for the display command
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
227 if ((val == 0x0C) || (val == 0x00) || (val == 0x01) || (val == 0x02) || (val == 0x0A)) {
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
228 cmd = val;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
229 nchars = 0;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
230 } else {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
231 cmd = 0xFE;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
232 // display unknown cmd byte
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
233 DebugPulse();
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
234 show(0xFF, "", 10);
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
235 tft.printf("%02X-> %02x", cmd, val);
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
236 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
237
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
238 } else if (cmd == 0x99) { // waiting for a 0x00, it's the DP that sent a keypress event
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
239 if (val != 0x00) {
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
240 show(0xFF, "", 0);
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
241 tft.printf("%02X kp %02X", cmd, val);
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
242 }
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
243 cmd = 0xFF;
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
244
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
245 } else if (nchars == 0) { // waiting for the number of chars to display
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
246 if (val>MAX_BUFF) {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
247 // display warning
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
248 //dsp();
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
249 //tft << cmd << " got len " << val;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
250 //DebugPulse();
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
251 show(0xFF, "", 0);
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
252 tft.printf("%02X len %d", cmd, val);
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
253 cmd = 0xFE; // weird
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
254 } else {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
255 nchars = val;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
256 curchar = 0;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
257 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
258
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
259 } else { // a character to display
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
260 buffer[curchar] = val;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
261 curchar++;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
262 if (curchar == nchars) {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
263 buffer[curchar] = 0x00;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
264 show(cmd, buffer, nchars);
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
265 nchars = 0;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
266 curchar = 0;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
267 cmd = 0xFE;
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
268 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
269 }
2
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
270
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
271 DebugPulse(4);
d0826e4a1ff7 several improvements
David Douard <david.douard@logilab.fr>
parents: 1
diff changeset
272
1
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
273 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
274 }
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
275
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
276 int main()
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
277 {
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
278 setup();
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
279 while(1)
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
280 loop();
3021fc79cc3b kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff changeset
281 }

mercurial