ensures we get the latest available HID data (#345)

Fixed input delay
This commit is contained in:
Robert Borg 2020-05-17 17:52:16 +02:00 committed by GitHub
parent ce3cb236b1
commit cd659366b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -505,8 +505,33 @@ namespace BetterJoyForCemu {
private int ReceiveRaw() {
if (handle == IntPtr.Zero) return -2;
HIDapi.hid_set_nonblocking(handle, 1);
byte[] raw_buf = new byte[report_len];
int ret = HIDapi.hid_read_timeout(handle, raw_buf, new UIntPtr(report_len), 5000);
byte[] raw_buf;
byte[][] buffers = new byte[][] { new byte[report_len], new byte[report_len] };
int ret = HIDapi.hid_read(handle, buffers[0], new UIntPtr(report_len));
if (ret == 0) return ret;
int ret2;
// read data until there is no more to read and discard all but the latest data
while(true)
{
ret2 = HIDapi.hid_read(handle, buffers[1], new UIntPtr(report_len));
if(ret2 == 0)
{
raw_buf = buffers[0];
break;
}
ret = HIDapi.hid_read(handle, buffers[1], new UIntPtr(report_len));
if(ret == 0)
{
ret = ret2;
raw_buf = buffers[1];
break;
}
}
if (ret > 0) {
// Process packets as soon as they come
for (int n = 0; n < 3; n++) {