Base station firmware
USBHID/USBMouse.h@0:ecc3925d3f8c, 2016-05-24 (annotated)
- Committer:
- Perijah
- Date:
- Tue May 24 13:16:55 2016 +0000
- Revision:
- 0:ecc3925d3f8c
Base station firmware
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Perijah | 0:ecc3925d3f8c | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
Perijah | 0:ecc3925d3f8c | 2 | * |
Perijah | 0:ecc3925d3f8c | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
Perijah | 0:ecc3925d3f8c | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
Perijah | 0:ecc3925d3f8c | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
Perijah | 0:ecc3925d3f8c | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
Perijah | 0:ecc3925d3f8c | 7 | * Software is furnished to do so, subject to the following conditions: |
Perijah | 0:ecc3925d3f8c | 8 | * |
Perijah | 0:ecc3925d3f8c | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
Perijah | 0:ecc3925d3f8c | 10 | * substantial portions of the Software. |
Perijah | 0:ecc3925d3f8c | 11 | * |
Perijah | 0:ecc3925d3f8c | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
Perijah | 0:ecc3925d3f8c | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
Perijah | 0:ecc3925d3f8c | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
Perijah | 0:ecc3925d3f8c | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Perijah | 0:ecc3925d3f8c | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Perijah | 0:ecc3925d3f8c | 17 | */ |
Perijah | 0:ecc3925d3f8c | 18 | |
Perijah | 0:ecc3925d3f8c | 19 | #ifndef USBMOUSE_H |
Perijah | 0:ecc3925d3f8c | 20 | #define USBMOUSE_H |
Perijah | 0:ecc3925d3f8c | 21 | |
Perijah | 0:ecc3925d3f8c | 22 | #include "USBHID.h" |
Perijah | 0:ecc3925d3f8c | 23 | |
Perijah | 0:ecc3925d3f8c | 24 | #define REPORT_ID_MOUSE 2 |
Perijah | 0:ecc3925d3f8c | 25 | |
Perijah | 0:ecc3925d3f8c | 26 | /* Common usage */ |
Perijah | 0:ecc3925d3f8c | 27 | |
Perijah | 0:ecc3925d3f8c | 28 | enum MOUSE_BUTTON |
Perijah | 0:ecc3925d3f8c | 29 | { |
Perijah | 0:ecc3925d3f8c | 30 | MOUSE_LEFT = 1, |
Perijah | 0:ecc3925d3f8c | 31 | MOUSE_RIGHT = 2, |
Perijah | 0:ecc3925d3f8c | 32 | MOUSE_MIDDLE = 4, |
Perijah | 0:ecc3925d3f8c | 33 | }; |
Perijah | 0:ecc3925d3f8c | 34 | |
Perijah | 0:ecc3925d3f8c | 35 | /* X and Y limits */ |
Perijah | 0:ecc3925d3f8c | 36 | /* These values do not directly map to screen pixels */ |
Perijah | 0:ecc3925d3f8c | 37 | /* Zero may be interpreted as meaning 'no movement' */ |
Perijah | 0:ecc3925d3f8c | 38 | #define X_MIN_ABS (1) /*!< Minimum value on x-axis */ |
Perijah | 0:ecc3925d3f8c | 39 | #define Y_MIN_ABS (1) /*!< Minimum value on y-axis */ |
Perijah | 0:ecc3925d3f8c | 40 | #define X_MAX_ABS (0x7fff) /*!< Maximum value on x-axis */ |
Perijah | 0:ecc3925d3f8c | 41 | #define Y_MAX_ABS (0x7fff) /*!< Maximum value on y-axis */ |
Perijah | 0:ecc3925d3f8c | 42 | |
Perijah | 0:ecc3925d3f8c | 43 | #define X_MIN_REL (-127) /*!< The maximum value that we can move to the left on the x-axis */ |
Perijah | 0:ecc3925d3f8c | 44 | #define Y_MIN_REL (-127) /*!< The maximum value that we can move up on the y-axis */ |
Perijah | 0:ecc3925d3f8c | 45 | #define X_MAX_REL (127) /*!< The maximum value that we can move to the right on the x-axis */ |
Perijah | 0:ecc3925d3f8c | 46 | #define Y_MAX_REL (127) /*!< The maximum value that we can move down on the y-axis */ |
Perijah | 0:ecc3925d3f8c | 47 | |
Perijah | 0:ecc3925d3f8c | 48 | enum MOUSE_TYPE |
Perijah | 0:ecc3925d3f8c | 49 | { |
Perijah | 0:ecc3925d3f8c | 50 | ABS_MOUSE, |
Perijah | 0:ecc3925d3f8c | 51 | REL_MOUSE, |
Perijah | 0:ecc3925d3f8c | 52 | }; |
Perijah | 0:ecc3925d3f8c | 53 | |
Perijah | 0:ecc3925d3f8c | 54 | /** |
Perijah | 0:ecc3925d3f8c | 55 | * |
Perijah | 0:ecc3925d3f8c | 56 | * USBMouse example |
Perijah | 0:ecc3925d3f8c | 57 | * @code |
Perijah | 0:ecc3925d3f8c | 58 | * #include "mbed.h" |
Perijah | 0:ecc3925d3f8c | 59 | * #include "USBMouse.h" |
Perijah | 0:ecc3925d3f8c | 60 | * |
Perijah | 0:ecc3925d3f8c | 61 | * USBMouse mouse; |
Perijah | 0:ecc3925d3f8c | 62 | * |
Perijah | 0:ecc3925d3f8c | 63 | * int main(void) |
Perijah | 0:ecc3925d3f8c | 64 | * { |
Perijah | 0:ecc3925d3f8c | 65 | * while (1) |
Perijah | 0:ecc3925d3f8c | 66 | * { |
Perijah | 0:ecc3925d3f8c | 67 | * mouse.move(20, 0); |
Perijah | 0:ecc3925d3f8c | 68 | * wait(0.5); |
Perijah | 0:ecc3925d3f8c | 69 | * } |
Perijah | 0:ecc3925d3f8c | 70 | * } |
Perijah | 0:ecc3925d3f8c | 71 | * |
Perijah | 0:ecc3925d3f8c | 72 | * @endcode |
Perijah | 0:ecc3925d3f8c | 73 | * |
Perijah | 0:ecc3925d3f8c | 74 | * |
Perijah | 0:ecc3925d3f8c | 75 | * @code |
Perijah | 0:ecc3925d3f8c | 76 | * #include "mbed.h" |
Perijah | 0:ecc3925d3f8c | 77 | * #include "USBMouse.h" |
Perijah | 0:ecc3925d3f8c | 78 | * #include <math.h> |
Perijah | 0:ecc3925d3f8c | 79 | * |
Perijah | 0:ecc3925d3f8c | 80 | * USBMouse mouse(ABS_MOUSE); |
Perijah | 0:ecc3925d3f8c | 81 | * |
Perijah | 0:ecc3925d3f8c | 82 | * int main(void) |
Perijah | 0:ecc3925d3f8c | 83 | * { |
Perijah | 0:ecc3925d3f8c | 84 | * uint16_t x_center = (X_MAX_ABS - X_MIN_ABS)/2; |
Perijah | 0:ecc3925d3f8c | 85 | * uint16_t y_center = (Y_MAX_ABS - Y_MIN_ABS)/2; |
Perijah | 0:ecc3925d3f8c | 86 | * uint16_t x_screen = 0; |
Perijah | 0:ecc3925d3f8c | 87 | * uint16_t y_screen = 0; |
Perijah | 0:ecc3925d3f8c | 88 | * |
Perijah | 0:ecc3925d3f8c | 89 | * uint32_t x_origin = x_center; |
Perijah | 0:ecc3925d3f8c | 90 | * uint32_t y_origin = y_center; |
Perijah | 0:ecc3925d3f8c | 91 | * uint32_t radius = 5000; |
Perijah | 0:ecc3925d3f8c | 92 | * uint32_t angle = 0; |
Perijah | 0:ecc3925d3f8c | 93 | * |
Perijah | 0:ecc3925d3f8c | 94 | * while (1) |
Perijah | 0:ecc3925d3f8c | 95 | * { |
Perijah | 0:ecc3925d3f8c | 96 | * x_screen = x_origin + cos((double)angle*3.14/180.0)*radius; |
Perijah | 0:ecc3925d3f8c | 97 | * y_screen = y_origin + sin((double)angle*3.14/180.0)*radius; |
Perijah | 0:ecc3925d3f8c | 98 | * |
Perijah | 0:ecc3925d3f8c | 99 | * mouse.move(x_screen, y_screen); |
Perijah | 0:ecc3925d3f8c | 100 | * angle += 3; |
Perijah | 0:ecc3925d3f8c | 101 | * wait(0.01); |
Perijah | 0:ecc3925d3f8c | 102 | * } |
Perijah | 0:ecc3925d3f8c | 103 | * } |
Perijah | 0:ecc3925d3f8c | 104 | * |
Perijah | 0:ecc3925d3f8c | 105 | * @endcode |
Perijah | 0:ecc3925d3f8c | 106 | */ |
Perijah | 0:ecc3925d3f8c | 107 | class USBMouse: public USBHID |
Perijah | 0:ecc3925d3f8c | 108 | { |
Perijah | 0:ecc3925d3f8c | 109 | public: |
Perijah | 0:ecc3925d3f8c | 110 | |
Perijah | 0:ecc3925d3f8c | 111 | /** |
Perijah | 0:ecc3925d3f8c | 112 | * Constructor |
Perijah | 0:ecc3925d3f8c | 113 | * |
Perijah | 0:ecc3925d3f8c | 114 | * @param mouse_type Mouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE) |
Perijah | 0:ecc3925d3f8c | 115 | * @param vendor_id Your vendor_id (default: 0x1234) |
Perijah | 0:ecc3925d3f8c | 116 | * @param product_id Your product_id (default: 0x0001) |
Perijah | 0:ecc3925d3f8c | 117 | * @param product_release Your preoduct_release (default: 0x0001) |
Perijah | 0:ecc3925d3f8c | 118 | * |
Perijah | 0:ecc3925d3f8c | 119 | */ |
Perijah | 0:ecc3925d3f8c | 120 | USBMouse(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0001, uint16_t product_release = 0x0001): |
Perijah | 0:ecc3925d3f8c | 121 | USBHID(0, 0, vendor_id, product_id, product_release, false) |
Perijah | 0:ecc3925d3f8c | 122 | { |
Perijah | 0:ecc3925d3f8c | 123 | button = 0; |
Perijah | 0:ecc3925d3f8c | 124 | this->mouse_type = mouse_type; |
Perijah | 0:ecc3925d3f8c | 125 | connect(); |
Perijah | 0:ecc3925d3f8c | 126 | }; |
Perijah | 0:ecc3925d3f8c | 127 | |
Perijah | 0:ecc3925d3f8c | 128 | /** |
Perijah | 0:ecc3925d3f8c | 129 | * Write a state of the mouse |
Perijah | 0:ecc3925d3f8c | 130 | * |
Perijah | 0:ecc3925d3f8c | 131 | * @param x x-axis position |
Perijah | 0:ecc3925d3f8c | 132 | * @param y y-axis position |
Perijah | 0:ecc3925d3f8c | 133 | * @param buttons buttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE) |
Perijah | 0:ecc3925d3f8c | 134 | * @param z wheel state (>0 to scroll down, <0 to scroll up) |
Perijah | 0:ecc3925d3f8c | 135 | * @returns true if there is no error, false otherwise |
Perijah | 0:ecc3925d3f8c | 136 | */ |
Perijah | 0:ecc3925d3f8c | 137 | bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z); |
Perijah | 0:ecc3925d3f8c | 138 | |
Perijah | 0:ecc3925d3f8c | 139 | |
Perijah | 0:ecc3925d3f8c | 140 | /** |
Perijah | 0:ecc3925d3f8c | 141 | * Move the cursor to (x, y) |
Perijah | 0:ecc3925d3f8c | 142 | * |
Perijah | 0:ecc3925d3f8c | 143 | * @param x-axis position |
Perijah | 0:ecc3925d3f8c | 144 | * @param y-axis position |
Perijah | 0:ecc3925d3f8c | 145 | * @returns true if there is no error, false otherwise |
Perijah | 0:ecc3925d3f8c | 146 | */ |
Perijah | 0:ecc3925d3f8c | 147 | bool move(int16_t x, int16_t y); |
Perijah | 0:ecc3925d3f8c | 148 | |
Perijah | 0:ecc3925d3f8c | 149 | /** |
Perijah | 0:ecc3925d3f8c | 150 | * Press one or several buttons |
Perijah | 0:ecc3925d3f8c | 151 | * |
Perijah | 0:ecc3925d3f8c | 152 | * @param button button state (ex: press(MOUSE_LEFT)) |
Perijah | 0:ecc3925d3f8c | 153 | * @returns true if there is no error, false otherwise |
Perijah | 0:ecc3925d3f8c | 154 | */ |
Perijah | 0:ecc3925d3f8c | 155 | bool press(uint8_t button); |
Perijah | 0:ecc3925d3f8c | 156 | |
Perijah | 0:ecc3925d3f8c | 157 | /** |
Perijah | 0:ecc3925d3f8c | 158 | * Release one or several buttons |
Perijah | 0:ecc3925d3f8c | 159 | * |
Perijah | 0:ecc3925d3f8c | 160 | * @param button button state (ex: release(MOUSE_LEFT)) |
Perijah | 0:ecc3925d3f8c | 161 | * @returns true if there is no error, false otherwise |
Perijah | 0:ecc3925d3f8c | 162 | */ |
Perijah | 0:ecc3925d3f8c | 163 | bool release(uint8_t button); |
Perijah | 0:ecc3925d3f8c | 164 | |
Perijah | 0:ecc3925d3f8c | 165 | /** |
Perijah | 0:ecc3925d3f8c | 166 | * Double click (MOUSE_LEFT) |
Perijah | 0:ecc3925d3f8c | 167 | * |
Perijah | 0:ecc3925d3f8c | 168 | * @returns true if there is no error, false otherwise |
Perijah | 0:ecc3925d3f8c | 169 | */ |
Perijah | 0:ecc3925d3f8c | 170 | bool doubleClick(); |
Perijah | 0:ecc3925d3f8c | 171 | |
Perijah | 0:ecc3925d3f8c | 172 | /** |
Perijah | 0:ecc3925d3f8c | 173 | * Click |
Perijah | 0:ecc3925d3f8c | 174 | * |
Perijah | 0:ecc3925d3f8c | 175 | * @param button state of the buttons ( ex: clic(MOUSE_LEFT)) |
Perijah | 0:ecc3925d3f8c | 176 | * @returns true if there is no error, false otherwise |
Perijah | 0:ecc3925d3f8c | 177 | */ |
Perijah | 0:ecc3925d3f8c | 178 | bool click(uint8_t button); |
Perijah | 0:ecc3925d3f8c | 179 | |
Perijah | 0:ecc3925d3f8c | 180 | /** |
Perijah | 0:ecc3925d3f8c | 181 | * Scrolling |
Perijah | 0:ecc3925d3f8c | 182 | * |
Perijah | 0:ecc3925d3f8c | 183 | * @param z value of the wheel (>0 to go down, <0 to go up) |
Perijah | 0:ecc3925d3f8c | 184 | * @returns true if there is no error, false otherwise |
Perijah | 0:ecc3925d3f8c | 185 | */ |
Perijah | 0:ecc3925d3f8c | 186 | bool scroll(int8_t z); |
Perijah | 0:ecc3925d3f8c | 187 | |
Perijah | 0:ecc3925d3f8c | 188 | /* |
Perijah | 0:ecc3925d3f8c | 189 | * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength. |
Perijah | 0:ecc3925d3f8c | 190 | * |
Perijah | 0:ecc3925d3f8c | 191 | * @returns pointer to the report descriptor |
Perijah | 0:ecc3925d3f8c | 192 | */ |
Perijah | 0:ecc3925d3f8c | 193 | virtual uint8_t * reportDesc(); |
Perijah | 0:ecc3925d3f8c | 194 | |
Perijah | 0:ecc3925d3f8c | 195 | protected: |
Perijah | 0:ecc3925d3f8c | 196 | /* |
Perijah | 0:ecc3925d3f8c | 197 | * Get configuration descriptor |
Perijah | 0:ecc3925d3f8c | 198 | * |
Perijah | 0:ecc3925d3f8c | 199 | * @returns pointer to the configuration descriptor |
Perijah | 0:ecc3925d3f8c | 200 | */ |
Perijah | 0:ecc3925d3f8c | 201 | virtual uint8_t * configurationDesc(); |
Perijah | 0:ecc3925d3f8c | 202 | |
Perijah | 0:ecc3925d3f8c | 203 | private: |
Perijah | 0:ecc3925d3f8c | 204 | MOUSE_TYPE mouse_type; |
Perijah | 0:ecc3925d3f8c | 205 | uint8_t button; |
Perijah | 0:ecc3925d3f8c | 206 | bool mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z); |
Perijah | 0:ecc3925d3f8c | 207 | }; |
Perijah | 0:ecc3925d3f8c | 208 | |
Perijah | 0:ecc3925d3f8c | 209 | #endif |