ConnectableDeviceImpl

class ConnectableDeviceImpl(val identifier: Identifier, initialDeviceInfo: DeviceInfoImpl, connectionSettings: ConnectionSettings, connectionManagerBuilder: (ConnectionSettings) -> DeviceConnectionManager, coroutineScope: CoroutineScope, createDeviceStateFlow: (DeviceConnectionManager, CoroutineContext) -> ConnectableDeviceStateFlowRepo = { connectionManager, context -> ConnectableDeviceStateImplRepo(connectionSettings.reconnectionSettings, connectionManager, context) }) : ConnectableDevice, CoroutineScope

Implementation of ConnectableDevice

Parameters

identifier

The Identifier of the device

initialDeviceInfo

the initial DeviceInfoImpl known about the device

connectionSettings

the ConnectionSettings to apply to the DeviceConnectionManager associated with this device

connectionManagerBuilder

creates a DeviceConnectionManager to manage connecting this device

coroutineScope

the CoroutineScope this device is running on]

createDeviceStateFlow

creates a ConnectableDeviceStateFlowRepo to manage the device connection state

Constructors

Link copied to clipboard
constructor(identifier: Identifier, initialDeviceInfo: DeviceInfoImpl, connectionSettings: ConnectionSettings, connectionManagerBuilder: (ConnectionSettings) -> DeviceConnectionManager, coroutineScope: CoroutineScope, createDeviceStateFlow: (DeviceConnectionManager, CoroutineContext) -> ConnectableDeviceStateFlowRepo = { connectionManager, context -> ConnectableDeviceStateImplRepo(connectionSettings.reconnectionSettings, connectionManager, context) })

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
open override val identifier: Identifier
Link copied to clipboard
open override val info: StateFlow<DeviceInfo>

A StateFlow of the latest DeviceInfo of the device

Link copied to clipboard
open override val state: Flow<DeviceState>

A Flow of the latest DeviceState of the device

Functions

Link copied to clipboard
open override fun advertisementDataDidUpdate(advertisementData: BaseAdvertisementData)

Notifies the device that the BaseAdvertisementData has updated

Link copied to clipboard
suspend fun ConnectableDevice.characteristic(serviceUUID: String, characteristicUUID: String): RemoteCharacteristic

The RemoteCharacteristic for serviceUUID/characteristicUUID of this ConnectableDevice, suspending until available.

Link copied to clipboard
fun ConnectableDevice.characteristicFlow(serviceUUID: String, characteristicUUID: String): Flow<RemoteCharacteristic>

The Flow of the RemoteCharacteristic for serviceUUID/characteristicUUID of this ConnectableDevice. Only emits after services have been discovered.

Link copied to clipboard
suspend fun ConnectableDevice.characteristicOrNull(serviceUUID: String, characteristicUUID: String): RemoteCharacteristic?

The RemoteCharacteristic for serviceUUID/characteristicUUID of this ConnectableDevice, or null if not available.

Link copied to clipboard
fun ConnectableDevice.characteristicOrNullFlow(serviceUUID: String, characteristicUUID: String): Flow<RemoteCharacteristic?>

The Flow of the RemoteCharacteristic for serviceUUID/characteristicUUID of this ConnectableDevice, or null if not available.

Link copied to clipboard
open suspend fun connect(reconnectionSettings: ConnectionSettings.ReconnectionSettings? = null): Boolean

Attempts to connect to the device. Cancelling this call tears down any in-flight connection attempt (CoreBluetooth has no connection timeout, so wrap this in e.g. withTimeoutOrNull to bound it).

Link copied to clipboard
fun ConnectableDevice.dataFlow(serviceUUID: String, characteristicUUID: String): Flow<ByteArray>

The Flow of the ByteArray value of the RemoteCharacteristic for serviceUUID/characteristicUUID of this ConnectableDevice. Only emits after services have been discovered.

inline fun <T> ConnectableDevice.dataFlow(serviceUUID: String, characteristicUUID: String, deserializationStrategy: DeserializationStrategy<T>, bluetoothFormat: BluetoothFormat = BluetoothFormat): Flow<T>

