Bluetooth: don't use singleton

This commit is contained in:
李通洲
2023-06-12 21:50:25 +08:00
parent fa99508a69
commit 88f354a872
8 changed files with 35 additions and 48 deletions
+12 -4
View File
@@ -30,17 +30,18 @@ static void printDevice(FFinstance* instance, FFBluetoothOptions* options, const
void ffPrintBluetooth(FFinstance* instance, FFBluetoothOptions* options)
{
const FFBluetoothResult* bluetooth = ffDetectBluetooth(instance);
FF_LIST_AUTO_DESTROY devices = ffListCreate(sizeof (FFBluetoothDevice));
const char* error = ffDetectBluetooth(instance, &devices);
if(bluetooth->error.length > 0)
if(error)
{
ffPrintError(instance, FF_BLUETOOTH_MODULE_NAME, 0, &options->moduleArgs, "%s", bluetooth->error.chars);
ffPrintError(instance, FF_BLUETOOTH_MODULE_NAME, 0, &options->moduleArgs, "%s", error);
return;
}
FF_LIST_AUTO_DESTROY filtered = ffListCreate(sizeof(FFBluetoothDevice*));
FF_LIST_FOR_EACH(FFBluetoothDevice, device, bluetooth->devices)
FF_LIST_FOR_EACH(FFBluetoothDevice, device, devices)
{
if(!device->connected && !options->showDisconnected)
continue;
@@ -59,6 +60,13 @@ void ffPrintBluetooth(FFinstance* instance, FFBluetoothOptions* options)
uint8_t index = (uint8_t) (filtered.length == 1 ? 0 : i + 1);
printDevice(instance, options, *(FFBluetoothDevice**)ffListGet(&filtered, i), index);
}
FF_LIST_FOR_EACH(FFBluetoothDevice, device, devices)
{
ffStrbufDestroy(&device->name);
ffStrbufDestroy(&device->type);
ffStrbufDestroy(&device->address);
}
}
void ffInitBluetoothOptions(FFBluetoothOptions* options)