-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support constructing
Peripheral
s using builder lambda (#108)
- Loading branch information
Showing
11 changed files
with
326 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.juul.kable | ||
|
||
/** Preferred transport for GATT connections to remote dual-mode devices. */ | ||
public enum class Transport { | ||
|
||
/** No preference of physical transport for GATT connections to remote dual-mode devices. */ | ||
Auto, | ||
|
||
/** Prefer BR/EDR transport for GATT connections to remote dual-mode devices. */ | ||
BrEdr, | ||
|
||
/** Prefer LE transport for GATT connections to remote dual-mode devices. */ | ||
Le, | ||
} | ||
|
||
/** Preferred Physical Layer (PHY) for connections to remote LE devices. */ | ||
public enum class Phy { | ||
|
||
/** Bluetooth LE 1M PHY. */ | ||
Le1M, | ||
|
||
/** | ||
* Bluetooth LE 2M PHY. | ||
* | ||
* Per [Exploring Bluetooth 5 – Going the Distance](https://www.bluetooth.com/blog/exploring-bluetooth-5-going-the-distance/#mcetoc_1d7vdh6b25): | ||
* "The new LE 2M PHY allows the physical layer to operate at 2 Ms/s and thus enables higher data rates than LE 1M | ||
* and Bluetooth 4." | ||
*/ | ||
Le2M, | ||
|
||
/** | ||
* Bluetooth LE Coded PHY. | ||
* | ||
* Per [Exploring Bluetooth 5 – Going the Distance](https://www.bluetooth.com/blog/exploring-bluetooth-5-going-the-distance/#mcetoc_1d7vdh6b26): | ||
* "The LE Coded PHY allows range to be quadrupled (approximately), compared to Bluetooth® 4 and this has been | ||
* accomplished without increasing the transmission power required." | ||
*/ | ||
LeCoded, | ||
} | ||
|
||
public actual class ServicesDiscoveredPeripheral internal constructor( | ||
private val peripheral: AndroidPeripheral | ||
) { | ||
|
||
public actual suspend fun read( | ||
characteristic: Characteristic, | ||
): ByteArray = peripheral.read(characteristic) | ||
|
||
public actual suspend fun read( | ||
descriptor: Descriptor, | ||
): ByteArray = peripheral.read(descriptor) | ||
|
||
public actual suspend fun write( | ||
characteristic: Characteristic, | ||
data: ByteArray, | ||
writeType: WriteType, | ||
) { | ||
peripheral.write(characteristic, data, writeType) | ||
} | ||
|
||
public actual suspend fun write( | ||
descriptor: Descriptor, | ||
data: ByteArray, | ||
) { | ||
peripheral.write(descriptor, data) | ||
} | ||
|
||
public suspend fun requestMtu( | ||
mtu: Int | ||
): Unit = peripheral.requestMtu(mtu) | ||
} | ||
|
||
public actual class PeripheralBuilder internal actual constructor() { | ||
|
||
internal var onServicesDiscovered: ServicesDiscoveredAction = {} | ||
public actual fun onServicesDiscovered(action: ServicesDiscoveredAction) { | ||
onServicesDiscovered = action | ||
} | ||
|
||
/** Preferred transport for GATT connections to remote dual-mode devices. */ | ||
public var transport: Transport = Transport.Le | ||
|
||
/** Preferred PHY for connections to remote LE device. */ | ||
public var phy: Phy = Phy.Le1M | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.