suppress hid events from host when device is disconnected
This commit is contained in:
@@ -360,6 +360,7 @@ void startADC() {
|
||||
|
||||
// forward HID report after processing
|
||||
bool forward_report(uint8_t instance, uint8_t const* report, uint16_t len) {
|
||||
if (device_state == DEVICE_ACTIVE ) {
|
||||
if (instance == 0x01 && report[0] == 0x03 && report[1] == 0xE2) {
|
||||
mute = !mute;
|
||||
}
|
||||
@@ -367,6 +368,9 @@ bool forward_report(uint8_t instance, uint8_t const* report, uint16_t len) {
|
||||
return tud_hid_n_report(instance, 0, report, len);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// save RGB configuration to flash
|
||||
void save_rgb_config(void) {
|
||||
// set save signature and number of bytes to be written into config
|
||||
|
||||
+10
-8
@@ -75,19 +75,17 @@ void usb_device_main(void) {
|
||||
while (true) {
|
||||
switch ( device_state ) {
|
||||
case DEVICE_ACTIVE:
|
||||
if (!tud_mounted()) {
|
||||
device_state = DEVICE_INACTIVE;
|
||||
}
|
||||
break;
|
||||
case DEVICE_INACTIVE:
|
||||
break;
|
||||
case DEVICE_RESTART:
|
||||
if (tud_disconnect()) {
|
||||
sleep_ms(10);
|
||||
if (tud_connect()) {
|
||||
if ( host_state == HOST_INACTIVE ) {
|
||||
device_state = DEVICE_INACTIVE;
|
||||
} else {
|
||||
device_state = DEVICE_ACTIVE;
|
||||
}
|
||||
}
|
||||
sleep_ms(10);
|
||||
tud_connect();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -214,7 +212,6 @@ uint8_t const * tud_hid_descriptor_report_cb(uint8_t itf)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// Invoked when received SET_REPORT control request or
|
||||
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
|
||||
void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) {
|
||||
@@ -238,6 +235,11 @@ uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_t
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Invoked when device is mounted
|
||||
void tud_mount_cb(void) {
|
||||
device_state = DEVICE_ACTIVE;
|
||||
}
|
||||
|
||||
// print message to CDC in raw hex
|
||||
void cdc_print_hex(uint8_t const* msg, uint16_t msg_len) {
|
||||
(void) msg;
|
||||
|
||||
Reference in New Issue
Block a user