示例#1
0
        /// <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);
        }
示例#2
0
 private static void compass_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     HeadingUpdated?.Invoke(sender, args.Reading);
 }
示例#3
0
        public override void ProcessIncoming(NMEASentence sentence)
        {
            if (sentence is NMEAStandartSentence)
            {
                NMEAStandartSentence nSentence = (sentence as NMEAStandartSentence);

                if (detected)
                {
                    ResetTimer();
                }

                if (nSentence.SentenceID == SentenceIdentifiers.HDT)
                {
                    if (!detected)
                    {
                        detected = true;
                    }

                    double hdn = O2D(nSentence.parameters[0]);
                    if (!double.IsNaN(hdn))
                    {
                        Heading = hdn;
                        HeadingUpdated.Rise(this, new EventArgs());
                    }
                }
                else if (nSentence.SentenceID == SentenceIdentifiers.RMC)
                {
                    if (!detected)
                    {
                        detected = true;
                    }

                    DateTime tStamp = nSentence.parameters[0] == null ? DateTime.MinValue : (DateTime)nSentence.parameters[0];

                    var      latitude         = O2D(nSentence.parameters[2]);
                    var      longitude        = O2D(nSentence.parameters[4]);
                    var      groundSpeed      = O2D(nSentence.parameters[6]);
                    var      courseOverGround = O2D(nSentence.parameters[7]);
                    DateTime dateTime         = nSentence.parameters[8] == null ? DateTime.MinValue : (DateTime)nSentence.parameters[8];

                    bool isValid = (nSentence.parameters[1].ToString() != "Invalid") &&
                                   (!double.IsNaN(latitude)) && latitude.IsValidLatDeg() &&
                                   (!double.IsNaN(longitude)) && longitude.IsValidLonDeg() &&
                                   (!double.IsNaN(groundSpeed)) &&
                                   (nSentence.parameters[11].ToString() != "N");

                    if (isValid)
                    {
                        dateTime    = dateTime.AddHours(tStamp.Hour);
                        dateTime    = dateTime.AddMinutes(tStamp.Minute);
                        dateTime    = dateTime.AddSeconds(tStamp.Second);
                        dateTime    = dateTime.AddMilliseconds(tStamp.Millisecond);
                        groundSpeed = 3.6 * NMEAParser.Bend2MpS(groundSpeed);

                        if (nSentence.parameters[3].ToString() == "S")
                        {
                            latitude = -latitude;
                        }
                        if (nSentence.parameters[5].ToString() == "W")
                        {
                            longitude = -longitude;
                        }

                        Latitude         = latitude;
                        Longitude        = longitude;
                        GroundSpeed      = groundSpeed;
                        CourseOverGround = courseOverGround;
                        GNSSTime         = dateTime;

                        LocationUpdated.Rise(this, new EventArgs());
                    }
                }
            }
        }
 public void OnHeadingUpdated()
 {
     HeadingUpdated?.Invoke(this, EventArgs.Empty);
 }
示例#5
0
 private void OnHeadingUpdated(HeadingData data)
 {
     HeadingUpdated?.Invoke(this, new HeadingEventArgs(data));
 }