13 class Keypad { |
13 class Keypad { |
14 public: |
14 public: |
15 Keypad(uint8_t nRows, DigitalIn rows[], |
15 Keypad(uint8_t nRows, DigitalIn rows[], |
16 uint8_t nColumns, DigitalOut cols[], |
16 uint8_t nColumns, DigitalOut cols[], |
17 int debounce_ms=20); |
17 int debounce_ms=20); |
18 |
18 |
19 /** Destructor |
19 /** Destructor |
20 */ |
20 */ |
21 ~Keypad(); |
21 ~Keypad(); |
22 |
22 |
23 void attach(const keyevent_callback_t& kp_callback=NULL, |
23 void attach(const keyevent_callback_t& kp_callback=NULL, |
24 const keyevent_callback_t& kr_callback=NULL); |
24 const keyevent_callback_t& kr_callback=NULL); |
25 |
25 |
26 void start(void); |
26 void start(void); |
27 void stop(void); |
27 void stop(void); |
28 |
28 |
29 |
29 |
30 protected: |
30 protected: |
31 std::vector<DigitalIn> _rows; |
31 std::vector<DigitalIn> _rows; |
32 std::vector<DigitalOut> _columns; |
32 std::vector<DigitalOut> _columns; |
33 int _debounce; // miliseconds |
33 int _debounce; // miliseconds |
34 |
34 |
35 void _kp(); |
35 void _kp(); |
36 void _kr(); |
36 void _kr(); |
37 void _keyPressed(int row); |
37 void _keyPressed(int row); |
38 void _keyReleased(int row); |
38 void _keyReleased(int row); |
39 void run(); |
39 void run(); |
40 |
40 |
41 private: |
41 private: |
42 keyevent_callback_t _kp_callback; |
42 keyevent_callback_t _kp_callback; |
43 keyevent_callback_t _kr_callback; |
43 keyevent_callback_t _kr_callback; |
44 bool _started; |
44 bool _started; |
45 Thread _loop; |
45 Thread _loop; |