Gamepad: rename identifier to serial number

This commit is contained in:
李通洲
2024-01-09 15:53:42 +08:00
parent f84bb1ebe2
commit bc52613410
6 changed files with 16 additions and 23 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
typedef struct FFGamepadDevice
{
FFstrbuf identifier;
FFstrbuf serial;
FFstrbuf name;
uint8_t battery; // 0-100%
} FFGamepadDevice;
+4 -4
View File
@@ -8,7 +8,7 @@
static void enumSet(IOHIDDeviceRef value, FFlist* results)
{
FFGamepadDevice* device = (FFGamepadDevice*) ffListAdd(results);
ffStrbufInit(&device->identifier);
ffStrbufInit(&device->serial);
ffStrbufInit(&device->name);
device->battery = 0;
@@ -18,9 +18,9 @@ static void enumSet(IOHIDDeviceRef value, FFlist* results)
CFStringRef product = IOHIDDeviceGetProperty(value, CFSTR(kIOHIDProductKey));
if (device->name.length)
{
ffCfStrGetString(product, &device->identifier);
ffCfStrGetString(product, &device->serial);
ffStrbufAppendC(&device->name, ' ');
ffStrbufAppend(&device->name, &device->identifier);
ffStrbufAppend(&device->name, &device->serial);
}
else
{
@@ -28,7 +28,7 @@ static void enumSet(IOHIDDeviceRef value, FFlist* results)
}
CFStringRef serialNumber = IOHIDDeviceGetProperty(value, CFSTR(kIOHIDSerialNumberKey));
ffCfStrGetString(serialNumber, &device->identifier);
ffCfStrGetString(serialNumber, &device->serial);
}
const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
+1 -1
View File
@@ -42,7 +42,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
if (ioctl(fd, USB_GET_DEVICEINFO, &di) != -1)
{
FFGamepadDevice* device = (FFGamepadDevice*) ffListAdd(devices);
ffStrbufInitS(&device->identifier, di.udi_serial);
ffStrbufInitS(&device->serial, di.udi_serial);
ffStrbufInitF(&device->name, "%s %s", di.udi_vendor, di.udi_product);
device->battery = 0;
}
+3 -3
View File
@@ -9,13 +9,13 @@ static void detectGamepad(FFlist* devices, FFstrbuf* name, FFstrbuf* path)
{
uint32_t baseLen = path->length;
FFGamepadDevice* device = (FFGamepadDevice*) ffListAdd(devices);
ffStrbufInit(&device->identifier);
ffStrbufInit(&device->serial);
ffStrbufInitMove(&device->name, name);
device->battery = 0;
ffStrbufAppendS(path, "uniq");
if (ffAppendFileBuffer(path->chars, &device->identifier))
ffStrbufTrimRightSpace(&device->identifier);
if (ffAppendFileBuffer(path->chars, &device->serial))
ffStrbufTrimRightSpace(&device->serial);
ffStrbufSubstrBefore(path, baseLen);
ffStrbufAppendS(path, "device/power_supply/"); // /sys/class/input/jsX/device/device/power_supply
+2 -9
View File
@@ -96,7 +96,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
continue;
FFGamepadDevice* device = (FFGamepadDevice*) ffListAdd(devices);
ffStrbufInit(&device->identifier);
ffStrbufInit(&device->serial);
ffStrbufInit(&device->name);
device->battery = 0;
@@ -142,14 +142,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
wchar_t serialNumber[127] = L"";
if (HidD_GetSerialNumberString(hHidFile, serialNumber, sizeof(serialNumber)))
ffStrbufSetWS(&device->identifier, serialNumber);
else if (caps.FeatureReportByteLength >= 6)
{
uint8_t* featureBuffer = malloc(caps.FeatureReportByteLength);
featureBuffer[0] = 18;
if (HidD_GetFeature(hHidFile, featureBuffer, caps.FeatureReportByteLength))
ffStrbufSetF(&device->identifier, "%02X:%02X:%02X:%02X:%02X:%02X", featureBuffer[0], featureBuffer[1], featureBuffer[2], featureBuffer[3], featureBuffer[4], featureBuffer[5]);
}
ffStrbufSetWS(&device->serial, serialNumber);
if (
(rdi.hid.dwVendorId == 0x054C && (