Exemplo n.º 1
0
        private void ParseAndAddData(string value)
        {
            if (!string.IsNullOrWhiteSpace(value))
            {
                DateTime timeStamp = DateTime.UtcNow;

                double[] xyz        = new double[3];
                string[] parsedData = value.Split(',');

                if (parsedData.Length != 3)
                {
                    return;
                }

                for (int i = 0; i < xyz.Length; i++)
                {
                    if (double.TryParse(parsedData[i], out double result))
                    {
                        xyz[i] = result;
                    }
                }

                var data = new AccelerometerReadingDto {
                    Timestamp = timeStamp,
                    X         = xyz[0],
                    Y         = xyz[1],
                    Z         = xyz[2],
                };

                AccelerometerChanged?.Invoke(new AccelerometerChangedEventArgs {
                    Data = data,
                });
            }
        }
Exemplo n.º 2
0
        private void Accelerometer_ReadingChanged(object sender, AccelerometerChangedEventArgs e)
        {
            var reading = new AccelerometerReadingDto {
                Timestamp = DateTime.UtcNow,
                X         = e.Reading.Acceleration.X,
                Y         = e.Reading.Acceleration.Y,
                Z         = e.Reading.Acceleration.Z,
            };

            jumpDetectionUtility.AddReading(reading);
            readings.Add(reading);

            Debug.WriteLine(reading);
        }
Exemplo n.º 3
0
        public void AddReading(AccelerometerReadingDto reading)
        {
            if (!started && (reading.X < -startTolerance || reading.X > startTolerance))
            {
                started = true;
            }

            if (!started)
            {
                return;
            }

            Debug.WriteLine(reading);

            readings.Enqueue(reading);

            if (IsFreefallReading(reading))
            {
                freefallReadings.Add(reading);
            }
            else
            {
                double jumpTime = freefallReadings.GetTime();

                if (jumpTime >= minJumpSeconds && jumpTime <= maxJumpSeconds)
                {
                    // The jump meets the minimum time requirment so create the jump
                    freefallReadings.Add(reading);

                    CreateJump();
                }

                takeoffReadings.Clear();
                freefallReadings.Clear();
            }

            // We don't want to store thousands of readings
            if (readings.Count > 30)
            {
                readings.Dequeue();
            }
        }
Exemplo n.º 4
0
 private bool IsFreefallReading(AccelerometerReadingDto reading)
 {
     return(Math.Abs(reading.X) <= Tolerance &&
            Math.Abs(reading.Y) <= Tolerance &&
            Math.Abs(reading.Z) <= Tolerance);
 }