Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: RGA-MJPEG_VideoDemo
Fork of USBHost_custom by
USBHostHID/USBHostKeyboard.h
- Committer:
- samux
- Date:
- 2013-03-06
- Revision:
- 3:0f5c32575eb8
- Parent:
- 2:5e8fdc541b98
- Child:
- 4:b320d68e98e7
File content as of revision 3:0f5c32575eb8:
/* Copyright (c) 2010-2011 mbed.org, MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef USBHOSTKEYBOARD_H
#define USBHOSTKEYBOARD_H
#include "USBHostConf.h"
#if USBHOST_KEYBOARD
#include "USBHost.h"
/**
* A class to communicate a USB keyboard
*/
class USBHostKeyboard : public IUSBEnumerator {
public:
/**
* Constructor
*/
USBHostKeyboard();
/**
* Try to connect a keyboard device
*
* @return true if connection was successful
*/
bool connect();
/**
* Check if a keyboard is connected
*
* @returns true if a keyboard is connected
*/
bool connected();
/**
* Attach a callback called when a keyboard event is received
*
* @param ptr function pointer
*/
inline void attach(void (*ptr)(uint8_t key)) {
if (ptr != NULL) {
onKey = ptr;
}
}
/**
* Attach a callback called when a keyboard event is received
*
* @param ptr function pointer
*/
inline void attach(void (*ptr)(uint8_t keyCode, uint8_t modifier)) {
if (ptr != NULL) {
onKeyCode = ptr;
}
}
protected:
//From IUSBEnumerator
virtual void setVidPid(uint16_t vid, uint16_t pid);
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
virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
private:
USBHost * host;
USBDeviceConnected * dev;
USBEndpoint * int_in;
uint8_t report[9];
int keyboard_intf;
bool keyboard_device_found;
bool dev_connected;
void rxHandler();
void (*onKey)(uint8_t key);
void (*onKeyCode)(uint8_t key, uint8_t modifier);
int report_id;
void init();
};
#endif
#endif
