Skip to content

Commit

Permalink
Added functionality to disconnect from BLE device (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
richturner authored Jul 12, 2024
2 parents 03bd9ed + 354dfe8 commit c55214d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ORLib/src/main/java/io/openremote/orlib/service/BleProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,18 @@ class BleProvider(val context: Context) {
}
}

@SuppressLint("MissingPermission")
fun disconnectFromDevice(bleCallback: BleCallback) {
currentGatt?.disconnect()
bleCallback.accept(
hashMapOf(
"action" to "DISCONNECT_FROM_DEVICE",
"provider" to "ble",
"success" to (currentGatt != null),
)
)
}

@SuppressLint("MissingPermission")
fun sendToDevice(characteristicID: String, value: Any, callback: BleCallback) {
val characteristic =
Expand Down
8 changes: 8 additions & 0 deletions ORLib/src/main/java/io/openremote/orlib/ui/OrMainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,14 @@ open class OrMainActivity : Activity() {
})
}

action.equals("DISCONNECT_FROM_DEVICE", ignoreCase = true) -> {
bleProvider?.disconnectFromDevice(object : BleProvider.BleCallback {
override fun accept(responseData: Map<String, Any>) {
notifyClient(responseData)
}
})
}

action.equals("SEND_TO_DEVICE", ignoreCase = true) -> {
val attributeId = data.getString("attributeId")
val value = data.get("value")
Expand Down

0 comments on commit c55214d

Please sign in to comment.