My Teensy 3 is self-powered by a battery and I am trying to detect when the USB cable is unplugged from a host. When USB is plugged into a host, "usb_configuration" changes from 0 to 1. But when the cable is unplugged usb_configuration does not change back to 0. To fix this, I made a change to usb_dev.c in usb_isr() around line 937:
Is this a sensible way to go about it? Is there a better way?
Code:
if ((status & USB_ISTAT_SLEEP /* 10 */ )) {
//serial_print("sleep\n");
usb_configuration = 0; // ADDED to reset current configuration
USB0_ISTAT = USB_ISTAT_SLEEP;
}
Is this a sensible way to go about it? Is there a better way?