Commit ffbdf9a

derdilla <82763757+NobodyForNothing@users.noreply.github.com>
2024-04-19 19:05:34
replace internal ble bloc emit with direct invocation
Signed-off-by: derdilla <82763757+NobodyForNothing@users.noreply.github.com>
1 parent f12f3d0
Changed files (2)
app
app/lib/components/ble_input/ble_input_bloc.dart
@@ -17,7 +17,6 @@ class BleInputBloc extends Bloc<BleInputEvent, BleInputState> {
     on<OpenBleInput>(_onOpenBleInput);
     on<CloseBleInput>(_onCloseBleInput);
     on<BleInputDeviceSelected>(_onBleInputDeviceSelected);
-    on<BleBluetoothMeasurementReceived>(_onBleBluetoothMeasurementReceived);
     // TODO: figure out exhaustive approach
 
     // TODO: show capabilities during testing:
@@ -110,10 +109,7 @@ class BleInputBloc extends Bloc<BleInputEvent, BleInputState> {
             deviceId: event.device.id,
           );
           // TODO: extract subscription
-          _ble.subscribeToCharacteristic(characteristic).listen((List<int> data) {
-            debugLog.add('BLE MESSAGE: $data');
-            add(BleBluetoothMeasurementReceived(data));
-          });
+          _ble.subscribeToCharacteristic(characteristic).listen(_onBleBluetoothMeasurementReceived);
           emit(BleConnectSuccess());
         } else if (update.connectionState == DeviceConnectionState.connecting) {
           emit(BleConnectInProgress());
@@ -127,11 +123,12 @@ class BleInputBloc extends Bloc<BleInputEvent, BleInputState> {
     }
   }
 
-  Future<void> _onBleBluetoothMeasurementReceived(BleBluetoothMeasurementReceived event, Emitter<BleInputState> emit) async {
+  void _onBleBluetoothMeasurementReceived(List<int> data, Emitter<BleInputState> emit) async {
     await _deviceStreamSubscribtion?.cancel();
     await _connectionUpdateStreamSubscribtion?.cancel();
     emit(BleMeasurementInProgress());
-    final decoded = BPMeasurementCharacteristic.parse(event.data);
+    debugLog.add('BLE MESSAGE: $data');
+    final decoded = BPMeasurementCharacteristic.parse(data);
     final record = BloodPressureRecord(
       decoded.time ?? DateTime.now(),
       // TODO: unit conversions
app/lib/components/ble_input/ble_input_events.dart
@@ -17,12 +17,3 @@ class BleInputDeviceSelected extends BleInputEvent {
   /// The device to connect with.
   final DiscoveredDevice device;
 }
-
-/// A measurement was started over bluetooth.
-class BleBluetoothMeasurementReceived extends BleInputEvent {
-  /// Transmit binary data from a bluetooth device.
-  BleBluetoothMeasurementReceived(this.data);
-
-  /// The binary data received.
-  final List<int> data;
-}