Наследование: IAccelerometerReadingChangedEventArgs
Пример #1
0
 private void Aceloro(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
 {
     //gamescreen.batcherBridge.drawText(50f, 50f, 50f, 50f,1, args.Reading.AccelerationX.ToString(), 1f, 1f, 1f, 1f, "ns");
     //if(!Settings.vibrate)
    //  Game.Update1((float)args.Reading.AccelerationX*2, (float)args.Reading.AccelerationY, (float)args.Reading.AccelerationZ); 
     
 }
Пример #2
0
        async private void ReadingChanged(object sender, AccelerometerReadingChangedEventArgs e)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                AccelerometerReading reading = e.Reading;
                ScenarioOutput_X.Text = "X = " + String.Format("{0,5:0.00}", reading.AccelerationX);
                ScenarioOutput_Y.Text = "Y = " + String.Format("{0,5:0.00}", reading.AccelerationY);
                ScenarioOutput_Z.Text = "Z = " + String.Format("{0,5:0.00}", reading.AccelerationZ);
                var newColor = new Color();
                newColor.A = 0xFF;

                int red = Math.Abs((int)(reading.AccelerationX * 100));
                int green = Math.Abs((int)(reading.AccelerationY * 100));
                int blue = Math.Abs((int)(reading.AccelerationZ * 100));

                newColor.R = byte.Parse(red.ToString());
                newColor.G = byte.Parse(green.ToString());
                newColor.B = byte.Parse(blue.ToString());

                ball.Fill = new SolidColorBrush(newColor);



            });
        }
Пример #3
0
 void acc_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
 {
     Dispatcher.BeginInvoke(() =>
     {
         accOut.Text = "Accelerometer: <" + args.Reading.AccelerationX + ", " + args.Reading.AccelerationY + ", " + args.Reading.AccelerationZ + ">";
     });
 }
 /// <summary>
 /// This is the event handler for ReadingChanged events.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 async private void ReadingChanged(object sender, AccelerometerReadingChangedEventArgs e)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         MainPage.SetReadingText(ScenarioOutput, e.Reading);
     });
 }
Пример #5
0
 async void ac_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
 {
     double x = args.Reading.AccelerationX * 100d;
     double y = args.Reading.AccelerationY * 100d;
     double z = args.Reading.AccelerationZ * 100d;
     System.Diagnostics.Debug.WriteLine("X={0:NO},Y={1:NO},Z={2}", x, y, z);
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
     {
         if (Math.Abs(x) > 100d || Math.Abs(y) > 60d || Math.Abs(z) > 50d)
         {
             try
             {
                 int imageIndex = new Random().Next(1, 5);
                 //this codes is going to read the image file from the storage that in the phone rather than in the computer.
                 Windows.Storage.StorageFile theFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(string.Format("ms-appx:///Assets/f{0}.png", imageIndex), UriKind.Absolute));
                 BitmapImage bitmap = new BitmapImage();
                 bitmap.SetSource(await theFile.OpenReadAsync());
                 this.img.Source= bitmap;
             }
             catch (Exception e)
             {
                 
                 throw e;
             }
         }
     });
 }
Пример #6
0
 private async void Accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
 {
     await toggleAccelerometer.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() =>
     {
         var val = 0f;
         if (togglePID.IsOn)
         {
             // Limit the accelerometer PID control to 500 RPM max
             val = (float)args.Reading.AccelerationZ * -500f;
             if (val > 500) val = 500;
             if (val < 0) val = 0;
             pid.SetPoint = (float)val;
             Slider.Value = (int)val;
         }
         else
         {
             val = (float)args.Reading.AccelerationZ * -100f;
             if (val > 100) val = 100;
             if (val < 0) val = 0;
             motor.Throttle = (double)val;
             Slider.Value = (int)val * 12.0;
         }
         
     }));
 }
Пример #7
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;
                });
            }
        }
        void accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
        {
            double magnitude = Math.Sqrt(
                args.Reading.AccelerationX * args.Reading.AccelerationX +
                args.Reading.AccelerationY * args.Reading.AccelerationY +
                args.Reading.AccelerationZ * args.Reading.AccelerationZ);

            if (magnitude > 1.01 && !stepping)
            {
                stepping = true;
                steps += 1;

                // Prevent a race condition of the last subscriber unsubscribing
                // before we get to the null check.
                EventHandler<int> handler = Stepped;

                // Event will be null if there are no subscribers 
                if (handler != null)
                {
                    handler(this, steps);
                }
            }
            else if (magnitude < 1.0)
            {
                stepping = false;
            }
        }
 private void accelerometer_ReadingChanged(object sender, Windows.Devices.Sensors.AccelerometerReadingChangedEventArgs e)
 {
     System.Windows.Application.Current.Dispatcher.BeginInvoke((Action) delegate
     {
         AccelerometerReading = e.Reading;
     });
 }
