Slower compass updates
This commit is contained in:
@@ -27,6 +27,15 @@ namespace NavCityBreda.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
public static double Now { get { return (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds; } }
|
||||
|
||||
public static string MillisecondsToTime(double millis)
|
||||
{
|
||||
DateTime time = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
string timestr = time.AddMilliseconds(millis) + "";
|
||||
return timestr;
|
||||
}
|
||||
|
||||
public static async Task<MapLocation> FindLocation(string location, Geopoint reference)
|
||||
{
|
||||
MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync(location, reference);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using NavCityBreda.Helpers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -12,6 +13,9 @@ namespace NavCityBreda.Model
|
||||
public delegate void OnHeadingUpdatedHandler(object sender, HeadingUpdatedEventArgs e);
|
||||
public event OnHeadingUpdatedHandler OnHeadingUpdated;
|
||||
|
||||
public delegate void OnHeadingUpdateSlowHandler(object sender, HeadingUpdatedEventArgs e);
|
||||
public event OnHeadingUpdateSlowHandler OnSlowHeadingUpdated;
|
||||
|
||||
private Compass comp;
|
||||
|
||||
private string status;
|
||||
@@ -20,6 +24,9 @@ namespace NavCityBreda.Model
|
||||
private CompassReading hdn;
|
||||
public CompassReading Heading { get { return hdn; } }
|
||||
|
||||
private CompassReading lastreading;
|
||||
private double lastreadingtime;
|
||||
|
||||
public CompassTracker()
|
||||
{
|
||||
status = "Waiting...";
|
||||
@@ -39,6 +46,7 @@ namespace NavCityBreda.Model
|
||||
private void Comp_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
|
||||
{
|
||||
UpdateHeading(args.Reading);
|
||||
UpdateSlowHeading(args.Reading);
|
||||
}
|
||||
|
||||
private void UpdateHeading(CompassReading r)
|
||||
@@ -50,6 +58,22 @@ namespace NavCityBreda.Model
|
||||
|
||||
OnHeadingUpdated(this, new HeadingUpdatedEventArgs(r));
|
||||
}
|
||||
|
||||
private void UpdateSlowHeading(CompassReading r)
|
||||
{
|
||||
if (lastreading == null) { lastreading = r; lastreadingtime = Util.Now; }
|
||||
|
||||
if (Math.Abs(r.HeadingMagneticNorth - lastreading.HeadingMagneticNorth) > 10 && Util.Now - lastreadingtime > 25)
|
||||
{
|
||||
lastreading = r;
|
||||
lastreadingtime = Util.Now;
|
||||
|
||||
//Make sure someone is listening
|
||||
if (OnSlowHeadingUpdated == null) return;
|
||||
|
||||
OnSlowHeadingUpdated(this, new HeadingUpdatedEventArgs(r));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class HeadingUpdatedEventArgs : EventArgs
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace NavCityBreda.Views
|
||||
public sealed partial class MapView : Page
|
||||
{
|
||||
MapIcon CurrentPosition;
|
||||
MapPolyline CurrentNavigationLine;
|
||||
|
||||
public MapView()
|
||||
{
|
||||
@@ -48,19 +49,22 @@ namespace NavCityBreda.Views
|
||||
CurrentPosition.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/CurrentLocationRound.png"));
|
||||
Map.MapElements.Add(CurrentPosition);
|
||||
|
||||
CurrentNavigationLine = new MapPolyline() { StrokeColor = Color.FromArgb(255, 255, 100, 100), StrokeThickness = 6, ZIndex = 20 };
|
||||
//Map.MapElements.Add(CurrentNavigationLine);
|
||||
|
||||
App.Geo.OnPositionUpdate += Geo_OnPositionUpdate;
|
||||
App.RouteManager.OnStatusUpdate += RouteManager_OnStatusUpdate;
|
||||
App.RouteManager.OnRouteChanged += RouteManager_OnRouteChanged;
|
||||
App.RouteManager.OnLandmarkVisited += RouteManager_OnLandmarkVisited;
|
||||
App.CompassTracker.OnHeadingUpdated += CompassTracker_OnHeadingUpdated;
|
||||
App.CompassTracker.OnSlowHeadingUpdated += CompassTracker_OnHeadingUpdated;
|
||||
}
|
||||
|
||||
private void CompassTracker_OnHeadingUpdated(object sender, HeadingUpdatedEventArgs e)
|
||||
{
|
||||
Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
|
||||
{
|
||||
if (Settings.Tracking && e.Heading.HeadingTrueNorth.HasValue) return;
|
||||
// Map.TryRotateToAsync((double)e.Heading.HeadingTrueNorth);
|
||||
if (Settings.Tracking && e.Heading.HeadingTrueNorth.HasValue)
|
||||
Map.TryRotateToAsync((double)e.Heading.HeadingTrueNorth);
|
||||
});
|
||||
|
||||
}
|
||||
@@ -78,8 +82,9 @@ namespace NavCityBreda.Views
|
||||
{
|
||||
Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
MapPolyline linebit = Util.GetRouteLine(e.Route, Color.FromArgb(255, 255, 100, 100));
|
||||
Map.MapElements.Add(linebit);
|
||||
Map.MapElements.Remove(CurrentNavigationLine);
|
||||
CurrentNavigationLine.Path = e.Route.Path;
|
||||
Map.MapElements.Add(CurrentNavigationLine);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -128,7 +133,7 @@ namespace NavCityBreda.Views
|
||||
Map.MapElements.Add(l.Icon);
|
||||
}
|
||||
|
||||
Map.MapElements.Add(Util.GetRouteLine(App.RouteManager.CurrentRoute.RouteObject, Color.FromArgb(200, 100, 100, 255)));
|
||||
Map.MapElements.Add(Util.GetRouteLine(App.RouteManager.CurrentRoute.RouteObject, Color.FromArgb(200, 100, 100, 255), 3));
|
||||
|
||||
ZoomRoute();
|
||||
}
|
||||
@@ -153,7 +158,7 @@ namespace NavCityBreda.Views
|
||||
private async void Zoom()
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(1));
|
||||
await Map.TrySetViewAsync(CurrentPosition.Location, 15, 0, 0, MapAnimationKind.Linear);
|
||||
await Map.TrySetViewAsync(CurrentPosition.Location, 15);
|
||||
}
|
||||
|
||||
private async void ZoomRoute()
|
||||
|
||||
Reference in New Issue
Block a user