Inheritance: ICompassReading
Exemple #1
0
 static HeadingNorth ConvertToHeadingNorth(CompassReading reading)
 {
     return new HeadingNorth
     {
         Magnetic = reading.HeadingMagneticNorth,
         True = reading.HeadingTrueNorth ?? 0.0
     };
 }
 void compass_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     Deployment.Current.Dispatcher.BeginInvoke(() =>
         {
             compassReading = args.Reading;
             ShowData();
         });
 }
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     compass = Compass.GetDefault();
     if (compass == null)
     {
         MessageBox.Show("不支持罗盘传感器");
         return;
     }
     compass.ReportInterval = 1000;
     compass.ReadingChanged += compass_ReadingChanged;
     compassReading = compass.GetCurrentReading();
     ShowData();
 }
        /// <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;

                CurrentHeading = 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;
                }*/
            });
        }
Exemple #5
0
 internal CompassReadingChangedEventArgs(CompassReading reading)
 {
     Reading = reading;
 }
Exemple #6
0
 public void setCompassReading(CompassReading reading)
 {
     //reading.
 }
 private void CompassOnReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     _lastCompassReading = args.Reading;
 }