]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/USBHost/USBHostHID/USBHostMouse.h
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / USBHost / USBHostHID / USBHostMouse.h
1 /* mbed USBHost Library
2 * Copyright (c) 2006-2013 ARM Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef USBHOSTMOUSE_H
18 #define USBHOSTMOUSE_H
19
20 #include "USBHostConf.h"
21
22 #if USBHOST_MOUSE
23
24 #include "USBHost.h"
25
26 /**
27 * A class to communicate a USB mouse
28 */
29 class USBHostMouse : public IUSBEnumerator {
30 public:
31
32 /**
33 * Constructor
34 */
35 USBHostMouse();
36
37 /**
38 * Try to connect a mouse device
39 *
40 * @return true if connection was successful
41 */
42 bool connect();
43
44 /**
45 * Check if a mouse is connected
46 *
47 * @returns true if a mouse is connected
48 */
49 bool connected();
50
51 /**
52 * Attach a callback called when a mouse event is received
53 *
54 * @param ptr function pointer
55 */
56 inline void attachEvent(void (*ptr)(uint8_t buttons, int8_t x, int8_t y, int8_t z)) {
57 if (ptr != NULL) {
58 onUpdate = ptr;
59 }
60 }
61
62 /**
63 * Attach a callback called when the button state changes
64 *
65 * @param ptr function pointer
66 */
67 inline void attachButtonEvent(void (*ptr)(uint8_t buttons)) {
68 if (ptr != NULL) {
69 onButtonUpdate = ptr;
70 }
71 }
72
73 /**
74 * Attach a callback called when the X axis value changes
75 *
76 * @param ptr function pointer
77 */
78 inline void attachXEvent(void (*ptr)(int8_t x)) {
79 if (ptr != NULL) {
80 onXUpdate = ptr;
81 }
82 }
83
84 /**
85 * Attach a callback called when the Y axis value changes
86 *
87 * @param ptr function pointer
88 */
89 inline void attachYEvent(void (*ptr)(int8_t y)) {
90 if (ptr != NULL) {
91 onYUpdate = ptr;
92 }
93 }
94
95 /**
96 * Attach a callback called when the Z axis value changes (scrolling)
97 *
98 * @param ptr function pointer
99 */
100 inline void attachZEvent(void (*ptr)(int8_t z)) {
101 if (ptr != NULL) {
102 onZUpdate = ptr;
103 }
104 }
105
106 protected:
107 //From IUSBEnumerator
108 virtual void setVidPid(uint16_t vid, uint16_t pid);
109 virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed
110 virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
111
112 private:
113 USBHost * host;
114 USBDeviceConnected * dev;
115 USBEndpoint * int_in;
116 uint8_t report[4];
117
118 bool dev_connected;
119 bool mouse_device_found;
120 int mouse_intf;
121
122 uint8_t buttons;
123 int8_t x;
124 int8_t y;
125 int8_t z;
126
127 void rxHandler();
128 void (*onUpdate)(uint8_t buttons, int8_t x, int8_t y, int8_t z);
129 void (*onButtonUpdate)(uint8_t buttons);
130 void (*onXUpdate)(int8_t x);
131 void (*onYUpdate)(int8_t y);
132 void (*onZUpdate)(int8_t z);
133 int report_id;
134 void init();
135 };
136
137 #endif
138
139 #endif
Imprint / Impressum