Improve setNotifiation completion (#42)
* Improve setNotifiation completion * Implement Windows * Minor android fixes * Few more fixes * Update changelog --------- Co-authored-by: Foti Dim <fdimanidis@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
## 0.9.10
|
## 0.9.10
|
||||||
* Fix Windows scan filter
|
* Fix Windows scan filter
|
||||||
* Improve service discovery on Linux
|
* Improve service discovery on Linux
|
||||||
|
* Use asynchronous callbacks for SetNotifiable
|
||||||
|
|
||||||
## 0.9.9
|
## 0.9.9
|
||||||
* Improve service discovery on Apple
|
* Improve service discovery on Apple
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// Autogenerated from Pigeon (v17.1.1), do not edit directly.
|
// Autogenerated from Pigeon (v18.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
|
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass")
|
||||||
|
|
||||||
package com.navideck.universal_ble
|
package com.navideck.universal_ble
|
||||||
|
|
||||||
@@ -16,14 +17,14 @@ private fun wrapResult(result: Any?): List<Any?> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun wrapError(exception: Throwable): List<Any?> {
|
private fun wrapError(exception: Throwable): List<Any?> {
|
||||||
if (exception is FlutterError) {
|
return if (exception is FlutterError) {
|
||||||
return listOf(
|
listOf(
|
||||||
exception.code,
|
exception.code,
|
||||||
exception.message,
|
exception.message,
|
||||||
exception.details
|
exception.details
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return listOf(
|
listOf(
|
||||||
exception.javaClass.simpleName,
|
exception.javaClass.simpleName,
|
||||||
exception.toString(),
|
exception.toString(),
|
||||||
"Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception)
|
"Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception)
|
||||||
@@ -58,15 +59,15 @@ data class UniversalBleScanResult (
|
|||||||
|
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("LocalVariableName")
|
||||||
fun fromList(list: List<Any?>): UniversalBleScanResult {
|
fun fromList(__pigeon_list: List<Any?>): UniversalBleScanResult {
|
||||||
val deviceId = list[0] as String
|
val deviceId = __pigeon_list[0] as String
|
||||||
val name = list[1] as String?
|
val name = __pigeon_list[1] as String?
|
||||||
val isPaired = list[2] as Boolean?
|
val isPaired = __pigeon_list[2] as Boolean?
|
||||||
val rssi = list[3].let { if (it is Int) it.toLong() else it as Long? }
|
val rssi = __pigeon_list[3].let { num -> if (num is Int) num.toLong() else num as Long? }
|
||||||
val manufacturerData = list[4] as ByteArray?
|
val manufacturerData = __pigeon_list[4] as ByteArray?
|
||||||
val manufacturerDataHead = list[5] as ByteArray?
|
val manufacturerDataHead = __pigeon_list[5] as ByteArray?
|
||||||
val services = list[6] as List<String?>?
|
val services = __pigeon_list[6] as List<String?>?
|
||||||
return UniversalBleScanResult(deviceId, name, isPaired, rssi, manufacturerData, manufacturerDataHead, services)
|
return UniversalBleScanResult(deviceId, name, isPaired, rssi, manufacturerData, manufacturerDataHead, services)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,10 +91,10 @@ data class UniversalBleService (
|
|||||||
|
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("LocalVariableName")
|
||||||
fun fromList(list: List<Any?>): UniversalBleService {
|
fun fromList(__pigeon_list: List<Any?>): UniversalBleService {
|
||||||
val uuid = list[0] as String
|
val uuid = __pigeon_list[0] as String
|
||||||
val characteristics = list[1] as List<UniversalBleCharacteristic?>?
|
val characteristics = __pigeon_list[1] as List<UniversalBleCharacteristic?>?
|
||||||
return UniversalBleService(uuid, characteristics)
|
return UniversalBleService(uuid, characteristics)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,10 +113,10 @@ data class UniversalBleCharacteristic (
|
|||||||
|
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("LocalVariableName")
|
||||||
fun fromList(list: List<Any?>): UniversalBleCharacteristic {
|
fun fromList(__pigeon_list: List<Any?>): UniversalBleCharacteristic {
|
||||||
val uuid = list[0] as String
|
val uuid = __pigeon_list[0] as String
|
||||||
val properties = list[1] as List<Long?>
|
val properties = __pigeon_list[1] as List<Long?>
|
||||||
return UniversalBleCharacteristic(uuid, properties)
|
return UniversalBleCharacteristic(uuid, properties)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,10 +139,10 @@ data class UniversalScanFilter (
|
|||||||
|
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("LocalVariableName")
|
||||||
fun fromList(list: List<Any?>): UniversalScanFilter {
|
fun fromList(__pigeon_list: List<Any?>): UniversalScanFilter {
|
||||||
val withServices = list[0] as List<String?>
|
val withServices = __pigeon_list[0] as List<String?>
|
||||||
val withManufacturerData = list[1] as List<UniversalManufacturerDataFilter?>
|
val withManufacturerData = __pigeon_list[1] as List<UniversalManufacturerDataFilter?>
|
||||||
return UniversalScanFilter(withServices, withManufacturerData)
|
return UniversalScanFilter(withServices, withManufacturerData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,11 +162,11 @@ data class UniversalManufacturerDataFilter (
|
|||||||
|
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("LocalVariableName")
|
||||||
fun fromList(list: List<Any?>): UniversalManufacturerDataFilter {
|
fun fromList(__pigeon_list: List<Any?>): UniversalManufacturerDataFilter {
|
||||||
val companyIdentifier = list[0].let { if (it is Int) it.toLong() else it as Long? }
|
val companyIdentifier = __pigeon_list[0].let { num -> if (num is Int) num.toLong() else num as Long? }
|
||||||
val data = list[1] as ByteArray?
|
val data = __pigeon_list[1] as ByteArray?
|
||||||
val mask = list[2] as ByteArray?
|
val mask = __pigeon_list[2] as ByteArray?
|
||||||
return UniversalManufacturerDataFilter(companyIdentifier, data, mask)
|
return UniversalManufacturerDataFilter(companyIdentifier, data, mask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -178,7 +179,6 @@ data class UniversalManufacturerDataFilter (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
private object UniversalBlePlatformChannelCodec : StandardMessageCodec() {
|
private object UniversalBlePlatformChannelCodec : StandardMessageCodec() {
|
||||||
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
|
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
|
||||||
return when (type) {
|
return when (type) {
|
||||||
@@ -249,7 +249,7 @@ interface UniversalBlePlatformChannel {
|
|||||||
fun stopScan()
|
fun stopScan()
|
||||||
fun connect(deviceId: String)
|
fun connect(deviceId: String)
|
||||||
fun disconnect(deviceId: String)
|
fun disconnect(deviceId: String)
|
||||||
fun setNotifiable(deviceId: String, service: String, characteristic: String, bleInputProperty: Long)
|
fun setNotifiable(deviceId: String, service: String, characteristic: String, bleInputProperty: Long, callback: (Result<Unit>) -> Unit)
|
||||||
fun discoverServices(deviceId: String, callback: (Result<List<UniversalBleService>>) -> Unit)
|
fun discoverServices(deviceId: String, callback: (Result<List<UniversalBleService>>) -> Unit)
|
||||||
fun readValue(deviceId: String, service: String, characteristic: String, callback: (Result<ByteArray>) -> Unit)
|
fun readValue(deviceId: String, service: String, characteristic: String, callback: (Result<ByteArray>) -> Unit)
|
||||||
fun requestMtu(deviceId: String, expectedMtu: Long, callback: (Result<Long>) -> Unit)
|
fun requestMtu(deviceId: String, expectedMtu: Long, callback: (Result<Long>) -> Unit)
|
||||||
@@ -265,10 +265,10 @@ interface UniversalBlePlatformChannel {
|
|||||||
UniversalBlePlatformChannelCodec
|
UniversalBlePlatformChannelCodec
|
||||||
}
|
}
|
||||||
/** Sets up an instance of `UniversalBlePlatformChannel` to handle messages through the `binaryMessenger`. */
|
/** Sets up an instance of `UniversalBlePlatformChannel` to handle messages through the `binaryMessenger`. */
|
||||||
@Suppress("UNCHECKED_CAST")
|
fun setUp(binaryMessenger: BinaryMessenger, api: UniversalBlePlatformChannel?, messageChannelSuffix: String = "") {
|
||||||
fun setUp(binaryMessenger: BinaryMessenger, api: UniversalBlePlatformChannel?) {
|
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
|
||||||
run {
|
run {
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getBluetoothAvailabilityState", codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getBluetoothAvailabilityState$separatedMessageChannelSuffix", codec)
|
||||||
if (api != null) {
|
if (api != null) {
|
||||||
channel.setMessageHandler { _, reply ->
|
channel.setMessageHandler { _, reply ->
|
||||||
api.getBluetoothAvailabilityState() { result: Result<Long> ->
|
api.getBluetoothAvailabilityState() { result: Result<Long> ->
|
||||||
@@ -286,7 +286,7 @@ interface UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
run {
|
run {
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.enableBluetooth", codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.enableBluetooth$separatedMessageChannelSuffix", codec)
|
||||||
if (api != null) {
|
if (api != null) {
|
||||||
channel.setMessageHandler { _, reply ->
|
channel.setMessageHandler { _, reply ->
|
||||||
api.enableBluetooth() { result: Result<Boolean> ->
|
api.enableBluetooth() { result: Result<Boolean> ->
|
||||||
@@ -304,17 +304,16 @@ interface UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
run {
|
run {
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.startScan", codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.startScan$separatedMessageChannelSuffix", codec)
|
||||||
if (api != null) {
|
if (api != null) {
|
||||||
channel.setMessageHandler { message, reply ->
|
channel.setMessageHandler { message, reply ->
|
||||||
val args = message as List<Any?>
|
val args = message as List<Any?>
|
||||||
val filterArg = args[0] as UniversalScanFilter?
|
val filterArg = args[0] as UniversalScanFilter?
|
||||||
var wrapped: List<Any?>
|
val wrapped: List<Any?> = try {
|
||||||
try {
|
|
||||||
api.startScan(filterArg)
|
api.startScan(filterArg)
|
||||||
wrapped = listOf<Any?>(null)
|
listOf<Any?>(null)
|
||||||
} catch (exception: Throwable) {
|
} catch (exception: Throwable) {
|
||||||
wrapped = wrapError(exception)
|
wrapError(exception)
|
||||||
}
|
}
|
||||||
reply.reply(wrapped)
|
reply.reply(wrapped)
|
||||||
}
|
}
|
||||||
@@ -323,15 +322,14 @@ interface UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
run {
|
run {
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.stopScan", codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.stopScan$separatedMessageChannelSuffix", codec)
|
||||||
if (api != null) {
|
if (api != null) {
|
||||||
channel.setMessageHandler { _, reply ->
|
channel.setMessageHandler { _, reply ->
|
||||||
var wrapped: List<Any?>
|
val wrapped: List<Any?> = try {
|
||||||
try {
|
|
||||||
api.stopScan()
|
api.stopScan()
|
||||||
wrapped = listOf<Any?>(null)
|
listOf<Any?>(null)
|
||||||
} catch (exception: Throwable) {
|
} catch (exception: Throwable) {
|
||||||
wrapped = wrapError(exception)
|
wrapError(exception)
|
||||||
}
|
}
|
||||||
reply.reply(wrapped)
|
reply.reply(wrapped)
|
||||||
}
|
}
|
||||||
@@ -340,17 +338,16 @@ interface UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
run {
|
run {
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.connect", codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.connect$separatedMessageChannelSuffix", codec)
|
||||||
if (api != null) {
|
if (api != null) {
|
||||||
channel.setMessageHandler { message, reply ->
|
channel.setMessageHandler { message, reply ->
|
||||||
val args = message as List<Any?>
|
val args = message as List<Any?>
|
||||||
val deviceIdArg = args[0] as String
|
val deviceIdArg = args[0] as String
|
||||||
var wrapped: List<Any?>
|
val wrapped: List<Any?> = try {
|
||||||
try {
|
|
||||||
api.connect(deviceIdArg)
|
api.connect(deviceIdArg)
|
||||||
wrapped = listOf<Any?>(null)
|
listOf<Any?>(null)
|
||||||
} catch (exception: Throwable) {
|
} catch (exception: Throwable) {
|
||||||
wrapped = wrapError(exception)
|
wrapError(exception)
|
||||||
}
|
}
|
||||||
reply.reply(wrapped)
|
reply.reply(wrapped)
|
||||||
}
|
}
|
||||||
@@ -359,17 +356,16 @@ interface UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
run {
|
run {
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.disconnect", codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.disconnect$separatedMessageChannelSuffix", codec)
|
||||||
if (api != null) {
|
if (api != null) {
|
||||||
channel.setMessageHandler { message, reply ->
|
channel.setMessageHandler { message, reply ->
|
||||||
val args = message as List<Any?>
|
val args = message as List<Any?>
|
||||||
val deviceIdArg = args[0] as String
|
val deviceIdArg = args[0] as String
|
||||||
var wrapped: List<Any?>
|
val wrapped: List<Any?> = try {
|
||||||
try {
|
|
||||||
api.disconnect(deviceIdArg)
|
api.disconnect(deviceIdArg)
|
||||||
wrapped = listOf<Any?>(null)
|
listOf<Any?>(null)
|
||||||
} catch (exception: Throwable) {
|
} catch (exception: Throwable) {
|
||||||
wrapped = wrapError(exception)
|
wrapError(exception)
|
||||||
}
|
}
|
||||||
reply.reply(wrapped)
|
reply.reply(wrapped)
|
||||||
}
|
}
|
||||||
@@ -378,29 +374,29 @@ interface UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
run {
|
run {
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.setNotifiable", codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.setNotifiable$separatedMessageChannelSuffix", codec)
|
||||||
if (api != null) {
|
if (api != null) {
|
||||||
channel.setMessageHandler { message, reply ->
|
channel.setMessageHandler { message, reply ->
|
||||||
val args = message as List<Any?>
|
val args = message as List<Any?>
|
||||||
val deviceIdArg = args[0] as String
|
val deviceIdArg = args[0] as String
|
||||||
val serviceArg = args[1] as String
|
val serviceArg = args[1] as String
|
||||||
val characteristicArg = args[2] as String
|
val characteristicArg = args[2] as String
|
||||||
val bleInputPropertyArg = args[3].let { if (it is Int) it.toLong() else it as Long }
|
val bleInputPropertyArg = args[3].let { num -> if (num is Int) num.toLong() else num as Long }
|
||||||
var wrapped: List<Any?>
|
api.setNotifiable(deviceIdArg, serviceArg, characteristicArg, bleInputPropertyArg) { result: Result<Unit> ->
|
||||||
try {
|
val error = result.exceptionOrNull()
|
||||||
api.setNotifiable(deviceIdArg, serviceArg, characteristicArg, bleInputPropertyArg)
|
if (error != null) {
|
||||||
wrapped = listOf<Any?>(null)
|
reply.reply(wrapError(error))
|
||||||
} catch (exception: Throwable) {
|
} else {
|
||||||
wrapped = wrapError(exception)
|
reply.reply(wrapResult(null))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
reply.reply(wrapped)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
channel.setMessageHandler(null)
|
channel.setMessageHandler(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
run {
|
run {
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.discoverServices", codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.discoverServices$separatedMessageChannelSuffix", codec)
|
||||||
if (api != null) {
|
if (api != null) {
|
||||||
channel.setMessageHandler { message, reply ->
|
channel.setMessageHandler { message, reply ->
|
||||||
val args = message as List<Any?>
|
val args = message as List<Any?>
|
||||||
@@ -420,7 +416,7 @@ interface UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
run {
|
run {
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.readValue", codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.readValue$separatedMessageChannelSuffix", codec)
|
||||||
if (api != null) {
|
if (api != null) {
|
||||||
channel.setMessageHandler { message, reply ->
|
channel.setMessageHandler { message, reply ->
|
||||||
val args = message as List<Any?>
|
val args = message as List<Any?>
|
||||||
@@ -442,12 +438,12 @@ interface UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
run {
|
run {
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.requestMtu", codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.requestMtu$separatedMessageChannelSuffix", codec)
|
||||||
if (api != null) {
|
if (api != null) {
|
||||||
channel.setMessageHandler { message, reply ->
|
channel.setMessageHandler { message, reply ->
|
||||||
val args = message as List<Any?>
|
val args = message as List<Any?>
|
||||||
val deviceIdArg = args[0] as String
|
val deviceIdArg = args[0] as String
|
||||||
val expectedMtuArg = args[1].let { if (it is Int) it.toLong() else it as Long }
|
val expectedMtuArg = args[1].let { num -> if (num is Int) num.toLong() else num as Long }
|
||||||
api.requestMtu(deviceIdArg, expectedMtuArg) { result: Result<Long> ->
|
api.requestMtu(deviceIdArg, expectedMtuArg) { result: Result<Long> ->
|
||||||
val error = result.exceptionOrNull()
|
val error = result.exceptionOrNull()
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
@@ -463,7 +459,7 @@ interface UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
run {
|
run {
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.writeValue", codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.writeValue$separatedMessageChannelSuffix", codec)
|
||||||
if (api != null) {
|
if (api != null) {
|
||||||
channel.setMessageHandler { message, reply ->
|
channel.setMessageHandler { message, reply ->
|
||||||
val args = message as List<Any?>
|
val args = message as List<Any?>
|
||||||
@@ -471,7 +467,7 @@ interface UniversalBlePlatformChannel {
|
|||||||
val serviceArg = args[1] as String
|
val serviceArg = args[1] as String
|
||||||
val characteristicArg = args[2] as String
|
val characteristicArg = args[2] as String
|
||||||
val valueArg = args[3] as ByteArray
|
val valueArg = args[3] as ByteArray
|
||||||
val bleOutputPropertyArg = args[4].let { if (it is Int) it.toLong() else it as Long }
|
val bleOutputPropertyArg = args[4].let { num -> if (num is Int) num.toLong() else num as Long }
|
||||||
api.writeValue(deviceIdArg, serviceArg, characteristicArg, valueArg, bleOutputPropertyArg) { result: Result<Unit> ->
|
api.writeValue(deviceIdArg, serviceArg, characteristicArg, valueArg, bleOutputPropertyArg) { result: Result<Unit> ->
|
||||||
val error = result.exceptionOrNull()
|
val error = result.exceptionOrNull()
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
@@ -486,7 +482,7 @@ interface UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
run {
|
run {
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.isPaired", codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.isPaired$separatedMessageChannelSuffix", codec)
|
||||||
if (api != null) {
|
if (api != null) {
|
||||||
channel.setMessageHandler { message, reply ->
|
channel.setMessageHandler { message, reply ->
|
||||||
val args = message as List<Any?>
|
val args = message as List<Any?>
|
||||||
@@ -506,17 +502,16 @@ interface UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
run {
|
run {
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.pair", codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.pair$separatedMessageChannelSuffix", codec)
|
||||||
if (api != null) {
|
if (api != null) {
|
||||||
channel.setMessageHandler { message, reply ->
|
channel.setMessageHandler { message, reply ->
|
||||||
val args = message as List<Any?>
|
val args = message as List<Any?>
|
||||||
val deviceIdArg = args[0] as String
|
val deviceIdArg = args[0] as String
|
||||||
var wrapped: List<Any?>
|
val wrapped: List<Any?> = try {
|
||||||
try {
|
|
||||||
api.pair(deviceIdArg)
|
api.pair(deviceIdArg)
|
||||||
wrapped = listOf<Any?>(null)
|
listOf<Any?>(null)
|
||||||
} catch (exception: Throwable) {
|
} catch (exception: Throwable) {
|
||||||
wrapped = wrapError(exception)
|
wrapError(exception)
|
||||||
}
|
}
|
||||||
reply.reply(wrapped)
|
reply.reply(wrapped)
|
||||||
}
|
}
|
||||||
@@ -525,17 +520,16 @@ interface UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
run {
|
run {
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.unPair", codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.unPair$separatedMessageChannelSuffix", codec)
|
||||||
if (api != null) {
|
if (api != null) {
|
||||||
channel.setMessageHandler { message, reply ->
|
channel.setMessageHandler { message, reply ->
|
||||||
val args = message as List<Any?>
|
val args = message as List<Any?>
|
||||||
val deviceIdArg = args[0] as String
|
val deviceIdArg = args[0] as String
|
||||||
var wrapped: List<Any?>
|
val wrapped: List<Any?> = try {
|
||||||
try {
|
|
||||||
api.unPair(deviceIdArg)
|
api.unPair(deviceIdArg)
|
||||||
wrapped = listOf<Any?>(null)
|
listOf<Any?>(null)
|
||||||
} catch (exception: Throwable) {
|
} catch (exception: Throwable) {
|
||||||
wrapped = wrapError(exception)
|
wrapError(exception)
|
||||||
}
|
}
|
||||||
reply.reply(wrapped)
|
reply.reply(wrapped)
|
||||||
}
|
}
|
||||||
@@ -544,7 +538,7 @@ interface UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
run {
|
run {
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getConnectedDevices", codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getConnectedDevices$separatedMessageChannelSuffix", codec)
|
||||||
if (api != null) {
|
if (api != null) {
|
||||||
channel.setMessageHandler { message, reply ->
|
channel.setMessageHandler { message, reply ->
|
||||||
val args = message as List<Any?>
|
val args = message as List<Any?>
|
||||||
@@ -566,7 +560,6 @@ interface UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
private object UniversalBleCallbackChannelCodec : StandardMessageCodec() {
|
private object UniversalBleCallbackChannelCodec : StandardMessageCodec() {
|
||||||
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
|
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
|
||||||
return when (type) {
|
return when (type) {
|
||||||
@@ -594,8 +587,7 @@ private object UniversalBleCallbackChannelCodec : StandardMessageCodec() {
|
|||||||
*
|
*
|
||||||
* Generated class from Pigeon that represents Flutter messages that can be called from Kotlin.
|
* Generated class from Pigeon that represents Flutter messages that can be called from Kotlin.
|
||||||
*/
|
*/
|
||||||
@Suppress("UNCHECKED_CAST")
|
class UniversalBleCallbackChannel(private val binaryMessenger: BinaryMessenger, private val messageChannelSuffix: String = "") {
|
||||||
class UniversalBleCallbackChannel(private val binaryMessenger: BinaryMessenger) {
|
|
||||||
companion object {
|
companion object {
|
||||||
/** The codec used by UniversalBleCallbackChannel. */
|
/** The codec used by UniversalBleCallbackChannel. */
|
||||||
val codec: MessageCodec<Any?> by lazy {
|
val codec: MessageCodec<Any?> by lazy {
|
||||||
@@ -604,7 +596,8 @@ class UniversalBleCallbackChannel(private val binaryMessenger: BinaryMessenger)
|
|||||||
}
|
}
|
||||||
fun onAvailabilityChanged(stateArg: Long, callback: (Result<Unit>) -> Unit)
|
fun onAvailabilityChanged(stateArg: Long, callback: (Result<Unit>) -> Unit)
|
||||||
{
|
{
|
||||||
val channelName = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onAvailabilityChanged"
|
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
|
||||||
|
val channelName = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onAvailabilityChanged$separatedMessageChannelSuffix"
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
|
||||||
channel.send(listOf(stateArg)) {
|
channel.send(listOf(stateArg)) {
|
||||||
if (it is List<*>) {
|
if (it is List<*>) {
|
||||||
@@ -620,7 +613,8 @@ class UniversalBleCallbackChannel(private val binaryMessenger: BinaryMessenger)
|
|||||||
}
|
}
|
||||||
fun onPairStateChange(deviceIdArg: String, isPairedArg: Boolean, errorArg: String?, callback: (Result<Unit>) -> Unit)
|
fun onPairStateChange(deviceIdArg: String, isPairedArg: Boolean, errorArg: String?, callback: (Result<Unit>) -> Unit)
|
||||||
{
|
{
|
||||||
val channelName = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onPairStateChange"
|
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
|
||||||
|
val channelName = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onPairStateChange$separatedMessageChannelSuffix"
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
|
||||||
channel.send(listOf(deviceIdArg, isPairedArg, errorArg)) {
|
channel.send(listOf(deviceIdArg, isPairedArg, errorArg)) {
|
||||||
if (it is List<*>) {
|
if (it is List<*>) {
|
||||||
@@ -636,7 +630,8 @@ class UniversalBleCallbackChannel(private val binaryMessenger: BinaryMessenger)
|
|||||||
}
|
}
|
||||||
fun onScanResult(resultArg: UniversalBleScanResult, callback: (Result<Unit>) -> Unit)
|
fun onScanResult(resultArg: UniversalBleScanResult, callback: (Result<Unit>) -> Unit)
|
||||||
{
|
{
|
||||||
val channelName = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onScanResult"
|
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
|
||||||
|
val channelName = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onScanResult$separatedMessageChannelSuffix"
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
|
||||||
channel.send(listOf(resultArg)) {
|
channel.send(listOf(resultArg)) {
|
||||||
if (it is List<*>) {
|
if (it is List<*>) {
|
||||||
@@ -652,7 +647,8 @@ class UniversalBleCallbackChannel(private val binaryMessenger: BinaryMessenger)
|
|||||||
}
|
}
|
||||||
fun onValueChanged(deviceIdArg: String, characteristicIdArg: String, valueArg: ByteArray, callback: (Result<Unit>) -> Unit)
|
fun onValueChanged(deviceIdArg: String, characteristicIdArg: String, valueArg: ByteArray, callback: (Result<Unit>) -> Unit)
|
||||||
{
|
{
|
||||||
val channelName = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onValueChanged"
|
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
|
||||||
|
val channelName = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onValueChanged$separatedMessageChannelSuffix"
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
|
||||||
channel.send(listOf(deviceIdArg, characteristicIdArg, valueArg)) {
|
channel.send(listOf(deviceIdArg, characteristicIdArg, valueArg)) {
|
||||||
if (it is List<*>) {
|
if (it is List<*>) {
|
||||||
@@ -668,7 +664,8 @@ class UniversalBleCallbackChannel(private val binaryMessenger: BinaryMessenger)
|
|||||||
}
|
}
|
||||||
fun onConnectionChanged(deviceIdArg: String, stateArg: Long, callback: (Result<Unit>) -> Unit)
|
fun onConnectionChanged(deviceIdArg: String, stateArg: Long, callback: (Result<Unit>) -> Unit)
|
||||||
{
|
{
|
||||||
val channelName = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onConnectionChanged"
|
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
|
||||||
|
val channelName = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onConnectionChanged$separatedMessageChannelSuffix"
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
|
||||||
channel.send(listOf(deviceIdArg, stateArg)) {
|
channel.send(listOf(deviceIdArg, stateArg)) {
|
||||||
if (it is List<*>) {
|
if (it is List<*>) {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import android.bluetooth.le.ScanCallback.SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES
|
|||||||
import android.bluetooth.le.ScanCallback.SCAN_FAILED_SCANNING_TOO_FREQUENTLY
|
import android.bluetooth.le.ScanCallback.SCAN_FAILED_SCANNING_TOO_FREQUENTLY
|
||||||
import android.bluetooth.le.ScanFilter
|
import android.bluetooth.le.ScanFilter
|
||||||
import android.bluetooth.le.ScanResult
|
import android.bluetooth.le.ScanResult
|
||||||
|
import android.os.Build
|
||||||
import android.os.ParcelUuid
|
import android.os.ParcelUuid
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
@@ -24,7 +25,7 @@ import java.util.UUID
|
|||||||
private const val TAG = "UniversalBlePlugin"
|
private const val TAG = "UniversalBlePlugin"
|
||||||
|
|
||||||
val knownGatts = mutableListOf<BluetoothGatt>()
|
val knownGatts = mutableListOf<BluetoothGatt>()
|
||||||
|
val ccdCharacteristic = "00002902-0000-1000-8000-00805f9b34fb"
|
||||||
|
|
||||||
enum class BleConnectionState(val value: Long) {
|
enum class BleConnectionState(val value: Long) {
|
||||||
Connected(0),
|
Connected(0),
|
||||||
@@ -216,12 +217,12 @@ fun BluetoothGatt.getCharacteristic(
|
|||||||
|
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
fun BluetoothGatt.setNotifiable(
|
fun BluetoothGatt.setNotifiable(
|
||||||
gattCharacteristic: BluetoothGattCharacteristic,
|
gattCharacteristic: BluetoothGattCharacteristic,
|
||||||
bleInputProperty: Long,
|
bleInputProperty: Long,
|
||||||
) {
|
): Boolean {
|
||||||
val descClientCharConfirmation =
|
val descClientCharConfirmation = UUID.fromString(ccdCharacteristic)
|
||||||
UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")
|
|
||||||
val descriptor = gattCharacteristic.getDescriptor(descClientCharConfirmation)
|
val descriptor = gattCharacteristic.getDescriptor(descClientCharConfirmation)
|
||||||
val bleInputPropertyEnum: BleInputProperty =
|
val bleInputPropertyEnum: BleInputProperty =
|
||||||
BleInputProperty.values().first { it.value == bleInputProperty }
|
BleInputProperty.values().first { it.value == bleInputProperty }
|
||||||
@@ -230,8 +231,13 @@ fun BluetoothGatt.setNotifiable(
|
|||||||
BleInputProperty.Indication -> BluetoothGattDescriptor.ENABLE_INDICATION_VALUE to true
|
BleInputProperty.Indication -> BluetoothGattDescriptor.ENABLE_INDICATION_VALUE to true
|
||||||
else -> BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE to false
|
else -> BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE to false
|
||||||
}
|
}
|
||||||
descriptor.value = value
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
setCharacteristicNotification(descriptor.characteristic, enable) && writeDescriptor(descriptor)
|
writeDescriptor(descriptor, value)
|
||||||
|
} else {
|
||||||
|
descriptor.value = value
|
||||||
|
writeDescriptor(descriptor)
|
||||||
|
}
|
||||||
|
return setCharacteristicNotification(descriptor.characteristic, enable)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BluetoothDevice.removeBond() {
|
fun BluetoothDevice.removeBond() {
|
||||||
@@ -303,4 +309,11 @@ class WriteResultFuture(
|
|||||||
val characteristicId: String,
|
val characteristicId: String,
|
||||||
val serviceId: String,
|
val serviceId: String,
|
||||||
val result: (Result<Unit>) -> Unit,
|
val result: (Result<Unit>) -> Unit,
|
||||||
|
)
|
||||||
|
|
||||||
|
class CharacteristicSubscriptionFuture(
|
||||||
|
val deviceId: String,
|
||||||
|
val characteristicId: String,
|
||||||
|
val serviceId: String,
|
||||||
|
val result: (Result<Unit>) -> Unit,
|
||||||
)
|
)
|
||||||
@@ -17,13 +17,11 @@ import android.content.IntentFilter
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.os.ParcelUuid
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
||||||
import io.flutter.embedding.engine.plugins.activity.ActivityAware
|
import io.flutter.embedding.engine.plugins.activity.ActivityAware
|
||||||
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
|
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
|
||||||
import io.flutter.plugin.common.*
|
import io.flutter.plugin.common.*
|
||||||
import java.util.*
|
|
||||||
import java.util.concurrent.CountDownLatch
|
import java.util.concurrent.CountDownLatch
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
@@ -42,6 +40,8 @@ class UniversalBlePlugin : UniversalBlePlatformChannel, BluetoothGattCallback(),
|
|||||||
private val mtuResultFutureList = mutableListOf<MtuResultFuture>()
|
private val mtuResultFutureList = mutableListOf<MtuResultFuture>()
|
||||||
private val bleCharacteristicFutureList = mutableListOf<BleCharacteristicFuture>()
|
private val bleCharacteristicFutureList = mutableListOf<BleCharacteristicFuture>()
|
||||||
private val discoverServicesFutureList = mutableListOf<DiscoverServicesFuture>()
|
private val discoverServicesFutureList = mutableListOf<DiscoverServicesFuture>()
|
||||||
|
private val characteristicSubscriptionFutureList =
|
||||||
|
mutableListOf<CharacteristicSubscriptionFuture>()
|
||||||
private val writeResultFutureList = mutableListOf<WriteResultFuture>()
|
private val writeResultFutureList = mutableListOf<WriteResultFuture>()
|
||||||
private val cachedServicesMap = mutableMapOf<String, List<String>>()
|
private val cachedServicesMap = mutableMapOf<String, List<String>>()
|
||||||
private val devicesStateMap = mutableMapOf<String, Int>()
|
private val devicesStateMap = mutableMapOf<String, Int>()
|
||||||
@@ -56,7 +56,7 @@ class UniversalBlePlugin : UniversalBlePlatformChannel, BluetoothGattCallback(),
|
|||||||
|
|
||||||
val intentFilter = IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED)
|
val intentFilter = IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED)
|
||||||
intentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED)
|
intentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED)
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
context.registerReceiver(broadcastReceiver, intentFilter, RECEIVER_EXPORTED)
|
context.registerReceiver(broadcastReceiver, intentFilter, RECEIVER_EXPORTED)
|
||||||
} else {
|
} else {
|
||||||
context.registerReceiver(broadcastReceiver, intentFilter)
|
context.registerReceiver(broadcastReceiver, intentFilter)
|
||||||
@@ -225,15 +225,50 @@ class UniversalBlePlugin : UniversalBlePlatformChannel, BluetoothGattCallback(),
|
|||||||
service: String,
|
service: String,
|
||||||
characteristic: String,
|
characteristic: String,
|
||||||
bleInputProperty: Long,
|
bleInputProperty: Long,
|
||||||
|
callback: (Result<Unit>) -> Unit,
|
||||||
) {
|
) {
|
||||||
val gatt = deviceId.toBluetoothGatt()
|
try {
|
||||||
val gattCharacteristic = gatt.getCharacteristic(service, characteristic)
|
val gatt = deviceId.toBluetoothGatt()
|
||||||
?: throw FlutterError(
|
val gattCharacteristic = gatt.getCharacteristic(service, characteristic)
|
||||||
"IllegalArgument",
|
?: throw FlutterError(
|
||||||
"Unknown characteristic: $characteristic",
|
"IllegalArgument",
|
||||||
null
|
"Unknown characteristic: $characteristic",
|
||||||
|
null
|
||||||
|
)
|
||||||
|
|
||||||
|
if (gatt.setNotifiable(gattCharacteristic, bleInputProperty)) {
|
||||||
|
characteristicSubscriptionFutureList.add(
|
||||||
|
CharacteristicSubscriptionFuture(
|
||||||
|
gatt.device.address,
|
||||||
|
gattCharacteristic.uuid.toString(),
|
||||||
|
gattCharacteristic.service.uuid.toString(),
|
||||||
|
callback
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
callback(
|
||||||
|
Result.failure(
|
||||||
|
FlutterError(
|
||||||
|
"Failed",
|
||||||
|
"Failed to update subscription state",
|
||||||
|
null
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} catch (e: FlutterError) {
|
||||||
|
callback(Result.failure(e))
|
||||||
|
} catch (e: Exception) {
|
||||||
|
callback(
|
||||||
|
Result.failure(
|
||||||
|
FlutterError(
|
||||||
|
"Failed",
|
||||||
|
"Failed to update subscription state",
|
||||||
|
e.toString()
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
gatt.setNotifiable(gattCharacteristic, bleInputProperty)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun readValue(
|
override fun readValue(
|
||||||
@@ -268,6 +303,16 @@ class UniversalBlePlugin : UniversalBlePlatformChannel, BluetoothGattCallback(),
|
|||||||
)
|
)
|
||||||
} catch (e: FlutterError) {
|
} catch (e: FlutterError) {
|
||||||
callback(Result.failure(e))
|
callback(Result.failure(e))
|
||||||
|
} catch (e: Exception) {
|
||||||
|
callback(
|
||||||
|
Result.failure(
|
||||||
|
FlutterError(
|
||||||
|
"Failed",
|
||||||
|
"Failed to read value",
|
||||||
|
e.toString()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,16 +345,6 @@ class UniversalBlePlugin : UniversalBlePlatformChannel, BluetoothGattCallback(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCharacteristicRead(
|
|
||||||
gatt: BluetoothGatt,
|
|
||||||
characteristic: BluetoothGattCharacteristic,
|
|
||||||
status: Int,
|
|
||||||
) {
|
|
||||||
// Pass data to new api
|
|
||||||
onCharacteristicRead(gatt, characteristic, characteristic.value, status)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
override fun writeValue(
|
override fun writeValue(
|
||||||
deviceId: String,
|
deviceId: String,
|
||||||
service: String,
|
service: String,
|
||||||
@@ -356,18 +391,23 @@ class UniversalBlePlugin : UniversalBlePlatformChannel, BluetoothGattCallback(),
|
|||||||
}
|
}
|
||||||
writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE
|
writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE
|
||||||
}
|
}
|
||||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
||||||
// val result = gatt.writeCharacteristic(gattCharacteristic, value, writeType)
|
val result = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
// Log.v(TAG,"writeResult $characteristic: $result => ${result.parseBluetoothStatusCodeError()}")
|
val writeResult = gatt.writeCharacteristic(gattCharacteristic, value, writeType)
|
||||||
// return
|
writeResult == BluetoothGatt.GATT_SUCCESS
|
||||||
// }
|
} else {
|
||||||
gattCharacteristic.value = value
|
@Suppress("DEPRECATION")
|
||||||
gattCharacteristic.writeType = writeType
|
gattCharacteristic.value = value
|
||||||
val result = gatt.writeCharacteristic(gattCharacteristic)
|
gattCharacteristic.writeType = writeType
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
gatt.writeCharacteristic(gattCharacteristic)
|
||||||
|
}
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
callback(Result.failure(FlutterError("Failed", "Failed to write", null)))
|
callback(Result.failure(FlutterError("Failed", "Failed to write", null)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (writeType == BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT) {
|
if (writeType == BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT) {
|
||||||
// wait for the result
|
// wait for the result
|
||||||
writeResultFutureList.add(
|
writeResultFutureList.add(
|
||||||
@@ -535,13 +575,13 @@ class UniversalBlePlugin : UniversalBlePlatformChannel, BluetoothGattCallback(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If its a known gatt, just discover services
|
// If its a known gatt, just discover services
|
||||||
knownGatts.find { it.device.address == device.address }?.let {
|
knownGatts.find { it.device.address == device.address }?.let { gatt ->
|
||||||
it.services?.let { services ->
|
gatt.services?.let { services ->
|
||||||
updateCallback(services.map { service -> service.uuid.toString() })
|
updateCallback(services.map { service -> service.uuid.toString() })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (it.discoverServices()) {
|
if (gatt.discoverServices()) {
|
||||||
discoverServicesFutureList.add(
|
discoverServicesFutureList.add(
|
||||||
DiscoverServicesFuture(device.address) { uuids: Result<List<UniversalBleService>> ->
|
DiscoverServicesFuture(device.address) { uuids: Result<List<UniversalBleService>> ->
|
||||||
if (uuids.isSuccess) {
|
if (uuids.isSuccess) {
|
||||||
@@ -616,7 +656,16 @@ class UniversalBlePlugin : UniversalBlePlatformChannel, BluetoothGattCallback(),
|
|||||||
}
|
}
|
||||||
} else if (intent.action == BluetoothDevice.ACTION_BOND_STATE_CHANGED) {
|
} else if (intent.action == BluetoothDevice.ACTION_BOND_STATE_CHANGED) {
|
||||||
val device: BluetoothDevice =
|
val device: BluetoothDevice =
|
||||||
intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE) ?: return
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
intent.getParcelableExtra(
|
||||||
|
BluetoothDevice.EXTRA_DEVICE,
|
||||||
|
BluetoothDevice::class.java
|
||||||
|
)
|
||||||
|
?: return
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE) ?: return
|
||||||
|
}
|
||||||
// get pairing failed error
|
// get pairing failed error
|
||||||
when (intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.ERROR)) {
|
when (intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.ERROR)) {
|
||||||
BluetoothDevice.BOND_BONDING -> {
|
BluetoothDevice.BOND_BONDING -> {
|
||||||
@@ -665,7 +714,7 @@ class UniversalBlePlugin : UniversalBlePlatformChannel, BluetoothGattCallback(),
|
|||||||
|
|
||||||
override fun onScanResult(callbackType: Int, result: ScanResult) {
|
override fun onScanResult(callbackType: Int, result: ScanResult) {
|
||||||
// Log.v(TAG, "onScanResult: $result")
|
// Log.v(TAG, "onScanResult: $result")
|
||||||
var serviceUuids: Array<String> = arrayOf<String>()
|
var serviceUuids: Array<String> = arrayOf()
|
||||||
result.device.uuids?.forEach {
|
result.device.uuids?.forEach {
|
||||||
serviceUuids += it.uuid.toString()
|
serviceUuids += it.uuid.toString()
|
||||||
}
|
}
|
||||||
@@ -687,7 +736,7 @@ class UniversalBlePlugin : UniversalBlePlatformChannel, BluetoothGattCallback(),
|
|||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBatchScanResults(results: MutableList<ScanResult>?) {
|
override fun onBatchScanResults(results: MutableList<ScanResult>?) {
|
||||||
Log.v(TAG, "onBatchScanResults: $results")
|
Log.v(TAG, "onBatchScanResults: $results")
|
||||||
}
|
}
|
||||||
@@ -717,16 +766,62 @@ class UniversalBlePlugin : UniversalBlePlatformChannel, BluetoothGattCallback(),
|
|||||||
override fun onCharacteristicChanged(
|
override fun onCharacteristicChanged(
|
||||||
gatt: BluetoothGatt,
|
gatt: BluetoothGatt,
|
||||||
characteristic: BluetoothGattCharacteristic,
|
characteristic: BluetoothGattCharacteristic,
|
||||||
|
value: ByteArray,
|
||||||
) {
|
) {
|
||||||
mainThreadHandler?.post {
|
mainThreadHandler?.post {
|
||||||
callbackChannel?.onValueChanged(
|
callbackChannel?.onValueChanged(
|
||||||
deviceIdArg = gatt.device.address,
|
deviceIdArg = gatt.device.address,
|
||||||
characteristicIdArg = characteristic.uuid.toString(),
|
characteristicIdArg = characteristic.uuid.toString(),
|
||||||
valueArg = characteristic.value
|
valueArg = value
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDescriptorWrite(
|
||||||
|
gatt: BluetoothGatt?,
|
||||||
|
descriptor: BluetoothGattDescriptor?,
|
||||||
|
status: Int,
|
||||||
|
) {
|
||||||
|
super.onDescriptorWrite(gatt, descriptor, status)
|
||||||
|
if (descriptor?.uuid.toString() == ccdCharacteristic) {
|
||||||
|
val char: String? = descriptor?.characteristic?.uuid?.toString()
|
||||||
|
val service: String? = descriptor?.characteristic?.service?.uuid?.toString()
|
||||||
|
val deviceId: String? = gatt?.device?.address;
|
||||||
|
if (deviceId != null && char != null && service != null) {
|
||||||
|
updateSubscriptionState(deviceId, char, service, status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateSubscriptionState(
|
||||||
|
deviceId: String,
|
||||||
|
characteristic: String,
|
||||||
|
service: String,
|
||||||
|
status: Int,
|
||||||
|
) {
|
||||||
|
characteristicSubscriptionFutureList.filter {
|
||||||
|
it.deviceId == deviceId &&
|
||||||
|
it.characteristicId == characteristic &&
|
||||||
|
it.serviceId == service
|
||||||
|
}.forEach {
|
||||||
|
characteristicSubscriptionFutureList.remove(it)
|
||||||
|
val error: String? = status.parseGattErrorCode()
|
||||||
|
if (error != null) {
|
||||||
|
it.result(
|
||||||
|
Result.failure(
|
||||||
|
FlutterError(
|
||||||
|
status.toString(),
|
||||||
|
"Failed to update subscription state: $error",
|
||||||
|
null,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
it.result(Result.success(Unit))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun isBluetoothAvailable(): Boolean {
|
private fun isBluetoothAvailable(): Boolean {
|
||||||
return bluetoothManager.adapter.isEnabled
|
return bluetoothManager.adapter.isEnabled
|
||||||
}
|
}
|
||||||
@@ -750,6 +845,24 @@ class UniversalBlePlugin : UniversalBlePlatformChannel, BluetoothGattCallback(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Depreciated Members, ( Requires to support older android devices )
|
||||||
|
@Suppress("OVERRIDE_DEPRECATION", "DEPRECATION")
|
||||||
|
override fun onCharacteristicRead(
|
||||||
|
gatt: BluetoothGatt,
|
||||||
|
characteristic: BluetoothGattCharacteristic,
|
||||||
|
status: Int,
|
||||||
|
) {
|
||||||
|
onCharacteristicRead(gatt, characteristic, characteristic.value, status)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("OVERRIDE_DEPRECATION", "DEPRECATION")
|
||||||
|
override fun onCharacteristicChanged(
|
||||||
|
gatt: BluetoothGatt,
|
||||||
|
characteristic: BluetoothGattCharacteristic,
|
||||||
|
) {
|
||||||
|
onCharacteristicChanged(gatt, characteristic, characteristic.value)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean {
|
||||||
if (requestCode == bluetoothEnableRequestCode) {
|
if (requestCode == bluetoothEnableRequestCode) {
|
||||||
val future = bluetoothEnableRequestFuture ?: return false
|
val future = bluetoothEnableRequestFuture ?: return false
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Autogenerated from Pigeon (v17.1.1), do not edit directly.
|
// Autogenerated from Pigeon (v18.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
@@ -53,14 +53,15 @@ struct UniversalBleScanResult {
|
|||||||
var manufacturerDataHead: FlutterStandardTypedData? = nil
|
var manufacturerDataHead: FlutterStandardTypedData? = nil
|
||||||
var services: [String?]? = nil
|
var services: [String?]? = nil
|
||||||
|
|
||||||
static func fromList(_ list: [Any?]) -> UniversalBleScanResult? {
|
// swift-format-ignore: AlwaysUseLowerCamelCase
|
||||||
let deviceId = list[0] as! String
|
static func fromList(_ __pigeon_list: [Any?]) -> UniversalBleScanResult? {
|
||||||
let name: String? = nilOrValue(list[1])
|
let deviceId = __pigeon_list[0] as! String
|
||||||
let isPaired: Bool? = nilOrValue(list[2])
|
let name: String? = nilOrValue(__pigeon_list[1])
|
||||||
let rssi: Int64? = isNullish(list[3]) ? nil : (list[3] is Int64? ? list[3] as! Int64? : Int64(list[3] as! Int32))
|
let isPaired: Bool? = nilOrValue(__pigeon_list[2])
|
||||||
let manufacturerData: FlutterStandardTypedData? = nilOrValue(list[4])
|
let rssi: Int64? = isNullish(__pigeon_list[3]) ? nil : (__pigeon_list[3] is Int64? ? __pigeon_list[3] as! Int64? : Int64(__pigeon_list[3] as! Int32))
|
||||||
let manufacturerDataHead: FlutterStandardTypedData? = nilOrValue(list[5])
|
let manufacturerData: FlutterStandardTypedData? = nilOrValue(__pigeon_list[4])
|
||||||
let services: [String?]? = nilOrValue(list[6])
|
let manufacturerDataHead: FlutterStandardTypedData? = nilOrValue(__pigeon_list[5])
|
||||||
|
let services: [String?]? = nilOrValue(__pigeon_list[6])
|
||||||
|
|
||||||
return UniversalBleScanResult(
|
return UniversalBleScanResult(
|
||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
@@ -90,9 +91,10 @@ struct UniversalBleService {
|
|||||||
var uuid: String
|
var uuid: String
|
||||||
var characteristics: [UniversalBleCharacteristic?]? = nil
|
var characteristics: [UniversalBleCharacteristic?]? = nil
|
||||||
|
|
||||||
static func fromList(_ list: [Any?]) -> UniversalBleService? {
|
// swift-format-ignore: AlwaysUseLowerCamelCase
|
||||||
let uuid = list[0] as! String
|
static func fromList(_ __pigeon_list: [Any?]) -> UniversalBleService? {
|
||||||
let characteristics: [UniversalBleCharacteristic?]? = nilOrValue(list[1])
|
let uuid = __pigeon_list[0] as! String
|
||||||
|
let characteristics: [UniversalBleCharacteristic?]? = nilOrValue(__pigeon_list[1])
|
||||||
|
|
||||||
return UniversalBleService(
|
return UniversalBleService(
|
||||||
uuid: uuid,
|
uuid: uuid,
|
||||||
@@ -112,9 +114,10 @@ struct UniversalBleCharacteristic {
|
|||||||
var uuid: String
|
var uuid: String
|
||||||
var properties: [Int64?]
|
var properties: [Int64?]
|
||||||
|
|
||||||
static func fromList(_ list: [Any?]) -> UniversalBleCharacteristic? {
|
// swift-format-ignore: AlwaysUseLowerCamelCase
|
||||||
let uuid = list[0] as! String
|
static func fromList(_ __pigeon_list: [Any?]) -> UniversalBleCharacteristic? {
|
||||||
let properties = list[1] as! [Int64?]
|
let uuid = __pigeon_list[0] as! String
|
||||||
|
let properties = __pigeon_list[1] as! [Int64?]
|
||||||
|
|
||||||
return UniversalBleCharacteristic(
|
return UniversalBleCharacteristic(
|
||||||
uuid: uuid,
|
uuid: uuid,
|
||||||
@@ -136,9 +139,10 @@ struct UniversalScanFilter {
|
|||||||
var withServices: [String?]
|
var withServices: [String?]
|
||||||
var withManufacturerData: [UniversalManufacturerDataFilter?]
|
var withManufacturerData: [UniversalManufacturerDataFilter?]
|
||||||
|
|
||||||
static func fromList(_ list: [Any?]) -> UniversalScanFilter? {
|
// swift-format-ignore: AlwaysUseLowerCamelCase
|
||||||
let withServices = list[0] as! [String?]
|
static func fromList(_ __pigeon_list: [Any?]) -> UniversalScanFilter? {
|
||||||
let withManufacturerData = list[1] as! [UniversalManufacturerDataFilter?]
|
let withServices = __pigeon_list[0] as! [String?]
|
||||||
|
let withManufacturerData = __pigeon_list[1] as! [UniversalManufacturerDataFilter?]
|
||||||
|
|
||||||
return UniversalScanFilter(
|
return UniversalScanFilter(
|
||||||
withServices: withServices,
|
withServices: withServices,
|
||||||
@@ -159,10 +163,11 @@ struct UniversalManufacturerDataFilter {
|
|||||||
var data: FlutterStandardTypedData? = nil
|
var data: FlutterStandardTypedData? = nil
|
||||||
var mask: FlutterStandardTypedData? = nil
|
var mask: FlutterStandardTypedData? = nil
|
||||||
|
|
||||||
static func fromList(_ list: [Any?]) -> UniversalManufacturerDataFilter? {
|
// swift-format-ignore: AlwaysUseLowerCamelCase
|
||||||
let companyIdentifier: Int64? = isNullish(list[0]) ? nil : (list[0] is Int64? ? list[0] as! Int64? : Int64(list[0] as! Int32))
|
static func fromList(_ __pigeon_list: [Any?]) -> UniversalManufacturerDataFilter? {
|
||||||
let data: FlutterStandardTypedData? = nilOrValue(list[1])
|
let companyIdentifier: Int64? = isNullish(__pigeon_list[0]) ? nil : (__pigeon_list[0] is Int64? ? __pigeon_list[0] as! Int64? : Int64(__pigeon_list[0] as! Int32))
|
||||||
let mask: FlutterStandardTypedData? = nilOrValue(list[2])
|
let data: FlutterStandardTypedData? = nilOrValue(__pigeon_list[1])
|
||||||
|
let mask: FlutterStandardTypedData? = nilOrValue(__pigeon_list[2])
|
||||||
|
|
||||||
return UniversalManufacturerDataFilter(
|
return UniversalManufacturerDataFilter(
|
||||||
companyIdentifier: companyIdentifier,
|
companyIdentifier: companyIdentifier,
|
||||||
@@ -245,7 +250,7 @@ protocol UniversalBlePlatformChannel {
|
|||||||
func stopScan() throws
|
func stopScan() throws
|
||||||
func connect(deviceId: String) throws
|
func connect(deviceId: String) throws
|
||||||
func disconnect(deviceId: String) throws
|
func disconnect(deviceId: String) throws
|
||||||
func setNotifiable(deviceId: String, service: String, characteristic: String, bleInputProperty: Int64) throws
|
func setNotifiable(deviceId: String, service: String, characteristic: String, bleInputProperty: Int64, completion: @escaping (Result<Void, Error>) -> Void)
|
||||||
func discoverServices(deviceId: String, completion: @escaping (Result<[UniversalBleService], Error>) -> Void)
|
func discoverServices(deviceId: String, completion: @escaping (Result<[UniversalBleService], Error>) -> Void)
|
||||||
func readValue(deviceId: String, service: String, characteristic: String, completion: @escaping (Result<FlutterStandardTypedData, Error>) -> Void)
|
func readValue(deviceId: String, service: String, characteristic: String, completion: @escaping (Result<FlutterStandardTypedData, Error>) -> Void)
|
||||||
func requestMtu(deviceId: String, expectedMtu: Int64, completion: @escaping (Result<Int64, Error>) -> Void)
|
func requestMtu(deviceId: String, expectedMtu: Int64, completion: @escaping (Result<Int64, Error>) -> Void)
|
||||||
@@ -261,8 +266,9 @@ class UniversalBlePlatformChannelSetup {
|
|||||||
/// The codec used by UniversalBlePlatformChannel.
|
/// The codec used by UniversalBlePlatformChannel.
|
||||||
static var codec: FlutterStandardMessageCodec { UniversalBlePlatformChannelCodec.shared }
|
static var codec: FlutterStandardMessageCodec { UniversalBlePlatformChannelCodec.shared }
|
||||||
/// Sets up an instance of `UniversalBlePlatformChannel` to handle messages through the `binaryMessenger`.
|
/// Sets up an instance of `UniversalBlePlatformChannel` to handle messages through the `binaryMessenger`.
|
||||||
static func setUp(binaryMessenger: FlutterBinaryMessenger, api: UniversalBlePlatformChannel?) {
|
static func setUp(binaryMessenger: FlutterBinaryMessenger, api: UniversalBlePlatformChannel?, messageChannelSuffix: String = "") {
|
||||||
let getBluetoothAvailabilityStateChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getBluetoothAvailabilityState", binaryMessenger: binaryMessenger, codec: codec)
|
let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
|
||||||
|
let getBluetoothAvailabilityStateChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getBluetoothAvailabilityState\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||||
if let api = api {
|
if let api = api {
|
||||||
getBluetoothAvailabilityStateChannel.setMessageHandler { _, reply in
|
getBluetoothAvailabilityStateChannel.setMessageHandler { _, reply in
|
||||||
api.getBluetoothAvailabilityState { result in
|
api.getBluetoothAvailabilityState { result in
|
||||||
@@ -277,7 +283,7 @@ class UniversalBlePlatformChannelSetup {
|
|||||||
} else {
|
} else {
|
||||||
getBluetoothAvailabilityStateChannel.setMessageHandler(nil)
|
getBluetoothAvailabilityStateChannel.setMessageHandler(nil)
|
||||||
}
|
}
|
||||||
let enableBluetoothChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.enableBluetooth", binaryMessenger: binaryMessenger, codec: codec)
|
let enableBluetoothChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.enableBluetooth\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||||
if let api = api {
|
if let api = api {
|
||||||
enableBluetoothChannel.setMessageHandler { _, reply in
|
enableBluetoothChannel.setMessageHandler { _, reply in
|
||||||
api.enableBluetooth { result in
|
api.enableBluetooth { result in
|
||||||
@@ -292,7 +298,7 @@ class UniversalBlePlatformChannelSetup {
|
|||||||
} else {
|
} else {
|
||||||
enableBluetoothChannel.setMessageHandler(nil)
|
enableBluetoothChannel.setMessageHandler(nil)
|
||||||
}
|
}
|
||||||
let startScanChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.startScan", binaryMessenger: binaryMessenger, codec: codec)
|
let startScanChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.startScan\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||||
if let api = api {
|
if let api = api {
|
||||||
startScanChannel.setMessageHandler { message, reply in
|
startScanChannel.setMessageHandler { message, reply in
|
||||||
let args = message as! [Any?]
|
let args = message as! [Any?]
|
||||||
@@ -307,7 +313,7 @@ class UniversalBlePlatformChannelSetup {
|
|||||||
} else {
|
} else {
|
||||||
startScanChannel.setMessageHandler(nil)
|
startScanChannel.setMessageHandler(nil)
|
||||||
}
|
}
|
||||||
let stopScanChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.stopScan", binaryMessenger: binaryMessenger, codec: codec)
|
let stopScanChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.stopScan\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||||
if let api = api {
|
if let api = api {
|
||||||
stopScanChannel.setMessageHandler { _, reply in
|
stopScanChannel.setMessageHandler { _, reply in
|
||||||
do {
|
do {
|
||||||
@@ -320,7 +326,7 @@ class UniversalBlePlatformChannelSetup {
|
|||||||
} else {
|
} else {
|
||||||
stopScanChannel.setMessageHandler(nil)
|
stopScanChannel.setMessageHandler(nil)
|
||||||
}
|
}
|
||||||
let connectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.connect", binaryMessenger: binaryMessenger, codec: codec)
|
let connectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.connect\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||||
if let api = api {
|
if let api = api {
|
||||||
connectChannel.setMessageHandler { message, reply in
|
connectChannel.setMessageHandler { message, reply in
|
||||||
let args = message as! [Any?]
|
let args = message as! [Any?]
|
||||||
@@ -335,7 +341,7 @@ class UniversalBlePlatformChannelSetup {
|
|||||||
} else {
|
} else {
|
||||||
connectChannel.setMessageHandler(nil)
|
connectChannel.setMessageHandler(nil)
|
||||||
}
|
}
|
||||||
let disconnectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.disconnect", binaryMessenger: binaryMessenger, codec: codec)
|
let disconnectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.disconnect\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||||
if let api = api {
|
if let api = api {
|
||||||
disconnectChannel.setMessageHandler { message, reply in
|
disconnectChannel.setMessageHandler { message, reply in
|
||||||
let args = message as! [Any?]
|
let args = message as! [Any?]
|
||||||
@@ -350,7 +356,7 @@ class UniversalBlePlatformChannelSetup {
|
|||||||
} else {
|
} else {
|
||||||
disconnectChannel.setMessageHandler(nil)
|
disconnectChannel.setMessageHandler(nil)
|
||||||
}
|
}
|
||||||
let setNotifiableChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.setNotifiable", binaryMessenger: binaryMessenger, codec: codec)
|
let setNotifiableChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.setNotifiable\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||||
if let api = api {
|
if let api = api {
|
||||||
setNotifiableChannel.setMessageHandler { message, reply in
|
setNotifiableChannel.setMessageHandler { message, reply in
|
||||||
let args = message as! [Any?]
|
let args = message as! [Any?]
|
||||||
@@ -358,17 +364,19 @@ class UniversalBlePlatformChannelSetup {
|
|||||||
let serviceArg = args[1] as! String
|
let serviceArg = args[1] as! String
|
||||||
let characteristicArg = args[2] as! String
|
let characteristicArg = args[2] as! String
|
||||||
let bleInputPropertyArg = args[3] is Int64 ? args[3] as! Int64 : Int64(args[3] as! Int32)
|
let bleInputPropertyArg = args[3] is Int64 ? args[3] as! Int64 : Int64(args[3] as! Int32)
|
||||||
do {
|
api.setNotifiable(deviceId: deviceIdArg, service: serviceArg, characteristic: characteristicArg, bleInputProperty: bleInputPropertyArg) { result in
|
||||||
try api.setNotifiable(deviceId: deviceIdArg, service: serviceArg, characteristic: characteristicArg, bleInputProperty: bleInputPropertyArg)
|
switch result {
|
||||||
reply(wrapResult(nil))
|
case .success:
|
||||||
} catch {
|
reply(wrapResult(nil))
|
||||||
reply(wrapError(error))
|
case .failure(let error):
|
||||||
|
reply(wrapError(error))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setNotifiableChannel.setMessageHandler(nil)
|
setNotifiableChannel.setMessageHandler(nil)
|
||||||
}
|
}
|
||||||
let discoverServicesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.discoverServices", binaryMessenger: binaryMessenger, codec: codec)
|
let discoverServicesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.discoverServices\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||||
if let api = api {
|
if let api = api {
|
||||||
discoverServicesChannel.setMessageHandler { message, reply in
|
discoverServicesChannel.setMessageHandler { message, reply in
|
||||||
let args = message as! [Any?]
|
let args = message as! [Any?]
|
||||||
@@ -385,7 +393,7 @@ class UniversalBlePlatformChannelSetup {
|
|||||||
} else {
|
} else {
|
||||||
discoverServicesChannel.setMessageHandler(nil)
|
discoverServicesChannel.setMessageHandler(nil)
|
||||||
}
|
}
|
||||||
let readValueChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.readValue", binaryMessenger: binaryMessenger, codec: codec)
|
let readValueChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.readValue\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||||
if let api = api {
|
if let api = api {
|
||||||
readValueChannel.setMessageHandler { message, reply in
|
readValueChannel.setMessageHandler { message, reply in
|
||||||
let args = message as! [Any?]
|
let args = message as! [Any?]
|
||||||
@@ -404,7 +412,7 @@ class UniversalBlePlatformChannelSetup {
|
|||||||
} else {
|
} else {
|
||||||
readValueChannel.setMessageHandler(nil)
|
readValueChannel.setMessageHandler(nil)
|
||||||
}
|
}
|
||||||
let requestMtuChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.requestMtu", binaryMessenger: binaryMessenger, codec: codec)
|
let requestMtuChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.requestMtu\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||||
if let api = api {
|
if let api = api {
|
||||||
requestMtuChannel.setMessageHandler { message, reply in
|
requestMtuChannel.setMessageHandler { message, reply in
|
||||||
let args = message as! [Any?]
|
let args = message as! [Any?]
|
||||||
@@ -422,7 +430,7 @@ class UniversalBlePlatformChannelSetup {
|
|||||||
} else {
|
} else {
|
||||||
requestMtuChannel.setMessageHandler(nil)
|
requestMtuChannel.setMessageHandler(nil)
|
||||||
}
|
}
|
||||||
let writeValueChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.writeValue", binaryMessenger: binaryMessenger, codec: codec)
|
let writeValueChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.writeValue\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||||
if let api = api {
|
if let api = api {
|
||||||
writeValueChannel.setMessageHandler { message, reply in
|
writeValueChannel.setMessageHandler { message, reply in
|
||||||
let args = message as! [Any?]
|
let args = message as! [Any?]
|
||||||
@@ -443,7 +451,7 @@ class UniversalBlePlatformChannelSetup {
|
|||||||
} else {
|
} else {
|
||||||
writeValueChannel.setMessageHandler(nil)
|
writeValueChannel.setMessageHandler(nil)
|
||||||
}
|
}
|
||||||
let isPairedChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.isPaired", binaryMessenger: binaryMessenger, codec: codec)
|
let isPairedChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.isPaired\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||||
if let api = api {
|
if let api = api {
|
||||||
isPairedChannel.setMessageHandler { message, reply in
|
isPairedChannel.setMessageHandler { message, reply in
|
||||||
let args = message as! [Any?]
|
let args = message as! [Any?]
|
||||||
@@ -460,7 +468,7 @@ class UniversalBlePlatformChannelSetup {
|
|||||||
} else {
|
} else {
|
||||||
isPairedChannel.setMessageHandler(nil)
|
isPairedChannel.setMessageHandler(nil)
|
||||||
}
|
}
|
||||||
let pairChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.pair", binaryMessenger: binaryMessenger, codec: codec)
|
let pairChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.pair\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||||
if let api = api {
|
if let api = api {
|
||||||
pairChannel.setMessageHandler { message, reply in
|
pairChannel.setMessageHandler { message, reply in
|
||||||
let args = message as! [Any?]
|
let args = message as! [Any?]
|
||||||
@@ -475,7 +483,7 @@ class UniversalBlePlatformChannelSetup {
|
|||||||
} else {
|
} else {
|
||||||
pairChannel.setMessageHandler(nil)
|
pairChannel.setMessageHandler(nil)
|
||||||
}
|
}
|
||||||
let unPairChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.unPair", binaryMessenger: binaryMessenger, codec: codec)
|
let unPairChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.unPair\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||||
if let api = api {
|
if let api = api {
|
||||||
unPairChannel.setMessageHandler { message, reply in
|
unPairChannel.setMessageHandler { message, reply in
|
||||||
let args = message as! [Any?]
|
let args = message as! [Any?]
|
||||||
@@ -490,7 +498,7 @@ class UniversalBlePlatformChannelSetup {
|
|||||||
} else {
|
} else {
|
||||||
unPairChannel.setMessageHandler(nil)
|
unPairChannel.setMessageHandler(nil)
|
||||||
}
|
}
|
||||||
let getConnectedDevicesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getConnectedDevices", binaryMessenger: binaryMessenger, codec: codec)
|
let getConnectedDevicesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getConnectedDevices\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||||
if let api = api {
|
if let api = api {
|
||||||
getConnectedDevicesChannel.setMessageHandler { message, reply in
|
getConnectedDevicesChannel.setMessageHandler { message, reply in
|
||||||
let args = message as! [Any?]
|
let args = message as! [Any?]
|
||||||
@@ -557,14 +565,16 @@ protocol UniversalBleCallbackChannelProtocol {
|
|||||||
}
|
}
|
||||||
class UniversalBleCallbackChannel: UniversalBleCallbackChannelProtocol {
|
class UniversalBleCallbackChannel: UniversalBleCallbackChannelProtocol {
|
||||||
private let binaryMessenger: FlutterBinaryMessenger
|
private let binaryMessenger: FlutterBinaryMessenger
|
||||||
init(binaryMessenger: FlutterBinaryMessenger) {
|
private let messageChannelSuffix: String
|
||||||
|
init(binaryMessenger: FlutterBinaryMessenger, messageChannelSuffix: String = "") {
|
||||||
self.binaryMessenger = binaryMessenger
|
self.binaryMessenger = binaryMessenger
|
||||||
|
self.messageChannelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
|
||||||
}
|
}
|
||||||
var codec: FlutterStandardMessageCodec {
|
var codec: FlutterStandardMessageCodec {
|
||||||
return UniversalBleCallbackChannelCodec.shared
|
return UniversalBleCallbackChannelCodec.shared
|
||||||
}
|
}
|
||||||
func onAvailabilityChanged(state stateArg: Int64, completion: @escaping (Result<Void, FlutterError>) -> Void) {
|
func onAvailabilityChanged(state stateArg: Int64, completion: @escaping (Result<Void, FlutterError>) -> Void) {
|
||||||
let channelName: String = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onAvailabilityChanged"
|
let channelName: String = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onAvailabilityChanged\(messageChannelSuffix)"
|
||||||
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
|
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
|
||||||
channel.sendMessage([stateArg] as [Any?]) { response in
|
channel.sendMessage([stateArg] as [Any?]) { response in
|
||||||
guard let listResponse = response as? [Any?] else {
|
guard let listResponse = response as? [Any?] else {
|
||||||
@@ -582,7 +592,7 @@ class UniversalBleCallbackChannel: UniversalBleCallbackChannelProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
func onPairStateChange(deviceId deviceIdArg: String, isPaired isPairedArg: Bool, error errorArg: String?, completion: @escaping (Result<Void, FlutterError>) -> Void) {
|
func onPairStateChange(deviceId deviceIdArg: String, isPaired isPairedArg: Bool, error errorArg: String?, completion: @escaping (Result<Void, FlutterError>) -> Void) {
|
||||||
let channelName: String = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onPairStateChange"
|
let channelName: String = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onPairStateChange\(messageChannelSuffix)"
|
||||||
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
|
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
|
||||||
channel.sendMessage([deviceIdArg, isPairedArg, errorArg] as [Any?]) { response in
|
channel.sendMessage([deviceIdArg, isPairedArg, errorArg] as [Any?]) { response in
|
||||||
guard let listResponse = response as? [Any?] else {
|
guard let listResponse = response as? [Any?] else {
|
||||||
@@ -600,7 +610,7 @@ class UniversalBleCallbackChannel: UniversalBleCallbackChannelProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
func onScanResult(result resultArg: UniversalBleScanResult, completion: @escaping (Result<Void, FlutterError>) -> Void) {
|
func onScanResult(result resultArg: UniversalBleScanResult, completion: @escaping (Result<Void, FlutterError>) -> Void) {
|
||||||
let channelName: String = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onScanResult"
|
let channelName: String = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onScanResult\(messageChannelSuffix)"
|
||||||
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
|
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
|
||||||
channel.sendMessage([resultArg] as [Any?]) { response in
|
channel.sendMessage([resultArg] as [Any?]) { response in
|
||||||
guard let listResponse = response as? [Any?] else {
|
guard let listResponse = response as? [Any?] else {
|
||||||
@@ -618,7 +628,7 @@ class UniversalBleCallbackChannel: UniversalBleCallbackChannelProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
func onValueChanged(deviceId deviceIdArg: String, characteristicId characteristicIdArg: String, value valueArg: FlutterStandardTypedData, completion: @escaping (Result<Void, FlutterError>) -> Void) {
|
func onValueChanged(deviceId deviceIdArg: String, characteristicId characteristicIdArg: String, value valueArg: FlutterStandardTypedData, completion: @escaping (Result<Void, FlutterError>) -> Void) {
|
||||||
let channelName: String = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onValueChanged"
|
let channelName: String = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onValueChanged\(messageChannelSuffix)"
|
||||||
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
|
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
|
||||||
channel.sendMessage([deviceIdArg, characteristicIdArg, valueArg] as [Any?]) { response in
|
channel.sendMessage([deviceIdArg, characteristicIdArg, valueArg] as [Any?]) { response in
|
||||||
guard let listResponse = response as? [Any?] else {
|
guard let listResponse = response as? [Any?] else {
|
||||||
@@ -636,7 +646,7 @@ class UniversalBleCallbackChannel: UniversalBleCallbackChannelProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
func onConnectionChanged(deviceId deviceIdArg: String, state stateArg: Int64, completion: @escaping (Result<Void, FlutterError>) -> Void) {
|
func onConnectionChanged(deviceId deviceIdArg: String, state stateArg: Int64, completion: @escaping (Result<Void, FlutterError>) -> Void) {
|
||||||
let channelName: String = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onConnectionChanged"
|
let channelName: String = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onConnectionChanged\(messageChannelSuffix)"
|
||||||
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
|
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
|
||||||
channel.sendMessage([deviceIdArg, stateArg] as [Any?]) { response in
|
channel.sendMessage([deviceIdArg, stateArg] as [Any?]) { response in
|
||||||
guard let listResponse = response as? [Any?] else {
|
guard let listResponse = response as? [Any?] else {
|
||||||
|
|||||||
@@ -227,6 +227,20 @@ class CharacteristicWriteFuture {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CharacteristicNotifyFuture {
|
||||||
|
let deviceId: String
|
||||||
|
let characteristicId: String
|
||||||
|
let serviceId: String?
|
||||||
|
let result: (Result<Void, Error>) -> Void
|
||||||
|
|
||||||
|
init(deviceId: String, characteristicId: String, serviceId: String?, result: @escaping (Result<Void, Error>) -> Void) {
|
||||||
|
self.deviceId = deviceId
|
||||||
|
self.characteristicId = characteristicId
|
||||||
|
self.serviceId = serviceId
|
||||||
|
self.result = result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class DiscoverServicesFuture {
|
class DiscoverServicesFuture {
|
||||||
let deviceId: String
|
let deviceId: String
|
||||||
let result: (Result<[UniversalBleService], Error>) -> Void
|
let result: (Result<[UniversalBleService], Error>) -> Void
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ private class BleCentralDarwin: NSObject, UniversalBlePlatformChannel, CBCentral
|
|||||||
private var discoveredServicesProgressMap: [String: [UniversalBleService]] = [:]
|
private var discoveredServicesProgressMap: [String: [UniversalBleService]] = [:]
|
||||||
private var characteristicReadFutures = [CharacteristicReadFuture]()
|
private var characteristicReadFutures = [CharacteristicReadFuture]()
|
||||||
private var characteristicWriteFutures = [CharacteristicWriteFuture]()
|
private var characteristicWriteFutures = [CharacteristicWriteFuture]()
|
||||||
|
private var characteristicNotifyFutures = [CharacteristicNotifyFuture]()
|
||||||
private var discoverServicesFutures = [DiscoverServicesFuture]()
|
private var discoverServicesFutures = [DiscoverServicesFuture]()
|
||||||
private var bluetoothAvailabilityStateCallback: ((Result<Int64, Error>) -> Void)? {
|
private var bluetoothAvailabilityStateCallback: ((Result<Int64, Error>) -> Void)? {
|
||||||
didSet {
|
didSet {
|
||||||
@@ -122,13 +123,13 @@ private class BleCentralDarwin: NSObject, UniversalBlePlatformChannel, CBCentral
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if discoveredServicesProgressMap[deviceId] != nil {
|
if discoveredServicesProgressMap[deviceId] != nil {
|
||||||
print("Services discovery already in progress for :\(deviceId), waiting for completion.")
|
print("Services discovery already in progress for :\(deviceId), waiting for completion.")
|
||||||
discoverServicesFutures.append(DiscoverServicesFuture(deviceId: deviceId, result: completion))
|
discoverServicesFutures.append(DiscoverServicesFuture(deviceId: deviceId, result: completion))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if let cachedServices = peripheral.services {
|
if let cachedServices = peripheral.services {
|
||||||
// If services already discovered no need to discover again
|
// If services already discovered no need to discover again
|
||||||
if !cachedServices.isEmpty {
|
if !cachedServices.isEmpty {
|
||||||
@@ -138,8 +139,7 @@ private class BleCentralDarwin: NSObject, UniversalBlePlatformChannel, CBCentral
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
peripheral.discoverServices(nil)
|
peripheral.discoverServices(nil)
|
||||||
discoverServicesFutures.append(DiscoverServicesFuture(deviceId: deviceId, result: completion))
|
discoverServicesFutures.append(DiscoverServicesFuture(deviceId: deviceId, result: completion))
|
||||||
}
|
}
|
||||||
@@ -154,23 +154,30 @@ private class BleCentralDarwin: NSObject, UniversalBlePlatformChannel, CBCentral
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setNotifiable(deviceId: String, service: String, characteristic: String, bleInputProperty: Int64) throws {
|
func setNotifiable(deviceId: String, service: String, characteristic: String, bleInputProperty: Int64, completion: @escaping (Result<Void, any Error>) -> Void) {
|
||||||
let peripheral = try deviceId.getPeripheral()
|
guard let peripheral = discoveredPeripherals[deviceId] else {
|
||||||
|
completion(Result.failure(FlutterError(code: "IllegalArgument", message: "Unknown deviceId:\(self)", details: nil)))
|
||||||
guard let c = peripheral.getCharacteristic(characteristic, of: service) else {
|
return
|
||||||
throw FlutterError(code: "IllegalArgument", message: "Unknown characteristic:\(characteristic)", details: nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if bleInputProperty == BleInputProperty.notification.rawValue && !c.properties.contains(.notify) {
|
guard let gattCharacteristic = peripheral.getCharacteristic(characteristic, of: service) else {
|
||||||
throw FlutterError(code: "InvalidAction", message: "Characteristic does not support notify", details: nil)
|
completion(Result.failure(FlutterError(code: "IllegalArgument", message: "Unknown characteristic:\(characteristic)", details: nil)))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if bleInputProperty == BleInputProperty.indication.rawValue && !c.properties.contains(.indicate) {
|
if bleInputProperty == BleInputProperty.notification.rawValue && !gattCharacteristic.properties.contains(.notify) {
|
||||||
throw FlutterError(code: "InvalidAction", message: "Characteristic does not support indicate", details: nil)
|
completion(Result.failure(FlutterError(code: "InvalidAction", message: "Characteristic does not support notify", details: nil)))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if bleInputProperty == BleInputProperty.indication.rawValue && !gattCharacteristic.properties.contains(.indicate) {
|
||||||
|
completion(Result.failure(FlutterError(code: "InvalidAction", message: "Characteristic does not support indicate", details: nil)))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let shouldNotify = bleInputProperty != BleInputProperty.disabled.rawValue
|
let shouldNotify = bleInputProperty != BleInputProperty.disabled.rawValue
|
||||||
peripheral.setNotifyValue(shouldNotify, for: c)
|
peripheral.setNotifyValue(shouldNotify, for: gattCharacteristic)
|
||||||
|
characteristicNotifyFutures.append(CharacteristicNotifyFuture(deviceId: deviceId, characteristicId: gattCharacteristic.uuid.uuidStr, serviceId: gattCharacteristic.service?.uuid.uuidStr, result: completion))
|
||||||
}
|
}
|
||||||
|
|
||||||
func readValue(deviceId: String, service: String, characteristic: String, completion: @escaping (Result<FlutterStandardTypedData, Error>) -> Void) {
|
func readValue(deviceId: String, service: String, characteristic: String, completion: @escaping (Result<FlutterStandardTypedData, Error>) -> Void) {
|
||||||
@@ -338,8 +345,6 @@ private class BleCentralDarwin: NSObject, UniversalBlePlatformChannel, CBCentral
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: Error?) {
|
public func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: Error?) {
|
||||||
// print("peripheral:didWriteValueForCharacteristic \(characteristic.uuid.uuidStr) error: \(String(describing: error))")
|
|
||||||
// Update futures for writeValue
|
|
||||||
characteristicWriteFutures.removeAll { future in
|
characteristicWriteFutures.removeAll { future in
|
||||||
if future.deviceId == peripheral.uuid.uuidString && future.characteristicId == characteristic.uuid.uuidStr && future.serviceId == characteristic.service?.uuid.uuidStr {
|
if future.deviceId == peripheral.uuid.uuidString && future.characteristicId == characteristic.uuid.uuidStr && future.serviceId == characteristic.service?.uuid.uuidStr {
|
||||||
if let flutterError = error?.toFlutterError() {
|
if let flutterError = error?.toFlutterError() {
|
||||||
@@ -353,6 +358,20 @@ private class BleCentralDarwin: NSObject, UniversalBlePlatformChannel, CBCentral
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func peripheral(_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: Error?) {
|
||||||
|
characteristicNotifyFutures.removeAll { future in
|
||||||
|
if future.deviceId == peripheral.uuid.uuidString && future.characteristicId == characteristic.uuid.uuidStr && future.serviceId == characteristic.service?.uuid.uuidStr {
|
||||||
|
if let flutterError = error?.toFlutterError() {
|
||||||
|
future.result(Result.failure(flutterError))
|
||||||
|
} else {
|
||||||
|
future.result(Result.success({}()))
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
|
public func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
|
||||||
// Update callbackChannel if notifying
|
// Update callbackChannel if notifying
|
||||||
if characteristic.isNotifying {
|
if characteristic.isNotifying {
|
||||||
|
|||||||
@@ -38,4 +38,4 @@ SPEC CHECKSUMS:
|
|||||||
|
|
||||||
PODFILE CHECKSUM: 819463e6a0290f5a72f145ba7cde16e8b6ef0796
|
PODFILE CHECKSUM: 819463e6a0290f5a72f145ba7cde16e8b6ef0796
|
||||||
|
|
||||||
COCOAPODS: 1.14.3
|
COCOAPODS: 1.15.2
|
||||||
|
|||||||
@@ -215,7 +215,7 @@
|
|||||||
isa = PBXProject;
|
isa = PBXProject;
|
||||||
attributes = {
|
attributes = {
|
||||||
BuildIndependentTargetsInParallel = YES;
|
BuildIndependentTargetsInParallel = YES;
|
||||||
LastUpgradeCheck = 1430;
|
LastUpgradeCheck = 1510;
|
||||||
ORGANIZATIONNAME = "";
|
ORGANIZATIONNAME = "";
|
||||||
TargetAttributes = {
|
TargetAttributes = {
|
||||||
331C8080294A63A400263BE5 = {
|
331C8080294A63A400263BE5 = {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "1430"
|
LastUpgradeVersion = "1510"
|
||||||
version = "1.3">
|
version = "1.3">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
|
|||||||
@@ -410,7 +410,7 @@ packages:
|
|||||||
path: ".."
|
path: ".."
|
||||||
relative: true
|
relative: true
|
||||||
source: path
|
source: path
|
||||||
version: "0.9.9"
|
version: "0.9.10"
|
||||||
vector_math:
|
vector_math:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Autogenerated from Pigeon (v17.1.1), do not edit directly.
|
// Autogenerated from Pigeon (v18.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers
|
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers
|
||||||
|
|
||||||
@@ -237,16 +237,21 @@ class UniversalBlePlatformChannel {
|
|||||||
/// Constructor for [UniversalBlePlatformChannel]. The [binaryMessenger] named argument is
|
/// Constructor for [UniversalBlePlatformChannel]. The [binaryMessenger] named argument is
|
||||||
/// available for dependency injection. If it is left null, the default
|
/// available for dependency injection. If it is left null, the default
|
||||||
/// BinaryMessenger will be used which routes to the host platform.
|
/// BinaryMessenger will be used which routes to the host platform.
|
||||||
UniversalBlePlatformChannel({BinaryMessenger? binaryMessenger})
|
UniversalBlePlatformChannel(
|
||||||
: __pigeon_binaryMessenger = binaryMessenger;
|
{BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''})
|
||||||
|
: __pigeon_binaryMessenger = binaryMessenger,
|
||||||
|
__pigeon_messageChannelSuffix =
|
||||||
|
messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : '';
|
||||||
final BinaryMessenger? __pigeon_binaryMessenger;
|
final BinaryMessenger? __pigeon_binaryMessenger;
|
||||||
|
|
||||||
static const MessageCodec<Object?> pigeonChannelCodec =
|
static const MessageCodec<Object?> pigeonChannelCodec =
|
||||||
_UniversalBlePlatformChannelCodec();
|
_UniversalBlePlatformChannelCodec();
|
||||||
|
|
||||||
|
final String __pigeon_messageChannelSuffix;
|
||||||
|
|
||||||
Future<int> getBluetoothAvailabilityState() async {
|
Future<int> getBluetoothAvailabilityState() async {
|
||||||
const String __pigeon_channelName =
|
final String __pigeon_channelName =
|
||||||
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getBluetoothAvailabilityState';
|
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getBluetoothAvailabilityState$__pigeon_messageChannelSuffix';
|
||||||
final BasicMessageChannel<Object?> __pigeon_channel =
|
final BasicMessageChannel<Object?> __pigeon_channel =
|
||||||
BasicMessageChannel<Object?>(
|
BasicMessageChannel<Object?>(
|
||||||
__pigeon_channelName,
|
__pigeon_channelName,
|
||||||
@@ -274,8 +279,8 @@ class UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> enableBluetooth() async {
|
Future<bool> enableBluetooth() async {
|
||||||
const String __pigeon_channelName =
|
final String __pigeon_channelName =
|
||||||
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.enableBluetooth';
|
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.enableBluetooth$__pigeon_messageChannelSuffix';
|
||||||
final BasicMessageChannel<Object?> __pigeon_channel =
|
final BasicMessageChannel<Object?> __pigeon_channel =
|
||||||
BasicMessageChannel<Object?>(
|
BasicMessageChannel<Object?>(
|
||||||
__pigeon_channelName,
|
__pigeon_channelName,
|
||||||
@@ -303,8 +308,8 @@ class UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> startScan(UniversalScanFilter? filter) async {
|
Future<void> startScan(UniversalScanFilter? filter) async {
|
||||||
const String __pigeon_channelName =
|
final String __pigeon_channelName =
|
||||||
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.startScan';
|
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.startScan$__pigeon_messageChannelSuffix';
|
||||||
final BasicMessageChannel<Object?> __pigeon_channel =
|
final BasicMessageChannel<Object?> __pigeon_channel =
|
||||||
BasicMessageChannel<Object?>(
|
BasicMessageChannel<Object?>(
|
||||||
__pigeon_channelName,
|
__pigeon_channelName,
|
||||||
@@ -327,8 +332,8 @@ class UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> stopScan() async {
|
Future<void> stopScan() async {
|
||||||
const String __pigeon_channelName =
|
final String __pigeon_channelName =
|
||||||
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.stopScan';
|
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.stopScan$__pigeon_messageChannelSuffix';
|
||||||
final BasicMessageChannel<Object?> __pigeon_channel =
|
final BasicMessageChannel<Object?> __pigeon_channel =
|
||||||
BasicMessageChannel<Object?>(
|
BasicMessageChannel<Object?>(
|
||||||
__pigeon_channelName,
|
__pigeon_channelName,
|
||||||
@@ -351,8 +356,8 @@ class UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> connect(String deviceId) async {
|
Future<void> connect(String deviceId) async {
|
||||||
const String __pigeon_channelName =
|
final String __pigeon_channelName =
|
||||||
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.connect';
|
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.connect$__pigeon_messageChannelSuffix';
|
||||||
final BasicMessageChannel<Object?> __pigeon_channel =
|
final BasicMessageChannel<Object?> __pigeon_channel =
|
||||||
BasicMessageChannel<Object?>(
|
BasicMessageChannel<Object?>(
|
||||||
__pigeon_channelName,
|
__pigeon_channelName,
|
||||||
@@ -375,8 +380,8 @@ class UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> disconnect(String deviceId) async {
|
Future<void> disconnect(String deviceId) async {
|
||||||
const String __pigeon_channelName =
|
final String __pigeon_channelName =
|
||||||
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.disconnect';
|
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.disconnect$__pigeon_messageChannelSuffix';
|
||||||
final BasicMessageChannel<Object?> __pigeon_channel =
|
final BasicMessageChannel<Object?> __pigeon_channel =
|
||||||
BasicMessageChannel<Object?>(
|
BasicMessageChannel<Object?>(
|
||||||
__pigeon_channelName,
|
__pigeon_channelName,
|
||||||
@@ -400,8 +405,8 @@ class UniversalBlePlatformChannel {
|
|||||||
|
|
||||||
Future<void> setNotifiable(String deviceId, String service,
|
Future<void> setNotifiable(String deviceId, String service,
|
||||||
String characteristic, int bleInputProperty) async {
|
String characteristic, int bleInputProperty) async {
|
||||||
const String __pigeon_channelName =
|
final String __pigeon_channelName =
|
||||||
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.setNotifiable';
|
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.setNotifiable$__pigeon_messageChannelSuffix';
|
||||||
final BasicMessageChannel<Object?> __pigeon_channel =
|
final BasicMessageChannel<Object?> __pigeon_channel =
|
||||||
BasicMessageChannel<Object?>(
|
BasicMessageChannel<Object?>(
|
||||||
__pigeon_channelName,
|
__pigeon_channelName,
|
||||||
@@ -425,8 +430,8 @@ class UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<List<UniversalBleService?>> discoverServices(String deviceId) async {
|
Future<List<UniversalBleService?>> discoverServices(String deviceId) async {
|
||||||
const String __pigeon_channelName =
|
final String __pigeon_channelName =
|
||||||
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.discoverServices';
|
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.discoverServices$__pigeon_messageChannelSuffix';
|
||||||
final BasicMessageChannel<Object?> __pigeon_channel =
|
final BasicMessageChannel<Object?> __pigeon_channel =
|
||||||
BasicMessageChannel<Object?>(
|
BasicMessageChannel<Object?>(
|
||||||
__pigeon_channelName,
|
__pigeon_channelName,
|
||||||
@@ -456,8 +461,8 @@ class UniversalBlePlatformChannel {
|
|||||||
|
|
||||||
Future<Uint8List> readValue(
|
Future<Uint8List> readValue(
|
||||||
String deviceId, String service, String characteristic) async {
|
String deviceId, String service, String characteristic) async {
|
||||||
const String __pigeon_channelName =
|
final String __pigeon_channelName =
|
||||||
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.readValue';
|
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.readValue$__pigeon_messageChannelSuffix';
|
||||||
final BasicMessageChannel<Object?> __pigeon_channel =
|
final BasicMessageChannel<Object?> __pigeon_channel =
|
||||||
BasicMessageChannel<Object?>(
|
BasicMessageChannel<Object?>(
|
||||||
__pigeon_channelName,
|
__pigeon_channelName,
|
||||||
@@ -485,8 +490,8 @@ class UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<int> requestMtu(String deviceId, int expectedMtu) async {
|
Future<int> requestMtu(String deviceId, int expectedMtu) async {
|
||||||
const String __pigeon_channelName =
|
final String __pigeon_channelName =
|
||||||
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.requestMtu';
|
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.requestMtu$__pigeon_messageChannelSuffix';
|
||||||
final BasicMessageChannel<Object?> __pigeon_channel =
|
final BasicMessageChannel<Object?> __pigeon_channel =
|
||||||
BasicMessageChannel<Object?>(
|
BasicMessageChannel<Object?>(
|
||||||
__pigeon_channelName,
|
__pigeon_channelName,
|
||||||
@@ -515,8 +520,8 @@ class UniversalBlePlatformChannel {
|
|||||||
|
|
||||||
Future<void> writeValue(String deviceId, String service,
|
Future<void> writeValue(String deviceId, String service,
|
||||||
String characteristic, Uint8List value, int bleOutputProperty) async {
|
String characteristic, Uint8List value, int bleOutputProperty) async {
|
||||||
const String __pigeon_channelName =
|
final String __pigeon_channelName =
|
||||||
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.writeValue';
|
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.writeValue$__pigeon_messageChannelSuffix';
|
||||||
final BasicMessageChannel<Object?> __pigeon_channel =
|
final BasicMessageChannel<Object?> __pigeon_channel =
|
||||||
BasicMessageChannel<Object?>(
|
BasicMessageChannel<Object?>(
|
||||||
__pigeon_channelName,
|
__pigeon_channelName,
|
||||||
@@ -545,8 +550,8 @@ class UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> isPaired(String deviceId) async {
|
Future<bool> isPaired(String deviceId) async {
|
||||||
const String __pigeon_channelName =
|
final String __pigeon_channelName =
|
||||||
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.isPaired';
|
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.isPaired$__pigeon_messageChannelSuffix';
|
||||||
final BasicMessageChannel<Object?> __pigeon_channel =
|
final BasicMessageChannel<Object?> __pigeon_channel =
|
||||||
BasicMessageChannel<Object?>(
|
BasicMessageChannel<Object?>(
|
||||||
__pigeon_channelName,
|
__pigeon_channelName,
|
||||||
@@ -574,8 +579,8 @@ class UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> pair(String deviceId) async {
|
Future<void> pair(String deviceId) async {
|
||||||
const String __pigeon_channelName =
|
final String __pigeon_channelName =
|
||||||
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.pair';
|
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.pair$__pigeon_messageChannelSuffix';
|
||||||
final BasicMessageChannel<Object?> __pigeon_channel =
|
final BasicMessageChannel<Object?> __pigeon_channel =
|
||||||
BasicMessageChannel<Object?>(
|
BasicMessageChannel<Object?>(
|
||||||
__pigeon_channelName,
|
__pigeon_channelName,
|
||||||
@@ -598,8 +603,8 @@ class UniversalBlePlatformChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> unPair(String deviceId) async {
|
Future<void> unPair(String deviceId) async {
|
||||||
const String __pigeon_channelName =
|
final String __pigeon_channelName =
|
||||||
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.unPair';
|
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.unPair$__pigeon_messageChannelSuffix';
|
||||||
final BasicMessageChannel<Object?> __pigeon_channel =
|
final BasicMessageChannel<Object?> __pigeon_channel =
|
||||||
BasicMessageChannel<Object?>(
|
BasicMessageChannel<Object?>(
|
||||||
__pigeon_channelName,
|
__pigeon_channelName,
|
||||||
@@ -623,8 +628,8 @@ class UniversalBlePlatformChannel {
|
|||||||
|
|
||||||
Future<List<UniversalBleScanResult?>> getConnectedDevices(
|
Future<List<UniversalBleScanResult?>> getConnectedDevices(
|
||||||
List<String?> withServices) async {
|
List<String?> withServices) async {
|
||||||
const String __pigeon_channelName =
|
final String __pigeon_channelName =
|
||||||
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getConnectedDevices';
|
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getConnectedDevices$__pigeon_messageChannelSuffix';
|
||||||
final BasicMessageChannel<Object?> __pigeon_channel =
|
final BasicMessageChannel<Object?> __pigeon_channel =
|
||||||
BasicMessageChannel<Object?>(
|
BasicMessageChannel<Object?>(
|
||||||
__pigeon_channelName,
|
__pigeon_channelName,
|
||||||
@@ -692,12 +697,17 @@ abstract class UniversalBleCallbackChannel {
|
|||||||
|
|
||||||
void onConnectionChanged(String deviceId, int state);
|
void onConnectionChanged(String deviceId, int state);
|
||||||
|
|
||||||
static void setup(UniversalBleCallbackChannel? api,
|
static void setUp(
|
||||||
{BinaryMessenger? binaryMessenger}) {
|
UniversalBleCallbackChannel? api, {
|
||||||
|
BinaryMessenger? binaryMessenger,
|
||||||
|
String messageChannelSuffix = '',
|
||||||
|
}) {
|
||||||
|
messageChannelSuffix =
|
||||||
|
messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : '';
|
||||||
{
|
{
|
||||||
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<
|
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<
|
||||||
Object?>(
|
Object?>(
|
||||||
'dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onAvailabilityChanged',
|
'dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onAvailabilityChanged$messageChannelSuffix',
|
||||||
pigeonChannelCodec,
|
pigeonChannelCodec,
|
||||||
binaryMessenger: binaryMessenger);
|
binaryMessenger: binaryMessenger);
|
||||||
if (api == null) {
|
if (api == null) {
|
||||||
@@ -725,7 +735,7 @@ abstract class UniversalBleCallbackChannel {
|
|||||||
{
|
{
|
||||||
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<
|
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<
|
||||||
Object?>(
|
Object?>(
|
||||||
'dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onPairStateChange',
|
'dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onPairStateChange$messageChannelSuffix',
|
||||||
pigeonChannelCodec,
|
pigeonChannelCodec,
|
||||||
binaryMessenger: binaryMessenger);
|
binaryMessenger: binaryMessenger);
|
||||||
if (api == null) {
|
if (api == null) {
|
||||||
@@ -757,7 +767,7 @@ abstract class UniversalBleCallbackChannel {
|
|||||||
{
|
{
|
||||||
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<
|
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<
|
||||||
Object?>(
|
Object?>(
|
||||||
'dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onScanResult',
|
'dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onScanResult$messageChannelSuffix',
|
||||||
pigeonChannelCodec,
|
pigeonChannelCodec,
|
||||||
binaryMessenger: binaryMessenger);
|
binaryMessenger: binaryMessenger);
|
||||||
if (api == null) {
|
if (api == null) {
|
||||||
@@ -786,7 +796,7 @@ abstract class UniversalBleCallbackChannel {
|
|||||||
{
|
{
|
||||||
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<
|
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<
|
||||||
Object?>(
|
Object?>(
|
||||||
'dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onValueChanged',
|
'dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onValueChanged$messageChannelSuffix',
|
||||||
pigeonChannelCodec,
|
pigeonChannelCodec,
|
||||||
binaryMessenger: binaryMessenger);
|
binaryMessenger: binaryMessenger);
|
||||||
if (api == null) {
|
if (api == null) {
|
||||||
@@ -821,7 +831,7 @@ abstract class UniversalBleCallbackChannel {
|
|||||||
{
|
{
|
||||||
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<
|
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<
|
||||||
Object?>(
|
Object?>(
|
||||||
'dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onConnectionChanged',
|
'dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onConnectionChanged$messageChannelSuffix',
|
||||||
pigeonChannelCodec,
|
pigeonChannelCodec,
|
||||||
binaryMessenger: binaryMessenger);
|
binaryMessenger: binaryMessenger);
|
||||||
if (api == null) {
|
if (api == null) {
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ class UniversalBlePigeonChannel extends UniversalBlePlatform {
|
|||||||
|
|
||||||
/// To set listeners
|
/// To set listeners
|
||||||
void _setupListeners() {
|
void _setupListeners() {
|
||||||
UniversalBleCallbackChannel.setup(_UniversalBleCallbackHandler(
|
UniversalBleCallbackChannel.setUp(_UniversalBleCallbackHandler(
|
||||||
scanResult: (BleScanResult scanResult) => onScanResult?.call(scanResult),
|
scanResult: (BleScanResult scanResult) => onScanResult?.call(scanResult),
|
||||||
availabilityChange: (AvailabilityState state) =>
|
availabilityChange: (AvailabilityState state) =>
|
||||||
onAvailabilityChange?.call(state),
|
onAvailabilityChange?.call(state),
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ abstract class UniversalBlePlatformChannel {
|
|||||||
|
|
||||||
void disconnect(String deviceId);
|
void disconnect(String deviceId);
|
||||||
|
|
||||||
|
@async
|
||||||
void setNotifiable(
|
void setNotifiable(
|
||||||
String deviceId,
|
String deviceId,
|
||||||
String service,
|
String service,
|
||||||
|
|||||||
+1
-1
@@ -32,7 +32,7 @@ dev_dependencies:
|
|||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
flutter_lints: ^2.0.0
|
flutter_lints: ^2.0.0
|
||||||
pigeon: ^17.1.1
|
pigeon: ^18.0.1
|
||||||
|
|
||||||
flutter:
|
flutter:
|
||||||
plugin:
|
plugin:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Autogenerated from Pigeon (v17.1.1), do not edit directly.
|
// Autogenerated from Pigeon (v18.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
|
|
||||||
#undef _HAS_EXCEPTIONS
|
#undef _HAS_EXCEPTIONS
|
||||||
@@ -453,8 +453,16 @@ const flutter::StandardMessageCodec& UniversalBlePlatformChannel::GetCodec() {
|
|||||||
void UniversalBlePlatformChannel::SetUp(
|
void UniversalBlePlatformChannel::SetUp(
|
||||||
flutter::BinaryMessenger* binary_messenger,
|
flutter::BinaryMessenger* binary_messenger,
|
||||||
UniversalBlePlatformChannel* api) {
|
UniversalBlePlatformChannel* api) {
|
||||||
|
UniversalBlePlatformChannel::SetUp(binary_messenger, api, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
void UniversalBlePlatformChannel::SetUp(
|
||||||
|
flutter::BinaryMessenger* binary_messenger,
|
||||||
|
UniversalBlePlatformChannel* api,
|
||||||
|
const std::string& message_channel_suffix) {
|
||||||
|
const std::string prepended_suffix = message_channel_suffix.length() > 0 ? std::string(".") + message_channel_suffix : "";
|
||||||
{
|
{
|
||||||
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getBluetoothAvailabilityState", &GetCodec());
|
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getBluetoothAvailabilityState" + prepended_suffix, &GetCodec());
|
||||||
if (api != nullptr) {
|
if (api != nullptr) {
|
||||||
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
||||||
try {
|
try {
|
||||||
@@ -476,7 +484,7 @@ void UniversalBlePlatformChannel::SetUp(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.enableBluetooth", &GetCodec());
|
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.enableBluetooth" + prepended_suffix, &GetCodec());
|
||||||
if (api != nullptr) {
|
if (api != nullptr) {
|
||||||
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
||||||
try {
|
try {
|
||||||
@@ -498,7 +506,7 @@ void UniversalBlePlatformChannel::SetUp(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.startScan", &GetCodec());
|
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.startScan" + prepended_suffix, &GetCodec());
|
||||||
if (api != nullptr) {
|
if (api != nullptr) {
|
||||||
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
||||||
try {
|
try {
|
||||||
@@ -522,7 +530,7 @@ void UniversalBlePlatformChannel::SetUp(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.stopScan", &GetCodec());
|
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.stopScan" + prepended_suffix, &GetCodec());
|
||||||
if (api != nullptr) {
|
if (api != nullptr) {
|
||||||
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
||||||
try {
|
try {
|
||||||
@@ -543,7 +551,7 @@ void UniversalBlePlatformChannel::SetUp(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.connect", &GetCodec());
|
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.connect" + prepended_suffix, &GetCodec());
|
||||||
if (api != nullptr) {
|
if (api != nullptr) {
|
||||||
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
||||||
try {
|
try {
|
||||||
@@ -571,7 +579,7 @@ void UniversalBlePlatformChannel::SetUp(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.disconnect", &GetCodec());
|
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.disconnect" + prepended_suffix, &GetCodec());
|
||||||
if (api != nullptr) {
|
if (api != nullptr) {
|
||||||
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
||||||
try {
|
try {
|
||||||
@@ -599,7 +607,7 @@ void UniversalBlePlatformChannel::SetUp(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.setNotifiable", &GetCodec());
|
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.setNotifiable" + prepended_suffix, &GetCodec());
|
||||||
if (api != nullptr) {
|
if (api != nullptr) {
|
||||||
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
||||||
try {
|
try {
|
||||||
@@ -628,14 +636,15 @@ void UniversalBlePlatformChannel::SetUp(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const int64_t ble_input_property_arg = encodable_ble_input_property_arg.LongValue();
|
const int64_t ble_input_property_arg = encodable_ble_input_property_arg.LongValue();
|
||||||
std::optional<FlutterError> output = api->SetNotifiable(device_id_arg, service_arg, characteristic_arg, ble_input_property_arg);
|
api->SetNotifiable(device_id_arg, service_arg, characteristic_arg, ble_input_property_arg, [reply](std::optional<FlutterError>&& output) {
|
||||||
if (output.has_value()) {
|
if (output.has_value()) {
|
||||||
reply(WrapError(output.value()));
|
reply(WrapError(output.value()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EncodableList wrapped;
|
EncodableList wrapped;
|
||||||
wrapped.push_back(EncodableValue());
|
wrapped.push_back(EncodableValue());
|
||||||
reply(EncodableValue(std::move(wrapped)));
|
reply(EncodableValue(std::move(wrapped)));
|
||||||
|
});
|
||||||
} catch (const std::exception& exception) {
|
} catch (const std::exception& exception) {
|
||||||
reply(WrapError(exception.what()));
|
reply(WrapError(exception.what()));
|
||||||
}
|
}
|
||||||
@@ -645,7 +654,7 @@ void UniversalBlePlatformChannel::SetUp(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.discoverServices", &GetCodec());
|
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.discoverServices" + prepended_suffix, &GetCodec());
|
||||||
if (api != nullptr) {
|
if (api != nullptr) {
|
||||||
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
||||||
try {
|
try {
|
||||||
@@ -674,7 +683,7 @@ void UniversalBlePlatformChannel::SetUp(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.readValue", &GetCodec());
|
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.readValue" + prepended_suffix, &GetCodec());
|
||||||
if (api != nullptr) {
|
if (api != nullptr) {
|
||||||
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
||||||
try {
|
try {
|
||||||
@@ -715,7 +724,7 @@ void UniversalBlePlatformChannel::SetUp(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.requestMtu", &GetCodec());
|
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.requestMtu" + prepended_suffix, &GetCodec());
|
||||||
if (api != nullptr) {
|
if (api != nullptr) {
|
||||||
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
||||||
try {
|
try {
|
||||||
@@ -750,7 +759,7 @@ void UniversalBlePlatformChannel::SetUp(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.writeValue", &GetCodec());
|
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.writeValue" + prepended_suffix, &GetCodec());
|
||||||
if (api != nullptr) {
|
if (api != nullptr) {
|
||||||
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
||||||
try {
|
try {
|
||||||
@@ -803,7 +812,7 @@ void UniversalBlePlatformChannel::SetUp(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.isPaired", &GetCodec());
|
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.isPaired" + prepended_suffix, &GetCodec());
|
||||||
if (api != nullptr) {
|
if (api != nullptr) {
|
||||||
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
||||||
try {
|
try {
|
||||||
@@ -832,7 +841,7 @@ void UniversalBlePlatformChannel::SetUp(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.pair", &GetCodec());
|
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.pair" + prepended_suffix, &GetCodec());
|
||||||
if (api != nullptr) {
|
if (api != nullptr) {
|
||||||
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
||||||
try {
|
try {
|
||||||
@@ -860,7 +869,7 @@ void UniversalBlePlatformChannel::SetUp(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.unPair", &GetCodec());
|
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.unPair" + prepended_suffix, &GetCodec());
|
||||||
if (api != nullptr) {
|
if (api != nullptr) {
|
||||||
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
||||||
try {
|
try {
|
||||||
@@ -888,7 +897,7 @@ void UniversalBlePlatformChannel::SetUp(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getConnectedDevices", &GetCodec());
|
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.getConnectedDevices" + prepended_suffix, &GetCodec());
|
||||||
if (api != nullptr) {
|
if (api != nullptr) {
|
||||||
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
||||||
try {
|
try {
|
||||||
@@ -963,7 +972,14 @@ void UniversalBleCallbackChannelCodecSerializer::WriteValue(
|
|||||||
|
|
||||||
// Generated class from Pigeon that represents Flutter messages that can be called from C++.
|
// Generated class from Pigeon that represents Flutter messages that can be called from C++.
|
||||||
UniversalBleCallbackChannel::UniversalBleCallbackChannel(flutter::BinaryMessenger* binary_messenger)
|
UniversalBleCallbackChannel::UniversalBleCallbackChannel(flutter::BinaryMessenger* binary_messenger)
|
||||||
: binary_messenger_(binary_messenger) {}
|
: binary_messenger_(binary_messenger),
|
||||||
|
message_channel_suffix_("") {}
|
||||||
|
|
||||||
|
UniversalBleCallbackChannel::UniversalBleCallbackChannel(
|
||||||
|
flutter::BinaryMessenger* binary_messenger,
|
||||||
|
const std::string& message_channel_suffix)
|
||||||
|
: binary_messenger_(binary_messenger),
|
||||||
|
message_channel_suffix_(message_channel_suffix.length() > 0 ? std::string(".") + message_channel_suffix : "") {}
|
||||||
|
|
||||||
const flutter::StandardMessageCodec& UniversalBleCallbackChannel::GetCodec() {
|
const flutter::StandardMessageCodec& UniversalBleCallbackChannel::GetCodec() {
|
||||||
return flutter::StandardMessageCodec::GetInstance(&UniversalBleCallbackChannelCodecSerializer::GetInstance());
|
return flutter::StandardMessageCodec::GetInstance(&UniversalBleCallbackChannelCodecSerializer::GetInstance());
|
||||||
@@ -973,7 +989,7 @@ void UniversalBleCallbackChannel::OnAvailabilityChanged(
|
|||||||
int64_t state_arg,
|
int64_t state_arg,
|
||||||
std::function<void(void)>&& on_success,
|
std::function<void(void)>&& on_success,
|
||||||
std::function<void(const FlutterError&)>&& on_error) {
|
std::function<void(const FlutterError&)>&& on_error) {
|
||||||
const std::string channel_name = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onAvailabilityChanged";
|
const std::string channel_name = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onAvailabilityChanged" + message_channel_suffix_;
|
||||||
BasicMessageChannel<> channel(binary_messenger_, channel_name, &GetCodec());
|
BasicMessageChannel<> channel(binary_messenger_, channel_name, &GetCodec());
|
||||||
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
||||||
EncodableValue(state_arg),
|
EncodableValue(state_arg),
|
||||||
@@ -1000,7 +1016,7 @@ void UniversalBleCallbackChannel::OnPairStateChange(
|
|||||||
const std::string* error_arg,
|
const std::string* error_arg,
|
||||||
std::function<void(void)>&& on_success,
|
std::function<void(void)>&& on_success,
|
||||||
std::function<void(const FlutterError&)>&& on_error) {
|
std::function<void(const FlutterError&)>&& on_error) {
|
||||||
const std::string channel_name = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onPairStateChange";
|
const std::string channel_name = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onPairStateChange" + message_channel_suffix_;
|
||||||
BasicMessageChannel<> channel(binary_messenger_, channel_name, &GetCodec());
|
BasicMessageChannel<> channel(binary_messenger_, channel_name, &GetCodec());
|
||||||
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
||||||
EncodableValue(device_id_arg),
|
EncodableValue(device_id_arg),
|
||||||
@@ -1027,7 +1043,7 @@ void UniversalBleCallbackChannel::OnScanResult(
|
|||||||
const UniversalBleScanResult& result_arg,
|
const UniversalBleScanResult& result_arg,
|
||||||
std::function<void(void)>&& on_success,
|
std::function<void(void)>&& on_success,
|
||||||
std::function<void(const FlutterError&)>&& on_error) {
|
std::function<void(const FlutterError&)>&& on_error) {
|
||||||
const std::string channel_name = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onScanResult";
|
const std::string channel_name = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onScanResult" + message_channel_suffix_;
|
||||||
BasicMessageChannel<> channel(binary_messenger_, channel_name, &GetCodec());
|
BasicMessageChannel<> channel(binary_messenger_, channel_name, &GetCodec());
|
||||||
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
||||||
CustomEncodableValue(result_arg),
|
CustomEncodableValue(result_arg),
|
||||||
@@ -1054,7 +1070,7 @@ void UniversalBleCallbackChannel::OnValueChanged(
|
|||||||
const std::vector<uint8_t>& value_arg,
|
const std::vector<uint8_t>& value_arg,
|
||||||
std::function<void(void)>&& on_success,
|
std::function<void(void)>&& on_success,
|
||||||
std::function<void(const FlutterError&)>&& on_error) {
|
std::function<void(const FlutterError&)>&& on_error) {
|
||||||
const std::string channel_name = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onValueChanged";
|
const std::string channel_name = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onValueChanged" + message_channel_suffix_;
|
||||||
BasicMessageChannel<> channel(binary_messenger_, channel_name, &GetCodec());
|
BasicMessageChannel<> channel(binary_messenger_, channel_name, &GetCodec());
|
||||||
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
||||||
EncodableValue(device_id_arg),
|
EncodableValue(device_id_arg),
|
||||||
@@ -1082,7 +1098,7 @@ void UniversalBleCallbackChannel::OnConnectionChanged(
|
|||||||
int64_t state_arg,
|
int64_t state_arg,
|
||||||
std::function<void(void)>&& on_success,
|
std::function<void(void)>&& on_success,
|
||||||
std::function<void(const FlutterError&)>&& on_error) {
|
std::function<void(const FlutterError&)>&& on_error) {
|
||||||
const std::string channel_name = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onConnectionChanged";
|
const std::string channel_name = "dev.flutter.pigeon.universal_ble.UniversalBleCallbackChannel.onConnectionChanged" + message_channel_suffix_;
|
||||||
BasicMessageChannel<> channel(binary_messenger_, channel_name, &GetCodec());
|
BasicMessageChannel<> channel(binary_messenger_, channel_name, &GetCodec());
|
||||||
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
|
||||||
EncodableValue(device_id_arg),
|
EncodableValue(device_id_arg),
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Autogenerated from Pigeon (v17.1.1), do not edit directly.
|
// Autogenerated from Pigeon (v18.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
|
|
||||||
#ifndef PIGEON_UNIVERSAL_BLE_G_H_
|
#ifndef PIGEON_UNIVERSAL_BLE_G_H_
|
||||||
@@ -280,11 +280,12 @@ class UniversalBlePlatformChannel {
|
|||||||
virtual std::optional<FlutterError> StopScan() = 0;
|
virtual std::optional<FlutterError> StopScan() = 0;
|
||||||
virtual std::optional<FlutterError> Connect(const std::string& device_id) = 0;
|
virtual std::optional<FlutterError> Connect(const std::string& device_id) = 0;
|
||||||
virtual std::optional<FlutterError> Disconnect(const std::string& device_id) = 0;
|
virtual std::optional<FlutterError> Disconnect(const std::string& device_id) = 0;
|
||||||
virtual std::optional<FlutterError> SetNotifiable(
|
virtual void SetNotifiable(
|
||||||
const std::string& device_id,
|
const std::string& device_id,
|
||||||
const std::string& service,
|
const std::string& service,
|
||||||
const std::string& characteristic,
|
const std::string& characteristic,
|
||||||
int64_t ble_input_property) = 0;
|
int64_t ble_input_property,
|
||||||
|
std::function<void(std::optional<FlutterError> reply)> result) = 0;
|
||||||
virtual void DiscoverServices(
|
virtual void DiscoverServices(
|
||||||
const std::string& device_id,
|
const std::string& device_id,
|
||||||
std::function<void(ErrorOr<flutter::EncodableList> reply)> result) = 0;
|
std::function<void(ErrorOr<flutter::EncodableList> reply)> result) = 0;
|
||||||
@@ -319,6 +320,10 @@ class UniversalBlePlatformChannel {
|
|||||||
static void SetUp(
|
static void SetUp(
|
||||||
flutter::BinaryMessenger* binary_messenger,
|
flutter::BinaryMessenger* binary_messenger,
|
||||||
UniversalBlePlatformChannel* api);
|
UniversalBlePlatformChannel* api);
|
||||||
|
static void SetUp(
|
||||||
|
flutter::BinaryMessenger* binary_messenger,
|
||||||
|
UniversalBlePlatformChannel* api,
|
||||||
|
const std::string& message_channel_suffix);
|
||||||
static flutter::EncodableValue WrapError(std::string_view error_message);
|
static flutter::EncodableValue WrapError(std::string_view error_message);
|
||||||
static flutter::EncodableValue WrapError(const FlutterError& error);
|
static flutter::EncodableValue WrapError(const FlutterError& error);
|
||||||
|
|
||||||
@@ -351,6 +356,9 @@ class UniversalBleCallbackChannelCodecSerializer : public flutter::StandardCodec
|
|||||||
class UniversalBleCallbackChannel {
|
class UniversalBleCallbackChannel {
|
||||||
public:
|
public:
|
||||||
UniversalBleCallbackChannel(flutter::BinaryMessenger* binary_messenger);
|
UniversalBleCallbackChannel(flutter::BinaryMessenger* binary_messenger);
|
||||||
|
UniversalBleCallbackChannel(
|
||||||
|
flutter::BinaryMessenger* binary_messenger,
|
||||||
|
const std::string& message_channel_suffix);
|
||||||
static const flutter::StandardMessageCodec& GetCodec();
|
static const flutter::StandardMessageCodec& GetCodec();
|
||||||
void OnAvailabilityChanged(
|
void OnAvailabilityChanged(
|
||||||
int64_t state,
|
int64_t state,
|
||||||
@@ -380,6 +388,7 @@ class UniversalBleCallbackChannel {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
flutter::BinaryMessenger* binary_messenger_;
|
flutter::BinaryMessenger* binary_messenger_;
|
||||||
|
std::string message_channel_suffix_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace universal_ble
|
} // namespace universal_ble
|
||||||
|
|||||||
@@ -206,17 +206,21 @@ namespace universal_ble
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<FlutterError> UniversalBlePlugin::SetNotifiable(
|
void UniversalBlePlugin::SetNotifiable(
|
||||||
const std::string &device_id,
|
const std::string &device_id,
|
||||||
const std::string &service,
|
const std::string &service,
|
||||||
const std::string &characteristic,
|
const std::string &characteristic,
|
||||||
int64_t ble_input_property)
|
int64_t ble_input_property,
|
||||||
|
std::function<void(std::optional<FlutterError> reply)> result)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto it = connectedDevices.find(_str_to_mac_address(device_id));
|
auto it = connectedDevices.find(_str_to_mac_address(device_id));
|
||||||
if (it == connectedDevices.end())
|
if (it == connectedDevices.end())
|
||||||
return FlutterError("IllegalArgument", "Unknown devicesId:" + device_id);
|
{
|
||||||
|
result(FlutterError("IllegalArgument", "Unknown devicesId:" + device_id));
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto bluetoothAgent = *it->second;
|
auto bluetoothAgent = *it->second;
|
||||||
GattCharacteristicObject &gatt_characteristic_holder = bluetoothAgent._fetch_characteristic(service, characteristic);
|
GattCharacteristicObject &gatt_characteristic_holder = bluetoothAgent._fetch_characteristic(service, characteristic);
|
||||||
GattCharacteristic gattCharacteristic = gatt_characteristic_holder.obj;
|
GattCharacteristic gattCharacteristic = gatt_characteristic_holder.obj;
|
||||||
@@ -228,7 +232,8 @@ namespace universal_ble
|
|||||||
descriptorValue = GattClientCharacteristicConfigurationDescriptorValue::Notify;
|
descriptorValue = GattClientCharacteristicConfigurationDescriptorValue::Notify;
|
||||||
if ((properties & GattCharacteristicProperties::Notify) == GattCharacteristicProperties::None)
|
if ((properties & GattCharacteristicProperties::Notify) == GattCharacteristicProperties::None)
|
||||||
{
|
{
|
||||||
return FlutterError("Characteristic does not support notify");
|
result(FlutterError("Characteristic does not support notify"));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ble_input_property == static_cast<int>(BleInputProperty::indication))
|
else if (ble_input_property == static_cast<int>(BleInputProperty::indication))
|
||||||
@@ -236,21 +241,21 @@ namespace universal_ble
|
|||||||
descriptorValue = GattClientCharacteristicConfigurationDescriptorValue::Indicate;
|
descriptorValue = GattClientCharacteristicConfigurationDescriptorValue::Indicate;
|
||||||
if ((properties & GattCharacteristicProperties::Indicate) == GattCharacteristicProperties::None)
|
if ((properties & GattCharacteristicProperties::Indicate) == GattCharacteristicProperties::None)
|
||||||
{
|
{
|
||||||
return FlutterError("Characteristic does not support indicate");
|
result(FlutterError("Characteristic does not support indicate"));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetNotifiableAsync(bluetoothAgent, service, characteristic, descriptorValue);
|
SetNotifiableAsync(bluetoothAgent, service, characteristic, descriptorValue, result);
|
||||||
return std::nullopt;
|
|
||||||
}
|
}
|
||||||
catch (const FlutterError &err)
|
catch (const FlutterError &err)
|
||||||
{
|
{
|
||||||
return err;
|
return result(err);
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
std::cout << "SetNotifiableLog: Unknown error" << std::endl;
|
std::cout << "SetNotifiableLog: Unknown error" << std::endl;
|
||||||
return FlutterError("Unknown error");
|
return result(FlutterError("Unknown error"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1178,7 +1183,9 @@ namespace universal_ble
|
|||||||
};
|
};
|
||||||
|
|
||||||
winrt::fire_and_forget UniversalBlePlugin::SetNotifiableAsync(BluetoothDeviceAgent &bluetoothDeviceAgent, const std::string &service,
|
winrt::fire_and_forget UniversalBlePlugin::SetNotifiableAsync(BluetoothDeviceAgent &bluetoothDeviceAgent, const std::string &service,
|
||||||
const std::string &characteristic, GattClientCharacteristicConfigurationDescriptorValue descriptorValue)
|
const std::string &characteristic,
|
||||||
|
GattClientCharacteristicConfigurationDescriptorValue descriptorValue,
|
||||||
|
std::function<void(std::optional<FlutterError> reply)> result)
|
||||||
{
|
{
|
||||||
GattCharacteristicObject &gatt_characteristic_holder = bluetoothDeviceAgent._fetch_characteristic(service, characteristic);
|
GattCharacteristicObject &gatt_characteristic_holder = bluetoothDeviceAgent._fetch_characteristic(service, characteristic);
|
||||||
GattCharacteristic gattCharacteristic = gatt_characteristic_holder.obj;
|
GattCharacteristic gattCharacteristic = gatt_characteristic_holder.obj;
|
||||||
@@ -1205,11 +1212,15 @@ namespace universal_ble
|
|||||||
std::cout << "FailedToSubscribe: Unknown" << to_uuidstr(gattCharacteristic.Uuid()) << std::endl;
|
std::cout << "FailedToSubscribe: Unknown" << to_uuidstr(gattCharacteristic.Uuid()) << std::endl;
|
||||||
}
|
}
|
||||||
if (status != GattCommunicationStatus::Success)
|
if (status != GattCommunicationStatus::Success)
|
||||||
|
{
|
||||||
|
result(FlutterError("Failed to update notification state"));
|
||||||
co_return;
|
co_return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
std::cout << "FailedToPerformThisOperationOn: " << to_uuidstr(gattCharacteristic.Uuid()) << std::endl;
|
std::cout << "FailedToPerformThisOperationOn: " << to_uuidstr(gattCharacteristic.Uuid()) << std::endl;
|
||||||
|
result(FlutterError("Failed to update notification state"));
|
||||||
co_return;
|
co_return;
|
||||||
}
|
}
|
||||||
// create uniqKey with uuid and deviceId
|
// create uniqKey with uuid and deviceId
|
||||||
@@ -1239,6 +1250,7 @@ namespace universal_ble
|
|||||||
}
|
}
|
||||||
characteristicsTokens[uniqTokenKey] = gattCharacteristic.ValueChanged({this, &UniversalBlePlugin::GattCharacteristic_ValueChanged});
|
characteristicsTokens[uniqTokenKey] = gattCharacteristic.ValueChanged({this, &UniversalBlePlugin::GattCharacteristic_ValueChanged});
|
||||||
}
|
}
|
||||||
|
result(std::nullopt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UniversalBlePlugin::GattCharacteristic_ValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args)
|
void UniversalBlePlugin::GattCharacteristic_ValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args)
|
||||||
|
|||||||
@@ -113,7 +113,8 @@ namespace universal_ble
|
|||||||
void CleanConnection(uint64_t bluetoothAddress);
|
void CleanConnection(uint64_t bluetoothAddress);
|
||||||
void DiscoverServicesAsync(BluetoothDeviceAgent &bluetoothDeviceAgent, std::function<void(ErrorOr<flutter::EncodableList> reply)>);
|
void DiscoverServicesAsync(BluetoothDeviceAgent &bluetoothDeviceAgent, std::function<void(ErrorOr<flutter::EncodableList> reply)>);
|
||||||
winrt::fire_and_forget SetNotifiableAsync(BluetoothDeviceAgent &bluetoothDeviceAgent, const std::string &service,
|
winrt::fire_and_forget SetNotifiableAsync(BluetoothDeviceAgent &bluetoothDeviceAgent, const std::string &service,
|
||||||
const std::string &characteristic, GattClientCharacteristicConfigurationDescriptorValue descriptorValue);
|
const std::string &characteristic, GattClientCharacteristicConfigurationDescriptorValue descriptorValue,
|
||||||
|
std::function<void(std::optional<FlutterError> reply)> result );
|
||||||
void GattCharacteristic_ValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args);
|
void GattCharacteristic_ValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args);
|
||||||
AvailabilityState getAvailabilityStateFromRadio(RadioState radioState);
|
AvailabilityState getAvailabilityStateFromRadio(RadioState radioState);
|
||||||
std::string parsePairingFailError(Enumeration::DevicePairingResult result);
|
std::string parsePairingFailError(Enumeration::DevicePairingResult result);
|
||||||
@@ -135,11 +136,12 @@ namespace universal_ble
|
|||||||
void DiscoverServices(
|
void DiscoverServices(
|
||||||
const std::string &device_id,
|
const std::string &device_id,
|
||||||
std::function<void(ErrorOr<flutter::EncodableList> reply)> result) override;
|
std::function<void(ErrorOr<flutter::EncodableList> reply)> result) override;
|
||||||
std::optional<FlutterError> SetNotifiable(
|
void SetNotifiable(
|
||||||
const std::string &device_id,
|
const std::string &device_id,
|
||||||
const std::string &service,
|
const std::string &service,
|
||||||
const std::string &characteristic,
|
const std::string &characteristic,
|
||||||
int64_t ble_input_property) override;
|
int64_t ble_input_property,
|
||||||
|
std::function<void(std::optional<FlutterError> reply)> result) override;
|
||||||
void ReadValue(
|
void ReadValue(
|
||||||
const std::string &device_id,
|
const std::string &device_id,
|
||||||
const std::string &service,
|
const std::string &service,
|
||||||
|
|||||||
Reference in New Issue
Block a user