btleplug icon indicating copy to clipboard operation
btleplug copied to clipboard

Feat: CentralState

Open szymonlesisz opened this issue 1 year ago • 1 comments

Hi,

I'm working on bluetooth integration for trezor-suite app and i would like to use btleplug as a bridge between the electron app and bluetooth device. To make it work i would like to contribute and address some missing features and issues

CentralState

Implementation of https://github.com/deviceplug/btleplug/issues/280 for macos, windows and linux.

I wasn't sure should i extend existing adapter_info method or just add new adapter_state, just for clarity i've added new function. I'm leaving this decision to you. Also i'm not sure about the naming adapter_state() -> CentralState i didn't want to mess up current naming convention. Feel free to nitpick anything.

Tested on Windows 10, macOS sonoma, linux nixOS

Commits

  • c244d4170b93fa904bf67d0848926058284cdd30 add CBManagerState getter https://developer.apple.com/documentation/corebluetooth/cbmanagerstate in corebluetooth delegate. The state is emitted in CentralDelegateEvent::DidUpdateState event.

  • 6cdb1707a39554cba32811326254cd363b38cee3 add api::Adapter.adapter_state function and CentralEvent::StateUpdate event, by default all targets returns CentralState::Unknown

  • e13a5e1b8f7a5f6501912fa3016341662684131d implementation for corebluetooth using delegate centralmanager_state getter

  • 08ef9a1770f7446c7d3505f029b827a7233b30a3 implementation for bluez using BluetoothEvent::Adapter event

  • c608e55143613d6f88379416b80cdff5c565c7b3 implementation for winrtble using Radio.State() https://github.com/microsoft/windows-rs/blob/master/crates/libs/windows/src/Windows/Devices/Radios/mod.rs - there might be some side effects, not sure why sometimes i'm receiving same event twice, but i don't mind that

szymonlesisz avatar Feb 19 '24 15:02 szymonlesisz

sorry for the force-push, too many fixes for cargo fmt

szymonlesisz avatar Feb 19 '24 15:02 szymonlesisz

wait this feature merged 😁

Yongle-Fu avatar Aug 13 '24 08:08 Yongle-Fu

Hi, i've rebased over recent dev branch and resolve conflicts with Use objc2-core-bluetooth

is there anything else i can do to push things forward?

im expecting more conflicts with https://github.com/deviceplug/btleplug/pull/388

szymonlesisz avatar Sep 10 '24 12:09 szymonlesisz

ff96d68 and 20dc206 are just format fixes

3e09084 removed clone plus added radio.StateChanged error handler, not sure if this was the reason but now im receiving StateChanged once as expected (reference to note in the description)

pls let me know when to squash my fixups

szymonlesisz avatar Sep 10 '24 17:09 szymonlesisz