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.
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
Thank you, Rob.
I've made a pull request for the patch with examples.
arduino:master
← robvdveer:master
opened 08:37PM - 02 Dec 15 UTC
This patch allows the Arduino sketch to respond to USB Host suspend/wake by sett… ings a callback functions or using the isSuspended() function on the USBDevice instance. The suspend handler will be called when the host PC is put to sleep (or shuts down), and the WakeUp handler is called when the PC resumes from sleep.
PS. I apologise for the changes in whitespace I was unable to avoid that.
Usage:
```
void setup()
{
USBDevice.setWakeUpHandler(&handleWakeup);
USBDevice.setSuspendHandler(&handleSuspend);
}
...
void handleWakeup()
{
}
void handleSuspend()
{
}
```
or
```
void loop()
{
if(USBDevice.isSuspended())
{
....
}
}
```
you already have one supporter!
robtillaart:
you already have one supporter!
Yes! And from none other than the great NicoHood himself!