The Flow of the T value of the RemoteCharacteristic for serviceUUID/characteristicUUID of this ConnectableDevice. Only emits after services have been discovered.

Link copied to clipboard
fun ConnectableDevice.dataOrEmptyFlow(serviceUUID: String, characteristicUUID: String): Flow<ByteArray>

The Flow of the ByteArray value of the RemoteCharacteristic for serviceUUID/characteristicUUID of this ConnectableDevice. Emits an empty ByteArray if not available.

Link copied to clipboard
inline fun <T> ConnectableDevice.dataOrNullFlow(serviceUUID: String, characteristicUUID: String, deserializationStrategy: DeserializationStrategy<T>, bluetoothFormat: BluetoothFormat = BluetoothFormat): Flow<T?>

The Flow of the T value of the RemoteCharacteristic for serviceUUID/characteristicUUID of this ConnectableDevice. Emits null if not available.

Link copied to clipboard
suspend fun ConnectableDevice.descriptor(serviceUUID: String, characteristicUUID: String, descriptorUUID: String): RemoteDescriptor
Link copied to clipboard
fun ConnectableDevice.descriptorFlow(serviceUUID: String, characteristicUUID: String, descriptorUUID: String): Flow<RemoteDescriptor>

The Flow of the RemoteDescriptor for serviceUUID/characteristicUUID/descriptorUUID of this ConnectableDevice. Only emits after services have been discovered.

Link copied to clipboard
fun ConnectableDevice.descriptorOrNullFlow(serviceUUID: String, characteristicUUID: String, descriptorUUID: String): Flow<RemoteDescriptor?>

The Flow of the RemoteDescriptor for serviceUUID/characteristicUUID/descriptorUUID of this ConnectableDevice, or null if not available.

Link copied to clipboard
open suspend fun disconnect()

Attempts to disconnect from the device

Link copied to clipboard

Gets a (Flow of) the list of Service associated with the ConnectableDevice This will automatically discover services if the device is in a ConnectableDeviceState.Connected.NoServices state. This differs from services in that the resulting flow will only emit once services are discovered.

Link copied to clipboard
fun ConnectableDevice.distance(environmentalFactor: Double = 2.0, averageOver: Int = 5): Flow<Double>

Gets the (Flow of) the distance in meters between the scanner and a ConnectableDevice. To get a more stable result, this method will average the distance over the last averageOver results.

Link copied to clipboard
Link copied to clipboard
open override fun handleConnected()

Notifies the device that is has connected

Link copied to clipboard
open override fun handleDisconnected()

Notifies the device that is has disconnected

Link copied to clipboard
fun ConnectableDevice.mtu(): Flow<Int?>

Gets the (Flow of) the MTU from a ConnectableDevice

Link copied to clipboard

Attempts to request a MTU size for the ConnectableDevice from a ConnectableDevice

Link copied to clipboard
open override fun rssiDidUpdate(rssi: RSSI)

Notifies the device that the RSSI has updated

Link copied to clipboard
suspend fun ConnectableDevice.service(serviceUUID: String): RemoteService

The RemoteService for serviceUUID of this ConnectableDevice, suspending until services have been discovered.

Link copied to clipboard

The Flow of the RemoteService for serviceUUID of this ConnectableDevice. Only emits after services have been discovered.

Link copied to clipboard

The RemoteService for serviceUUID of this ConnectableDevice, or null if not available.

Link copied to clipboard

The Flow of the RemoteService for serviceUUID of this ConnectableDevice, or null if not available.

Link copied to clipboard

Gets a (Flow of) the list of Service associated with the ConnectableDevice This will automatically discover services if the device is in a ConnectableDeviceState.Connected.NoServices state.

Link copied to clipboard

Attempts to request an update to the RSSI of the ConnectableDevice from a ConnectableDevice When this method completes, the devices should have had ConnectableDeviceState.Connected.readRssi called