BLEManager
Main BLE manager for Electric Unicycles.
This class is responsible for BLE scanning, connection lifecycle management, protocol selection, command transmission, and decoded data delivery.
Threading model:
Internal asynchronous work is executed on a background coroutine scope based on
Dispatchers.IO + SupervisorJob().Public callbacks exposed by this manager (
ConnectionCallback,DataCallback, andErrorCallback) are not guaranteed to be invoked on the Android main thread.Callers must explicitly switch to
Dispatchers.Main,runOnUiThread, or an equivalent UI mechanism before touching Android views.
Rationale:
BLE operations, retries, polling, and response timeouts are background work and should not run on the main thread.
Keeping callback dispatching explicit avoids hiding threading behavior from the library consumer and keeps the manager usable from non-UI contexts as well.
Properties
Functions
Connect to a specific device
Disconnect from current device
Send a command to the connected device
Get currently connected device
Get current connection state
Initialize the BLE Manager
Check if Bluetooth is enabled
Register a protocol for device detection and data processing
Callback registration methods.
Start scanning for EUC devices
Stop scanning for devices