BLECommonService improvement
This commit is contained in:
parent
22cad1a761
commit
b16318da2c
1 changed files with 13 additions and 10 deletions
|
@ -167,16 +167,18 @@ class BLECommonService @Inject internal constructor(
|
|||
@Synchronized
|
||||
private fun writeCharacteristicNoResponse(characteristic: BluetoothGattCharacteristic, data: ByteArray) {
|
||||
Thread(Runnable {
|
||||
SystemClock.sleep(WRITE_DELAY_MILLIS)
|
||||
if (bluetoothAdapter == null || bluetoothGatt == null) {
|
||||
aapsLogger.error("BluetoothAdapter not initialized_ERROR")
|
||||
isConnecting = false
|
||||
isConnected = false
|
||||
return@Runnable
|
||||
synchronized(this) {
|
||||
SystemClock.sleep(WRITE_DELAY_MILLIS)
|
||||
if (bluetoothAdapter == null || bluetoothGatt == null) {
|
||||
aapsLogger.error("BluetoothAdapter not initialized_ERROR")
|
||||
isConnecting = false
|
||||
isConnected = false
|
||||
return@Runnable
|
||||
}
|
||||
characteristic.value = data
|
||||
characteristic.writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE
|
||||
bluetoothGatt?.writeCharacteristic(characteristic)
|
||||
}
|
||||
characteristic.value = data
|
||||
characteristic.writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE
|
||||
bluetoothGatt?.writeCharacteristic(characteristic)
|
||||
}).start()
|
||||
SystemClock.sleep(50)
|
||||
}
|
||||
|
@ -200,6 +202,7 @@ class BLECommonService @Inject internal constructor(
|
|||
return bluetoothGatt?.services
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun findCharacteristic() {
|
||||
val gattServices = getSupportedGattServices() ?: return
|
||||
var uuid: String
|
||||
|
@ -214,7 +217,7 @@ class BLECommonService @Inject internal constructor(
|
|||
// nRF Connect 참고하여 추가함
|
||||
val descriptor: BluetoothGattDescriptor = uartIndicate!!.getDescriptor(UUID.fromString(CHARACTERISTIC_CONFIG_UUID))
|
||||
descriptor.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
|
||||
bluetoothGatt!!.writeDescriptor(descriptor)
|
||||
bluetoothGatt?.writeDescriptor(descriptor)
|
||||
}
|
||||
if (WRITE_UUID == uuid) {
|
||||
uartWrite = gattCharacteristic
|
||||
|
|
Loading…
Reference in a new issue