2 /* USB device example: relative mouse */
3 /* Copyright (c) 2011 ARM Limited. All rights reserved. */
10 #define REPORT_ID_MOUSE 2
22 /* These values do not directly map to screen pixels */
23 /* Zero may be interpreted as meaning 'no movement' */
24 #define X_MIN_ABS (1) /*!< Minimum value on x-axis */
25 #define Y_MIN_ABS (1) /*!< Minimum value on y-axis */
26 #define X_MAX_ABS (0x7fff) /*!< Maximum value on x-axis */
27 #define Y_MAX_ABS (0x7fff) /*!< Maximum value on y-axis */
29 #define X_MIN_REL (-127) /*!< The maximum value that we can move to the left on the x-axis */
30 #define Y_MIN_REL (-127) /*!< The maximum value that we can move up on the y-axis */
31 #define X_MAX_REL (127) /*!< The maximum value that we can move to the right on the x-axis */
32 #define Y_MAX_REL (127) /*!< The maximum value that we can move down on the y-axis */
45 * #include "USBMouse.h"
63 * #include "USBMouse.h"
66 * USBMouse mouse(ABS_MOUSE);
70 * uint16_t x_center = (X_MAX_ABS - X_MIN_ABS)/2;
71 * uint16_t y_center = (Y_MAX_ABS - Y_MIN_ABS)/2;
72 * uint16_t x_screen = 0;
73 * uint16_t y_screen = 0;
75 * uint32_t x_origin = x_center;
76 * uint32_t y_origin = y_center;
77 * uint32_t radius = 5000;
82 * x_screen = x_origin + cos((double)angle*3.14/180.0)*radius;
83 * y_screen = y_origin + sin((double)angle*3.14/180.0)*radius;
85 * mouse.move(x_screen, y_screen);
93 class USBMouse
: public USBHID
100 * @param mouse_type Mouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE)
101 * @param vendor_id Your vendor_id (default: 0x1234)
102 * @param product_id Your product_id (default: 0x0001)
103 * @param product_release Your preoduct_release (default: 0x0001)
106 USBMouse(MOUSE_TYPE mouse_type
= REL_MOUSE
, uint16_t vendor_id
= 0x1234, uint16_t product_id
= 0x0001, uint16_t product_release
= 0x0001):
107 USBHID(0, 0, vendor_id
, product_id
, product_release
, false)
110 this->mouse_type
= mouse_type
;
115 * Write a state of the mouse
117 * @param x x-axis position
118 * @param y y-axis position
119 * @param buttons buttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE)
120 * @param z wheel state (>0 to scroll down, <0 to scroll up)
121 * @returns true if there is no error, false otherwise
123 bool update(int16_t x
, int16_t y
, uint8_t buttons
, int8_t z
);
127 * Move the cursor to (x, y)
129 * @param x-axis position
130 * @param y-axis position
131 * @returns true if there is no error, false otherwise
133 bool move(int16_t x
, int16_t y
);
136 * Press one or several buttons
138 * @param button button state (ex: press(MOUSE_LEFT))
139 * @returns true if there is no error, false otherwise
141 bool press(uint8_t button
);
144 * Release one or several buttons
146 * @param button button state (ex: release(MOUSE_LEFT))
147 * @returns true if there is no error, false otherwise
149 bool release(uint8_t button
);
152 * Double click (MOUSE_LEFT)
154 * @returns true if there is no error, false otherwise
161 * @param button state of the buttons ( ex: clic(MOUSE_LEFT))
162 * @returns true if there is no error, false otherwise
164 bool click(uint8_t button
);
169 * @param z value of the wheel (>0 to go down, <0 to go up)
170 * @returns true if there is no error, false otherwise
172 bool scroll(int8_t z
);
175 * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
177 * @returns pointer to the report descriptor
179 virtual uint8_t * reportDesc();
182 MOUSE_TYPE mouse_type
;
184 bool mouseSend(int8_t x
, int8_t y
, uint8_t buttons
, int8_t z
);