Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ChaNFSSD mbed ChaNFS
USBMouse.h
00001 /* USBMouse.h */ 00002 /* USB device example: relative mouse */ 00003 /* Copyright (c) 2011 ARM Limited. All rights reserved. */ 00004 00005 #ifndef USBMOUSE_H 00006 #define USBMOUSE_H 00007 00008 #include "USBHID.h" 00009 00010 #define REPORT_ID_MOUSE 2 00011 00012 /* Common usage */ 00013 00014 enum MOUSE_BUTTON 00015 { 00016 MOUSE_LEFT = 1, 00017 MOUSE_RIGHT = 2, 00018 MOUSE_MIDDLE = 4, 00019 }; 00020 00021 /* X and Y limits */ 00022 /* These values do not directly map to screen pixels */ 00023 /* Zero may be interpreted as meaning 'no movement' */ 00024 #define X_MIN_ABS (1) /*!< Minimum value on x-axis */ 00025 #define Y_MIN_ABS (1) /*!< Minimum value on y-axis */ 00026 #define X_MAX_ABS (0x7fff) /*!< Maximum value on x-axis */ 00027 #define Y_MAX_ABS (0x7fff) /*!< Maximum value on y-axis */ 00028 00029 #define X_MIN_REL (-127) /*!< The maximum value that we can move to the left on the x-axis */ 00030 #define Y_MIN_REL (-127) /*!< The maximum value that we can move up on the y-axis */ 00031 #define X_MAX_REL (127) /*!< The maximum value that we can move to the right on the x-axis */ 00032 #define Y_MAX_REL (127) /*!< The maximum value that we can move down on the y-axis */ 00033 00034 enum MOUSE_TYPE 00035 { 00036 ABS_MOUSE, 00037 REL_MOUSE, 00038 }; 00039 00040 /** 00041 * 00042 * USBMouse example 00043 * @code 00044 * #include "mbed.h" 00045 * #include "USBMouse.h" 00046 * 00047 * USBMouse mouse; 00048 * 00049 * int main(void) 00050 * { 00051 * while (1) 00052 * { 00053 * mouse.move(20, 0); 00054 * wait(0.5); 00055 * } 00056 * } 00057 * 00058 * @endcode 00059 * 00060 * 00061 * @code 00062 * #include "mbed.h" 00063 * #include "USBMouse.h" 00064 * #include <math.h> 00065 * 00066 * USBMouse mouse(ABS_MOUSE); 00067 * 00068 * int main(void) 00069 * { 00070 * uint16_t x_center = (X_MAX_ABS - X_MIN_ABS)/2; 00071 * uint16_t y_center = (Y_MAX_ABS - Y_MIN_ABS)/2; 00072 * uint16_t x_screen = 0; 00073 * uint16_t y_screen = 0; 00074 * 00075 * uint32_t x_origin = x_center; 00076 * uint32_t y_origin = y_center; 00077 * uint32_t radius = 5000; 00078 * uint32_t angle = 0; 00079 * 00080 * while (1) 00081 * { 00082 * x_screen = x_origin + cos((double)angle*3.14/180.0)*radius; 00083 * y_screen = y_origin + sin((double)angle*3.14/180.0)*radius; 00084 * 00085 * mouse.move(x_screen, y_screen); 00086 * angle += 3; 00087 * wait(0.01); 00088 * } 00089 * } 00090 * 00091 * @endcode 00092 */ 00093 class USBMouse: public USBHID 00094 { 00095 public: 00096 00097 /** 00098 * Constructor 00099 * 00100 * @param mouse_type Mouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE) 00101 * @param vendor_id Your vendor_id (default: 0x1234) 00102 * @param product_id Your product_id (default: 0x0001) 00103 * @param product_release Your preoduct_release (default: 0x0001) 00104 * 00105 */ 00106 USBMouse(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0001, uint16_t product_release = 0x0001): 00107 USBHID(0, 0, vendor_id, product_id, product_release, false) 00108 { 00109 button = 0; 00110 this->mouse_type = mouse_type; 00111 connect(); 00112 }; 00113 00114 /** 00115 * Write a state of the mouse 00116 * 00117 * @param x x-axis position 00118 * @param y y-axis position 00119 * @param buttons buttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE) 00120 * @param z wheel state (>0 to scroll down, <0 to scroll up) 00121 * @returns true if there is no error, false otherwise 00122 */ 00123 bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z); 00124 00125 00126 /** 00127 * Move the cursor to (x, y) 00128 * 00129 * @param x-axis position 00130 * @param y-axis position 00131 * @returns true if there is no error, false otherwise 00132 */ 00133 bool move(int16_t x, int16_t y); 00134 00135 /** 00136 * Press one or several buttons 00137 * 00138 * @param button button state (ex: press(MOUSE_LEFT)) 00139 * @returns true if there is no error, false otherwise 00140 */ 00141 bool press(uint8_t button); 00142 00143 /** 00144 * Release one or several buttons 00145 * 00146 * @param button button state (ex: release(MOUSE_LEFT)) 00147 * @returns true if there is no error, false otherwise 00148 */ 00149 bool release(uint8_t button); 00150 00151 /** 00152 * Double click (MOUSE_LEFT) 00153 * 00154 * @returns true if there is no error, false otherwise 00155 */ 00156 bool doubleClick(); 00157 00158 /** 00159 * Click 00160 * 00161 * @param button state of the buttons ( ex: clic(MOUSE_LEFT)) 00162 * @returns true if there is no error, false otherwise 00163 */ 00164 bool click(uint8_t button); 00165 00166 /** 00167 * Scrolling 00168 * 00169 * @param z value of the wheel (>0 to go down, <0 to go up) 00170 * @returns true if there is no error, false otherwise 00171 */ 00172 bool scroll(int8_t z); 00173 00174 /* 00175 * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength. 00176 * 00177 * @returns pointer to the report descriptor 00178 */ 00179 virtual uint8_t * reportDesc(); 00180 00181 private: 00182 MOUSE_TYPE mouse_type; 00183 uint8_t button; 00184 bool mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z); 00185 }; 00186 00187 #endif
Generated on Wed Jul 13 2022 11:42:57 by
