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