private async void Compass_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     double degrees = args.Reading.HeadingMagneticNorth;
     await Dispatcher.RunAsync(
         CoreDispatcherPriority.Normal,
         () => Rotation.Angle = degrees);
 }
 private void OnCompassReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         txtHeading.Text = args.Reading.HeadingMagneticNorth.ToString();
     });
 }
Exemplo n.º 3
0
        private async void CompassOnCurrentValueChanged(Compass compass, CompassReadingChangedEventArgs args)
        {
            var heading = (float)args.Reading.HeadingMagneticNorth;
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => CompassIndicator.ControllerHeading = heading);

            DroneController.ControllerHeading = heading;
        }
Exemplo n.º 4
0
 private void C_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         Com.Text = args.Reading.HeadingTrueNorth.ToString();
     });
 }
Exemplo n.º 5
0
        /// <summary>
        /// <see cref="Compass.ReadingChanged"/> event handler for compass value changes.
        /// </summary>
        /// <param name="sender">source object that issue this event</param>
        /// <param name="e">The <see cref="CompassReadingChangedEventArgs"/> instance containing the event data.</param>
        private async void compass_ReadingChanged(object sender, CompassReadingChangedEventArgs e)
        {
            if (!isStarted)
            {
                return;
            }

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (e.Reading.HeadingAccuracy < ACCURACY_THRESHOLD)
                {
                    txtMessage.Text = App.LoadString("RequireCalibration");
                }
                else
                {
                    txtMessage.Text = "";
                }

                string reading = String.Format(CultureInfo.CurrentCulture,
                                               "{0}: {1,5:0.00} (°)\r\n{2}: {3,5:0.00} (°)\r\n{4}: {5}",
                                               App.LoadString("TrueHeading"),
                                               e.Reading.HeadingTrueNorth,
                                               App.LoadString("MagneticHeading"),
                                               e.Reading.HeadingMagneticNorth,
                                               App.LoadString("Accuracy"),
                                               e.Reading.HeadingAccuracy);

                txtStatus.Text          = reading;
                rotateTransform.Angle   = (-1) * Convert.ToDouble(e.Reading.HeadingTrueNorth, CultureInfo.CurrentCulture);
                rotateTransform.CenterX = imgPage.ActualWidth / 2;
                rotateTransform.CenterY = imgPage.ActualHeight / 2;

                App.LogComment(reading.Replace("\r\n", " "));
            });
        }
 async void OnCompassReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         ShowCompassValues(args.Reading);
     });
 }
Exemplo n.º 7
0
        public async void NewCom(Compass sender, CompassReadingChangedEventArgs args)
        {
            var reading = args == null?sender?.GetCurrentReading() : args.Reading;

            await this.dispatcher.RunAsync(
                CoreDispatcherPriority.Normal,
                () =>
            {
                this[COMPASS] = reading == null
                                            ? this[COMPASS].New(0, 0, 0, 0)
                                            : this[COMPASS].New(
                    reading.HeadingMagneticNorth,
                    reading.HeadingTrueNorth ?? 0,
                    0,
                    0);
                if (this[COMPASS].IsChanged)
                {
                    this.OnPropertyChanged(new PropertyChangedEventArgs("ItemsList"));
                    this.OnSensorUpdated?.Invoke(this[COMPASS]);
                }
            });

            if (this.SensorSwitches.M.HasValue && (this.SensorSwitches.M.Value == 1 || this.SensorSwitches.M.Value == 3))
            {
                this.SensorSwitches.M = 0;
            }
        }
Exemplo n.º 8
0
 void MainPage_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     Dispatcher.BeginInvoke(new Action(() =>
     {
         var n            = args.Reading.HeadingTrueNorth;
         TextCompass.Text = string.Format(@"Compass:{0}, North:{1}", args.Reading.HeadingMagneticNorth,
                                          n != null ? n.ToString() : @"Flse");
     }));
 }
 async void MainPage_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         var n            = args.Reading.HeadingTrueNorth;
         TextCompass.Text = string.Format(@"Compass:{0}, North:{1}", args.Reading.HeadingMagneticNorth,
                                          n != null ? n.ToString() : @"Flse");
     });
 }
