Thu, 07 Oct 2021 21:05:13 +0200
Reduce the sleep time of the send_pending_key thread to 1ms
to get a chance of sending a keycode when the CPU flood the FP with DSP
messages (e.g. after the last 'Last-N' value).
24
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
1 | #ifndef KEYPAD_H |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
2 | #define KEYPAD_H |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
3 | |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
4 | #include "mbed.h" |
26 | 5 | //#include "rtos.h" |
24
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
6 | #include <vector> |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
7 | |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
8 | |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
9 | typedef Callback<void(uint8_t, uint8_t)> keyevent_callback_t; |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
10 | |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
11 | class Keypad { |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
12 | public: |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
13 | Keypad(uint8_t nRows, DigitalIn rows[], |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
14 | uint8_t nColumns, DigitalOut cols[], |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
15 | int debounce_ms=20); |
26 | 16 | |
24
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
17 | /** Destructor |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
18 | */ |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
19 | ~Keypad(); |
26 | 20 | |
24
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
21 | void attach(const keyevent_callback_t& kp_callback=NULL, |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
22 | const keyevent_callback_t& kr_callback=NULL); |
26 | 23 | |
24
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
24 | void start(void); |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
25 | void stop(void); |
26 | 26 | |
27 | ||
24
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
28 | protected: |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
29 | std::vector<DigitalIn> _rows; |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
30 | std::vector<DigitalOut> _columns; |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
31 | int _debounce; // miliseconds |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
32 | |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
33 | void _kp(); |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
34 | void _kr(); |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
35 | void _keyPressed(int row); |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
36 | void _keyReleased(int row); |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
37 | void run(); |
26 | 38 | |
24
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
39 | private: |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
40 | keyevent_callback_t _kp_callback; |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
41 | keyevent_callback_t _kr_callback; |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
42 | bool _started; |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
43 | Thread _loop; |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
44 | //tloop.start(&loop); |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
45 | uint8_t _nrows; |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
46 | uint8_t _ncols; |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
47 | uint8_t *_keys; |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
48 | }; |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
49 | |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
50 | |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
51 | #endif // KEYPAD_H |