dhgdh

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by joey shelton

Committer:
cyberjoey
Date:
Sat Oct 22 01:31:58 2016 +0000
Revision:
9:6bb35cef007d
Parent:
1:55a6170b404f
WORKING

Who changed what in which revision?

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