Exemplo n.º 10
0
        private async void ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
                CompassReading reading      = args.Reading;
                double headingMagneticNorth = reading.HeadingMagneticNorth;
                MagneticNorthHeading.Text   = String.Format("{0,5:0.0}", headingMagneticNorth);
                if (reading.HeadingTrueNorth != null)
                {
                    double?headingTrueNorth = reading.HeadingTrueNorth.Value;
                    double diff             = Math.Abs(headingTrueNorth.Value - headingMagneticNorth);
                    DiffTrueMag.Text        = String.Format("Diff: {0,5:0.0}", diff);
                }

                if (_lockAzimuth)
                {
                    _runtimeSettings.Azimuth = headingMagneticNorth;
                    _lockAzimuth             = false;
                }

                RotateTransform rt = new RotateTransform {
                    Angle = 360.0 - headingMagneticNorth
                };
                CompassRose.RenderTransform   = rt;
                CompassNeedle.RenderTransform = _runtimeSettings.Azimuth < 0
                                              ? rt
                                              : new RotateTransform {
                    Angle = _runtimeSettings.Azimuth - headingMagneticNorth
                };

                String accuracy = "Accurracy: ";

                switch (reading.HeadingAccuracy)
                {
                case MagnetometerAccuracy.Unreliable:
                    accuracy += "Unreliable";
                    break;

                case MagnetometerAccuracy.Approximate:
                    accuracy += "Approximate";
                    break;

                case MagnetometerAccuracy.High:
                    accuracy += "High";
                    break;

                case MagnetometerAccuracy.Unknown:
                    accuracy += "Unknown";
                    break;

                default:
                    accuracy += "No data";
                    break;
                }

                AccurracyTB.Text = accuracy;
            });
        }
Exemplo n.º 11
0
 private void HeadingChanged(CompassReadingChangedEventArgs args)
 {
     _lastKnownHeading = args.Reading;
     if (ShowUserOnMap)
     {
         SelfMarker.IsArrowVisible  = true;
         SelfMarker.RotationDegrees = args.Reading.HeadingMagneticNorth;
     }
 }
 private async void OnCompassReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
         CompassReading reading = args.Reading;
         if (reading.HeadingTrueNorth.HasValue)
         {
             CanvasCtrl.Invalidate();
         }
     });
 }
 private async void OnCompassReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
         //https://docs.microsoft.com/en-us/windows/uwp/devices-sensors/sensor-orientation
         CompassReading reading = args.Reading;
         if (reading.HeadingTrueNorth.HasValue)
         {
             CanvasCtrl.Invalidate();
         }
     });
 }
Exemplo n.º 14
0
        void OnReadingChanged(Sensor sender, CompassReadingChangedEventArgs args)
        {
            var handler = changed;

            if (handler != null)
            {
                var value = ConvertToHeadingNorth(args.Reading);
                var e     = new CompassEventArgs(value);
                handler.Invoke(this, e);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// This is the event handler for Compass' ReadingChanged events.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        async private void ReadingChanged(object sender, CompassReadingChangedEventArgs e)
        {
            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                CompassReading reading = e.Reading;

                Heading = e.Reading;

                // Calibrate if needed
                if (reading.HeadingAccuracy != MagnetometerAccuracy.High)
                {
                    calibrationBar.RequestCalibration(reading.HeadingAccuracy);
                }

                if (mapState == MapPositionState.FollowAndRotate)
                {
                    GeolocationPin.Heading = 0;
                    MapMain.Heading        = (double)reading.HeadingTrueNorth;
                }
                else
                {
                    // This has to be the negative
                    GeolocationPin.Heading = (int)(MapMain.Heading - reading.HeadingTrueNorth.Value);
                }

                /*ScenarioOutput_MagneticNorth.Text = String.Format("{0,5:0.00}", reading.HeadingMagneticNorth);
                 * if (reading.HeadingTrueNorth != null)
                 * {
                 *  ScenarioOutput_TrueNorth.Text = String.Format("{0,5:0.00}", reading.HeadingTrueNorth);
                 * }
                 * else
                 * {
                 *  ScenarioOutput_TrueNorth.Text = "No data";
                 * }
                 * switch (reading.HeadingAccuracy)
                 * {
                 *  case MagnetometerAccuracy.Unknown:
                 *      ScenarioOutput_HeadingAccuracy.Text = "Unknown";
                 *      break;
                 *  case MagnetometerAccuracy.Unreliable:
                 *      ScenarioOutput_HeadingAccuracy.Text = "Unreliable";
                 *      break;
                 *  case MagnetometerAccuracy.Approximate:
                 *      ScenarioOutput_HeadingAccuracy.Text = "Approximate";
                 *      break;
                 *  case MagnetometerAccuracy.High:
                 *      ScenarioOutput_HeadingAccuracy.Text = "High";
                 *      break;
                 *  default:
                 *      ScenarioOutput_HeadingAccuracy.Text = "No data";
                 *      break;
                 * }*/
            });
        }
