Sun, 25 Oct 2020 22:15:35 +0100
Reformat Keypad.cpp
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
1 | #include "stdio.h" |
4
219766126afb
another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents:
3
diff
changeset
|
2 | |
21 | 3 | #include <mbed.h> |
4 | #include <rtos.h> | |
5 | #include <string> | |
4
219766126afb
another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents:
3
diff
changeset
|
6 | |
3
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
7 | #include "Terminal6x8.h" |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
8 | #include "Mono19x27.h" |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
9 | #include "Mono15x22.h" |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
10 | #include "Arial12x12.h" |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
11 | |
3
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
12 | #include "SSD1322.h" |
5 | 13 | #include "hp34comm.h" |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
14 | |
19 | 15 | #include "QEI.h" |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
17
diff
changeset
|
16 | #include "Keypad.h" |
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
17
diff
changeset
|
17 | |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
18 | // Pins and device declarations |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
19 | #if defined TARGET_NUCLEO_F446RE |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
20 | #include "def_f446re.h" |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
21 | #elif defined TARGET_HP34970_FP_F303RD |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
22 | #include "def_hp34970_fp.h" |
8 | 23 | #endif |
24 | ||
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
25 | #include "platform/CircularBuffer.h" |
26 | 26 | |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
27 | |
19 | 28 | SSD1322 *dsp; |
29 | HPSerial *hp; | |
8 | 30 | volatile uint8_t must_refresh; |
31 | Thread tdsp, tloop; | |
19 | 32 | Ticker blinker; |
33 | Timeout rst_delay; | |
34 | Timeout splashscreen_timer; | |
35 | InterruptIn rst(HP_RST); | |
36 | ||
37 | QEI qenc(KP_ENC1, KP_ENC2, NC, 16); | |
38 | volatile uint8_t knob; | |
39 | volatile bool splashscreen; | |
40 | ||
41 | ||
42 | typedef enum { | |
43 | KEY_NONE=0, | |
44 | KEY_PRESSED, | |
45 | KEY_RELEASED | |
46 | } key_event_t; | |
47 | ||
48 | typedef struct keycode { | |
49 | uint8_t row; | |
50 | uint8_t col; | |
51 | key_event_t keyevent; | |
52 | } keycode_t; | |
53 | ||
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
54 | //volatile keycode_t cur_keycode; |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
55 | |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
56 | #define KEY_BUF_SIZE 10 |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
57 | CircularBuffer<keycode_t, KEY_BUF_SIZE> key_buf; |
5 | 58 | |
19 | 59 | PinName kp_rows[] = { |
60 | KP_R0, | |
61 | KP_R1, | |
62 | KP_R2, | |
63 | KP_R3 | |
64 | }; | |
65 | ||
66 | PinName kp_colums[] = { | |
67 | KP_C0, KP_C1, | |
68 | KP_C2, KP_C3, | |
69 | KP_C4 | |
70 | }; | |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
17
diff
changeset
|
71 | |
19 | 72 | DigitalIn kp_in[] = { |
73 | KP_R0, | |
74 | KP_R1, | |
75 | KP_R2, | |
76 | KP_R3 | |
77 | }; | |
78 | ||
79 | DigitalOut kp_out[] = { | |
80 | KP_C0, KP_C1, | |
81 | KP_C2, KP_C3, | |
82 | KP_C4 | |
83 | }; | |
84 | ||
85 | uint8_t kp_nrows = sizeof(kp_in)/sizeof(kp_in[0]); | |
86 | uint8_t kp_ncols = sizeof(kp_out)/sizeof(kp_out[0]); | |
87 | ||
88 | void kp_cb(uint8_t row, uint8_t col); | |
89 | void kr_cb(uint8_t row, uint8_t col); | |
90 | ||
91 | Keypad *kpad; | |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
92 | uint8_t curchar; |
26 | 93 | //uint8_t curcmd; |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
94 | uint8_t nchars; |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
95 | char buffer[MAX_BUFF+1]; |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
96 | |
8 | 97 | void timeout_h() { |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
98 | #if defined(HAS_LED) |
8 | 99 | led = !led; |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
100 | #endif |
8 | 101 | } |
102 | ||
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
103 | typedef struct _DSP |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
104 | { |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
105 | uint8_t cmd; |
3
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
106 | uint8_t color; |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
107 | uint8_t bgcolor; |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
108 | uint8_t x0; |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
109 | uint8_t y0; |
5 | 110 | uint8_t fmt; // 0x01=>ascii, 0x02=>hex, 0x04=>bits, 0x08=>flags, 0x80=>ignore |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
111 | uint8_t maxsize; |
3
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
112 | uint8_t width; |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
113 | const unsigned char* font; |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
114 | char buffer[MAX_BUFF+1]; |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
115 | } DSP; |
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 | static DSP table[] = |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
118 | { |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
119 | { 0x00, 0xF, 0x0, 0, 0, 0x01, MAX_BUFF, 245, Mono19x27}, // main display |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
120 | { 0x0C, 0xF, 0x0,196, 34, 0x01, 3, 45, Mono15x22}, // channels display |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
121 | { 0x0A, 0xF, 0x0, 0, 57, 0x08, 4, 0, Terminal6x8}, // flags + bits |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
122 | }; |
2 | 123 | |
3
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
124 | // 9x10 |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
125 | const unsigned char icon_alarm[] __attribute__((aligned (2))) = |
3
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
126 | { |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
127 | 0x1c, 0x0, |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
128 | 0x3e, 0x0, |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
129 | 0x7f, 0x0, |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
130 | 0x7f, 0x0, |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
131 | 0x7f, 0x0, |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
132 | 0x7f, 0x0, |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
133 | 0x7f, 0x0, |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
134 | 0x7f, 0x0, |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
135 | 0xff, 0x80, |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
136 | 0x10, 0x0 |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
137 | }; |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
138 | |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
139 | const unsigned char icon_curve[] __attribute__((aligned (2))) = |
3
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
140 | { |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
141 | 0x80, 0x0, |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
142 | 0x80, 0x0, |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
143 | 0x80, 0x80, |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
144 | 0x81, 0x0, |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
145 | 0x9e, 0x0, |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
146 | 0xa0, 0x0, |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
147 | 0xc0, 0x0, |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
148 | 0x80, 0x0, |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
149 | 0x80, 0x0, |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
150 | 0xff, 0x80 |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
151 | }; |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
152 | |
2 | 153 | typedef struct _FLAG |
154 | { | |
155 | uint8_t flag; | |
156 | uint8_t x; | |
157 | uint8_t y; | |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
158 | bool reverse; |
2 | 159 | const char* msg; |
3
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
160 | const unsigned char* icon; |
2 | 161 | } FLAG; |
162 | ||
5 | 163 | typedef struct _FRAME |
164 | { | |
8 | 165 | uint16_t flag; |
5 | 166 | uint8_t x0; |
167 | uint8_t y0; | |
168 | uint8_t x1; | |
169 | uint8_t y1; | |
170 | } FRAME; | |
171 | ||
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
172 | static const FLAG flags[] = |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
173 | { |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
174 | // flag, zone, x0, y0, reverse, msg, icon |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
175 | // right-side icons area |
26 | 176 | { 0x00, 246, 0, false, NULL, icon_alarm}, // F1.0 |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
177 | { 0x01, 246, 11, false, NULL, icon_curve}, // F1.1 |
22 | 178 | |
21 | 179 | // F1.2 == Channel frame |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
180 | { 0x03, 197, 27, false, "Channel"}, // F1.3 |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
181 | // F1.7 == Alarm frame |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
182 | |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
183 | { 0x34, 0, 28+8, false, "MON"}, // F4.4 |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
184 | { 0x33, 0, 28+16, false, "VIEW"}, // F4.3 |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
185 | { 0x35, 0, 28, true, "SCAN"}, // F4.5 |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
186 | { 0x36, 0, 28+25, true, "CONFIG"}, // F4.6 |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
187 | |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
188 | { 0x32, 40, 52, false, "*"}, // F4.2 |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
189 | { 0x31, 50, 52, false, "ADRS"}, // F4.1 |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
190 | { 0x30, 80, 52, false, "RMT"}, // F4.0 |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
191 | { 0x27, 104, 52, true, "ERROR"}, // F3.7 |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
192 | |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
193 | { 0x26, 140, 52, false, "EXT"}, // F3.6 |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
194 | { 0x25, 164, 52, false, "ONCE"}, // F3.5 |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
195 | |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
196 | { 0x23, 104, 28+16, false, "MEM"}, // F3.3 |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
197 | |
19 | 198 | |
8 | 199 | // col 5 |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
200 | { 0x14, 244, 22, false, "4W"}, // F2.4 |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
201 | { 0x15, 244, 30, false, "OC"}, // F2.5 |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
202 | { 0x22, 129, 28+16, false, "LAST"}, // F3.2 |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
203 | { 0x21, 129, 28+16, false, "MIN"}, // F3.1 |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
204 | { 0x20, 129, 28+16, false, "MAX"}, // F3.0 |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
205 | { 0x17, 129, 28+16, false, "AVG"}, // F2.7 |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
206 | |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
207 | { 0x05, 154+0, 17+10, false, "Alarm"}, // F1.5 |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
208 | { 0x06, 154+0, 17+20, false, "H"}, // F1.6 |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
209 | { 0x13, 154+6, 17+20, false, "1"}, // F2.3 |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
210 | { 0x10, 154+12, 17+20, false, "2"}, // F2.0 |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
211 | { 0x12, 154+18, 17+20, false, "3"}, // F2.2 |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
212 | { 0x11, 154+24, 17+20, false, "4"}, // F2.1 |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
213 | { 0x04, 154+30, 17+20, false, "L"}, // F1.4 |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
214 | |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
215 | }; |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
216 | |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
217 | static const FRAME zones[] = |
22 | 218 | { // flag, x0, y0, x1, y1 |
8 | 219 | { 0x001, 0, 0, 245, 27}, // main display area |
220 | { 0x002, 246, 0, 255, 27}, // right notif area | |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
221 | { 0x004, 208, 35, 254, 62}, // channels display area |
8 | 222 | { 0x008, 160, 28, 202, 54}, // alarms area |
223 | { 0x010, 0, 28, 32, 54}, // flags col1 | |
224 | { 0x020, 33, 28, 70, 54}, // flags col2 | |
225 | { 0x040, 71, 28, 103, 54}, // flags col3 | |
226 | { 0x080, 104, 28, 128, 54}, // flags col4 | |
227 | { 0x100, 129, 28, 159, 54}, // flags col5 | |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
228 | |
22 | 229 | // { 0x8000, 0, 55, 255, 63}, // flags bits display area |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
230 | }; |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
231 | |
5 | 232 | static const FRAME frames[] = |
233 | { | |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
234 | { 0x02, 194, 30, 243, 53}, // F1.2 - channel frame |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
235 | { 0x07, 151, 30, 192, 46}, // F1.7 - alarm frame |
5 | 236 | }; |
237 | ||
3
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
238 | |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
239 | #ifdef DEBUG |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
240 | |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
241 | DigitalOut dbgpin(DBGPIN); |
5 | 242 | inline void pulse(uint8_t count=1, bool stayup=false) |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
243 | { |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
244 | dbgpin = 0; |
5 | 245 | wait_us(2); |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
246 | while (count--) |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
247 | { |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
248 | dbgpin = 1; |
5 | 249 | wait_us(2); |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
250 | dbgpin = 0; |
5 | 251 | wait_us(2); |
252 | } | |
253 | if (stayup) | |
254 | dbgpin = 1; | |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
255 | } |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
256 | #else |
5 | 257 | inline void pulse(uint8_t count=1, bool stayup=false) |
1
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 | #endif |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
260 | |
19 | 261 | // callbacks & thread functions |
262 | void loop(); | |
263 | void copy_to_lcd(void); | |
264 | void test_dsp(); | |
265 | void reset(void); | |
266 | void reset_irq(void); | |
267 | void qei_cb(int dir); | |
268 | void end_splashscreen(void); | |
22 | 269 | void show(uint8_t, const char*, uint8_t); |
4
219766126afb
another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents:
3
diff
changeset
|
270 | |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
271 | /* |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
272 | #if defined(HAVE_PC) |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
273 | FileHandle *mbed::mbed_override_console(int fd) |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
274 | { |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
275 | return static_cast<FileHandle*> (&pc); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
276 | } |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
277 | #endif |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
278 | */ |
3
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
279 | |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
280 | void setup() { |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
281 | #if defined(HAVE_PC) |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
282 | #if defined(TARGET_NUCLEO_F446RE) |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
283 | pc.set_baud(115200); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
284 | #endif |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
285 | |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
286 | /* |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
287 | #if defined(TARGET_HP34970_FP_F303RD) |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
288 | pc.init(); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
289 | pc.connect(); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
290 | #endif |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
291 | */ |
8 | 292 | #endif |
21 | 293 | |
19 | 294 | printf("\n\nSETUP\n"); |
295 | printf(" System Core Clock = %.3f MHZ\r\n", | |
8 | 296 | (float)SystemCoreClock/1000000); |
21 | 297 | |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
298 | /* |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
299 | #if defined(HAS_LED) |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
300 | printf("Attaching Led 1: %d\n", LED1); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
301 | blinker.attach(callback(timeout_h), 0.5f); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
302 | #endif |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
303 | */ |
21 | 304 | |
19 | 305 | hp = NULL; |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
306 | #if defined(TARGET_NUCLEO_F446RE) |
22 | 307 | printf("Serial communication pins\r\n"); |
308 | printf(" USBRX=%d\r\n", USBRX); | |
309 | printf(" USBTX=%d\r\n", USBTX); | |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
310 | #endif |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
311 | #if defined(TARGET_HP34970_FP_F303RD) |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
312 | printf("Serial communication via USB\r\n"); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
313 | #endif |
22 | 314 | |
21 | 315 | printf("Setup HP communication pins\r\n"); |
316 | printf(" HP_RX=%d\r\n", HP_RX); | |
19 | 317 | DigitalIn(HP_RX).mode(PullDown); |
21 | 318 | printf(" HP_TX=%d\r\n", HP_TX); |
19 | 319 | DigitalOut(HP_TX).write(1); |
21 | 320 | printf(" HP_RST=%d\r\n", HP_RST); |
19 | 321 | DigitalIn(HP_RST).mode(PullDown); |
21 | 322 | |
323 | printf(" setup QEI pins\r\n"); | |
324 | printf(" ENC1=%d\r\n", KP_ENC1); | |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
325 | DigitalIn(KP_ENC1).mode(PullDown); |
21 | 326 | printf(" ENC2=%d\r\n", KP_ENC2); |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
327 | DigitalIn(KP_ENC2).mode(PullDown); |
19 | 328 | qenc.attach(&qei_cb); |
329 | ||
21 | 330 | printf(" setup Keypad\r\n"); |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
331 | //cur_keycode.keyevent = KEY_NONE; |
19 | 332 | uint8_t nrows = sizeof(kp_rows)/sizeof(kp_rows[0]); |
333 | uint8_t ncols = sizeof(kp_colums)/sizeof(kp_colums[0]); | |
334 | ||
335 | kpad = new Keypad(nrows, kp_in, ncols, kp_out); | |
21 | 336 | printf(" attach Keypad callbacks\r\n"); |
19 | 337 | kpad->attach(&kp_cb, &kr_cb); |
21 | 338 | printf(" start Keypad\r\n"); |
339 | kpad->start(); | |
340 | ||
341 | printf("Setup OLED display\r\n"); | |
19 | 342 | // init the LCD |
21 | 343 | printf(" DSP_MOSI=%d\r\n", DSP_MOSI); |
344 | printf(" DSP_MISO=%d\r\n", DSP_MISO); | |
345 | printf(" DSP_SCLK=%d\r\n", DSP_SCLK); | |
346 | printf(" DSP_CS=%d\r\n", DSP_CS); | |
347 | printf(" DSP_RST=%d\r\n", DSP_RST); | |
348 | printf(" DSP_DC=%d\r\n", DSP_DC); | |
19 | 349 | dsp = new SSD1322(20000000, DSP_MOSI, DSP_MISO, DSP_SCLK, DSP_CS, |
350 | DSP_RST, DSP_DC, "SSD1322"); | |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
351 | |
21 | 352 | printf(" configure DSP\r\n"); |
8 | 353 | dsp->background(Black); // set background to black |
354 | dsp->foreground(0xF); | |
355 | dsp->cls(); | |
19 | 356 | |
26 | 357 | //curcmd = 0xFF; |
8 | 358 | curchar = 0; |
359 | nchars = 0; | |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
360 | |
8 | 361 | for (uint8_t i=0; i<sizeof(table)/sizeof(table[0]); ++i) |
362 | memset(table[i].buffer, 0, MAX_BUFF+1); | |
19 | 363 | |
21 | 364 | printf(" display splash screen\r\n"); |
8 | 365 | dsp->locate(30, 10); |
366 | dsp->set_font((unsigned char*)Mono19x27); | |
367 | dsp->printf("HP34970A"); | |
368 | dsp->set_font((unsigned char*)Terminal6x8); | |
369 | dsp->locate(90, 40); | |
370 | dsp->printf("David Douard"); | |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
371 | dsp->locate(0, 52); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
372 | dsp->printf("Clock = %d ", SystemCoreClock); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
373 | |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
374 | RCC_OscInitTypeDef cfg; |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
375 | HAL_RCC_GetOscConfig(&cfg); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
376 | if (cfg.HSEState == RCC_HSE_BYPASS) |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
377 | dsp->printf("HSE:EXT "); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
378 | else if (cfg.HSEState == RCC_HSE_ON) |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
379 | dsp->printf("HSE:XTAL "); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
380 | else |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
381 | dsp->printf("HSE:OFF "); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
382 | |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
383 | if (cfg.HSIState == RCC_HSI_ON) |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
384 | dsp->printf("HSI:ON "); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
385 | else |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
386 | dsp->printf("HSI:OFF "); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
387 | |
8 | 388 | dsp->copy_to_lcd(); |
19 | 389 | |
21 | 390 | printf("Starting LCD thread\r\n"); |
19 | 391 | tdsp.start(©_to_lcd); |
392 | ||
22 | 393 | printf("Starting Event thread\r\n"); |
394 | tloop.start(&loop); | |
395 | ||
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
396 | /* |
22 | 397 | dsp->clrbuff(); |
398 | show(0x00, "HH:MM:\tSS\t:mmmm", 15); // main dsp | |
399 | show(0x0C, "888", 3); // channel dsp | |
400 | show(0x0A, "\xFF\xFF\xFF\xFF", 4); // all flags | |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
401 | */ |
21 | 402 | |
403 | printf("Attaching timers\r\n"); | |
22 | 404 | splashscreen = true; |
19 | 405 | splashscreen_timer.attach(callback(&end_splashscreen), 2); |
406 | rst.fall(&reset_irq); | |
21 | 407 | |
408 | printf("SETUP DONE\r\n"); | |
19 | 409 | } |
8 | 410 | |
19 | 411 | void end_splashscreen(void) |
412 | { | |
26 | 413 | // print is forbidden here because we are in an ISR context here |
414 | //printf("End of splash screen CB\r\n"); | |
19 | 415 | splashscreen = false; |
416 | } | |
417 | ||
418 | void reset_irq(void) | |
419 | { | |
21 | 420 | rst_delay.attach(callback(&reset), 0.1); |
19 | 421 | } |
422 | ||
423 | void reset(void) | |
424 | { | |
425 | if (DigitalIn(HP_RST).read() == 0) { | |
426 | if (hp == NULL) { | |
21 | 427 | printf("setup HP communication handler\r\n"); |
19 | 428 | hp = new HPSerial(HP_TX, HP_RX); |
429 | } | |
21 | 430 | |
431 | printf("!! RST !! (gstate=%d, state=%d)\r\n", | |
19 | 432 | hp->gstate(), hp->state()); |
433 | //printf("Value is ... %X\n", hp->search()); | |
434 | hp->startup(); | |
435 | } | |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
436 | } |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
437 | |
4
219766126afb
another attempt using a more complete support of the protocol and async serial stuff
David Douard <david.douard@logilab.fr>
parents:
3
diff
changeset
|
438 | void copy_to_lcd(void) { |
19 | 439 | //uint8_t mask=1; |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
440 | |
5 | 441 | while(1) { |
442 | pulse(0, true); | |
19 | 443 | if ((splashscreen == false) && (must_refresh)) { |
8 | 444 | must_refresh = 0; |
19 | 445 | //Thread::wait(20); // give a bit of time for some more cmds |
8 | 446 | dsp->copy_to_lcd(); |
447 | } | |
448 | ||
449 | /* | |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
450 | if (must_refresh & mask) { |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
451 | for(uint8_t i=0; i<sizeof(zones)/sizeof(zones[0]); i++) |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
452 | if (zones[i].flag == mask) { |
8 | 453 | dsp->copy_to_lcd(zones[i].x0/4, (zones[i].x1+3)/4, |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
454 | zones[i].y0, zones[i].y1); |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
455 | must_refresh &= ~mask; |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
456 | break; |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
457 | } |
5 | 458 | } |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
459 | mask = mask << 1; |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
460 | if (mask == 0) { |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
461 | mask = 1; |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
462 | } |
8 | 463 | */ |
5 | 464 | pulse(0, false); |
26 | 465 | |
466 | ThisThread::sleep_for(30); | |
5 | 467 | } |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
468 | } |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
469 | |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
470 | void show(uint8_t cmd, const char *intxt, uint8_t nchar=0) |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
471 | { |
26 | 472 | uint8_t i; |
473 | // uint8_t len; | |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
474 | uint16_t bgcolor, fgcolor; |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
475 | char *oldv; |
26 | 476 | // char *txt; |
477 | char *txtp; | |
478 | static char txt[256]; | |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
479 | |
21 | 480 | |
22 | 481 | if (cmd == 0xFF) // cls |
482 | { | |
483 | dsp->clrbuff(); | |
484 | } | |
485 | else | |
486 | { | |
26 | 487 | //txt = (char *)malloc(strlen(intxt)+1); |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
488 | strcpy(txt, intxt); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
489 | txtp = txt; |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
490 | |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
491 | pulse(1, true); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
492 | |
26 | 493 | // len = MAX_BUFF; |
22 | 494 | |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
495 | for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) { |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
496 | if (table[i].cmd == cmd) { |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
497 | bgcolor = table[i].bgcolor; |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
498 | fgcolor = table[i].color; |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
499 | dsp->background(bgcolor); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
500 | dsp->foreground(fgcolor); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
501 | dsp->set_font((unsigned char*) table[i].font); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
502 | oldv = table[i].buffer; |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
503 | |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
504 | dsp->locate(table[i].x0, table[i].y0); |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
505 | |
26 | 506 | if (table[i].fmt & 0x01) // ASCII text |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
507 | { |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
508 | if (strncmp(oldv, txt, table[i].maxsize) != 0) |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
509 | { |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
510 | if (table[i].width > 0) |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
511 | dsp->fillrect(table[i].x0, |
26 | 512 | table[i].y0, |
513 | table[i].x0 + table[i].width, | |
514 | table[i].y0 + table[i].font[2], | |
515 | bgcolor); | |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
516 | for (uint8_t k=0; ;k++) |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
517 | { |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
518 | if (txtp[k] == 0x00) |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
519 | { |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
520 | dsp->printf(txtp); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
521 | break; |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
522 | } |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
523 | if (txtp[k] == 0x09) |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
524 | { // \t is a special char for 'unselected' display value |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
525 | txtp[k] = 0x00; |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
526 | dsp->printf(txtp); |
5 | 527 | |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
528 | if (fgcolor == table[i].color) |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
529 | fgcolor /= 2; |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
530 | else |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
531 | fgcolor = table[i].color; |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
532 | dsp->foreground(fgcolor); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
533 | txtp = &(txtp[k+1]); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
534 | k = 0; |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
535 | } |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
536 | } |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
537 | if (cmd == 0x00) // main area |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
538 | must_refresh |= 0x01; |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
539 | if (cmd == 0x0C) // channels area |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
540 | must_refresh |= 0x04; |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
541 | } |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
542 | } |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
543 | /* |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
544 | if (table[i].fmt & 0x02 ) { |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
545 | // hex |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
546 | for (uint8_t j=0;; j++) { |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
547 | if (txt[j] == 0x00) |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
548 | break; |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
549 | dsp->printf("%02X ", txt[j]); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
550 | } |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
551 | for (uint8_t j=3*strlen(txt); j<table[i].maxsize; j++) |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
552 | dsp->printf(" "); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
553 | } |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
554 | */ |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
555 | if (table[i].fmt & 0x08 ) // flag indicators |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
556 | { |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
557 | // flags |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
558 | for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++) |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
559 | { |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
560 | for (uint8_t k=0; k<8; k++) |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
561 | { |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
562 | if (1) |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
563 | { //(txt[j] & (1 << k) ) != (oldv[j] & (1 << k))) { |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
564 | for (uint8_t l=0; |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
565 | l<(sizeof(flags)/sizeof(flags[0])); ++l) |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
566 | { |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
567 | if (flags[l].flag == ((j<<4) + k)) { |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
568 | if (txtp[j] & (1 << k)) |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
569 | { |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
570 | dsp->foreground(flags[l].reverse ? bgcolor : fgcolor); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
571 | dsp->background(flags[l].reverse ? fgcolor : bgcolor); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
572 | } |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
573 | else |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
574 | { |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
575 | dsp->foreground(bgcolor); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
576 | dsp->background(bgcolor); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
577 | } |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
578 | if (flags[l].msg != NULL) |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
579 | { // a string |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
580 | dsp->locate(flags[l].x, flags[l].y); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
581 | dsp->printf(flags[l].msg);} |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
582 | else |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
583 | { // an icon |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
584 | Bitmap_s pic = {9, 10, 2, (char*) flags[l].icon}; |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
585 | dsp->Bitmap_BW(pic, flags[l].x, flags[l].y); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
586 | } |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
587 | must_refresh = 1; //|= zones[m].flag; |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
588 | break; |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
589 | } |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
590 | } |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
591 | } |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
592 | } |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
593 | } |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
594 | |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
595 | // draw frames (Alarm and Channel) |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
596 | for (uint8_t l=0; |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
597 | l<(sizeof(frames)/sizeof(frames[0])); ++l) |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
598 | { |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
599 | uint16_t color; |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
600 | if (frames[l].flag & txt[0]) // frame flags are on the 1st byte only |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
601 | color = fgcolor/6; |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
602 | else |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
603 | color = bgcolor; |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
604 | dsp->hline(frames[l].x0+1, frames[l].x0+3, frames[l].y0, color); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
605 | dsp->hline(frames[l].x1-3, frames[l].x1-1, frames[l].y0, color); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
606 | dsp->hline(frames[l].x0+1, frames[l].x1-1, frames[l].y1, color); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
607 | |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
608 | dsp->vline(frames[l].x0, frames[l].y0+1, frames[l].y1-1, color); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
609 | dsp->vline(frames[l].x1, frames[l].y0+1, frames[l].y1-1, color); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
610 | } |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
611 | } |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
612 | |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
613 | for(uint8_t j=0; j<table[i].maxsize; j++) |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
614 | oldv[j] = txt[j]; |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
615 | break; |
22 | 616 | } |
617 | } | |
26 | 618 | //free(txt); |
23
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
619 | //dsp->copy_to_lcd(); |
daf26b083899
Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
22
diff
changeset
|
620 | pulse(1, false); |
22 | 621 | } |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
622 | } |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
623 | |
3
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
624 | void test_dsp() |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
625 | { |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
626 | const FRAME *z; |
22 | 627 | printf("TEST DSP\r\n"); |
628 | dsp->cls(); | |
629 | printf("TEST DSP #2\r\n"); | |
3
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
630 | show(0x00, "8g8g8g8g8g8g8", 13); // main dsp |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
631 | show(0x0C, "888", 3); // channel dsp |
5 | 632 | show(0x0A, "\xFF\xFF\xFF\xFF", 4); // all flags |
8 | 633 | dsp->copy_to_lcd(); |
26 | 634 | ThisThread::sleep_for(3); |
8 | 635 | dsp->cls(); |
22 | 636 | printf("TEST DSP #3\r\n"); |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
637 | |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
638 | for (uint8_t i=0; i<(sizeof(zones)/sizeof(zones[0])); i++) |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
639 | { |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
640 | z = &zones[i]; |
8 | 641 | dsp->fillrect(z->x0, z->y0, z->x1, z->y1, 4+i); |
642 | dsp->locate(z->x0+1, z->y0+1); | |
643 | dsp->printf("%d", i); | |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
644 | } |
8 | 645 | |
646 | /* | |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
647 | for (uint8_t i=0; i<(sizeof(zones)/sizeof(zones[0])); i++) |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
648 | { |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
649 | z = &zones[i]; |
8 | 650 | printf("Zone %d [%x]: %d, %d, %d, %d\n", i, z->flag, |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
651 | z->x0, z->y0, z->x1, z->y1); |
8 | 652 | must_refresh = z->flag; |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
653 | wait(1); |
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
654 | } |
8 | 655 | printf("Done\n"); |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
656 | wait(2); |
8 | 657 | printf("Copy ALL\n"); |
658 | dsp->copy_to_lcd(); | |
659 | */ | |
26 | 660 | ThisThread::sleep_for(2); |
8 | 661 | dsp->cls(); |
22 | 662 | printf("TEST DSP DONE\r\n"); |
3
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
663 | } |
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
664 | |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
665 | |
19 | 666 | void loop() |
667 | { // run over and over | |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
668 | keycode_t key; |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
669 | |
8 | 670 | unsigned int err[8]; |
671 | for (uint8_t i=0; i<8; i++) | |
672 | err[i] = 0; | |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
673 | int p, pp; // rot encoder pulse counters |
21 | 674 | p = 0; |
675 | pp = 0; | |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
676 | |
8 | 677 | while(1) { |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
678 | p = qenc.getPulses(); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
679 | if (p != pp) |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
680 | { |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
681 | dsp->locate(0, 0); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
682 | dsp->printf("Pulses = %d ", p); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
683 | dsp->copy_to_lcd(); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
684 | pp = p; |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
685 | } |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
686 | |
19 | 687 | if (knob != 0) |
21 | 688 | { |
689 | if (hp != NULL) | |
690 | { | |
691 | printf("Sending keycode %X\r\n", knob); | |
692 | hp->sendkey(knob); | |
693 | printf(" DONE\r\n"); | |
694 | } | |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
695 | else |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
696 | { |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
697 | dsp->locate(70, 0); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
698 | dsp->printf("Knob = %X ", knob); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
699 | dsp->copy_to_lcd(); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
700 | } |
21 | 701 | knob = 0; |
19 | 702 | } |
703 | ||
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
704 | if (!key_buf.empty()) //cur_keycode.keyevent != KEY_NONE) |
21 | 705 | { |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
706 | key_buf.pop(key); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
707 | printf("Keycode %dx%d: %s\r\n", |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
708 | key.row, key.col, key.keyevent==KEY_PRESSED?"pressed":"released"); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
709 | if (hp != NULL) { |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
710 | } |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
711 | else |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
712 | { |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
713 | dsp->locate(140, 0); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
714 | dsp->printf("KC: %dx%d: %s", |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
715 | key.row, key.col,key.keyevent==KEY_PRESSED?"PRE":"REL"); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
716 | dsp->copy_to_lcd(); |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
717 | } |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
718 | // cur_keycode.keyevent = KEY_NONE; |
21 | 719 | } |
19 | 720 | |
21 | 721 | |
19 | 722 | if ((hp != NULL) && (hp->cmd_available())) |
723 | { | |
21 | 724 | HPSerial::CMD cmd; |
725 | if (hp->pop(cmd)) | |
726 | { | |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
727 | #if defined(HAS_LED) |
21 | 728 | led = 1; |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
729 | #endif |
21 | 730 | for (uint8_t i=0; i<7; i++) |
731 | if (hp->nerrors(i) > err[i]) { | |
732 | printf("ERR: %d/%d/%d/%d/%d/%d/%d\r\n", | |
733 | hp->nerrors(0), | |
734 | hp->nerrors(1), | |
735 | hp->nerrors(2), | |
736 | hp->nerrors(3), | |
737 | hp->nerrors(4), | |
738 | hp->nerrors(5), | |
739 | hp->nerrors(6) | |
740 | ); | |
741 | break; | |
742 | } | |
743 | for (uint8_t i=0; i<7; i++) | |
744 | err[i] = hp->nerrors(i); | |
19 | 745 | |
21 | 746 | printf("CMD[%d] %02X", (int)cmd.id, cmd.cmd); |
19 | 747 | |
21 | 748 | if ((cmd.cmd == 0x00) || (cmd.cmd == 0x0C)) |
749 | printf(": '%s'\r\n", cmd.value); | |
750 | else { | |
751 | printf(":"); | |
752 | for (uint8_t i=0; i<cmd.size; i++) | |
753 | printf("%02x ", cmd.value[i]); | |
754 | printf("\r\n"); | |
755 | } | |
756 | show(cmd.cmd, cmd.value, cmd.size); | |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
757 | #if defined(HAS_LED) |
21 | 758 | led = 0; |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
759 | #endif |
21 | 760 | } |
761 | } | |
762 | //else | |
26 | 763 | ThisThread::sleep_for(1); |
5 | 764 | } |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
765 | } |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
766 | |
19 | 767 | void qei_cb(int dir) |
768 | { | |
769 | if(dir == 1) // turn right | |
770 | knob = 0x80; | |
771 | else // turn left | |
772 | knob = 0x83; | |
773 | } | |
774 | ||
775 | void kp_cb(uint8_t row, uint8_t col) | |
776 | { | |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
777 | keycode_t key; |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
778 | key.row = row; |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
779 | key.col = col; |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
780 | key.keyevent = KEY_PRESSED; |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
781 | if(!key_buf.full()) |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
782 | key_buf.push(key); |
19 | 783 | } |
784 | ||
785 | void kr_cb(uint8_t row, uint8_t col) | |
786 | { | |
32
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
787 | keycode_t key; |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
788 | key.row = row; |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
789 | key.col = col; |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
790 | key.keyevent = KEY_RELEASED; |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
791 | if(!key_buf.full()) |
bc1d6ecbb0cc
Update the main code: extract headers and use a CircularBuffer for key events
David Douard <david.douard@sdf3.org>
parents:
28
diff
changeset
|
792 | key_buf.push(key); |
19 | 793 | } |
794 | ||
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
795 | int main() |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
796 | { |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
797 | setup(); |
21 | 798 | printf("Main loop (noop)\r\n"); |
19 | 799 | while(1) |
22 | 800 | { |
801 | timeout_h(); | |
26 | 802 | ThisThread::sleep_for(1); |
22 | 803 | } |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
804 | } |