Patch: Detecting computer sleep/wake through USB

Hi,

I've modified the Arduino USBCore files so that my sketch knows when the USB host (PC) enters or exits Sleep mode. This allows me for example to dim the leds on my connected project or display a special icon on the TFT screen when the host is powered but not running.

The patch consists of adding a callback method to the USBDevice object.

It use used in the following example:

void setup()
{
   USBDevice.setSuspendCallback(&handleSuspend);
   USBDevice.setWakeUpCallback(&handleWakeUp);
}

void handleSuspend()
{
   ...
}

void handleWakeUp()
{
   ...
}

I think this would be a good addition to the Arduino USB core. But I have no idea how to submit my change.

Github is the word... - GitHub - arduino/Arduino: Arduino IDE 1.x

i'll prep a pull request then and see what happens.

Probably it will take quite some time to get it merged.
Posting good & usable examples might make it more interesting for the core team :slight_smile:

Thank you, Rob.

I've made a pull request for the patch with examples.

you already have one supporter!

robtillaart:
you already have one supporter!

Yes! And from none other than the great NicoHood himself!