Esempio n. 1
0
        void HandleSensorChanged(SensorEvent e)
        {
            var values = e.Values;

            if (values == null || values.Count < 3)
            {
                return;
            }

            var x = e.Values[0];
            var y = e.Values[1];
            var z = e.Values[2];

            DateTimeOffset dateTimeOffset;

            long timeStamp = e.Timestamp;

            if (timeStamp > -62135596800000 && timeStamp < 253402300799999)
            {
                dateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(e.Timestamp);
            }
            else
            {
                dateTimeOffset = DateTimeOffset.Now;
            }

            var rawAcceleration = new Vector3D(x, y, z);

            float alpha = 0.8f;

            gravityArray[0] = alpha * gravityArray[0] + (1 - alpha) * x;
            gravityArray[1] = alpha * gravityArray[1] + (1 - alpha) * y;
            gravityArray[2] = alpha * gravityArray[2] + (1 - alpha) * z;

            var lx = x - gravityArray[0];
            var ly = y - gravityArray[1];
            var lz = z - gravityArray[2];

            var linearAcceleration = new Vector3D(lx, ly, lz);

            var newReading = new AccelerometerReading(dateTimeOffset,
                                                      linearAcceleration, null, null, null);

            Reading = newReading;

            OnReadingChanged(new AccelerometerReadingChangedEventArgs(newReading));
        }
Esempio n. 2
0
 public AccelerometerReadingChangedEventArgs(
     AccelerometerReading reading)
 {
     Reading = reading;
 }