startGyroscope method
Starts streaming gyroscope data from the smartphone at the given samplingRate
(Hz).
Returns a stream of SensorEvents.
Implementation
@override
Future<Stream<SensorEvent>> startGyroscope(double samplingRate) async {
try {
final samplingPeriod = Duration(
microseconds: (1000000 / samplingRate).round(),
);
final double radTodeg = 180 / pi;
_gyroStream ??= gyroscopeEventStream(samplingPeriod: samplingPeriod).map(
(e) => SensorEvent(
radTodeg * e.x,
radTodeg * e.y,
radTodeg * e.z,
e.timestamp,
),
);
return _gyroStream!;
} catch (e) {
if (kDebugMode) {
print('Error starting gyroscope: $e');
}
rethrow;
}
}