1 | /*
|
---|
2 | Copyright (c) 2012 Arduino. All right reserved.
|
---|
3 |
|
---|
4 | This library is free software; you can redistribute it and/or
|
---|
5 | modify it under the terms of the GNU Lesser General Public
|
---|
6 | License as published by the Free Software Foundation; either
|
---|
7 | version 2.1 of the License, or (at your option) any later version.
|
---|
8 |
|
---|
9 | This library is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
---|
12 | See the GNU Lesser General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU Lesser General Public
|
---|
15 | License along with this library; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
17 | */
|
---|
18 |
|
---|
19 | #ifndef KEYBOARD_CONTROLLER_H
|
---|
20 | #define KEYBOARD_CONTROLLER_H
|
---|
21 |
|
---|
22 | #include <hidboot.h>
|
---|
23 |
|
---|
24 | enum KeyboardModifiers {
|
---|
25 | LeftCtrl = 1,
|
---|
26 | LeftShift = 2,
|
---|
27 | Alt = 4,
|
---|
28 | LeftCmd = 8,
|
---|
29 | RightCtrl = 16,
|
---|
30 | RightShift = 32,
|
---|
31 | AltGr = 64,
|
---|
32 | RightCmd = 128
|
---|
33 | };
|
---|
34 |
|
---|
35 | class KeyboardController : public KeyboardReportParser {
|
---|
36 | public:
|
---|
37 | KeyboardController(USBHost &usb) : hostKeyboard(&usb), key(0), keyOem(0), modifiers(0) {
|
---|
38 | hostKeyboard.SetReportParser(0, this);
|
---|
39 | };
|
---|
40 |
|
---|
41 | uint8_t getKey() { return key; };
|
---|
42 | uint8_t getModifiers() { return modifiers; };
|
---|
43 | uint8_t getOemKey() { return keyOem; };
|
---|
44 |
|
---|
45 | protected:
|
---|
46 | virtual void OnKeyDown(uint8_t mod, uint8_t key);
|
---|
47 | virtual void OnKeyUp(uint8_t mod, uint8_t key);
|
---|
48 |
|
---|
49 | private:
|
---|
50 | HIDBoot<HID_PROTOCOL_KEYBOARD> hostKeyboard;
|
---|
51 | uint8_t key, keyOem, modifiers;
|
---|
52 | };
|
---|
53 |
|
---|
54 | #endif
|
---|