Exemplo n.º 16
0
 private async void Compass_ReadingChanged(Compass sender, CompassReadingChangedEventArgs e)
 {
     CompassReading reading = e.Reading;
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         if (reading.HeadingTrueNorth.HasValue)
         {
             trueNorth.Text = string.Format("{0,5:0.00}", (double)reading.HeadingTrueNorth - COMPASS_ADJUSTMENT);
         }
         magNorth.Text = string.Format("{0,5:0.00}", reading.HeadingMagneticNorth - COMPASS_ADJUSTMENT);
     });
 }
 void CompassReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     if (args.Reading.HeadingTrueNorth != null && SensorValueChanged != null)
     {
         SensorValueChanged(this, new SensorValueChangedEventArgs {
             ValueType = MotionSensorValueType.Single, SensorType = MotionSensorType.Compass, Value = new MotionValue()
             {
                 Value = args.Reading.HeadingTrueNorth
             }
         });
     }
 }
Exemplo n.º 18
0
 private void _compass_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     try
     {
         od_kompasa = args.Reading.HeadingTrueNorth.Value - qibla_angle;
         accuracy   = args.Reading.HeadingAccuracy;
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Greška pri očitavanju kompasa uređaja " + "(" + ex.Message + ")");
     }
 }
Exemplo n.º 19
0
 async void c_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         MagneticNorth.Text = args.Reading.HeadingMagneticNorth.ToString();
         if (args.Reading.HeadingTrueNorth != null)
         {
             TrueNorth.Text = args.Reading.HeadingTrueNorth.ToString();
         }
         TimeStamp.Text = args.Reading.Timestamp.ToString();
     });
 }
Exemplo n.º 20
0
        private void CompassReadingChanged(object sender, CompassReadingChangedEventArgs e)
        {
            m_compassReading = e.Reading;
            string val = "(none)";

            if (m_compassReading != null)
            {
                val = Math.Round(Adjust90(m_compassReading.HeadingMagneticNorth), 0).ToString() + "°";
            }

            Dispatcher.BeginInvoke(() => { compassText.Text = "Compass: " + val; });
        }
Exemplo n.º 21
0
        async void _compass_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
        {
            var res = args.Reading;

            double val = res.HeadingTrueNorth ?? res.HeadingMagneticNorth;
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                      () =>
            {
                rotatTransform.Angle = -val;
                Display(val);
            });
        }
Exemplo n.º 22
0
 private async void Compass_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     await CoreWindow.Dispatcher.TryRunAsync(CoreDispatcherPriority.Normal, delegate
     {
         if (CompassEnabled)
         {
             if (args.Reading.HeadingTrueNorth.HasValue)
             {
                 Map.Heading = args.Reading.HeadingTrueNorth.Value;
             }
         }
     });
 }
Exemplo n.º 23
0
        private async void ReadingChanged(object sender, CompassReadingChangedEventArgs e)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                CompassReading reading = e.Reading;

                if (reading.HeadingMagneticNorth != null &
                    reading.HeadingTrueNorth != null &
                    reading.HeadingAccuracy != null)
                {
                    showmsg(1);
                }
            });
        }
 /// <summary>
 /// This is the event handler for ReadingChanged events.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 async private void ReadingChanged(object sender, CompassReadingChangedEventArgs e)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         CompassReading reading            = e.Reading;
         ScenarioOutput_MagneticNorth.Text = String.Format("{0,5:0.00}", reading.HeadingMagneticNorth);
         if (reading.HeadingTrueNorth != null)
         {
             ScenarioOutput_TrueNorth.Text = String.Format("{0,5:0.00}", reading.HeadingTrueNorth);
         }
         else
         {
             ScenarioOutput_TrueNorth.Text = "No data";
         }
     });
 }
