Exemplo n.º 1
0
bool HIDDevice::processReadResult()
{

    OVR_ASSERT(ReadRequested);

    DWORD bytesRead = 0;

    if (GetOverlappedResult(Device, &ReadOverlapped, &bytesRead, FALSE))
    {
        // We've got data.
        if (Handler)
        {
            Handler->OnInputReport(ReadBuffer, bytesRead);
        }

        // TBD: Not needed?
        // Event should be reset by Read call...
        ReadOverlapped.Pointer = 0;
        ReadOverlapped.Internal = 0;
        ReadOverlapped.InternalHigh = 0;
        return true;
    }
    else
    {
        if (GetLastError() != ERROR_IO_PENDING)
        {
            closeDeviceOnIOError();
            return false;
        }
    }

    return false;
}
//-----------------------------------------------------------------------------
void HIDDevice::OnEvent(int i, int fd)
{
    OVR_UNUSED(i);

    int bytes = 0;

    if(DeviceHandle){

    	bytes = hid_read(DeviceHandle, ReadBuffer, ReadBufferSize);
    }

    // We have data to read from the device
    //int bytes = read(fd, ReadBuffer, ReadBufferSize);
    if (bytes >= 0)
    {
// TODO: I need to handle partial messages and package reconstruction
    	if(bytes > 0){
			if (Handler)
			{
				Handler->OnInputReport(ReadBuffer, bytes);
			}
    	}
    }
    else
    {   // Close the device on read error.
        closeDeviceOnIOError();
    }
}
Exemplo n.º 3
0
bool HIDDevice::initializeRead()
{

    if (!ReadRequested)
    {
        HIDManager->Manager->pThread->AddOverlappedEvent(this, ReadOverlapped.hEvent);
        ReadRequested = true;
    }

    // Read resets the event...
    while(::ReadFile(Device, ReadBuffer, InputReportBufferLength, 0, &ReadOverlapped))
    {
        processReadResult();
    }

    if (GetLastError() != ERROR_IO_PENDING)
    {
        // Some other error (such as unplugged).
        closeDeviceOnIOError();
        return false;
    }

    return true;
}