Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow usage of an external qualifier for peripherals #11

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dlevache
Copy link

@dlevache dlevache commented Apr 3, 2024

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 weliem/blessed-android#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)

@weliem
Copy link
Owner

weliem commented Apr 5, 2024

So how does this fix solve your issue? If you are not use Centralmanager as the provider, what are you using then?

@dlevache
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants