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 MOUSE_CONTROLLER_H
|
---|
20 | #define MOUSE_CONTROLLER_H
|
---|
21 |
|
---|
22 | #include <hidboot.h>
|
---|
23 |
|
---|
24 | enum MouseButton {
|
---|
25 | LEFT_BUTTON = 0x01,
|
---|
26 | MIDDLE_BUTTON = 0x02,
|
---|
27 | RIGHT_BUTTON = 0x04
|
---|
28 | };
|
---|
29 |
|
---|
30 | class MouseController : public MouseReportParser
|
---|
31 | {
|
---|
32 | public:
|
---|
33 | MouseController(USBHost &usb) : hostMouse(&usb), dx(0), dy(0), buttons(0) {
|
---|
34 | hostMouse.SetReportParser(0, this);
|
---|
35 | };
|
---|
36 |
|
---|
37 | bool getButton(MouseButton button) { return (buttons & button) == button; };
|
---|
38 | int getXChange();
|
---|
39 | int getYChange();
|
---|
40 | // int getWheelChange(); // Not implemented
|
---|
41 |
|
---|
42 | protected:
|
---|
43 | virtual void OnMouseMove(MOUSEINFO *mi);
|
---|
44 | virtual void OnLeftButtonUp(MOUSEINFO *mi);
|
---|
45 | virtual void OnLeftButtonDown(MOUSEINFO *mi);
|
---|
46 | virtual void OnMiddleButtonUp(MOUSEINFO *mi);
|
---|
47 | virtual void OnMiddleButtonDown(MOUSEINFO *mi);
|
---|
48 | virtual void OnRightButtonUp(MOUSEINFO *mi);
|
---|
49 | virtual void OnRightButtonDown(MOUSEINFO *mi);
|
---|
50 |
|
---|
51 | private:
|
---|
52 | HIDBoot<HID_PROTOCOL_MOUSE> hostMouse;
|
---|
53 | int dx, dy;
|
---|
54 | int buttons;
|
---|
55 | };
|
---|
56 |
|
---|
57 | #endif
|
---|