startSensors method

Map<String, StreamSubscription> startSensors({
  1. void callback(
    1. SensorData
    )?,
})

Implementation

Map<String, StreamSubscription> startSensors(
    {void 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
  };
}