mbed-os
Fork of mbed-os by
features/unsupported/USBHost/USBHostHID/USBHostMouse.h@1:3deb71413561, 2017-07-20 (annotated)
- Committer:
- xuaner
- Date:
- Thu Jul 20 14:26:57 2017 +0000
- Revision:
- 1:3deb71413561
- Parent:
- 0:f269e3021894
mbed_os
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:f269e3021894 | 1 | /* mbed USBHost Library |
elessair | 0:f269e3021894 | 2 | * Copyright (c) 2006-2013 ARM Limited |
elessair | 0:f269e3021894 | 3 | * |
elessair | 0:f269e3021894 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
elessair | 0:f269e3021894 | 5 | * you may not use this file except in compliance with the License. |
elessair | 0:f269e3021894 | 6 | * You may obtain a copy of the License at |
elessair | 0:f269e3021894 | 7 | * |
elessair | 0:f269e3021894 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
elessair | 0:f269e3021894 | 9 | * |
elessair | 0:f269e3021894 | 10 | * Unless required by applicable law or agreed to in writing, software |
elessair | 0:f269e3021894 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
elessair | 0:f269e3021894 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
elessair | 0:f269e3021894 | 13 | * See the License for the specific language governing permissions and |
elessair | 0:f269e3021894 | 14 | * limitations under the License. |
elessair | 0:f269e3021894 | 15 | */ |
elessair | 0:f269e3021894 | 16 | |
elessair | 0:f269e3021894 | 17 | #ifndef USBHOSTMOUSE_H |
elessair | 0:f269e3021894 | 18 | #define USBHOSTMOUSE_H |
elessair | 0:f269e3021894 | 19 | |
elessair | 0:f269e3021894 | 20 | #include "USBHostConf.h" |
elessair | 0:f269e3021894 | 21 | |
elessair | 0:f269e3021894 | 22 | #if USBHOST_MOUSE |
elessair | 0:f269e3021894 | 23 | |
elessair | 0:f269e3021894 | 24 | #include "USBHost.h" |
elessair | 0:f269e3021894 | 25 | |
elessair | 0:f269e3021894 | 26 | /** |
elessair | 0:f269e3021894 | 27 | * A class to communicate a USB mouse |
elessair | 0:f269e3021894 | 28 | */ |
elessair | 0:f269e3021894 | 29 | class USBHostMouse : public IUSBEnumerator { |
elessair | 0:f269e3021894 | 30 | public: |
elessair | 0:f269e3021894 | 31 | |
elessair | 0:f269e3021894 | 32 | /** |
elessair | 0:f269e3021894 | 33 | * Constructor |
elessair | 0:f269e3021894 | 34 | */ |
elessair | 0:f269e3021894 | 35 | USBHostMouse(); |
elessair | 0:f269e3021894 | 36 | |
elessair | 0:f269e3021894 | 37 | /** |
elessair | 0:f269e3021894 | 38 | * Try to connect a mouse device |
elessair | 0:f269e3021894 | 39 | * |
elessair | 0:f269e3021894 | 40 | * @return true if connection was successful |
elessair | 0:f269e3021894 | 41 | */ |
elessair | 0:f269e3021894 | 42 | bool connect(); |
elessair | 0:f269e3021894 | 43 | |
elessair | 0:f269e3021894 | 44 | /** |
elessair | 0:f269e3021894 | 45 | * Check if a mouse is connected |
elessair | 0:f269e3021894 | 46 | * |
elessair | 0:f269e3021894 | 47 | * @returns true if a mouse is connected |
elessair | 0:f269e3021894 | 48 | */ |
elessair | 0:f269e3021894 | 49 | bool connected(); |
elessair | 0:f269e3021894 | 50 | |
elessair | 0:f269e3021894 | 51 | /** |
elessair | 0:f269e3021894 | 52 | * Attach a callback called when a mouse event is received |
elessair | 0:f269e3021894 | 53 | * |
elessair | 0:f269e3021894 | 54 | * @param ptr function pointer |
elessair | 0:f269e3021894 | 55 | */ |
elessair | 0:f269e3021894 | 56 | inline void attachEvent(void (*ptr)(uint8_t buttons, int8_t x, int8_t y, int8_t z)) { |
elessair | 0:f269e3021894 | 57 | if (ptr != NULL) { |
elessair | 0:f269e3021894 | 58 | onUpdate = ptr; |
elessair | 0:f269e3021894 | 59 | } |
elessair | 0:f269e3021894 | 60 | } |
elessair | 0:f269e3021894 | 61 | |
elessair | 0:f269e3021894 | 62 | /** |
elessair | 0:f269e3021894 | 63 | * Attach a callback called when the button state changes |
elessair | 0:f269e3021894 | 64 | * |
elessair | 0:f269e3021894 | 65 | * @param ptr function pointer |
elessair | 0:f269e3021894 | 66 | */ |
elessair | 0:f269e3021894 | 67 | inline void attachButtonEvent(void (*ptr)(uint8_t buttons)) { |
elessair | 0:f269e3021894 | 68 | if (ptr != NULL) { |
elessair | 0:f269e3021894 | 69 | onButtonUpdate = ptr; |
elessair | 0:f269e3021894 | 70 | } |
elessair | 0:f269e3021894 | 71 | } |
elessair | 0:f269e3021894 | 72 | |
elessair | 0:f269e3021894 | 73 | /** |
elessair | 0:f269e3021894 | 74 | * Attach a callback called when the X axis value changes |
elessair | 0:f269e3021894 | 75 | * |
elessair | 0:f269e3021894 | 76 | * @param ptr function pointer |
elessair | 0:f269e3021894 | 77 | */ |
elessair | 0:f269e3021894 | 78 | inline void attachXEvent(void (*ptr)(int8_t x)) { |
elessair | 0:f269e3021894 | 79 | if (ptr != NULL) { |
elessair | 0:f269e3021894 | 80 | onXUpdate = ptr; |
elessair | 0:f269e3021894 | 81 | } |
elessair | 0:f269e3021894 | 82 | } |
elessair | 0:f269e3021894 | 83 | |
elessair | 0:f269e3021894 | 84 | /** |
elessair | 0:f269e3021894 | 85 | * Attach a callback called when the Y axis value changes |
elessair | 0:f269e3021894 | 86 | * |
elessair | 0:f269e3021894 | 87 | * @param ptr function pointer |
elessair | 0:f269e3021894 | 88 | */ |
elessair | 0:f269e3021894 | 89 | inline void attachYEvent(void (*ptr)(int8_t y)) { |
elessair | 0:f269e3021894 | 90 | if (ptr != NULL) { |
elessair | 0:f269e3021894 | 91 | onYUpdate = ptr; |
elessair | 0:f269e3021894 | 92 | } |
elessair | 0:f269e3021894 | 93 | } |
elessair | 0:f269e3021894 | 94 | |
elessair | 0:f269e3021894 | 95 | /** |
elessair | 0:f269e3021894 | 96 | * Attach a callback called when the Z axis value changes (scrolling) |
elessair | 0:f269e3021894 | 97 | * |
elessair | 0:f269e3021894 | 98 | * @param ptr function pointer |
elessair | 0:f269e3021894 | 99 | */ |
elessair | 0:f269e3021894 | 100 | inline void attachZEvent(void (*ptr)(int8_t z)) { |
elessair | 0:f269e3021894 | 101 | if (ptr != NULL) { |
elessair | 0:f269e3021894 | 102 | onZUpdate = ptr; |
elessair | 0:f269e3021894 | 103 | } |
elessair | 0:f269e3021894 | 104 | } |
elessair | 0:f269e3021894 | 105 | |
elessair | 0:f269e3021894 | 106 | protected: |
elessair | 0:f269e3021894 | 107 | //From IUSBEnumerator |
elessair | 0:f269e3021894 | 108 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
elessair | 0:f269e3021894 | 109 | virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed |
elessair | 0:f269e3021894 | 110 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used |
elessair | 0:f269e3021894 | 111 | |
elessair | 0:f269e3021894 | 112 | private: |
elessair | 0:f269e3021894 | 113 | USBHost * host; |
elessair | 0:f269e3021894 | 114 | USBDeviceConnected * dev; |
elessair | 0:f269e3021894 | 115 | USBEndpoint * int_in; |
elessair | 0:f269e3021894 | 116 | uint8_t report[4]; |
elessair | 0:f269e3021894 | 117 | |
elessair | 0:f269e3021894 | 118 | bool dev_connected; |
elessair | 0:f269e3021894 | 119 | bool mouse_device_found; |
elessair | 0:f269e3021894 | 120 | int mouse_intf; |
elessair | 0:f269e3021894 | 121 | |
elessair | 0:f269e3021894 | 122 | uint8_t buttons; |
elessair | 0:f269e3021894 | 123 | int8_t x; |
elessair | 0:f269e3021894 | 124 | int8_t y; |
elessair | 0:f269e3021894 | 125 | int8_t z; |
elessair | 0:f269e3021894 | 126 | |
elessair | 0:f269e3021894 | 127 | void rxHandler(); |
elessair | 0:f269e3021894 | 128 | void (*onUpdate)(uint8_t buttons, int8_t x, int8_t y, int8_t z); |
elessair | 0:f269e3021894 | 129 | void (*onButtonUpdate)(uint8_t buttons); |
elessair | 0:f269e3021894 | 130 | void (*onXUpdate)(int8_t x); |
elessair | 0:f269e3021894 | 131 | void (*onYUpdate)(int8_t y); |
elessair | 0:f269e3021894 | 132 | void (*onZUpdate)(int8_t z); |
elessair | 0:f269e3021894 | 133 | int report_id; |
elessair | 0:f269e3021894 | 134 | void init(); |
elessair | 0:f269e3021894 | 135 | }; |
elessair | 0:f269e3021894 | 136 | |
elessair | 0:f269e3021894 | 137 | #endif |
elessair | 0:f269e3021894 | 138 | |
elessair | 0:f269e3021894 | 139 | #endif |