startSensors method
Implementation
Map<String, StreamSubscription<dynamic>> startSensors(
{Function(SensorData)? callback}) {
StreamSubscription<GyroscopeEvent>? gyroSubscription;
StreamSubscription<AccelerometerEvent>? accelSubscription;
sensorData = SensorData(
gyroX: [],
gyroY: [],
gyroZ: [],
accelX: [],
accelY: [],
accelZ: [],
);
gyroSubscription = gyroscopeEvents.listen((GyroscopeEvent event) {
sensorData.gyroX.add(event.x);
sensorData.gyroY.add(event.y);
sensorData.gyroZ.add(event.z);
if (callback != null) callback(sensorData);
});
accelSubscription = accelerometerEvents.listen((AccelerometerEvent event) {
sensorData.accelX.add(event.x);
sensorData.accelY.add(event.y);
sensorData.accelZ.add(event.z);
if (callback != null) callback(sensorData);
});
return {
'gyroSubscription': gyroSubscription,
'accelSubscription': accelSubscription
};
}