From 48b43ddf06d1e2ddf36e9e3e588261f1beeb39c4 Mon Sep 17 00:00:00 2001 From: reasje Date: Mon, 29 Jul 2024 14:01:26 +0330 Subject: [PATCH] fix: ring commands map --- .../domain/blueberry_ring_use_case.dart | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/features/common/packages/bluetooth/blueberry_ring/domain/blueberry_ring_use_case.dart b/lib/features/common/packages/bluetooth/blueberry_ring/domain/blueberry_ring_use_case.dart index 49cb2571..f2c8f780 100644 --- a/lib/features/common/packages/bluetooth/blueberry_ring/domain/blueberry_ring_use_case.dart +++ b/lib/features/common/packages/bluetooth/blueberry_ring/domain/blueberry_ring_use_case.dart @@ -60,7 +60,7 @@ class BlueberryRingUseCase extends ReactiveUseCase { withKeywords: ['2301'], ); - await Future.delayed(const Duration(seconds: 2), () async { + await Future.delayed(const Duration(seconds: 4), () async { final scanResults = _bluetoothUseCase.scanResults.value; if (scanResults.isNotEmpty) { // only one scan results @@ -166,9 +166,8 @@ class BlueberryRingUseCase extends ReactiveUseCase { final command = BlueberryCommands.readLevel(); collectLog('readLevel:command $command'); blueberryRingCharacteristic.value?.write(command); - final value = await blueberryRingNotificationsCharacteristic.value?.lastValueStream.firstWhere((element) => element.isNotEmpty); + final value = await blueberryRingNotificationsCharacteristic.value?.lastValueStream.firstWhere((element) => element.isNotEmpty && element.first == command.first); collectLog('readLevel:value $value'); - collectLog('readLevel:lastValue ${blueberryRingNotificationsCharacteristic.value!.lastValue}'); return BlueberryResolves.readLevel(Uint8List.fromList(value!)); }, ); @@ -180,9 +179,8 @@ class BlueberryRingUseCase extends ReactiveUseCase { final command = BlueberryCommands.readVersion(); collectLog('readVersion:command $command'); blueberryRingCharacteristic.value?.write(command); - final value = await blueberryRingNotificationsCharacteristic.value?.lastValueStream.firstWhere((element) => element.isNotEmpty); + final value = await blueberryRingNotificationsCharacteristic.value?.lastValueStream.firstWhere((element) => element.isNotEmpty && element.first == command.first); collectLog('readVersion:value $value'); - collectLog('readLevel:lastValue ${blueberryRingNotificationsCharacteristic.value!.lastValue}'); return BlueberryResolves.readVersion(Uint8List.fromList(value!)); }, ); @@ -194,9 +192,8 @@ class BlueberryRingUseCase extends ReactiveUseCase { final command = BlueberryCommands.readTime(); collectLog('readTime:command $command'); blueberryRingCharacteristic.value?.write(command); - final value = await blueberryRingNotificationsCharacteristic.value?.lastValueStream.firstWhere((element) => element.isNotEmpty); + final value = await blueberryRingNotificationsCharacteristic.value?.lastValueStream.firstWhere((element) => element.isNotEmpty && element.first == command.first); collectLog('readTime:value $value'); - collectLog('readLevel:lastValue ${blueberryRingNotificationsCharacteristic.value!.lastValue}'); return BlueberryResolves.readTime(Uint8List.fromList(value!)); }, ); @@ -208,9 +205,8 @@ class BlueberryRingUseCase extends ReactiveUseCase { final command = BlueberryCommands.readSleep(); collectLog('readSleep:command $command'); blueberryRingCharacteristic.value?.write(command); - final value = await blueberryRingNotificationsCharacteristic.value?.lastValueStream.firstWhere((element) => element.isNotEmpty); + final value = await blueberryRingNotificationsCharacteristic.value?.lastValueStream.firstWhere((element) => element.isNotEmpty && element.first == command.first); collectLog('readSleep:value $value'); - collectLog('readLevel:lastValue ${blueberryRingNotificationsCharacteristic.value!.lastValue}'); return BlueberryResolves.readSleep(Uint8List.fromList(value!)); }, ); @@ -222,9 +218,8 @@ class BlueberryRingUseCase extends ReactiveUseCase { final command = BlueberryCommands.readBloodOxygens(); collectLog('readBloodOxygens:command $command'); blueberryRingCharacteristic.value?.write(command); - final value = await blueberryRingNotificationsCharacteristic.value?.lastValueStream.firstWhere((element) => element.isNotEmpty); + final value = await blueberryRingNotificationsCharacteristic.value?.lastValueStream.firstWhere((element) => element.isNotEmpty && element.first == command.first); collectLog('readBloodOxygens:value $value'); - collectLog('readLevel:lastValue ${blueberryRingNotificationsCharacteristic.value!.lastValue}'); return BlueberryResolves.readBloodOxygens(Uint8List.fromList(value!)); }, ); @@ -236,9 +231,8 @@ class BlueberryRingUseCase extends ReactiveUseCase { final command = BlueberryCommands.readSteps(); collectLog('readSteps:command $command'); blueberryRingCharacteristic.value?.write(command); - final value = await blueberryRingNotificationsCharacteristic.value?.lastValueStream.firstWhere((element) => element.isNotEmpty); + final value = await blueberryRingNotificationsCharacteristic.value?.lastValueStream.firstWhere((element) => element.isNotEmpty && element.first == command.first); collectLog('readSteps:value $value'); - collectLog('readLevel:lastValue ${blueberryRingNotificationsCharacteristic.value!.lastValue}'); return BlueberryResolves.readSteps(Uint8List.fromList(value!)); }, ); @@ -250,9 +244,8 @@ class BlueberryRingUseCase extends ReactiveUseCase { final command = BlueberryCommands.readHeartRates(); collectLog('readHeartRate:command $command'); blueberryRingCharacteristic.value?.write(command); - final value = await blueberryRingNotificationsCharacteristic.value?.lastValueStream.firstWhere((element) => element.isNotEmpty); + final value = await blueberryRingNotificationsCharacteristic.value?.lastValueStream.firstWhere((element) => element.isNotEmpty && element.first == command.first); collectLog('readHeartRate:value $value'); - collectLog('readLevel:lastValue ${blueberryRingNotificationsCharacteristic.value!.lastValue}'); return BlueberryResolves.readHeartRates(Uint8List.fromList(value!)); }, );