Пример #1
0
        private void ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
        {
            var reading = args.Reading;

            Vector current = new Vector(reading.AccelerationX, reading.AccelerationY, reading.AccelerationZ);
            var delta = new Vector(current.X - _previousValue.X, current.Y - _previousValue.Y, current.Z - _previousValue.Z);

            _previousValue = current;

            if (delta.Length() > 1.0) {
                Dispatcher.BeginInvoke(() => {
                    statusTextBlock.Text = "receiving data from accelerometer.";

                    // Show the numeric values
                    xTextBlock.Text = "X: " + reading.AccelerationX.ToString("0.00");
                    yTextBlock.Text = "Y: " + reading.AccelerationY.ToString("0.00");
                    zTextBlock.Text = "Z: " + reading.AccelerationZ.ToString("0.00");

                    // Show the values graphically
                    xLine.X2 = xLine.X1 + reading.AccelerationX * 100;
                    yLine.Y2 = yLine.Y1 - reading.AccelerationY * 100;
                    zLine.X2 = zLine.X1 - reading.AccelerationZ * 50;
                    zLine.Y2 = zLine.Y1 + reading.AccelerationZ * 50;
                });
            }
        }
Пример #2
0
        private void UpdateUI(SensorData.Vector reading)
        {
            ScenarioOutput_X.Text = String.Format("{0,5:0.00}", reading.X);
            ScenarioOutput_Y.Text = String.Format("{0,5:0.00}", reading.Y);
            ScenarioOutput_Z.Text = String.Format("{0,5:0.00}", reading.Z);

            // Show the values graphically
            xLine.X2 = xLine.X1 + reading.X * 100;
            yLine.Y2 = yLine.Y1 - reading.Y * 100;
            zLine.X2 = zLine.X1 - reading.Z * 50;
            zLine.Y2 = zLine.Y1 + reading.Z * 50;
        }
        private void UpdateUI(SensorData.Vector reading)
        {
            statusTextBlock.Text = "Receiving data from accelerometer...";

            // Show the numeric values
            xTextBlock.Text = "X: " + reading.X.ToString("0.00");
            yTextBlock.Text = "Y: " + reading.Y.ToString("0.00");
            zTextBlock.Text = "Z: " + reading.Z.ToString("0.00");

            // Show the values graphically
            xLine.X2 = xLine.X1 + reading.X * 100;
            yLine.Y2 = yLine.Y1 - reading.Y * 100;
            zLine.X2 = zLine.X1 - reading.Z * 50;
            zLine.Y2 = zLine.Y1 + reading.Z * 50;
        }
        public static IObservable<Vector> FindBigMovements(this IObservable<Vector> source)
        {
            // Use the Scan method to compare each element to the previous one
            var deltas =
                source.Scan(
                    new { last = new Vector(), delta = new Vector() },
                    (state, current) => {
                        var last = current;
                        var delta = new Vector(current.X - state.last.X, current.Y - state.last.Y, current.Z - state.last.Z);
                        return new { last, delta };
                    }
                );

            return deltas
                    .Where(d => d.delta.Length() > 1.0)
                    .Select(d => d.delta);
        }
Пример #5
0
        private static IEnumerable<Vector> EmulateAccelerometerReading()
        {
            // Create a random number generator
            Random random = new Random();

            // Loop indefinitely
            for (double theta = 0; ; theta += .1) {
                // Generate a Vector3 in which the values of each axes slowly drift between -1 and 1 and
                Vector reading = new Vector((float)Math.Sin(theta), (float)Math.Cos(theta * 1.1), (float)Math.Sin(theta * .7));

                // At random intervals, generate a random spike in the data
                if (random.NextDouble() > .95) {
                    reading = new Vector((float)(random.NextDouble() * 3.0 - 1.5),
                     (float)(random.NextDouble() * 3.0 - 1.5),
                     (float)(random.NextDouble() * 3.0 - 1.5));

                }

                // return the vector and then sleep
                yield return reading;
                //Windows.System.Threading.Sleep(100);
                Task.Delay(100).Wait();
            }
        }