Пример #10
0
        private async void CalculateDeviceRotation(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
        {
            // Compute the rotation angle based on the accelerometer's position
            var angle = Math.Atan2(args.Reading.AccelerationY, args.Reading.AccelerationX) * toDegrees;

            // Since our arrow points upwards insted of the right, we rotate the coordinate system by 90 degrees
            angle += 90;

            // Ensure that the range of the value is between [0, 360)
            if (angle < 0)
            {
                angle += 360;
            }
            
            rotationAngle = angle;

            // Update the UI with the new value
            await Dispatcher.RunAsync(
                CoreDispatcherPriority.Normal,
                () =>
                {
                    deviceRotation.Text = rotationAngle.ToString();
                    UpdateArrowForRotation();
                });
        }
Пример #11
0
 void accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
 {
     Deployment.Current.Dispatcher.BeginInvoke(() =>
     {
         accelerometerReading = args.Reading;
         ShowData();
     });
 }
 /// <summary>
 /// Reads in the Accelerometer data for windows8 devices.
 /// </summary>
 private void Windows8AccelerometerChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
 {
     // For whatever reason, this is insconsistent with windows phone...
     // so lets swap the reading here.
     _currentReading.X = -(float)args.Reading.AccelerationY;
     _currentReading.Y = -(float)args.Reading.AccelerationX;
     _currentReading.Z = -(float)args.Reading.AccelerationZ;
 }
 private void OnAccelerometerReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
 {
   Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
   {
     this.tbx.Text = string.Format("X: {0}", args.Reading.AccelerationX);
     this.tby.Text = string.Format("Y: {0}", args.Reading.AccelerationY);
     this.tbz.Text = string.Format("Z: {0}", args.Reading.AccelerationZ);
   });
 }
Пример #14
0
        async void a_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
        {
            System.Diagnostics.Debug.WriteLine(args + "改变了。。。");
            // 拿到变化值
            await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {

            });
        }
 async void accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                 {
                     XValue.Text = args.Reading.AccelerationX.ToString();
                     YValue.Text = args.Reading.AccelerationY.ToString();
                     ZValue.Text = args.Reading.AccelerationZ.ToString();
                 });
 }
 private async void OnAccelerometerReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
 {
   var top = args.Reading.AccelerationZ;
   var left = args.Reading.AccelerationX;
   await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    {
      this.ViewModel.MoveBalls(top, left);
    });
 }
Пример #17
0
 async private void ReadingChanged(object sender, AccelerometerReadingChangedEventArgs e)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
         AccelerometerReading reading = e.Reading;
         ScenarioOutput_X.Text = String.Format("{0,5:0.00}", reading.AccelerationX);
         ScenarioOutput_Y.Text = String.Format("{0,5:0.00}", reading.AccelerationY);
         ScenarioOutput_Z.Text = String.Format("{0,5:0.00}", reading.AccelerationZ);
     });
 }
Пример #18
0
 void _accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
 {
     Dispatcher.BeginInvoke(() =>
     {
         lblX.Text = args.Reading.AccelerationX.ToString();
         lblY.Text = args.Reading.AccelerationY.ToString();
         lblZ.Text = args.Reading.AccelerationZ.ToString();
     });
 }
Пример #19
0
 private async void ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         AccelerometerReading reading = args.Reading;
         lblPosX.Text = "X = " + String.Format("{0,5:0.00}", reading.AccelerationX);
         lblPosY.Text = "Y = " + String.Format("{0,5:0.00}", reading.AccelerationY);
         lblPosZ.Text = "Z = " + String.Format("{0,5:0.00}", reading.AccelerationZ);
     });
 }
        /// <summary>
        /// This is the event handler for acceleroemter ReadingChanged events.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReadingChanged(object sender, AccelerometerReadingChangedEventArgs e)
        {
            SampleCount++;

            // Save the sample count if the foreground app is visible.
            bool appVisible = (bool)ApplicationData.Current.LocalSettings.Values["IsAppVisible"];
            if (appVisible)
            {
                ApplicationData.Current.LocalSettings.Values["SampleCount"] = SampleCount;
            }
        }
        private void AccelerometerOnReadingChanged(Windows.Devices.Sensors.Accelerometer sender, AccelerometerReadingChangedEventArgs args)
        {
            var handler = ReadingAvailable;

            if (handler == null)
                return;

            var reading = ToReading(args.Reading);

            handler(this, new MvxValueEventArgs<MvxAccelerometerReading>(reading));
        }
