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
|
@Synchronized
|
||||||
private fun writeCharacteristicNoResponse(characteristic: BluetoothGattCharacteristic, data: ByteArray) {
|
private fun writeCharacteristicNoResponse(characteristic: BluetoothGattCharacteristic, data: ByteArray) {
|
||||||
Thread(Runnable {
|
Thread(Runnable {
|
||||||
SystemClock.sleep(WRITE_DELAY_MILLIS)
|
synchronized(this) {
|
||||||
if (bluetoothAdapter == null || bluetoothGatt == null) {
|
SystemClock.sleep(WRITE_DELAY_MILLIS)
|
||||||
aapsLogger.error("BluetoothAdapter not initialized_ERROR")
|
if (bluetoothAdapter == null || bluetoothGatt == null) {
|
||||||
isConnecting = false
|
aapsLogger.error("BluetoothAdapter not initialized_ERROR")
|
||||||
isConnected = false
|
isConnecting = false
|
||||||
return@Runnable
|
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()
|
}).start()
|
||||||
SystemClock.sleep(50)
|
SystemClock.sleep(50)
|
||||||
}
|
}
|
||||||
|
@ -200,6 +202,7 @@ class BLECommonService @Inject internal constructor(
|
||||||
return bluetoothGatt?.services
|
return bluetoothGatt?.services
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
private fun findCharacteristic() {
|
private fun findCharacteristic() {
|
||||||
val gattServices = getSupportedGattServices() ?: return
|
val gattServices = getSupportedGattServices() ?: return
|
||||||
var uuid: String
|
var uuid: String
|
||||||
|
@ -214,7 +217,7 @@ class BLECommonService @Inject internal constructor(
|
||||||
// nRF Connect 참고하여 추가함
|
// nRF Connect 참고하여 추가함
|
||||||
val descriptor: BluetoothGattDescriptor = uartIndicate!!.getDescriptor(UUID.fromString(CHARACTERISTIC_CONFIG_UUID))
|
val descriptor: BluetoothGattDescriptor = uartIndicate!!.getDescriptor(UUID.fromString(CHARACTERISTIC_CONFIG_UUID))
|
||||||
descriptor.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
|
descriptor.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
|
||||||
bluetoothGatt!!.writeDescriptor(descriptor)
|
bluetoothGatt?.writeDescriptor(descriptor)
|
||||||
}
|
}
|
||||||
if (WRITE_UUID == uuid) {
|
if (WRITE_UUID == uuid) {
|
||||||
uartWrite = gattCharacteristic
|
uartWrite = gattCharacteristic
|
||||||
|
|
Loading…
Reference in a new issue