Exemplo n.º 25
0
        private Compass _compass; // Our app' s compass object

        // This event handler writes the current compass reading to
        // the textblocks on the app' s main page.

        private async void ReadingChanged(object sender, CompassReadingChangedEventArgs e)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                CompassReading reading = e.Reading;
                textBox_Magnetic.Text  = String.Format("{0,5:0.00}", reading.HeadingMagneticNorth);
                if (reading.HeadingTrueNorth.HasValue)
                {
                    textBox_True.Text = String.Format("{0,5:0.00}", reading.HeadingTrueNorth);
                }
                else
                {
                    textBox_True.Text = "No reading.";
                }
            });
        }
Exemplo n.º 26
0
 private async void ReadingChanged(object sender, CompassReadingChangedEventArgs e)
 {
     await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         try
         {
             CompassReading reading = e.Reading;
             txtMagnetic            = String.Format("{0,5:0.00}", reading.HeadingMagneticNorth);
             if (reading.HeadingTrueNorth.HasValue)
             {
                 txtNorth = String.Format("{0,5:0.00}", reading.HeadingTrueNorth);
             }
         }catch (Exception exc)
         {
         }
     });
 }
Exemplo n.º 27
0
        private async void compassSensor_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                CompassReading reading = args.Reading;

                if (reading.HeadingMagneticNorth != null)
                {
                    compassMagNorth.Text = String.Format("{0,5:0.00}", reading.HeadingMagneticNorth);
                }

                if (reading.HeadingTrueNorth != null)
                {
                    compassTrueNorth.Text = String.Format("{0,5:0.00}", reading.HeadingTrueNorth);
                }
            });
        }
Exemplo n.º 28
0
        /// <summary>
        /// This is the event handler for ReadingChanged events.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        async private void ReadingChanged(object sender, CompassReadingChangedEventArgs e)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                CompassReading reading            = e.Reading;
                ScenarioOutput_MagneticNorth.Text = String.Format("{0,5:0.00}", reading.HeadingMagneticNorth);
                if (reading.HeadingTrueNorth != null)
                {
                    ScenarioOutput_TrueNorth.Text = String.Format("{0,5:0.00}", reading.HeadingTrueNorth);
                }
                else
                {
                    ScenarioOutput_TrueNorth.Text = "No data";
                }
                switch (reading.HeadingAccuracy)
                {
                case MagnetometerAccuracy.Unknown:
                    ScenarioOutput_HeadingAccuracy.Text = "Unknown";
                    break;

                case MagnetometerAccuracy.Unreliable:
                    ScenarioOutput_HeadingAccuracy.Text = "Unreliable";
                    break;

                case MagnetometerAccuracy.Approximate:
                    ScenarioOutput_HeadingAccuracy.Text = "Approximate";
                    break;

                case MagnetometerAccuracy.High:
                    ScenarioOutput_HeadingAccuracy.Text = "High";
                    break;

                default:
                    ScenarioOutput_HeadingAccuracy.Text = "No data";
                    break;
                }
            });
        }
        // the values in the sensorArgs are currently not used by the FormulaEditorViewModel,
        // because the FormulaEvaluator uses the Get-Functions to get the current readings
        void _compass_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
        {
            try
            {
                CompassReading reading = args.Reading;

                if (reading != null)
                {
                    SensorEventArgs sensorArgs = new SensorEventArgs(reading.HeadingMagneticNorth);

                    if (SensorReadingChanged != null)
                    {
                        SensorReadingChanged(sender, sensorArgs);
                    }
                }
            }
            catch (Exception)
            {
                _compassEnabled = false;
            }

            _compassChecked = true;
        }
Exemplo n.º 30
0
        static void CompassReportedInterval(object sender, CompassReadingChangedEventArgs e)
        {
            var data = new CompassData(e.Reading.HeadingMagneticNorth);

            OnChanged(data);
        }