Пример #22
0
        private void ReadingChanged(object sender, Sensors.AccelerometerReadingChangedEventArgs e)
        {
            Sensors.AccelerometerReading reading = e.Reading;

            this.SendEvent("Accelerometer", new RNSensorsJsonObject
            {
                X         = reading.AccelerationX,
                Y         = reading.AccelerationY,
                Z         = reading.AccelerationZ,
                Timestamp = reading.Timestamp
            }.ToJObject());
        }
Пример #23
0
        private void OnPhoneAccelerometerReading(AccelerometerReadingChangedEventArgs args)
        {
            AccelerometerReading reading = args.Reading;
            DateTimeOffset ts = reading.Timestamp;
            EventItem accX = new EventItem { Stream = StreamsEnum.PhoneAccelerometerX, Timestamp = ts, Value = reading.AccelerationX };
            EventItem accY = new EventItem { Stream = StreamsEnum.PhoneAccelerometerY, Timestamp = ts, Value = reading.AccelerationY };
            EventItem accZ = new EventItem { Stream = StreamsEnum.PhoneAccelerometerZ, Timestamp = ts, Value = reading.AccelerationZ };

            //IList<EventItem> events = new[] { accX };
            IList<EventItem> events = new[] { accX, accY, accZ };
            //Debug.WriteLine(DateTime.Now);
            SendToQueue(events);
        }
Пример #24
0
 private async void ReadingChanged(object sender, AccelerometerReadingChangedEventArgs e)
 {
     //iskoristi ui thread da se pozove ocitanje. Bez ovog dodje do pristupanja jednog threada drugom sto je fatalno za program
     //tj pozivanje bindinga vrijednosti iz threada koji radi ocitavanje uredjaja 
     //ako se naleti na slican problem sa hardverskim uredjajima dispatcher je rjesenje
     await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         //uzeti ocitanje i ugurati u vrijednosti i pozvati callback da se promijeni UI preko binding
         AccelerometerReading reading = e.Reading;
         AccelX = reading.AccelerationX;
         AccelY = reading.AccelerationY;
         AccelZ = reading.AccelerationZ;
         Callback();
     });
 }
 public void myAccelHandler(Windows.Devices.Sensors.Accelerometer a, AccelerometerReadingChangedEventArgs e)
 {
     Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
         () =>
         {
             this.value_accel_x.Text = e.Reading.AccelerationX.ToString("0.00");
             this.accelX = e.Reading.AccelerationX;
             this.value_accel_y.Text = e.Reading.AccelerationY.ToString("0.00");
             this.accelY = e.Reading.AccelerationY;
             this.value_accel_z.Text = e.Reading.AccelerationZ.ToString("0.00");
             this.accelZ = e.Reading.AccelerationZ;
             checkTimeToLog();
         }
     );
 }
        private async void OnAccelerometerReading(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
        {
            _currentX += args.Reading.AccelerationX * 80;
            if (_currentX < _minX) _currentX = _minX;
            if (_currentX > _maxX) _currentX = _maxX;

            _currentY += -args.Reading.AccelerationY * 80;
            if (_currentY < _minY) _currentY = _minY;
            if (_currentY > _maxY) _currentY = _maxY;

            await Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
            {
                Canvas.SetLeft(ell1, _currentX);
                Canvas.SetTop(ell1, _currentY);
            });
        }
Пример #27
0
        private void ReadingChanged(object sender, Sensors.AccelerometerReadingChangedEventArgs e)
        {
            Sensors.AccelerometerReading reading = e.Reading;

            if (_lastReading.AddMilliseconds(interval) <= reading.Timestamp)
            {
                _lastReading = reading.Timestamp;

                this.SendEvent("Accelerometer", new RNSensorsJsonObject
                {
                    X         = reading.AccelerationX,
                    Y         = reading.AccelerationY,
                    Z         = reading.AccelerationZ,
                    Timestamp = reading.Timestamp
                }.ToJObject());
            }
        }
