File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ import 'package:c2bluetooth/constants.dart' as Identifiers;
1212import 'package:flutter_ble_lib_ios_15/flutter_ble_lib.dart' ;
1313import 'package:rxdart/rxdart.dart' ;
1414
15+ enum ErgometerConnectionState { connecting, connected, disconnected }
16+
1517class Ergometer {
1618 Peripheral _peripheral;
1719 Csafe ? _csafeClient;
@@ -58,6 +60,25 @@ class Ergometer {
5860 });
5961 }
6062
63+ /// Expose a stream of events to enable monitoring the erg's connection state
64+ /// This acts as a wrapper around the state provided by the internal bluetooth library to aid with swapping it out later.
65+ Stream <ErgometerConnectionState > monitorConnectionState () {
66+ return _peripheral.observeConnectionState ().asyncMap ((connectionState) {
67+ switch (connectionState) {
68+ case PeripheralConnectionState .connecting:
69+ return ErgometerConnectionState .connecting;
70+ case PeripheralConnectionState .connected:
71+ return ErgometerConnectionState .connected;
72+ case PeripheralConnectionState .disconnecting:
73+ return ErgometerConnectionState .disconnected;
74+ case PeripheralConnectionState .disconnected:
75+ return ErgometerConnectionState .disconnected;
76+ default :
77+ return ErgometerConnectionState .disconnected;
78+ }
79+ });
80+ }
81+
6182 /// A read function for the PM over bluetooth.
6283 ///
6384 /// Intended for passing to the csafe_fitness library to allow it to read data from the erg
You can’t perform that action at this time.
0 commit comments