From 91c5e5e7e0be57f767b5b25f81512135376c69fd Mon Sep 17 00:00:00 2001 From: jjangddu Date: Mon, 9 Mar 2026 17:36:47 +0900 Subject: [PATCH] fix: NIRS connection failure --- .claude/settings.local.json | 7 ++++ .../medilightv2android/ble/BleManager.kt | 33 ++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 .claude/settings.local.json diff --git a/.claude/settings.local.json b/.claude/settings.local.json new file mode 100644 index 0000000..e4a876c --- /dev/null +++ b/.claude/settings.local.json @@ -0,0 +1,7 @@ +{ + "permissions": { + "allow": [ + "Bash(git push -u origin master)" + ] + } +} diff --git a/app/src/main/java/com/example/medilightv2android/ble/BleManager.kt b/app/src/main/java/com/example/medilightv2android/ble/BleManager.kt index c7db27c..30c99f2 100644 --- a/app/src/main/java/com/example/medilightv2android/ble/BleManager.kt +++ b/app/src/main/java/com/example/medilightv2android/ble/BleManager.kt @@ -413,13 +413,38 @@ class BleManager private constructor(private val context: Context) { } } else { Log.w(TAG, "CCCD descriptor not found for RX characteristic") + // No CCCD but still mark ready if characteristics exist + handler.post { + if (txCharacteristic != null && rxCharacteristic != null) { + isServiceReady.value = true + Log.d(TAG, "Service ready (no CCCD)") + } + } + } + } ?: run { + // No RX characteristic, mark ready if TX exists + handler.post { + if (txCharacteristic != null) { + isServiceReady.value = true + Log.d(TAG, "Service ready (no RX)") + } } } + } - handler.post { - if (txCharacteristic != null && rxCharacteristic != null) { - isServiceReady.value = true - Log.d(TAG, "Service ready!") + override fun onDescriptorWrite(gatt: BluetoothGatt, descriptor: BluetoothGattDescriptor, status: Int) { + Log.d(TAG, "onDescriptorWrite: status=$status uuid=${descriptor.uuid}") + if (descriptor.uuid == CCCD_UUID) { + handler.post { + if (status == BluetoothGatt.GATT_SUCCESS) { + if (txCharacteristic != null && rxCharacteristic != null) { + isServiceReady.value = true + Log.d(TAG, "Service ready! (CCCD written)") + } + } else { + Log.e(TAG, "CCCD write failed with status: $status") + connectionError.value = "Notification setup failed (status $status)" + } } } }