Fixing issues with library dependencies

Dependencies:   FATFileSystem mbed-rtos

Fork of USBHost by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBHostKeyboard.h Source File

USBHostKeyboard.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 USBHOSTKEYBOARD_H
00018 #define USBHOSTKEYBOARD_H
00019 
00020 #include "USBHostConf.h"
00021 
00022 #if USBHOST_KEYBOARD
00023 
00024 #include "USBHost.h"
00025 
00026 /**
00027  * A class to communicate a USB keyboard
00028  */
00029 class USBHostKeyboard : public IUSBEnumerator {
00030 public:
00031 
00032     /**
00033     * Constructor
00034     */
00035     USBHostKeyboard();
00036 
00037     /**
00038      * Try to connect a keyboard device
00039      *
00040      * @return true if connection was successful
00041      */
00042     bool connect();
00043 
00044     /**
00045     * Check if a keyboard is connected
00046     *
00047     * @returns true if a keyboard is connected
00048     */
00049     bool connected();
00050 
00051     /**
00052      * Attach a callback called when a keyboard event is received
00053      *
00054      * @param ptr function pointer
00055      */
00056     inline void attach(void (*ptr)(uint8_t key)) {
00057         if (ptr != NULL) {
00058             onKey = ptr;
00059         }
00060     }
00061 
00062     /**
00063      * Attach a callback called when a keyboard event is received
00064      *
00065      * @param ptr function pointer
00066      */
00067     inline void attach(void (*ptr)(uint8_t keyCode, uint8_t modifier)) {
00068         if (ptr != NULL) {
00069             onKeyCode = ptr;
00070         }
00071     }
00072 
00073 protected:
00074     //From IUSBEnumerator
00075     virtual void setVidPid(uint16_t vid, uint16_t pid);
00076     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
00077     virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
00078 
00079 private:
00080     USBHost * host;
00081     USBDeviceConnected * dev;
00082     USBEndpoint * int_in;
00083     uint8_t report[9];
00084     int keyboard_intf;
00085     bool keyboard_device_found;
00086 
00087     bool dev_connected;
00088 
00089     void rxHandler();
00090 
00091     void (*onKey)(uint8_t key);
00092     void (*onKeyCode)(uint8_t key, uint8_t modifier);
00093 
00094     int report_id;
00095 
00096     void init();
00097 
00098 };
00099 
00100 #endif
00101 
00102 #endif