startGyroscope method

  1. @override
Future<Stream<SensorEvent>> startGyroscope(
  1. double samplingRate
)
override

Starts streaming gyroscope data from the Movesense device at the given samplingRate (Hz). Returns a stream of SensorEvents.

Implementation

@override
Future<Stream<SensorEvent>> startGyroscope(double samplingRate) async {
  try {
    if (connectedSerial == null) {
      throw Exception('No Movesense device connected');
    }
    if (_gyroController.isClosed) {
      _gyroController = StreamController<SensorEvent>.broadcast();
    }
    if (!_gyroController.hasListener && _gyroStreamSubscription == null) {
      _subscribeToGyro(samplingRate);
    }
    return _gyroController.stream;
  } catch (e) {
    if (kDebugMode) {
      print('Error starting Movesense gyroscope: $e');
    }
    rethrow;
  }
}