xref: /haiku/src/add-ons/kernel/drivers/input/hid_shared/HIDReport.h (revision 1deede7388b04dbeec5af85cae7164735ea9e70d)
1 /*
2  * Copyright 2009, Michael Lotz, mmlr@mlotz.ch.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef HID_REPORT_H
6 #define HID_REPORT_H
7 
8 #include "HIDParser.h"
9 
10 #ifndef USERLAND_HID
11 #include <condition_variable.h>
12 #endif
13 
14 #define HID_REPORT_TYPE_INPUT		0x01
15 #define HID_REPORT_TYPE_OUTPUT		0x02
16 #define HID_REPORT_TYPE_FEATURE		0x04
17 #define HID_REPORT_TYPE_ANY			0x07
18 
19 class HIDCollection;
20 class HIDReportItem;
21 
22 class HIDReport {
23 public:
24 								HIDReport(HIDParser *parser, uint8 type,
25 									uint8 id);
26 								~HIDReport();
27 
28 		uint8					Type() { return fType; };
29 		uint8					ID() { return fReportID; };
30 		size_t					ReportSize() { return (fReportSize + 7) / 8; };
31 
32 		HIDParser *				Parser() { return fParser; };
33 		HIDDevice *				Device() { return fParser->Device(); };
34 
35 		void					AddMainItem(global_item_state &globalState,
36 									local_item_state &localState,
37 									main_item_data &mainData,
38 									HIDCollection *collection);
39 
40 		void					SetReport(status_t status, uint8 *report,
41 									size_t length);
42 		uint8 *					CurrentReport() { return fCurrentReport; };
43 
44 #ifndef USERLAND_HID
45 		status_t				SendReport();
46 #endif
47 
48 		uint32					CountItems() { return fItemsUsed; };
49 		HIDReportItem *			ItemAt(uint32 index);
50 		HIDReportItem *			FindItem(uint16 usagePage, uint16 usageID);
51 
52 #ifndef USERLAND_HID
53 		status_t				WaitForReport(bigtime_t timeout);
54 		void					DoneProcessing();
55 #endif
56 
57 		void					PrintToStream();
58 
59 private:
60 		void					_SignExtend(uint32 &minimum, uint32 &maximum);
61 
62 		HIDParser *				fParser;
63 
64 		uint8					fType;
65 		uint8					fReportID;
66 		uint32					fReportSize;
67 
68 		uint32					fItemsUsed;
69 		uint32					fItemsAllocated;
70 		HIDReportItem **		fItems;
71 
72 		status_t				fReportStatus;
73 		uint8 *					fCurrentReport;
74 		int32					fBusyCount;
75 
76 #ifndef USERLAND_HID
77 		ConditionVariable		fConditionVariable;
78 #endif
79 };
80 
81 #endif // HID_REPORT_H
82