suppress HID messages when device is disconnected
This commit is contained in:
@@ -376,12 +376,17 @@ void startADC() {
|
|||||||
|
|
||||||
// forward HID report after processing
|
// forward HID report after processing
|
||||||
bool forward_report(uint8_t instance, uint8_t const* report, uint16_t len) {
|
bool forward_report(uint8_t instance, uint8_t const* report, uint16_t len) {
|
||||||
// toggle mute button color if mute button is pressed
|
// forward only if device is connected
|
||||||
if ( instance == 0x02 && report[0] == 0x02 && (report[2] & 0x01) ) {
|
if (device_state == DEVICE_ACTIVE) {
|
||||||
mute = !mute;
|
// toggle mute button color if mute button is pressed
|
||||||
|
if ( instance == 0x02 && report[0] == 0x02 && (report[2] & 0x01) ) {
|
||||||
|
mute = !mute;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tud_hid_n_report(instance, 0, report, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tud_hid_n_report(instance, 0, report, len);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// save RGB configuration to flash
|
// save RGB configuration to flash
|
||||||
|
|||||||
+10
-7
@@ -79,19 +79,17 @@ void usb_device_main(void) {
|
|||||||
while (true) {
|
while (true) {
|
||||||
switch ( device_state ) {
|
switch ( device_state ) {
|
||||||
case DEVICE_ACTIVE:
|
case DEVICE_ACTIVE:
|
||||||
|
if (!tud_mounted()) {
|
||||||
|
device_state = DEVICE_INACTIVE;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case DEVICE_INACTIVE:
|
case DEVICE_INACTIVE:
|
||||||
break;
|
break;
|
||||||
case DEVICE_RESTART:
|
case DEVICE_RESTART:
|
||||||
if (tud_disconnect()) {
|
if (tud_disconnect()) {
|
||||||
|
device_state = DEVICE_INACTIVE;
|
||||||
sleep_ms(10);
|
sleep_ms(10);
|
||||||
if (tud_connect()) {
|
tud_connect();
|
||||||
if ( host_state == HOST_INACTIVE ) {
|
|
||||||
device_state = DEVICE_INACTIVE;
|
|
||||||
} else {
|
|
||||||
device_state = DEVICE_ACTIVE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -243,6 +241,11 @@ uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_t
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Invoked when device is mounted
|
||||||
|
void tud_mount_cb(void) {
|
||||||
|
device_state = DEVICE_ACTIVE;
|
||||||
|
}
|
||||||
|
|
||||||
// print message to CDC in raw hex
|
// print message to CDC in raw hex
|
||||||
void cdc_print_hex(uint8_t const* msg, uint16_t msg_len) {
|
void cdc_print_hex(uint8_t const* msg, uint16_t msg_len) {
|
||||||
(void) msg;
|
(void) msg;
|
||||||
|
|||||||
Reference in New Issue
Block a user