blessed-kotlin
blessed-kotlin copied to clipboard
Allow usage of an external qualifier for peripherals
While using this library to run a BLE server in an application that is also using BLE devices, we encountered the same kind of problems than the ones mentioned here https://github.com/weliem/blessed-android/issues/156. I noticed that a fix has be proposed for this issue, but it cannot apply in our case. We are not using this library to connect to BLE devices, and this is not something that will be done in a near future.
Instead of using the BluetoothCentralManager as unique object used to qualify devices as peripheral or central devices, this PR proposes a way to register external peripheral qualifiers, through a new PeripheralQualifier interface.
BluetoothPeripheralManager has been updated to use a PeripheralQualifier instead of the BluetoothCentralManager.
BluetoothCentralManager now also implements PeripheralQualifier and can be passed to the BluetoothPeripheralManager.
The current usage can be replaced with:
val centralManager: BluetoothCentralManager
val peripheralManager: BluetoothPeripheralManager
[...]
// Old usage
peripheralManager.setCentralManager(centralManager)
// New usage
peripheralManager.setPeripheralQualifier(centralManager)
or, with an external qualifier:
val peripheralQualifier: PeripheralQualifier = object: PeripheralQualifier { device ->
// Apply a rule to determine if 'device' is a peripheral or a central
true / false
}
val peripheralManager: BluetoothPeripheralManager
[...]
peripheralManager.setPeripheralQualifier(peripheralQualifier)
So how does this fix solve your issue? If you are not use Centralmanager as the provider, what are you using then?
I can build a list of the devices I know I wanted to connect to, so I can build an implementation of the new provider that uses that list instead of the central manager. Sorry about the response delay, I did not receive any notification for the reply.