Sat, 07 Nov 2020 19:22:04 +0100
Fix display of flags and improve dimm char handling
24
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
1 | |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
2 | #ifndef KEYPAD_H |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
3 | #define KEYPAD_H |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
4 | |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
5 | #include "mbed.h" |
26 | 6 | //#include "rtos.h" |
24
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
7 | #include <vector> |
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 | |
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 | 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
|
12 | |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
13 | class Keypad { |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
14 | public: |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
15 | Keypad(uint8_t nRows, DigitalIn rows[], |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
16 | uint8_t nColumns, DigitalOut cols[], |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
17 | int debounce_ms=20); |
26 | 18 | |
24
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
19 | /** Destructor |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
20 | */ |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
21 | ~Keypad(); |
26 | 22 | |
24
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
23 | void attach(const keyevent_callback_t& kp_callback=NULL, |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
24 | const keyevent_callback_t& kr_callback=NULL); |
26 | 25 | |
24
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
26 | void start(void); |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
27 | void stop(void); |
26 | 28 | |
29 | ||
24
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
30 | protected: |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
31 | std::vector<DigitalIn> _rows; |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
32 | std::vector<DigitalOut> _columns; |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
33 | int _debounce; // miliseconds |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
34 | |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
35 | void _kp(); |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
36 | void _kr(); |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
37 | void _keyPressed(int row); |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
38 | void _keyReleased(int row); |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
39 | void run(); |
26 | 40 | |
24
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
41 | private: |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
42 | keyevent_callback_t _kp_callback; |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
43 | keyevent_callback_t _kr_callback; |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
44 | bool _started; |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
45 | Thread _loop; |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
46 | //tloop.start(&loop); |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
47 | uint8_t _nrows; |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
48 | uint8_t _ncols; |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
49 | uint8_t *_keys; |
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 | |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
52 | |
b43536c064f6
Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
53 | #endif // KEYPAD_H |