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