Page 1 of 1

Waking up tablet with key press

Posted: Fri Jun 10, 2016 2:21 pm
by arvydas
Hi,

I have a Windows tablet that needs to wake up after a certain amount of time with a custom VUSB based device. I turn off the screen with my software and send a message to the device to send a SPACE key after a certain amount of time. I got it working, however there is one problem. Sometimes the tablet does not wake up as it needs to send the key twice. I've noticed this with a normal keyboard connected to the tablet. When I press the ON/OFF button on the tablet, the screen turns off and most of the times it wakes up just by pressing a key on the keyboard once, but occasionally I have to press it twice.

My device works as follows:

1) Waits a certain amount of time
2) Sends key pressed
3) Waits a few milliseconds
4) Sends a key released

The code looks something like this:

Code: Select all

if (usbInterruptIsReady())
{
        // Step 2
   if (sendKeyState == 2)
   {
      usbSetInterrupt((uchar *)&keyboard_report, sizeof(keyboard_report));
      sendKeyState = 1;
   }
        // Step 4
   else if (sendKeyState == 1)
   {
      keyboard_report.key[0] = 0;
      usbSetInterrupt((uchar *)&keyboard_report, sizeof(keyboard_report));
      sendKeyState = 0;
   }
}


When the condition that requires two key presses occurs, my device only gets to the 4) after I press the ON/OFF button on the tablet to wake it up manually. I'm fairly certain that it gets blocked at usbInterruptIsReady() function call as it never becomes ready.

Is VUSB waiting to get acknowledgement from the OS that data has been received? Is there any way to avoid this?