Simple USBHost library for Nucleo F446RE/F411RE/F401RE FRDM-KL46Z/KL25Z/F64F LPC4088/LPC1768

Dependencies:   FATFileSystem

Dependents:   F401RE-BTstack_example F401RE-USBHostMSD_HelloWorld

Fork of KL46Z-USBHost by Norimasa Okamoto

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBHostMouse.h Source File

USBHostMouse.h

00001 /* mbed USBHost Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef USBHOSTMOUSE_H
00018 #define USBHOSTMOUSE_H
00019 
00020 #include "USBHostConf.h"
00021 
00022 #if USBHOST_MOUSE
00023 
00024 #include "USBHost.h"
00025 
00026 /** 
00027  * A class to communicate a USB mouse
00028  */
00029 class USBHostMouse : public IUSBEnumerator {
00030 public:
00031 
00032     /**
00033     * Constructor
00034     */
00035     USBHostMouse();
00036 
00037     /**
00038      * Try to connect a mouse device
00039      *
00040      * @return true if connection was successful
00041      */
00042     bool connect();
00043 
00044     /**
00045     * Check if a mouse is connected
00046     *
00047     * @returns true if a mouse is connected
00048     */
00049     bool connected();
00050 
00051     /**
00052      * Attach a callback called when a mouse event is received
00053      *
00054      * @param ptr function pointer
00055      */
00056     inline void attachEvent(void (*ptr)(uint8_t buttons, int8_t x, int8_t y, int8_t z)) {
00057         if (ptr != NULL) {
00058             onUpdate = ptr;
00059         }
00060     }
00061     
00062     /**
00063      * Attach a callback called when the button state changes
00064      *
00065      * @param ptr function pointer
00066      */
00067     inline void attachButtonEvent(void (*ptr)(uint8_t buttons)) {
00068         if (ptr != NULL) {
00069             onButtonUpdate = ptr;
00070         }
00071     }
00072     
00073     /**
00074      * Attach a callback called when the X axis value changes
00075      *
00076      * @param ptr function pointer
00077      */
00078     inline void attachXEvent(void (*ptr)(int8_t x)) {
00079         if (ptr != NULL) {
00080             onXUpdate = ptr;
00081         }
00082     }
00083     
00084     /**
00085      * Attach a callback called when the Y axis value changes
00086      *
00087      * @param ptr function pointer
00088      */
00089     inline void attachYEvent(void (*ptr)(int8_t y)) {
00090         if (ptr != NULL) {
00091             onYUpdate = ptr;
00092         }
00093     }
00094     
00095     /**
00096      * Attach a callback called when the Z axis value changes (scrolling)
00097      *
00098      * @param ptr function pointer
00099      */
00100     inline void attachZEvent(void (*ptr)(int8_t z)) {
00101         if (ptr != NULL) {
00102             onZUpdate = ptr;
00103         }
00104     }
00105 
00106 protected:
00107     //From IUSBEnumerator
00108     virtual void setVidPid(uint16_t vid, uint16_t pid);
00109     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
00110     virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
00111 
00112 private:
00113     USBHost * host;
00114     USBDeviceConnected * dev;
00115     USBEndpoint * int_in;
00116     uint8_t report[4];
00117     
00118     bool dev_connected;
00119     bool mouse_device_found;
00120     int mouse_intf;
00121 
00122     uint8_t buttons;
00123     int8_t x;
00124     int8_t y;
00125     int8_t z;
00126 
00127     void rxHandler();
00128     void (*onUpdate)(uint8_t buttons, int8_t x, int8_t y, int8_t z);
00129     void (*onButtonUpdate)(uint8_t buttons);
00130     void (*onXUpdate)(int8_t x);
00131     void (*onYUpdate)(int8_t y);
00132     void (*onZUpdate)(int8_t z);
00133     int report_id;
00134     void init();
00135 };
00136 
00137 #endif
00138 
00139 #endif