From ce648e9e44ca82ceacd979e73a816b4ea64f8a3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 27 Jul 2024 23:53:17 +0800 Subject: [PATCH] Bluetooth (Windows): tidy; update module description --- src/detection/bluetooth/bluetooth_windows.c | 29 +++++++++------------ src/modules/bluetooth/bluetooth.c | 6 ++--- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/detection/bluetooth/bluetooth_windows.c b/src/detection/bluetooth/bluetooth_windows.c index cf0c756b9..2ac377d01 100644 --- a/src/detection/bluetooth/bluetooth_windows.c +++ b/src/detection/bluetooth/bluetooth_windows.c @@ -15,18 +15,16 @@ const char* ffDetectBluetooth(FFlist* devices /* FFBluetoothResult */) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(bluetoothapis, BluetoothFindNextDevice) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(bluetoothapis, BluetoothFindDeviceClose) - BLUETOOTH_DEVICE_SEARCH_PARAMS btsp = { + BLUETOOTH_DEVICE_INFO btdi = { + .dwSize = sizeof(btdi) + }; + HBLUETOOTH_DEVICE_FIND hFind = ffBluetoothFindFirstDevice(&(BLUETOOTH_DEVICE_SEARCH_PARAMS) { .fReturnConnected = TRUE, .fReturnRemembered = TRUE, .fReturnAuthenticated = TRUE, .fReturnUnknown = TRUE, - .dwSize = sizeof(btsp) - }; - - BLUETOOTH_DEVICE_INFO btdi = { - .dwSize = sizeof(btdi) - }; - HBLUETOOTH_DEVICE_FIND hFind = ffBluetoothFindFirstDevice(&btsp, &btdi); + .dwSize = sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS) + }, &btdi); if(!hFind) { if (GetLastError() == ERROR_NO_MORE_ITEMS) @@ -37,21 +35,18 @@ const char* ffDetectBluetooth(FFlist* devices /* FFBluetoothResult */) do { FFBluetoothResult* device = ffListAdd(devices); - ffStrbufInit(&device->name); - ffStrbufInit(&device->address); - ffStrbufInit(&device->type); - device->battery = 0; - device->connected = !!btdi.fConnected; - - ffStrbufSetWS(&device->name, btdi.szName); - - ffStrbufAppendF(&device->address, "%02x:%02x:%02x:%02x:%02x:%02x", + ffStrbufInitWS(&device->name, btdi.szName); + ffStrbufInitF(&device->address, "%02x:%02x:%02x:%02x:%02x:%02x", btdi.Address.rgBytes[0], btdi.Address.rgBytes[1], btdi.Address.rgBytes[2], btdi.Address.rgBytes[3], btdi.Address.rgBytes[4], btdi.Address.rgBytes[5]); + ffStrbufInit(&device->type); + device->battery = 0; + device->connected = !!btdi.fConnected; + //https://btprodspecificationrefs.blob.core.windows.net/assigned-numbers/Assigned%20Number%20Types/Assigned%20Numbers.pdf if(BitTest(&btdi.ulClassofDevice, 13)) diff --git a/src/modules/bluetooth/bluetooth.c b/src/modules/bluetooth/bluetooth.c index fa010ec9b..037ca6335 100644 --- a/src/modules/bluetooth/bluetooth.c +++ b/src/modules/bluetooth/bluetooth.c @@ -178,8 +178,8 @@ void ffGenerateBluetoothJsonResult(FF_MAYBE_UNUSED FFBluetoothOptions* options, void ffPrintBluetoothHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_BLUETOOTH_MODULE_NAME, "{1} ({4})", FF_BLUETOOTH_NUM_FORMAT_ARGS, ((const char* []) { - "Name - name", - "Address - address", + "Name - device name", + "Address - remote device address", "Type - type", "Battery percentage number - battery-percentage", "Is connected - connected", @@ -192,7 +192,7 @@ void ffInitBluetoothOptions(FFBluetoothOptions* options) ffOptionInitModuleBaseInfo( &options->moduleInfo, FF_BLUETOOTH_MODULE_NAME, - "List bluetooth devices", + "List (connected) bluetooth devices", ffParseBluetoothCommandOptions, ffParseBluetoothJsonObject, ffPrintBluetooth,