Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years ago.
How to wake sleeping computer with mbed USB device? (mouse)
Hi,
I am working with the LPC1768. My design should make the mbed board act as a mouse and keyboard device when I plug it into a windows PC. So I am using the mbed USB library and then using the USBMouseKeyboard class.
So far, I have a functional mouse and keyboard working. The mbed is connected to a windows 7 machine and it behaves properly. The problem I am having is when the windows 7 machine goes to sleep. The code blocks at a USB write and I am not able to wake the PC using the mbed device. I have tried using the remoteWakeup() function, but this does not seem to change anything.
So, my question is, how can I use the mbed device to wake a sleeping computer using the mbed USB device class?
Thanks for any help, John
1 Answer
11 years ago.
Ok, I solved the problem. Just wanted to share to give others an idea of what needs to be done. I am no USB expert, so maybe there is a better way of solving this. Let me know if you have any suggestions as how to improve:
First, I added the remote wake up to the configuration descriptor
code
uint8_t * USBHID::configurationDesc() { static uint8_t configurationDescriptor[] = { CONFIGURATION_DESCRIPTOR_LENGTH,// bLength CONFIGURATION_DESCRIPTOR, // bDescriptorType LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB) MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB) 0x01, // bNumInterfaces DEFAULT_CONFIGURATION, // bConfigurationValue 0x00, // iConfiguration C_RESERVED | C_SELF_POWERED | C_REMOTE_WAKEUP, // bmAttributes ...
Now, whenever the windows PC goes to sleep, it informs the mbed device of the requestSetFeature for remote wakeup. When the PC wakes it clears this. I created a variable inside USBdevice.h: bool computerIsSleeping to keep track of the state. It is set in the following ways.
code
bool USBDevice::requestSetFeature() { ... case DEVICE_RECIPIENT: // JKL remote wakeup now enabled computerIsSleeping = true; break; ... } bool USBDevice::requestClearFeature() { ... case DEVICE_RECIPIENT: // JKL remote wakeup now enabled computerIsSleeping = false; break; ... }
And finally, whenever a USB send is performed, first check to see if the host PC is sleeping. If it is, use the wake function that Mbed has already provided for the LPC1768.
code
bool USBHID::send(HID_REPORT *report) { // check to see if computer is asleep, if it is, it needs to wake up if(computerIsSleeping) { remoteWakeup(); } return write(EPINT_IN, report->data, report->length, MAX_HID_REPORT_SIZE); }
Hopefully someone finds this helpful.
John