Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
fix: ring commands map
Browse files Browse the repository at this point in the history
  • Loading branch information
reasje committed Jul 29, 2024
1 parent 675556b commit 48b43dd
Showing 1 changed file with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!));
},
);
Expand All @@ -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!));
},
);
Expand All @@ -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!));
},
);
Expand All @@ -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!));
},
);
Expand All @@ -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!));
},
);
Expand All @@ -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!));
},
);
Expand All @@ -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!));
},
);
Expand Down

0 comments on commit 48b43dd

Please sign in to comment.