wrapping up with automatic navigation

* removed the ability to enable / disable automatic navigation
* automatic navigation (current step updates) are enabled for bike /
walk navigation
* tweaks to the way automatic navigation works
This commit is contained in:
dyedgreen
2016-07-04 17:23:30 +02:00
parent f17977ceaa
commit 8e6c9c1e4e
4 changed files with 9 additions and 74 deletions
+6 -2
View File
@@ -150,6 +150,8 @@ function sendCurrentStep(index, shouldRetry) {
// Start sending current step information
function startCurrentStepUpdates(stepPositionList) {
// Log the start of step updates
console.log('Current step updates started');
// Store the current route data
routeData.stepPositionList = stepPositionList;
routeData.currentStep = 0;
@@ -174,6 +176,8 @@ function startCurrentStepUpdates(stepPositionList) {
// Stop sending current step information
function stopCurrentStepUpdates() {
// Log the stop of step updates
console.log('Current step updates stopped');
// Clear the watch and stop receiving updates
navigator.geolocation.clearWatch(routeData.watchId);
}
@@ -196,8 +200,8 @@ function fetchAndSendRoute(routeType, searchText, messageNumber) {
console.log('Will send:', success, data.distance, data.time, data.stepList.length, data.stepIconsString, messageNumber);
// Send the route data to the watch
sendRoute(success, data.distance, data.time, data.stepList, data.stepIconsString, messageNumber);
// If the loading was successfull, start watching the position (if enabled in the config)
if (success && config.getNavigationSettings().auto) {
// If the loading was successfull, start watching the position if the route type is bike or walk
if (success && (routeType == 1 || routeType == 3)) {
startCurrentStepUpdates(data.stepPositionList);
}
});
-30
View File
@@ -1,35 +1,5 @@
// The config page (without the already stored name / addess pairs)
module.exports = [
// Navigation settings
{
type: 'section',
items: [
// Description
{
type: 'heading',
defaultValue: 'Navigation settings',
},
{
type: 'text',
defaultValue: 'Tailor the way directions work to your needs and preferences.',
},
// Enable / disable real time navigation
{
type: 'toggle',
messageKey: 'navigationAutoEnable',
label: 'Enable automatic navigation',
defaultValue: true,
description: 'Automatic navigation tells you when to take the next turn in real time based on the GPS of your phone. Disable this feature if you want to reduce battery usage on your phone or if your phones GPS is not accurate enought and causes problems.',
},
],
},
// Submit / store settings button
{
type: 'submit',
defaultValue: 'Save preferences',
},
// The named addessses section
{
type: 'section',
-40
View File
@@ -75,44 +75,6 @@ function getNamedAddresses() {
return [];
}
// Store the navigation settings
function storeNavigationSettings(configDict) {
// Settings object with default values
var navigationSettings = {
auto: true,
};
// Automatic turn by turn navigation
if (configDict.hasOwnProperty('navigationAutoEnable')) {
navigationSettings.auto = !!configDict.navigationAutoEnable.value;
}
// Store the settings
try {
localStorage.setItem('navigationSettings', JSON.stringify(navigationSettings));
} catch (e) {}
}
// Get the navigation settings (exposed)
function getNavigationSettings() {
// Settings object with default values
var navigationSettings = {
auto: true,
};
// Load the settings
try {
var navigationSettingsData = JSON.parse(localStorage.getItem('navigationSettings'));
// Automatic turn by turn navigation
if (navigationSettingsData.hasOwnProperty('auto')) {
navigationSettings.auto = !!navigationSettingsData.auto;
}
} catch (e) {}
// Return the settings
return navigationSettings;
}
// Clay things
var Clay = require('pebble-clay');
@@ -135,10 +97,8 @@ Pebble.addEventListener('webviewclosed', function(e) {
// Store the addresses returned by the config page
var configDict = clay.getSettings(e.response, false);
storeNamedAddresses(configDict);
storeNavigationSettings(configDict);
});
// Exports for use in the app.js
module.exports.getNamedAddresses = getNamedAddresses;
module.exports.getNavigationSettings = getNavigationSettings;
+3 -2
View File
@@ -223,11 +223,12 @@ function getCurrentStepIndex(steps, lat, lon, accuracy, currentIndex) {
// Determine the current step
try {
// Determine the max distance
var maxDistance = 25 + accuracy;
var maxDistance = 30 + accuracy;
// Loop through the steps and find the next one, that is close enought
var foundIndex = currentIndex;
steps.forEach(function(step, index) {
if (index > currentIndex && foundIndex <= currentIndex) {
// Test all upcoming waypoints
if (index > currentIndex) {
if (getApproxDistance(lat, lon, step.lat, step.lon) <= maxDistance) {
// Move on to this waypoint
foundIndex = index;