Skip to content

Commit

Permalink
Don't do connections when bluetooth is off
Browse files Browse the repository at this point in the history
  • Loading branch information
weliem committed May 26, 2024
1 parent b91c52a commit c7bed6c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions blessed/src/main/java/com/welie/blessed/BluetoothCentralManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,11 @@ class BluetoothCentralManager(private val context: Context) {

private fun connectPeripheral(peripheral: BluetoothPeripheral, resultCentralManagerCallback: BluetoothCentralManagerCallback) {
synchronized(connectLock) {
if (bleNotReady()) {
Logger.e(TAG, "cannot connect peripheral '%s' because Bluetooth is off", peripheral.address)
return
}

checkPeripheralStatus(peripheral)

// Check if the peripheral is cached or not. If not, issue a warning because connection may fail
Expand All @@ -496,6 +501,11 @@ class BluetoothCentralManager(private val context: Context) {
*/
fun autoConnectPeripheral(peripheral: BluetoothPeripheral) {
synchronized(connectLock) {
if (bleNotReady()) {
Logger.e(TAG, "cannot autoConnectPeripheral '%s' because Bluetooth is off", peripheral.address)
return
}

checkPeripheralStatus(peripheral)

// Check if the peripheral is uncached and start autoConnectPeripheralByScan
Expand Down

0 comments on commit c7bed6c

Please sign in to comment.