From bc5261341001d53be07f165b5ef43fb72eae68c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 9 Jan 2024 15:53:42 +0800 Subject: [PATCH] Gamepad: rename identifier to serial number --- src/detection/gamepad/gamepad.h | 2 +- src/detection/gamepad/gamepad_apple.c | 8 ++++---- src/detection/gamepad/gamepad_bsd.c | 2 +- src/detection/gamepad/gamepad_linux.c | 6 +++--- src/detection/gamepad/gamepad_windows.c | 11 ++--------- src/modules/gamepad/gamepad.c | 10 +++++----- 6 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/detection/gamepad/gamepad.h b/src/detection/gamepad/gamepad.h index 441b095dc..3caed4cc7 100644 --- a/src/detection/gamepad/gamepad.h +++ b/src/detection/gamepad/gamepad.h @@ -4,7 +4,7 @@ typedef struct FFGamepadDevice { - FFstrbuf identifier; + FFstrbuf serial; FFstrbuf name; uint8_t battery; // 0-100% } FFGamepadDevice; diff --git a/src/detection/gamepad/gamepad_apple.c b/src/detection/gamepad/gamepad_apple.c index de20ae5d8..bfeb65ed0 100644 --- a/src/detection/gamepad/gamepad_apple.c +++ b/src/detection/gamepad/gamepad_apple.c @@ -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 */) diff --git a/src/detection/gamepad/gamepad_bsd.c b/src/detection/gamepad/gamepad_bsd.c index 019fec23c..340ff1165 100644 --- a/src/detection/gamepad/gamepad_bsd.c +++ b/src/detection/gamepad/gamepad_bsd.c @@ -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; } diff --git a/src/detection/gamepad/gamepad_linux.c b/src/detection/gamepad/gamepad_linux.c index ac823e0fa..791412a70 100644 --- a/src/detection/gamepad/gamepad_linux.c +++ b/src/detection/gamepad/gamepad_linux.c @@ -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 diff --git a/src/detection/gamepad/gamepad_windows.c b/src/detection/gamepad/gamepad_windows.c index 7d533a616..65ee5c0f6 100644 --- a/src/detection/gamepad/gamepad_windows.c +++ b/src/detection/gamepad/gamepad_windows.c @@ -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 && ( diff --git a/src/modules/gamepad/gamepad.c b/src/modules/gamepad/gamepad.c index 55a2aba00..a74d603cc 100644 --- a/src/modules/gamepad/gamepad.c +++ b/src/modules/gamepad/gamepad.c @@ -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", }); }