@@ -95,6 +95,12 @@ int HID_::SendReport(uint8_t id, const void* data, int len)
95
95
return ret + ret2;
96
96
}
97
97
98
+ int HID_::RegisterReportReceiver (uint8_t id, void (*reportReceiver)(const void *data, int len))
99
+ {
100
+ this ->receiverId = id;
101
+ this ->reportReceiver = reportReceiver;
102
+ }
103
+
98
104
bool HID_::setup (USBSetup& setup)
99
105
{
100
106
if (pluggedInterface != setup.wIndex ) {
@@ -133,13 +139,23 @@ bool HID_::setup(USBSetup& setup)
133
139
}
134
140
if (request == HID_SET_REPORT)
135
141
{
136
- // uint8_t reportID = setup.wValueL;
137
- // uint16_t length = setup.wLength;
138
- // uint8_t data[length];
142
+ if (this ->reportReceiver == NULL )
143
+ {
144
+ return false ;
145
+ }
146
+ uint8_t reportID = setup.wValueL ;
147
+ uint16_t length = setup.wLength ;
148
+ uint8_t data[16 ];
139
149
// Make sure to not read more data than USB_EP_SIZE.
140
150
// You can read multiple times through a loop.
141
151
// The first byte (may!) contain the reportID on a multreport.
142
- // USB_RecvControl(data, length);
152
+ int numRead = USB_RecvControl (data, length);
153
+ if (numRead < 1 || data[0 ] != this ->receiverId )
154
+ {
155
+ return false ;
156
+ }
157
+
158
+ (*this ->reportReceiver )(data + 1 , length - 1 );
143
159
}
144
160
}
145
161
@@ -148,7 +164,8 @@ bool HID_::setup(USBSetup& setup)
148
164
149
165
HID_::HID_ (void ) : PluggableUSBModule(1 , 1 , epType),
150
166
rootNode(NULL ), descriptorSize(0 ),
151
- protocol(HID_REPORT_PROTOCOL), idle(1 )
167
+ protocol(HID_REPORT_PROTOCOL), idle(1 ),
168
+ receiverId(0 ), reportReceiver(NULL )
152
169
{
153
170
epType[0 ] = EP_TYPE_INTERRUPT_IN;
154
171
PluggableUSB ().plug (this );
0 commit comments