Make it possible to detect if connected PC is running or shut down (Controllers with USB, 32u4) #7363
Labels
Component: Hardware
Related to the design of Arduino's hardware products
Component: USB Device
Opposed to USB Host. Related to the USB subsystem (SerialUSB, HID, ...)
feature request
A request to make an enhancement (not a bug fix)
For some USB device projects it would be handy to know if the PC, my device is connected to, is still running or has been shut down. This has become a problem especially with "newer" motherboards, which now usually always have power on the USB power leads.
A common way to do this is to check if "SOF" events are still generated. Possible place to detect this would be:
https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/USBCore.cpp#L760
In another project (STM32 without Arduino libraries), I just used a timer interrupt counting up a variable. Then I reset this to zero every time a SOF event happens.
In my other code, I can now check the value of my variable. If it reaches a defined limit, the PC must have been shut down as the "resets to zero" no longer happen.
There may be simpler/better ways to do this in the Arduino core libraries and some API also has to be defined. Maybe you could consider adding such a feature. Would be very useful!
The text was updated successfully, but these errors were encountered: