1/* 2 * Copyright 2008-2011 Michael Lotz <mmlr@mlotz.ch> 3 * Distributed under the terms of the MIT license. 4 */ 5#ifndef USB_KEYBOARD_PROTOCOL_HANDLER_H 6#define USB_KEYBOARD_PROTOCOL_HANDLER_H 7 8 9#include "ProtocolHandler.h" 10 11#include <lock.h> 12 13 14class HIDReportItem; 15class HIDCollection; 16 17 18#define MAX_MODIFIERS 16 19#define MAX_KEYS 128 20#define MAX_LEDS 3 21 22 23class KeyboardProtocolHandler : public ProtocolHandler { 24public: 25 KeyboardProtocolHandler(HIDReport &inputReport, 26 HIDReport *outputReport); 27 virtual ~KeyboardProtocolHandler(); 28 29 static void AddHandlers(HIDDevice &device, 30 HIDCollection &collection, 31 ProtocolHandler *&handlerList); 32 33 virtual status_t Open(uint32 flags, uint32 *cookie); 34 virtual status_t Close(uint32 *cookie); 35 36 virtual status_t Control(uint32 *cookie, uint32 op, void *buffer, 37 size_t length); 38 39private: 40 void _WriteKey(uint32 key, bool down); 41 status_t _SetLEDs(uint8 *data); 42 status_t _ReadReport(bigtime_t timeout, uint32 *cookie); 43 44private: 45 mutex fLock; 46 47 HIDReport & fInputReport; 48 HIDReport * fOutputReport; 49 50 HIDReportItem * fModifiers[MAX_MODIFIERS]; 51 HIDReportItem * fKeys[MAX_KEYS]; 52 HIDReportItem * fLEDs[MAX_LEDS]; 53 54 bigtime_t fRepeatDelay; 55 bigtime_t fRepeatRate; 56 bigtime_t fCurrentRepeatDelay; 57 uint32 fCurrentRepeatKey; 58 59 uint32 fKeyCount; 60 uint32 fModifierCount; 61 62 uint8 fLastModifiers; 63 uint16 * fCurrentKeys; 64 uint16 * fLastKeys; 65 66 int32 fHasReader; 67 bool fHasDebugReader; 68}; 69 70 71#endif // USB_KEYBOARD_PROTOCOL_HANDLER_H 72