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 && (
+5 -5
View File
@@ -24,7 +24,7 @@ static void printDevice(FFGamepadOptions* options, const FFGamepadDevice* device
{
ffPrintFormat(FF_GAMEPAD_MODULE_NAME, index, &options->moduleArgs, FF_GAMEPAD_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRBUF, &device->name},
{FF_FORMAT_ARG_TYPE_STRBUF, &device->identifier},
{FF_FORMAT_ARG_TYPE_STRBUF, &device->serial},
{FF_FORMAT_ARG_TYPE_UINT8, &device->battery},
});
}
@@ -52,7 +52,7 @@ void ffPrintGamepad(FFGamepadOptions* options)
FF_LIST_FOR_EACH(FFGamepadDevice, device, result)
{
printDevice(options, device, result.length > 1 ? ++index : 0);
ffStrbufDestroy(&device->identifier);
ffStrbufDestroy(&device->serial);
ffStrbufDestroy(&device->name);
}
}
@@ -114,13 +114,13 @@ void ffGenerateGamepadJsonResult(FF_MAYBE_UNUSED FFGamepadOptions* options, yyjs
FF_LIST_FOR_EACH(FFGamepadDevice, device, result)
{
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
yyjson_mut_obj_add_strbuf(doc, obj, "identifier", &device->identifier);
yyjson_mut_obj_add_strbuf(doc, obj, "serial", &device->serial);
yyjson_mut_obj_add_strbuf(doc, obj, "name", &device->name);
}
FF_LIST_FOR_EACH(FFGamepadDevice, device, result)
{
ffStrbufDestroy(&device->identifier);
ffStrbufDestroy(&device->serial);
ffStrbufDestroy(&device->name);
}
}
@@ -129,7 +129,7 @@ void ffPrintGamepadHelpFormat(void)
{
ffPrintModuleFormatHelp(FF_GAMEPAD_MODULE_NAME, "{1}", FF_GAMEPAD_NUM_FORMAT_ARGS, (const char* []) {
"Name",
"Identifier",
"Serial number",
"Battery",
});
}