1 /* Copyright (c) 2010-2011 mbed.org, MIT License
3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4 * and associated documentation files (the "Software"), to deal in the Software without
5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
7 * Software is furnished to do so, subject to the following conditions:
9 * The above copyright notice and this permission notice shall be included in all copies or
10 * substantial portions of the Software.
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #define REPORT_ID_MOUSE 2
36 /* These values do not directly map to screen pixels */
37 /* Zero may be interpreted as meaning 'no movement' */
38 #define X_MIN_ABS (1) /*!< Minimum value on x-axis */
39 #define Y_MIN_ABS (1) /*!< Minimum value on y-axis */
40 #define X_MAX_ABS (0x7fff) /*!< Maximum value on x-axis */
41 #define Y_MAX_ABS (0x7fff) /*!< Maximum value on y-axis */
43 #define X_MIN_REL (-127) /*!< The maximum value that we can move to the left on the x-axis */
44 #define Y_MIN_REL (-127) /*!< The maximum value that we can move up on the y-axis */
45 #define X_MAX_REL (127) /*!< The maximum value that we can move to the right on the x-axis */
46 #define Y_MAX_REL (127) /*!< The maximum value that we can move down on the y-axis */
59 * #include "USBMouse.h"
77 * #include "USBMouse.h"
80 * USBMouse mouse(ABS_MOUSE);
84 * uint16_t x_center = (X_MAX_ABS - X_MIN_ABS)/2;
85 * uint16_t y_center = (Y_MAX_ABS - Y_MIN_ABS)/2;
86 * uint16_t x_screen = 0;
87 * uint16_t y_screen = 0;
89 * uint32_t x_origin = x_center;
90 * uint32_t y_origin = y_center;
91 * uint32_t radius = 5000;
96 * x_screen = x_origin + cos((double)angle*3.14/180.0)*radius;
97 * y_screen = y_origin + sin((double)angle*3.14/180.0)*radius;
99 * mouse.move(x_screen, y_screen);
107 class USBMouse: public USBHID
114 * @param mouse_type Mouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE)
115 * @param vendor_id Your vendor_id (default: 0x1234)
116 * @param product_id Your product_id (default: 0x0001)
117 * @param product_release Your preoduct_release (default: 0x0001)
120 USBMouse(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0001, uint16_t product_release = 0x0001):
121 USBHID(0, 0, vendor_id, product_id, product_release, false)
124 this->mouse_type = mouse_type;
129 * Write a state of the mouse
131 * @param x x-axis position
132 * @param y y-axis position
133 * @param buttons buttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE)
134 * @param z wheel state (>0 to scroll down, <0 to scroll up)
135 * @returns true if there is no error, false otherwise
137 bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z);
141 * Move the cursor to (x, y)
143 * @param x-axis position
144 * @param y-axis position
145 * @returns true if there is no error, false otherwise
147 bool move(int16_t x, int16_t y);
150 * Press one or several buttons
152 * @param button button state (ex: press(MOUSE_LEFT))
153 * @returns true if there is no error, false otherwise
155 bool press(uint8_t button);
158 * Release one or several buttons
160 * @param button button state (ex: release(MOUSE_LEFT))
161 * @returns true if there is no error, false otherwise
163 bool release(uint8_t button);
166 * Double click (MOUSE_LEFT)
168 * @returns true if there is no error, false otherwise
175 * @param button state of the buttons ( ex: clic(MOUSE_LEFT))
176 * @returns true if there is no error, false otherwise
178 bool click(uint8_t button);
183 * @param z value of the wheel (>0 to go down, <0 to go up)
184 * @returns true if there is no error, false otherwise
186 bool scroll(int8_t z);
189 * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
191 * @returns pointer to the report descriptor
193 virtual uint8_t * reportDesc();
197 * Get configuration descriptor
199 * @returns pointer to the configuration descriptor
201 virtual uint8_t * configurationDesc();
204 MOUSE_TYPE mouse_type;
206 bool mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z);