Пример #28
0
        private async void ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {

                AccelerometerReading reading = args.Reading;
                i++;

                txtXvalue.Text = String.Format("{0,5:0.00}", reading.AccelerationX);
                txtYvalue.Text = String.Format("{0,5:0.00}", reading.AccelerationY);
                txtZvalue.Text = String.Format("{0,5:0.00}", reading.AccelerationZ);


                this.AddDataEntry(reading.AccelerationX, reading.AccelerationY, reading.AccelerationZ);

                return;

            });
        }
Пример #29
0
        /// <summary>
        /// Compute the difference, in degrees, between the device's orientation and the up direction (against gravity).
        /// We only take into account the X and Y dimensions, i.e. device screen is perpendicular to the ground.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private async void CalculateDeviceRotation(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
        {
            m_rotationAngle = Constants.UIAngleOffset -
                Math.Atan2(args.Reading.AccelerationY, args.Reading.AccelerationX) * 180.0 / Math.PI;

            // Ensure that the range of the value is within [0, 360).
            if (m_rotationAngle >= 360)
            {
                m_rotationAngle -= 360;
            }

            // Update the UI with the new value.
            await Dispatcher.RunAsync(
                CoreDispatcherPriority.Normal,
                () =>
                {
                    deviceRotation.Text = Math.Floor(m_rotationAngle).ToString();
                    UpdateArrowForRotation();
                });
        }
Пример #30
0
        async private void ReadingChanged(object sender, AccelerometerReadingChangedEventArgs e)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
            {
                AccelerometerReading reading = e.Reading;

                _x = reading.AccelerationX;
                _y = reading.AccelerationY;
                _z = reading.AccelerationZ;

                LblX.Text = String.Format("{0,5:0.00}", _x);
                LblY.Text = String.Format("{0,5:0.00}", _y);
                LblZ.Text = String.Format("{0,5:0.00}", _z);

                var command = AnalyzeRobotCommand();

                if (command != "Nothing")
                {
                    lblCommand.Text = command;
                }

                if (command != "Nothing" && _isConnected)
                {
                    await SendMessageAsync(command);
                }
            });
        }
        private void Accelerometer_ReadingChanged( Accelerometer sender, AccelerometerReadingChangedEventArgs accel )
        {
            //var action = Dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler( () => UpdateUI( accel.Reading ) ) );

            ////X is the left/right tilt, while Y is the fwd/rev tilt
            //double lr = accel.Reading.AccelerationX;
            //double fb = accel.Reading.AccelerationY;

            //handleTurn( lr );
            //handleDirection( fb );
        }
Пример #32
0
 private void AccelerometerOnReadingChanged(AccelerometerSensor sender, AccelerometerReadingChangedEventArgs args)
 {
     LatestReading = args.Reading.AsVector3();
     readingAvailable.Invoke(sender, LatestReading);
 }
Пример #33
0
 private void Accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
 {
     var task = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         AccelX.Text = args.Reading.AccelerationX.ToString();
         AccelY.Text = args.Reading.AccelerationY.ToString();
         AccelZ.Text = args.Reading.AccelerationZ.ToString();
     });
 }
Пример #34
0
        async void accelerometer_ReadingChanged(Windows.Devices.Sensors.Accelerometer sender, Windows.Devices.Sensors.AccelerometerReadingChangedEventArgs args)
        {
            try
            {
                if (_locator.LocationStatus != PositionStatus.Disabled)
                {
                    try
                    {
                        Geoposition pos = await _locator.GetGeopositionAsync();

                        System.Diagnostics.Debug.WriteLine("LAT " + pos.Coordinate.Latitude + " " + pos.Coordinate.Longitude);


                        updateCoordList(pos.Coordinate.Latitude, pos.Coordinate.Longitude);

                        //update EndTime
                        this.setEndTime();
                    }
                    catch (Exception ex)
                    {
                        if (ex.HResult != unchecked ((int)0x800705b4))
                        {
                            System.Diagnostics.Debug.WriteLine(ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
        private async void AccelerometerOnReadingChanged(Sensor.Accelerometer sender, Sensor.AccelerometerReadingChangedEventArgs args)
        {
            await _dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                       () =>
            {
                XAcceleration = args.Reading.AccelerationX;
                YAcceleration = args.Reading.AccelerationY;
                ZAcceleration = args.Reading.AccelerationZ;

                SetupNewLocation();
            });
        }