lib/keypad/Keypad.h

Sun, 30 Aug 2020 22:53:15 +0200

author
David Douard <david.douard@sdfa3.org>
date
Sun, 30 Aug 2020 22:53:15 +0200
changeset 25
5b1e0b384d31
parent 24
b43536c064f6
child 26
86f099bda525
permissions
-rw-r--r--

Add .pio to hgignore

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"
b43536c064f6 Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff changeset
6 #include "rtos.h"
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);
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 /** 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();
b43536c064f6 Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff changeset
22
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);
b43536c064f6 Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff changeset
25
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);
b43536c064f6 Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff changeset
28
b43536c064f6 Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff changeset
29
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();
b43536c064f6 Add the (missing?) Keypad lib
David Douard <david.douard@logilab.fr>
parents:
diff changeset
40
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

mercurial