mirror of
https://github.com/Threnklyn/pebble-directions.git
synced 2026-05-18 21:03:27 +02:00
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:
+6
-2
@@ -150,6 +150,8 @@ function sendCurrentStep(index, shouldRetry) {
|
|||||||
|
|
||||||
// Start sending current step information
|
// Start sending current step information
|
||||||
function startCurrentStepUpdates(stepPositionList) {
|
function startCurrentStepUpdates(stepPositionList) {
|
||||||
|
// Log the start of step updates
|
||||||
|
console.log('Current step updates started');
|
||||||
// Store the current route data
|
// Store the current route data
|
||||||
routeData.stepPositionList = stepPositionList;
|
routeData.stepPositionList = stepPositionList;
|
||||||
routeData.currentStep = 0;
|
routeData.currentStep = 0;
|
||||||
@@ -174,6 +176,8 @@ function startCurrentStepUpdates(stepPositionList) {
|
|||||||
|
|
||||||
// Stop sending current step information
|
// Stop sending current step information
|
||||||
function stopCurrentStepUpdates() {
|
function stopCurrentStepUpdates() {
|
||||||
|
// Log the stop of step updates
|
||||||
|
console.log('Current step updates stopped');
|
||||||
// Clear the watch and stop receiving updates
|
// Clear the watch and stop receiving updates
|
||||||
navigator.geolocation.clearWatch(routeData.watchId);
|
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);
|
console.log('Will send:', success, data.distance, data.time, data.stepList.length, data.stepIconsString, messageNumber);
|
||||||
// Send the route data to the watch
|
// Send the route data to the watch
|
||||||
sendRoute(success, data.distance, data.time, data.stepList, data.stepIconsString, messageNumber);
|
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 the loading was successfull, start watching the position if the route type is bike or walk
|
||||||
if (success && config.getNavigationSettings().auto) {
|
if (success && (routeType == 1 || routeType == 3)) {
|
||||||
startCurrentStepUpdates(data.stepPositionList);
|
startCurrentStepUpdates(data.stepPositionList);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,35 +1,5 @@
|
|||||||
// The config page (without the already stored name / addess pairs)
|
// The config page (without the already stored name / addess pairs)
|
||||||
module.exports = [
|
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
|
// The named addessses section
|
||||||
{
|
{
|
||||||
type: 'section',
|
type: 'section',
|
||||||
|
|||||||
@@ -75,44 +75,6 @@ function getNamedAddresses() {
|
|||||||
return [];
|
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
|
// Clay things
|
||||||
var Clay = require('pebble-clay');
|
var Clay = require('pebble-clay');
|
||||||
@@ -135,10 +97,8 @@ Pebble.addEventListener('webviewclosed', function(e) {
|
|||||||
// Store the addresses returned by the config page
|
// Store the addresses returned by the config page
|
||||||
var configDict = clay.getSettings(e.response, false);
|
var configDict = clay.getSettings(e.response, false);
|
||||||
storeNamedAddresses(configDict);
|
storeNamedAddresses(configDict);
|
||||||
storeNavigationSettings(configDict);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Exports for use in the app.js
|
// Exports for use in the app.js
|
||||||
module.exports.getNamedAddresses = getNamedAddresses;
|
module.exports.getNamedAddresses = getNamedAddresses;
|
||||||
module.exports.getNavigationSettings = getNavigationSettings;
|
|
||||||
|
|||||||
+3
-2
@@ -223,11 +223,12 @@ function getCurrentStepIndex(steps, lat, lon, accuracy, currentIndex) {
|
|||||||
// Determine the current step
|
// Determine the current step
|
||||||
try {
|
try {
|
||||||
// Determine the max distance
|
// 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
|
// Loop through the steps and find the next one, that is close enought
|
||||||
var foundIndex = currentIndex;
|
var foundIndex = currentIndex;
|
||||||
steps.forEach(function(step, index) {
|
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) {
|
if (getApproxDistance(lat, lon, step.lat, step.lon) <= maxDistance) {
|
||||||
// Move on to this waypoint
|
// Move on to this waypoint
|
||||||
foundIndex = index;
|
foundIndex = index;
|
||||||
|
|||||||
Reference in New Issue
Block a user