Thu, 09 Sep 2021 21:59:53 +0200
Simplify a bit the rst logic and make a bit more robust
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 | |
5 | 7 | #include "hp34comm.h" |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
36
diff
changeset
|
8 | #include "display.h" |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
9 | |
19 | 10 | #include "QEI.h" |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
17
diff
changeset
|
11 | #include "Keypad.h" |
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
17
diff
changeset
|
12 | |
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
|
13 | // 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
|
14 | #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
|
15 | #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
|
16 | #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
|
17 | #include "def_hp34970_fp.h" |
8 | 18 | #endif |
19 | ||
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
|
20 | #include "platform/CircularBuffer.h" |
26 | 21 | |
48
fc55f6eaa8bc
Remove print statements
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
22 | // cannot make it work... |
fc55f6eaa8bc
Remove print statements
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
23 | // #include <USBSerial.h> |
fc55f6eaa8bc
Remove print statements
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
24 | // USBSerial usbcdc(false); |
fc55f6eaa8bc
Remove print statements
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
25 | |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
26 | |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
36
diff
changeset
|
27 | Display *dsp; |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
36
diff
changeset
|
28 | volatile bool splashscreen; |
19 | 29 | HPSerial *hp; |
44 | 30 | Thread tdsp(osPriorityNormal, OS_STACK_SIZE, nullptr, "DSP"); |
31 | Ticker dsp_refresh; | |
63
f71f6c0af3cd
Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents:
62
diff
changeset
|
32 | //Timeout rst_delay; |
19 | 33 | Timeout splashscreen_timer; |
44 | 34 | Timeout byescreen_timer; |
19 | 35 | InterruptIn rst(HP_RST); |
36 | ||
37 | QEI qenc(KP_ENC1, KP_ENC2, NC, 16); | |
38 | volatile uint8_t knob; | |
35
b2dca6b935bb
Indent src/main.cpp with 2-ws
David Douard <david.douard@sdf3.org>
parents:
34
diff
changeset
|
39 | bool shift; // true when kp is shifted, cleared by command 0x01 from Unit |
44 | 40 | bool must_reset; |
41 | bool must_shutdown; | |
19 | 42 | |
43 | typedef enum { | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
44 | KEY_NONE=0, |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
45 | KEY_PRESSED, |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
46 | KEY_RELEASED |
19 | 47 | } key_event_t; |
48 | ||
49 | typedef struct keycode { | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
50 | uint8_t row; |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
51 | uint8_t col; |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
52 | key_event_t keyevent; |
19 | 53 | } keycode_t; |
54 | ||
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
|
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 | |
34
94ab7ff42a1b
Add a key mapping table (protocol value vs. raw keycode) and send it
David Douard <david.douard@sdf3.org>
parents:
32
diff
changeset
|
59 | #define KP_NROWS 4 |
94ab7ff42a1b
Add a key mapping table (protocol value vs. raw keycode) and send it
David Douard <david.douard@sdf3.org>
parents:
32
diff
changeset
|
60 | #define KP_NCOLS 5 |
94ab7ff42a1b
Add a key mapping table (protocol value vs. raw keycode) and send it
David Douard <david.douard@sdf3.org>
parents:
32
diff
changeset
|
61 | DigitalIn kp_rows[KP_NROWS] = { |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
62 | KP_R0, |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
63 | KP_R1, |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
64 | KP_R2, |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
65 | KP_R3 |
19 | 66 | }; |
67 | ||
34
94ab7ff42a1b
Add a key mapping table (protocol value vs. raw keycode) and send it
David Douard <david.douard@sdf3.org>
parents:
32
diff
changeset
|
68 | DigitalOut kp_columns[KP_NCOLS] = { |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
69 | KP_C0, KP_C1, |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
70 | KP_C2, KP_C3, |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
71 | KP_C4 |
19 | 72 | }; |
18
4fd621551d55
[full replacement] implement a state machine for Rx
David Douard <david.douard@logilab.fr>
parents:
17
diff
changeset
|
73 | |
36
a6c7292742a0
Add support for the shift flag
David Douard <david.douard@sdf3.org>
parents:
35
diff
changeset
|
74 | /* key mapping |
a6c7292742a0
Add support for the shift flag
David Douard <david.douard@sdf3.org>
parents:
35
diff
changeset
|
75 | RxC code name |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
76 | 0x2 0x00 View |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
77 | 0x1 0x01 Mon |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
78 | 3x3 0x02 Sto/Rcl |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
79 | 0x0 0x03 Scan |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
80 | 1x2 0x04 Alarm |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
81 | 1x1 0x05 Mx+B |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
82 | 1x0 0x06 Measure |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
83 | 2x0 0x07 Interval |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
84 | 3x2 0x08 Card Reset |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
85 | 3x1 0x09 Close |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
86 | 3x0 0x0A Open |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
87 | 0x3 0x0B Read |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
88 | 2x3 0x0C Shift |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
89 | 1x3 0x0D Write |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
90 | 0x4 0x0E Left |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
91 | 1x4 0x0F Right |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
92 | 2x2 0x10 Advanced |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
93 | 2x1 0x11 Step |
34
94ab7ff42a1b
Add a key mapping table (protocol value vs. raw keycode) and send it
David Douard <david.douard@sdf3.org>
parents:
32
diff
changeset
|
94 | */ |
94ab7ff42a1b
Add a key mapping table (protocol value vs. raw keycode) and send it
David Douard <david.douard@sdf3.org>
parents:
32
diff
changeset
|
95 | |
36
a6c7292742a0
Add support for the shift flag
David Douard <david.douard@sdf3.org>
parents:
35
diff
changeset
|
96 | uint8_t kp_mapping[KP_NROWS][KP_NCOLS] = { |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
97 | {0x03, 0x01, 0x00, 0x0B, 0x0E}, |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
98 | {0x06, 0x05, 0x04, 0x0D, 0x0F}, |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
99 | {0x07, 0x11, 0x10, 0x0C, 0xFF}, |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
100 | {0x0A, 0x09, 0x08, 0x02, 0xFF} |
19 | 101 | }; |
102 | ||
44 | 103 | #define KC_SHIFT 0x0C |
104 | ||
19 | 105 | void kp_cb(uint8_t row, uint8_t col); |
106 | void kr_cb(uint8_t row, uint8_t col); | |
107 | ||
108 | Keypad *kpad; | |
44 | 109 | keycode_t last_key = {0, 0, KEY_NONE}; |
110 | ||
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
111 | uint8_t curchar; |
26 | 112 | //uint8_t curcmd; |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
113 | uint8_t nchars; |
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 | |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
36
diff
changeset
|
116 | void refresh_display(void); |
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
36
diff
changeset
|
117 | |
8 | 118 | 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
|
119 | #if defined(HAS_LED) |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
120 | 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
|
121 | #endif |
8 | 122 | } |
123 | ||
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
124 | #ifdef DEBUG |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
125 | |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
126 | DigitalOut dbgpin(DBGPIN); |
5 | 127 | 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
|
128 | { |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
129 | dbgpin = 0; |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
130 | wait_us(2); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
131 | while (count--) |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
132 | { |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
133 | dbgpin = 1; |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
134 | wait_us(2); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
135 | dbgpin = 0; |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
136 | wait_us(2); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
137 | } |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
138 | if (stayup) |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
139 | dbgpin = 1; |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
140 | } |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
141 | #else |
5 | 142 | 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
|
143 | {} |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
144 | #endif |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
145 | |
19 | 146 | // callbacks & thread functions |
147 | void reset(void); | |
148 | void reset_irq(void); | |
149 | void qei_cb(int dir); | |
150 | void end_splashscreen(void); | |
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
|
151 | |
44 | 152 | |
153 | #if defined(HAVE_PC) | |
154 | FileHandle *mbed::mbed_override_console(int fd) | |
155 | { | |
156 | return static_cast<FileHandle*> (&pc); | |
157 | } | |
158 | #endif | |
159 | ||
3
a3233abe730e
beginning of a working display using the 3.2 OLED module
David Douard <david.douard@logilab.fr>
parents:
2
diff
changeset
|
160 | |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
161 | void setup() { |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
162 | printf("\n\nSETUP\n"); |
44 | 163 | printf(" System Core Clock = %ld MHZ\r\n", SystemCoreClock/1000000); |
21 | 164 | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
165 | 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
|
166 | #if defined(TARGET_NUCLEO_F446RE) |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
167 | printf("Serial communication pins\r\n"); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
168 | printf(" USBRX=%d\r\n", USBRX); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
169 | 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
|
170 | #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
|
171 | #if defined(TARGET_HP34970_FP_F303RD) |
48
fc55f6eaa8bc
Remove print statements
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
172 | printf("Serial communication via UART4\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
|
173 | #endif |
22 | 174 | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
175 | printf("Setup HP communication pins\r\n"); |
48
fc55f6eaa8bc
Remove print statements
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
176 | //printf(" HP_RX=%d\r\n", HP_RX); |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
177 | DigitalIn(HP_RX).mode(PullDown); |
48
fc55f6eaa8bc
Remove print statements
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
178 | //printf(" HP_TX=%d\r\n", HP_TX); |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
179 | DigitalOut(HP_TX).write(1); |
48
fc55f6eaa8bc
Remove print statements
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
180 | //printf(" HP_RST=%d\r\n", HP_RST); |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
181 | DigitalIn(HP_RST).mode(PullDown); |
21 | 182 | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
183 | printf(" setup QEI pins\r\n"); |
48
fc55f6eaa8bc
Remove print statements
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
184 | //printf(" ENC1=%d\r\n", KP_ENC1); |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
185 | DigitalIn(KP_ENC1).mode(PullDown); |
48
fc55f6eaa8bc
Remove print statements
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
186 | //printf(" ENC2=%d\r\n", KP_ENC2); |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
187 | DigitalIn(KP_ENC2).mode(PullDown); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
188 | qenc.attach(&qei_cb); |
19 | 189 | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
190 | printf(" setup Keypad\r\n"); |
19 | 191 | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
192 | shift = false; |
44 | 193 | must_reset = false; |
194 | must_shutdown = false; | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
195 | kpad = new Keypad(KP_NROWS, kp_rows, KP_NCOLS, kp_columns); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
196 | printf(" attach Keypad callbacks\r\n"); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
197 | kpad->attach(&kp_cb, &kr_cb); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
198 | printf(" start Keypad\r\n"); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
199 | kpad->start(); |
21 | 200 | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
201 | printf("Setup OLED display\r\n"); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
202 | // init the LCD |
48
fc55f6eaa8bc
Remove print statements
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
203 | /* |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
204 | printf(" DSP_MOSI=%d\r\n", DSP_MOSI); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
205 | printf(" DSP_MISO=%d\r\n", DSP_MISO); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
206 | printf(" DSP_SCLK=%d\r\n", DSP_SCLK); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
207 | printf(" DSP_CS=%d\r\n", DSP_CS); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
208 | printf(" DSP_RST=%d\r\n", DSP_RST); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
209 | printf(" DSP_DC=%d\r\n", DSP_DC); |
48
fc55f6eaa8bc
Remove print statements
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
210 | */ |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
211 | dsp = new Display(20000000, DSP_MOSI, DSP_MISO, DSP_SCLK, DSP_CS, |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
212 | DSP_RST, DSP_DC, "SSD1322"); |
19 | 213 | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
214 | curchar = 0; |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
215 | nchars = 0; |
7
5cf4034ba4e0
attempt to update display by bloc
David Douard <david.douard@logilab.fr>
parents:
5
diff
changeset
|
216 | |
54
f6774bd0d570
Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents:
53
diff
changeset
|
217 | //for (uint8_t i=0; i<sizeof(table)/sizeof(table[0]); ++i) |
f6774bd0d570
Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents:
53
diff
changeset
|
218 | // memset(table[i].buffer, 0, MAX_BUFF+1); |
19 | 219 | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
220 | printf(" display splash screen\r\n"); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
221 | dsp->show_splashscreen(); |
19 | 222 | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
223 | printf("Starting LCD thread\r\n"); |
44 | 224 | // does not compile... |
225 | // dsp_refresh.attach(callback(dsp, &Display::copy_to_lcd), 50ms); | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
226 | tdsp.start(&refresh_display); |
22 | 227 | |
48
fc55f6eaa8bc
Remove print statements
David Douard <david.douard@sdf3.org>
parents:
44
diff
changeset
|
228 | printf("Attach timers\r\n"); |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
229 | splashscreen = true; |
62
55e3b4441b11
Stop splashscreen after 5s
David Douard <david.douard@sdfa3.org>
parents:
57
diff
changeset
|
230 | splashscreen_timer.attach(callback(&end_splashscreen), 5s); |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
231 | rst.fall(&reset_irq); |
21 | 232 | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
233 | printf("SETUP DONE\r\n"); |
19 | 234 | } |
8 | 235 | |
19 | 236 | void end_splashscreen(void) |
237 | { | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
238 | splashscreen = false; |
63
f71f6c0af3cd
Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents:
62
diff
changeset
|
239 | // wait for the reset irq from the CPU board |
f71f6c0af3cd
Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents:
62
diff
changeset
|
240 | must_shutdown = true; |
19 | 241 | } |
242 | ||
63
f71f6c0af3cd
Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents:
62
diff
changeset
|
243 | /* |
44 | 244 | void reset_irq_tmr(void) |
245 | { | |
246 | must_reset = true; | |
247 | } | |
63
f71f6c0af3cd
Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents:
62
diff
changeset
|
248 | */ |
44 | 249 | |
19 | 250 | void reset_irq(void) |
251 | { | |
63
f71f6c0af3cd
Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents:
62
diff
changeset
|
252 | must_reset = true; |
f71f6c0af3cd
Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents:
62
diff
changeset
|
253 | //rst_delay.attach(callback(&reset_irq_tmr), 50ms); |
19 | 254 | } |
255 | ||
256 | void reset(void) | |
257 | { | |
44 | 258 | // this should be called as a result of the HP_RST pin going LO |
259 | printf("Reset connection to the main unit\n"); | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
260 | if (DigitalIn(HP_RST).read() == 0) { |
57 | 261 | byescreen_timer.detach(); // cancel a "poweroff", if any |
63
f71f6c0af3cd
Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents:
62
diff
changeset
|
262 | splashscreen_timer.detach(); // same for splashscreen |
62
55e3b4441b11
Stop splashscreen after 5s
David Douard <david.douard@sdfa3.org>
parents:
57
diff
changeset
|
263 | splashscreen = false; // in case it still on |
57 | 264 | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
265 | if (hp == NULL) { |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
266 | printf("setup HP communication handler\r\n"); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
267 | hp = new HPSerial(HP_TX, HP_RX); |
63
f71f6c0af3cd
Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents:
62
diff
changeset
|
268 | } else { |
44 | 269 | printf("Connection already initialized\n"); |
270 | } | |
21 | 271 | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
272 | printf("!! RST !! (gstate=%d, state=%d)\r\n", |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
273 | hp->gstate(), hp->state()); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
274 | //printf("Value is ... %X\n", hp->search()); |
44 | 275 | dsp->power_on(); |
276 | dsp->cls(); | |
277 | printf("Initiate startup sequence\n"); | |
63
f71f6c0af3cd
Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents:
62
diff
changeset
|
278 | if (last_key.keyevent == KEY_PRESSED) { |
f71f6c0af3cd
Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents:
62
diff
changeset
|
279 | printf(" with key pressed\n"); |
49
c146d19101a3
Refactor HPSerial to get rid of packet collision misbehavior
David Douard <david.douard@sdf3.org>
parents:
48
diff
changeset
|
280 | hp->send_startup_seq(kp_mapping[last_key.row][last_key.col]); |
63
f71f6c0af3cd
Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents:
62
diff
changeset
|
281 | } else { |
49
c146d19101a3
Refactor HPSerial to get rid of packet collision misbehavior
David Douard <david.douard@sdf3.org>
parents:
48
diff
changeset
|
282 | hp->send_startup_seq(); |
63
f71f6c0af3cd
Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents:
62
diff
changeset
|
283 | } |
44 | 284 | } |
285 | else | |
286 | { | |
287 | printf("HP_RST is not LOW, skipping\n"); | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
288 | } |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
289 | } |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
290 | |
37
07e8ca2bdf6d
Extracted the display related functions in a Display class
David Douard <david.douard@sdf3.org>
parents:
36
diff
changeset
|
291 | void refresh_display(void) { |
44 | 292 | while(1) { //!must_shutdown) { |
293 | dsp->copy_to_lcd(); | |
294 | ThisThread::sleep_for(50ms); | |
295 | } | |
296 | } | |
8 | 297 | |
44 | 298 | void shutdown(void) |
299 | { | |
300 | must_shutdown = true; | |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
301 | } |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
302 | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
303 | void mainloop() |
19 | 304 | { // run over and over |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
305 | keycode_t key = {0, 0, KEY_NONE}; |
44 | 306 | uint8_t keycode; // actual sent value to the CPU |
307 | HPSerial::CMD cmd; | |
308 | unsigned int nkeys = 0; | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
309 | unsigned int err[8]; |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
310 | for (uint8_t i=0; i<8; i++) |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
311 | 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
|
312 | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
313 | while(1) { |
44 | 314 | if (must_reset) { |
315 | must_reset = false; | |
63
f71f6c0af3cd
Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents:
62
diff
changeset
|
316 | must_shutdown = false; // just in case... |
44 | 317 | reset(); |
318 | } | |
63
f71f6c0af3cd
Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents:
62
diff
changeset
|
319 | |
44 | 320 | if (must_shutdown) { |
321 | must_shutdown = false; | |
63
f71f6c0af3cd
Simplify a bit the rst logic and make a bit more robust
David Douard <david.douard@sdfa3.org>
parents:
62
diff
changeset
|
322 | dsp->cls(); |
44 | 323 | dsp->power_off(); |
324 | } | |
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 | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
326 | if (knob != 0) |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
327 | { |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
328 | if (hp != NULL) |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
329 | { |
44 | 330 | printf("KEY[%d] %s%X\n", nkeys++, knob<0x0F ? "0" : "", knob); |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
331 | hp->sendkey(knob); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
332 | } |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
333 | else |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
334 | { |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
335 | dsp->locate(70, 0); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
336 | dsp->printf("Knob = %X ", knob); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
337 | dsp->copy_to_lcd(); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
338 | } |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
339 | knob = 0; |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
340 | } |
34
94ab7ff42a1b
Add a key mapping table (protocol value vs. raw keycode) and send it
David Douard <david.douard@sdf3.org>
parents:
32
diff
changeset
|
341 | |
44 | 342 | if (!key_buf.empty()) |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
343 | { |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
344 | key_buf.pop(key); |
44 | 345 | keycode = kp_mapping[key.row][key.col]; |
346 | ||
347 | if ((keycode == KC_SHIFT) && (key.keyevent == KEY_PRESSED)) | |
348 | { | |
57 | 349 | // toggle the shift indicator |
350 | if (shift) | |
351 | shift = false; | |
352 | else | |
353 | shift = false; | |
354 | dsp->set_flag_status(0x0E, shift); | |
54
f6774bd0d570
Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents:
53
diff
changeset
|
355 | dsp->draw_flag(0x0E); |
44 | 356 | } |
357 | ||
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
358 | if (hp != NULL) { |
44 | 359 | if ((shift) && (keycode != KC_SHIFT)) |
360 | { | |
361 | keycode |= 0x20; // bit 5: key shifted | |
362 | shift = false; | |
54
f6774bd0d570
Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents:
53
diff
changeset
|
363 | dsp->set_flag_status(0x0E, false); |
44 | 364 | } |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
365 | if (key.keyevent == KEY_RELEASED) |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
366 | keycode |= 0x40; // bit 6: key relased |
44 | 367 | printf("KEY[%d] %s%X\n", nkeys++, keycode<0x0F ? "0" : "", keycode); |
368 | hp->sendkey(keycode); | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
369 | } |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
370 | else |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
371 | { |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
372 | dsp->locate(140, 0); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
373 | dsp->printf("KC: %dx%d[0x%s%X] %s", |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
374 | key.row, key.col, |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
375 | kp_mapping[key.row][key.col] <= 0x0F ? "0" : "", |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
376 | kp_mapping[key.row][key.col], |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
377 | key.keyevent==KEY_PRESSED ? "PRE" : "REL"); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
378 | dsp->copy_to_lcd(); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
379 | } |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
380 | } |
19 | 381 | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
382 | if ((hp != NULL) && (hp->cmd_available())) |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
383 | { |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
384 | if (hp->pop(cmd)) |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
385 | { |
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
|
386 | #if defined(HAS_LED) |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
387 | 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
|
388 | #endif |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
389 | for (uint8_t i=0; i<7; i++) |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
390 | if (hp->nerrors(i) > err[i]) { |
44 | 391 | printf("ERR: %X/%X/%X/%X/%X/%X/%X\n", |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
392 | hp->nerrors(0), |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
393 | hp->nerrors(1), |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
394 | hp->nerrors(2), |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
395 | hp->nerrors(3), |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
396 | hp->nerrors(4), |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
397 | hp->nerrors(5), |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
398 | hp->nerrors(6) |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
399 | ); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
400 | break; |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
401 | } |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
402 | for (uint8_t i=0; i<7; i++) |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
403 | err[i] = hp->nerrors(i); |
19 | 404 | |
44 | 405 | printf("CMD[%d] %s%X", (int)cmd.id, cmd.cmd<0x10 ? "0" : "", cmd.cmd); |
19 | 406 | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
407 | // 0x00: main display |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
408 | // 0x0C: channel display |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
409 | if ((cmd.cmd == 0x00) || (cmd.cmd == 0x0C)) |
44 | 410 | printf(": '%s'\n", cmd.value); |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
411 | else { |
44 | 412 | printf(": "); |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
413 | for (uint8_t i=0; i<cmd.size; i++) |
44 | 414 | printf("%s%X ", cmd.value[i] < 0x10 ? "0" : "", cmd.value[i]); |
415 | printf("\n"); | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
416 | } |
36
a6c7292742a0
Add support for the shift flag
David Douard <david.douard@sdf3.org>
parents:
35
diff
changeset
|
417 | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
418 | if (cmd.cmd == 0x01) { |
36
a6c7292742a0
Add support for the shift flag
David Douard <david.douard@sdf3.org>
parents:
35
diff
changeset
|
419 | // clear a flag |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
420 | if (cmd.value[0] == 0x0E) { |
36
a6c7292742a0
Add support for the shift flag
David Douard <david.douard@sdf3.org>
parents:
35
diff
changeset
|
421 | // clear the Shift flag |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
422 | shift = false; |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
423 | } |
54
f6774bd0d570
Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents:
53
diff
changeset
|
424 | dsp->set_flag_status(cmd.value[0], false); |
f6774bd0d570
Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents:
53
diff
changeset
|
425 | dsp->draw_flag(cmd.value[0]); |
52
098124b730eb
Add support for 0x08 and 0x09 command codes (display a flag dimm/bright)
David Douard <david.douard@sdf3.org>
parents:
49
diff
changeset
|
426 | } else if (cmd.cmd == 0x08) { |
098124b730eb
Add support for 0x08 and 0x09 command codes (display a flag dimm/bright)
David Douard <david.douard@sdf3.org>
parents:
49
diff
changeset
|
427 | // set a flag dimmed |
54
f6774bd0d570
Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents:
53
diff
changeset
|
428 | dsp->set_flag_status(cmd.value[0], true); |
f6774bd0d570
Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents:
53
diff
changeset
|
429 | dsp->set_flag_dim(cmd.value[0], true); |
f6774bd0d570
Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents:
53
diff
changeset
|
430 | dsp->draw_flag(cmd.value[0]); |
52
098124b730eb
Add support for 0x08 and 0x09 command codes (display a flag dimm/bright)
David Douard <david.douard@sdf3.org>
parents:
49
diff
changeset
|
431 | } else if (cmd.cmd == 0x09) { |
098124b730eb
Add support for 0x08 and 0x09 command codes (display a flag dimm/bright)
David Douard <david.douard@sdf3.org>
parents:
49
diff
changeset
|
432 | // set a flag bright |
54
f6774bd0d570
Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents:
53
diff
changeset
|
433 | dsp->set_flag_status(cmd.value[0], true); |
f6774bd0d570
Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents:
53
diff
changeset
|
434 | dsp->set_flag_dim(cmd.value[0], false); |
f6774bd0d570
Refactor the flag display system
David Douard <david.douard@sdf3.org>
parents:
53
diff
changeset
|
435 | dsp->draw_flag(cmd.value[0]); |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
436 | } else if (cmd.cmd == 0x86) { |
44 | 437 | // shutdown |
438 | dsp->show_byescreen(); | |
439 | byescreen_timer.attach(callback(&shutdown), 2s); | |
62
55e3b4441b11
Stop splashscreen after 5s
David Douard <david.douard@sdfa3.org>
parents:
57
diff
changeset
|
440 | } else { |
36
a6c7292742a0
Add support for the shift flag
David Douard <david.douard@sdf3.org>
parents:
35
diff
changeset
|
441 | // display related commands |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
442 | dsp->show(cmd.cmd, cmd.value, cmd.size); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
443 | } |
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
|
444 | #if defined(HAS_LED) |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
445 | 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
|
446 | #endif |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
447 | } |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
448 | } |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
449 | //else |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
450 | ThisThread::sleep_for(1ms); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
451 | } |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
452 | } |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
453 | |
44 | 454 | |
19 | 455 | void qei_cb(int dir) |
456 | { | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
457 | if(dir == 1) // turn right |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
458 | knob = 0x80; |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
459 | else // turn left |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
460 | knob = 0x81; // 83? |
19 | 461 | } |
462 | ||
463 | void kp_cb(uint8_t row, uint8_t col) | |
464 | { | |
44 | 465 | last_key.row = row; |
466 | last_key.col = col; | |
467 | last_key.keyevent = KEY_PRESSED; | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
468 | if(!key_buf.full()) |
44 | 469 | key_buf.push(last_key); |
19 | 470 | } |
471 | ||
472 | void kr_cb(uint8_t row, uint8_t col) | |
473 | { | |
44 | 474 | last_key.row = row; |
475 | last_key.col = col; | |
476 | last_key.keyevent = KEY_RELEASED; | |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
477 | if(!key_buf.full()) |
44 | 478 | key_buf.push(last_key); |
19 | 479 | } |
480 | ||
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
481 | int main() |
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
482 | { |
38
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
483 | setup(); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
484 | printf("Main loop (noop)\r\n"); |
ffef9bbb345d
kill tabs (again) in src/main.cpp
David Douard <david.douard@sdf3.org>
parents:
37
diff
changeset
|
485 | mainloop(); |
1
3021fc79cc3b
kinf of working prototype using a ILI9341 based TFT
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
486 | } |