re-enabling serial
[clinton/Smoothieware.git] / gcc4mbed / samples / MSTest / USBDevice / USBHID / USBMouse.h
1 /* USBMouse.h */
2 /* USB device example: relative mouse */
3 /* Copyright (c) 2011 ARM Limited. All rights reserved. */
4
5 #ifndef USBMOUSE_H
6 #define USBMOUSE_H
7
8 #include "USBHID.h"
9
10 #define REPORT_ID_MOUSE 2
11
12 /* Common usage */
13
14 enum MOUSE_BUTTON
15 {
16 MOUSE_LEFT = 1,
17 MOUSE_RIGHT = 2,
18 MOUSE_MIDDLE = 4,
19 };
20
21 /* X and Y limits */
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 */
28
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 */
33
34 enum MOUSE_TYPE
35 {
36 ABS_MOUSE,
37 REL_MOUSE,
38 };
39
40 /**
41 *
42 * USBMouse example
43 * @code
44 * #include "mbed.h"
45 * #include "USBMouse.h"
46 *
47 * USBMouse mouse;
48 *
49 * int main(void)
50 * {
51 * while (1)
52 * {
53 * mouse.move(20, 0);
54 * wait(0.5);
55 * }
56 * }
57 *
58 * @endcode
59 *
60 *
61 * @code
62 * #include "mbed.h"
63 * #include "USBMouse.h"
64 * #include <math.h>
65 *
66 * USBMouse mouse(ABS_MOUSE);
67 *
68 * int main(void)
69 * {
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;
74 *
75 * uint32_t x_origin = x_center;
76 * uint32_t y_origin = y_center;
77 * uint32_t radius = 5000;
78 * uint32_t angle = 0;
79 *
80 * while (1)
81 * {
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;
84 *
85 * mouse.move(x_screen, y_screen);
86 * angle += 3;
87 * wait(0.01);
88 * }
89 * }
90 *
91 * @endcode
92 */
93 class USBMouse: public USBHID
94 {
95 public:
96
97 /**
98 * Constructor
99 *
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)
104 *
105 */
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)
108 {
109 button = 0;
110 this->mouse_type = mouse_type;
111 connect();
112 };
113
114 /**
115 * Write a state of the mouse
116 *
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
122 */
123 bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z);
124
125
126 /**
127 * Move the cursor to (x, y)
128 *
129 * @param x-axis position
130 * @param y-axis position
131 * @returns true if there is no error, false otherwise
132 */
133 bool move(int16_t x, int16_t y);
134
135 /**
136 * Press one or several buttons
137 *
138 * @param button button state (ex: press(MOUSE_LEFT))
139 * @returns true if there is no error, false otherwise
140 */
141 bool press(uint8_t button);
142
143 /**
144 * Release one or several buttons
145 *
146 * @param button button state (ex: release(MOUSE_LEFT))
147 * @returns true if there is no error, false otherwise
148 */
149 bool release(uint8_t button);
150
151 /**
152 * Double click (MOUSE_LEFT)
153 *
154 * @returns true if there is no error, false otherwise
155 */
156 bool doubleClick();
157
158 /**
159 * Click
160 *
161 * @param button state of the buttons ( ex: clic(MOUSE_LEFT))
162 * @returns true if there is no error, false otherwise
163 */
164 bool click(uint8_t button);
165
166 /**
167 * Scrolling
168 *
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
171 */
172 bool scroll(int8_t z);
173
174 /*
175 * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
176 *
177 * @returns pointer to the report descriptor
178 */
179 virtual uint8_t * reportDesc();
180
181 private:
182 MOUSE_TYPE mouse_type;
183 uint8_t button;
184 bool mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z);
185 };
186
187 #endif