void OnMovementMeasurementValueChanged(object sender, MovementEventArgs e) { movement = e.Measurement; if (_timer == null) { var nowait = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => { StartTimer(); })); } }
void OnMovementMeasurementValueChanged(object sender, MovementEventArgs e) { this.movement = e.Measurement; this.absolutePosition = new MagnetometerMeasurement() { X = movement.MagX, Y = movement.MagY, Z = movement.MagZ }; // magnetometer has quite a bit of noise, if the value is less than 5 then chances are the // device is not moving. if (Math.Abs(movement.GyroX) > MinimumMovement) { rx += movement.MagX; speedX = 1d + Math.Min(3, Math.Abs(movement.MagX / 10)); } if (Math.Abs(movement.GyroY) > MinimumMovement) { ry += movement.MagY; speedY = 1d + Math.Min(3, Math.Abs(movement.MagY / 10)); } if (Math.Abs(movement.GyroZ) > MinimumMovement) { rz += movement.MagZ; speedZ = 1d + Math.Min(3, Math.Abs(movement.MagZ / 10)); } if (timer == null) { var nowait = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => { StartTimer(); })); } }
public static MovementMeasurement GetMovementMeasurements(byte[] sensorData) { if (sensorData.Length == 18) { MovementMeasurement measurement = new MovementMeasurement(); short gx = BitConverter.ToInt16(sensorData,0); short gy = BitConverter.ToInt16(sensorData,2); short gz = BitConverter.ToInt16(sensorData,4); short ax = BitConverter.ToInt16(sensorData,6); short ay = BitConverter.ToInt16(sensorData,8); short az = BitConverter.ToInt16(sensorData,10); short mx = BitConverter.ToInt16(sensorData,12); short my = BitConverter.ToInt16(sensorData,14); short mz = BitConverter.ToInt16(sensorData,16); measurement.GyroX = ((double)gx * 500.0) / 65536.0; measurement.GyroY = ((double)gy * 500.0) / 65536.0; measurement.GyroZ = ((double)gz * 500.0) / 65536.0; measurement.AccelX = ((double)ax / 32768); measurement.AccelY = ((double)ay / 32768); measurement.AccelZ = ((double)az / 32768); // on SensorTag CC2650 the conversion to micro tesla's is done in the firmware. measurement.MagX = (double)mx; measurement.MagY = (double)my; measurement.MagZ = (double)mz; return measurement; } return null; }