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