1 /* 2 * Copyright 2011, Michael Lotz, mmlr@mlotz.ch. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef HID_WRITER_H 6 #define HID_WRITER_H 7 8 #include "HIDDataTypes.h" 9 10 11 class HIDWriter { 12 public: 13 HIDWriter(size_t blockSize = 20); 14 ~HIDWriter(); 15 16 // High Level 17 18 status_t DefineInputPadding(uint8 count, 19 uint8 bitLength); 20 status_t DefineInputData(uint8 count, uint8 bitLength, 21 main_item_data data, uint32 logicalMinimum, 22 uint32 logicalMaximum, uint16 usagePage, 23 uint16 usageMinimum, 24 uint16 usageMaximum = 0xffff); 25 26 status_t BeginCollection(uint8 collectionType, 27 uint16 usagePage, uint16 usageID); 28 status_t EndCollection(); 29 30 // Low Level 31 32 status_t SetUsagePage(uint16 usagePage); 33 status_t SetLogicalMinimum(uint32 logicalMinimum); 34 status_t SetLogicalMaximum(uint32 logicalMaximum); 35 status_t SetReportSize(uint8 reportSize); 36 status_t SetReportID(uint8 reportID); 37 status_t SetReportCount(uint8 reportCount); 38 39 status_t LocalSetUsageID(uint16 usageID); 40 status_t LocalSetUsageMinimum(uint16 usageMinimum); 41 status_t LocalSetUsageMaximum(uint16 usageMaximum); 42 43 status_t BeginCollection(uint8 collectionType); 44 45 status_t Input(main_item_data data); 46 status_t Output(main_item_data data); 47 status_t Feature(main_item_data data); 48 49 // Generic 50 51 status_t WriteShortItem(uint8 type, uint8 tag, 52 uint32 value); 53 status_t Write(const void *data, size_t length); 54 BufferLength()55 size_t BufferLength() { return fBufferUsed; }; Buffer()56 const uint8 * Buffer() { return fBuffer; }; 57 58 void Reset(); 59 60 private: 61 size_t fBlockSize; 62 size_t fBufferAllocated; 63 size_t fBufferUsed; 64 uint8 * fBuffer; 65 status_t fStatus; 66 }; 67 68 #endif // HID_WRITER_H 69