early-access version 1988

This commit is contained in:
pineappleEA
2021-08-12 01:07:27 +02:00
parent e37f82ce96
commit 24ddfcbb39
265 changed files with 68343 additions and 5348 deletions

View File

@@ -1088,7 +1088,32 @@ int HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned ch
return -1; // Controller was disconnected
}
// TODO: Implement timeout?
static uint32_t getms()
{
struct timeval now;
gettimeofday(&now, NULL);
return (uint32_t)(now.tv_sec * 1000 + now.tv_usec / 1000);
}
static void delayms(uint32_t ms)
{
int was_error;
struct timespec elapsed, tv;
/* Set the timeout interval */
elapsed.tv_sec = ms / 1000;
elapsed.tv_nsec = (ms % 1000) * 1000000;
do {
errno = 0;
tv.tv_sec = elapsed.tv_sec;
tv.tv_nsec = elapsed.tv_nsec;
was_error = nanosleep(&tv, &elapsed);
} while (was_error && (errno == EINTR));
}
int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *device, unsigned char *data, size_t length, int milliseconds)
{
if ( device )
@@ -1097,7 +1122,17 @@ int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *device, unsigned ch
hid_device_ref<CHIDDevice> pDevice = FindDevice( device->m_nId );
if ( pDevice )
{
return pDevice->GetInput( data, length );
int nResult = pDevice->GetInput( data, length );
if ( nResult == 0 && milliseconds > 0 )
{
uint32_t start = getms();
do
{
delayms( 1 );
nResult = pDevice->GetInput( data, length );
} while ( nResult == 0 && ( getms() - start ) < milliseconds );
}
return nResult;
}
LOGV( "controller was disconnected" );
}

View File

@@ -326,7 +326,10 @@ static int get_string_property_utf8(IOHIDDeviceRef device, CFStringRef prop, cha
static int get_serial_number(IOHIDDeviceRef device, wchar_t *buf, size_t len)
{
return get_string_property(device, CFSTR(kIOHIDSerialNumberKey), buf, len);
// This crashes on M1 Macs, tracked by radar bug 79667729
//return get_string_property(device, CFSTR(kIOHIDSerialNumberKey), buf, len);
buf[0] = 0;
return 0;
}
static int get_manufacturer_string(IOHIDDeviceRef device, wchar_t *buf, size_t len)

View File

@@ -97,8 +97,8 @@ extern "C" {
} /* extern "C" */
#endif
#include <stdio.h>
#include <stdlib.h>
/*#include <stdio.h>*/
/*#include <stdlib.h>*/
#include "../hidapi/hidapi.h"