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