handle resending failed HID reports
This commit is contained in:
+30
-6
@@ -19,6 +19,7 @@ uint8_t num_mounted=0;
|
||||
static absolute_time_t request_time;
|
||||
static bool enabled=false;
|
||||
static uint8_t kb_addr=0;
|
||||
static struct hid_report last_report;
|
||||
|
||||
static void usb_host_init(void);
|
||||
static void host_ready(void);
|
||||
@@ -79,6 +80,22 @@ void usb_host_main(void) {
|
||||
if (enabled) {
|
||||
rgb_task(kb_addr);
|
||||
}
|
||||
|
||||
if (last_report.len > 0 ) {
|
||||
// previous report was not forwarded, resend
|
||||
if ( forward_report(last_report.instance, last_report.report, last_report.len) ) {
|
||||
// clear queue
|
||||
last_report.len = 0;
|
||||
memset(last_report.report, 0x00, REPORT_MAX_SIZE);
|
||||
|
||||
// continue requesting reports
|
||||
if ( !tuh_hid_receive_report(last_report.dev_addr, last_report.instance) ) {
|
||||
tud_cdc_write_str("Error: cannot request report\r\n");
|
||||
}
|
||||
} else {
|
||||
tud_cdc_write_str("Error: failed resend report\r\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -142,12 +159,19 @@ void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t cons
|
||||
cdc_print_hex(report, len);
|
||||
}
|
||||
|
||||
forward_report(instance, report, len);
|
||||
|
||||
// continue to request to receive report
|
||||
if ( !tuh_hid_receive_report(dev_addr, instance) )
|
||||
{
|
||||
tud_cdc_write_str("Error: cannot request report\r\n");
|
||||
// forward report to device output
|
||||
if ( !forward_report(instance, report, len) ) {
|
||||
tud_cdc_write_str("Error: cannot forward report\r\n");
|
||||
// queue report for resending
|
||||
last_report.dev_addr = dev_addr;
|
||||
last_report.instance = instance;
|
||||
last_report.len = len;
|
||||
memcpy(last_report.report, report, len);
|
||||
} else {
|
||||
// continue to request to receive report
|
||||
if ( !tuh_hid_receive_report(dev_addr, instance) ) {
|
||||
tud_cdc_write_str("Error: cannot request report\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user