private void PreviewControl_Tapped(object sender, TappedRoutedEventArgs e) { Pointer po = new Pointer(); if (pos != null) { i++; po.lat = pos.Coordinate.Latitude; po.lon = pos.Coordinate.Longitude; po.Yaw = c.GetCurrentReading().HeadingMagneticNorth; OrientationSensorReading reading2 = or.GetCurrentReading(); SensorQuaternion q = reading2.Quaternion; // get a reference to the object to avoid re-creating it for each access double y = reading2.Quaternion.Y; if (y < 0) { y = y + 2; } po.Pitch = y; li.Add(po); Tags.Text = i.ToString() + " Point(s) Tagged"; } }
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; } }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape; await StartCamera(); _compass = Compass.GetDefault(); if (_compass != null) { _compass.ReadingChanged += CompassReadingChanged; CompassChanged(_compass.GetCurrentReading()); } _gps = new Geolocator(); _gps.MovementThreshold = _movementThreshold; _gps.PositionChanged += GpsPositionChanged; if (_gps.LocationStatus == PositionStatus.Ready) { var pos = await _gps.GetGeopositionAsync(); if (pos != null && pos.Coordinate != null && pos.Coordinate.Point != null) { GpsChanged(pos.Coordinate.Point.Position); } } }
public void PrintSensors(bool fast = false) { //BarometerReading read = baro.GetCurrentReading(); var accR = acc.GetCurrentReading(); //Debug.WriteLine(Math.Sqrt(Math.Pow(accR.AccelerationX; 2) + Math.Pow(accR.AccelerationY; 2) + Math.Pow(accR.AccelerationZ; 2)) + " (" + accR.AccelerationX + "/" + accR.AccelerationX + "/" + accR.AccelerationX + ")"); //var actR = act.GetCurrentReadingAsync().GetResults(); //Debug.WriteLine(actR.Activity + " (" + actR.Confidence + ")"); //Debug.WriteLine(alt.GetCurrentReading().AltitudeChangeInMeters); //Debug.WriteLine(baro.GetCurrentReading().StationPressureInHectopascals); var compR = comp.GetCurrentReading(); //Debug.WriteLine(compR.HeadingMagneticNorth + " (+/-" + compR.HeadingAccuracy + ")"); var gyroR = gyro.GetCurrentReading(); //Debug.WriteLine("(" + gyroR.AngularVelocityX + "/" + gyroR.AngularVelocityY + "/" + gyroR.AngularVelocityZ + ")"); var incR = inc.GetCurrentReading(); //Debug.WriteLine("(" + incR.PitchDegrees + "/" + incR.RollDegrees + "/" + incR.YawDegrees + ")"); //var psR=ps.GetCurrentReading(); //Debug.WriteLine(psR.IsDetected + ": " + psR.DistanceInMillimeters); //Debug.WriteLine(sos.GetCurrentOrientation()); String csv = (Math.Sqrt(Math.Pow(accR.AccelerationX, 2) + Math.Pow(accR.AccelerationY, 2) + Math.Pow(accR.AccelerationZ, 2)) + ";" + accR.AccelerationX + ";" + accR.AccelerationY + ";" + accR.AccelerationZ + ";" + alt.GetCurrentReading().AltitudeChangeInMeters + ";" + baro.GetCurrentReading().StationPressureInHectopascals + ";" + compR.HeadingMagneticNorth + ";" + compR.HeadingTrueNorth + ";" + compR.HeadingAccuracy + ";" + gyroR.AngularVelocityX + ";" + gyroR.AngularVelocityY + ";" + gyroR.AngularVelocityZ + ";" + incR.PitchDegrees + ";" + incR.RollDegrees + ";" + incR.YawDegrees + ";" + sos.GetCurrentOrientation() + ";" + accR.Timestamp.ToUnixTimeMilliseconds() + ";" + fast); Debug.WriteLine(csv); StorageInterface.AppendToKnownStorageFile(Token, csv + "\r\n").GetAwaiter(); OUT.Text += csv + "\r\n"; }
public BindableCompass() { _compass = Compass.GetDefault(); if (_compass != null) { _compass.ReadingChanged += compass_CurrentValueChanged; AssignCurrentValue(_compass.GetCurrentReading()); } }
/// <summary> /// Starts the timer to update map objects and the handler to update position /// </summary> public static async Task InitializeDataUpdate() { if (SettingsService.Instance.IsCompassEnabled) { _compass = Compass.GetDefault(); if (_compass != null) { _compassTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(Math.Max(_compass.MinimumReportInterval, 50)) }; _compassTimer.Tick += (s, e) => { if (SettingsService.Instance.IsAutoRotateMapEnabled) { HeadingUpdated?.Invoke(null, _compass.GetCurrentReading()); } }; _compassTimer.Start(); } } _geolocator = new Geolocator { DesiredAccuracy = PositionAccuracy.High, DesiredAccuracyInMeters = 5, ReportInterval = 1000, MovementThreshold = 5 }; Busy.SetBusy(true, Resources.CodeResources.GetString("GettingGpsSignalText")); Geoposition = Geoposition ?? await _geolocator.GetGeopositionAsync(); GeopositionUpdated?.Invoke(null, Geoposition); _geolocator.PositionChanged += GeolocatorOnPositionChanged; // Before starting we need game settings GameSetting = await DataCache.GetAsync(nameof(GameSetting), async() => (await _client.Download.GetSettings()).Settings, DateTime.Now.AddMonths(1)); // Update geolocator settings based on server _geolocator.MovementThreshold = GameSetting.MapSettings.GetMapObjectsMinDistanceMeters; if (_heartbeat == null) { _heartbeat = new Heartbeat(); } await _heartbeat.StartDispatcher(); // Update before starting timer Busy.SetBusy(true, Resources.CodeResources.GetString("GettingUserDataText")); //await UpdateMapObjects(); await UpdateInventory(); await UpdateItemTemplates(); Busy.SetBusy(false); }
private void _compassTimer_Tick(object sender, object e) { var reading = _compass.GetCurrentReading(); if (reading == null) { IsCompassDataAvailable = false; return; } IsCompassDataAvailable = true; HeadingNorth = reading.HeadingTrueNorth ?? reading.HeadingMagneticNorth; }
void ReadCompassData() { if (compassSensor != null) { CompassReading reading = compassSensor.GetCurrentReading(); if (reading != null) { heading.Text = string.Format( "Magnetic Heading={0:F0}° True Heading={1:F0}°", reading.HeadingMagneticNorth, reading.HeadingTrueNorth); } } }
async void OnMainPageLoaded(object sender, RoutedEventArgs args) { if (compass != null) { ShowCompassValues(compass.GetCurrentReading()); compass.ReportInterval = compass.MinimumReportInterval; compass.ReadingChanged += OnCompassReadingChanged; } else { await new MessageDialog("Compass is not available").ShowAsync(); } }
public void OnGetCompass() { Compass sensor = Compass.GetDefault(); if (sensor != null) { CompassReading reading = sensor.GetCurrentReading(); CompassInfo = $"magnetic north: {reading.HeadingMagneticNorth} real north: {reading.HeadingTrueNorth} accuracy: {reading.HeadingAccuracy}"; } else { CompassInfo = "Compass not found"; } }
private async void OnGetCompass(object sender, RoutedEventArgs e) { Compass compass = Compass.GetDefault(); if (compass != null) { CompassReading reading = compass.GetCurrentReading(); this.DefaultViewModel["CompassResult"] = GetCompassResult(reading); } else { var dlg = new MessageDialog("No compass found"); await dlg.ShowAsync(); } }
/// <summary> /// This is the dispatcher callback. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> //<SnippetGetCurrentReadingCS> private void DisplayCurrentReading(object sender, object args) { CompassReading reading = _compass.GetCurrentReading(); if (reading != null) { 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"; } } }
public double GetCompass() { if (_compass != null) { CompassReading reading = _compass.GetCurrentReading(); if (reading != null) { //string magneticNorth = String.Format("{0,5:0.00}", reading.HeadingMagneticNorth); //if (reading.HeadingTrueNorth != null) //{ // string trueNorth = String.Format("{0,5:0.00}", reading.HeadingTrueNorth); //} return(reading.HeadingMagneticNorth); } } return(0.0); }
/// <summary> /// This is the dispatcher callback. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void DisplayCurrentReading(object sender, object args) { CompassReading reading = _compass.GetCurrentReading(); if (reading != null) { 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; } } }
private void ConfigureCompass() { // Get the reference to the sensor and see if it is available _compass = Compass.GetDefault(); if (_compass == null) { return; } _sensorSettings.IsCompassAvailable = true; // Set the minimum report interval. Care must be taken to ensure // it is not set to a value smaller than the device minimum var minInterval = _compass.MinimumReportInterval; _compass.ReportInterval = Math.Max(_sensorSettings.SensorReportInterval, minInterval); _compass.ReadingChanged += CompassOnReadingChanged; // Read the initial sensor value _sensorSettings.LatestCompassReading = _compass.GetCurrentReading(); }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. /// This parameter is typically used to configure the page.</param> protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); try { await StartCamera(); _orientationSensor = SimpleOrientationSensor.GetDefault(); if (_orientationSensor != null) { _orientationSensor.OrientationChanged += SimpleOrientationSensorReadingChanged; UpdateOrientation(_orientationSensor.GetCurrentOrientation()); } _compass = Compass.GetDefault(); if (_compass != null) { _compass.ReadingChanged += CompassReadingChanged; CompassChanged(_compass.GetCurrentReading()); } _gps = new Geolocator(); _gps.MovementThreshold = _movementThreshold; _gps.PositionChanged += GpsPositionChanged; if (_gps.LocationStatus == PositionStatus.Ready) { var pos = await _gps.GetGeopositionAsync(); if (pos != null && pos.Coordinate != null && pos.Coordinate.Point != null) { GpsChanged(pos.Coordinate.Point.Position); } } } catch { } }
/// <summary> /// Update Compass readings event and update UI strings and image /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">The <see cref="object"/> instance containing the event data.</param> private void UpdateCompass(object sender, EventArgs e) { try { Compass _compass = Compass.GetDefault(); if (_compass != null) { CompassReading reading = _compass.GetCurrentReading(); if (reading != null) { MagneticLbl.Text = String.Format(CultureInfo.CurrentCulture, "{0}: {1,5:0.00} (°)\r\n{2}: {3,5:0.00} (°)\r\n{4}: {5}", LocRM.GetString("TrueHeading"), reading.HeadingTrueNorth, LocRM.GetString("MagneticHeading"), reading.HeadingMagneticNorth, LocRM.GetString("Accuracy"), reading.HeadingAccuracy); Rotate(-(float)reading.HeadingMagneticNorth); } } else { // The device on which the application is running does not support the compass sensor MagneticLbl.Text = LocRM.GetString("NotFound"); _timer.Stop(); } } catch (Exception ex) { _timer.Stop(); DllLog.Log.LogError(ex.ToString()); } }
public CompassReading GetCompassReading() { if (_compass == null) { throw new InvalidOperationException("The compass is either not present or has not been initialized"); } var reading = _compass.GetCurrentReading(); return(reading); // Available reading values include: // reading.HeadingMagneticNorth // reading.HeadingTrueNorth // reading.HeadingAccuracy // reading.Timestamp // NOTE: // reading.HeadingAccuracy is a MagnetometerAccracyEnum value // Unknown - app should decide // Unreliable - High inaccuracy...apps should ask for a calibration // Approximate - Good for some, not for others...app should decide // High - All set. // However, you should not prompt the user to calibrate too frequently. We recommend no more than once every 10 minutes. }
private void CompassReadingChanged(Compass sender, CompassReadingChangedEventArgs args) { var reading = sender.GetCurrentReading(); CompassChanged(reading); }