我正在接收来自加速度计 (x,y,z) 和陀螺仪 (x,y,z) 的数据。如何将它们保存在 .csv 文件中?我正在使用 xamarin-forms (Xamarin-Essentials) - 我想将它们保存在 Android 或 iOS 智能手机的本地实习生内存中。如果我单击开始,我想开始写入数据,当我单击停止时,我想将数据保存在 .csv 文件中。
public void Gyroscope_ReadingChanged(object sender, GyroscopeChangedEventArgs e)
{
var data = e.Reading;
GlabelX.Text = data.AngularVelocity.X.ToString();
GlabelY.Text = data.AngularVelocity.Y.ToString();
GlabelZ.Text = data.AngularVelocity.Z.ToString();
}
public void Accelerometer_ReadingChanged(object sender, AccelerometerChangedEventArgs e)
{
LabelX.Text = e.Reading.Acceleration.X.ToString();
LabelY.Text = e.Reading.Acceleration.Y.ToString();
LabelZ.Text = e.Reading.Acceleration.Z.ToString();
}
private async void ButtonStart_Clicked(object sender, EventArgs e)
{
if (Gyroscope.IsMonitoring)
return;
Gyroscope.ReadingChanged += Gyroscope_ReadingChanged;
Gyroscope.Start(speed);
Accelerometer.ReadingChanged += Accelerometer_ReadingChanged;
Accelerometer.Start(speed);
}
private void ButtonStop_Clicked(object sender, EventArgs e)
{
if (!Gyroscope.IsMonitoring)
return;
Gyroscope.ReadingChanged -= Gyroscope_ReadingChanged;
Gyroscope.Stop();
Accelerometer.ReadingChanged -= Accelerometer_ReadingChanged;
Accelerometer.Stop();
}