From 84e9d12a097eeaf24754fd09c455228da02c0a84 Mon Sep 17 00:00:00 2001 From: frederic wagner Date: Tue, 26 Jul 2022 09:44:42 +0200 Subject: [PATCH] turn gps off --- apps/gipy/ChangeLog | 1 + apps/gipy/TODO | 7 ++----- apps/gipy/app.js | 21 +++++++++++++++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/apps/gipy/ChangeLog b/apps/gipy/ChangeLog index f3a355f3a..e44322007 100644 --- a/apps/gipy/ChangeLog +++ b/apps/gipy/ChangeLog @@ -37,3 +37,4 @@ * Better fonts (more free space, still readable). * Display direction to nearest point when lost. * Display average speed. + * Turn off gps when locked and between points diff --git a/apps/gipy/TODO b/apps/gipy/TODO index be499a869..88b2e3f6c 100644 --- a/apps/gipy/TODO +++ b/apps/gipy/TODO @@ -2,16 +2,13 @@ * bugs - meters seem to be a bit too long -- direction is still shitty on gps ? +- segment detection could be better ? * additional features -- turn off gps when moving to next waypoint -- display distance to next water/toilet - +- display distance to next water/toilet ? - dynamic map rescale - display scale (100m) -- get waypoints from osm - compress path ? diff --git a/apps/gipy/app.js b/apps/gipy/app.js index 59a2009d6..c8ca09791 100644 --- a/apps/gipy/app.js +++ b/apps/gipy/app.js @@ -124,6 +124,16 @@ class Status { this.distance_to_next_point = Math.ceil( this.position.distance(this.path.point(next_point)) ); + // disable gps when far from next point and locked + if (Bangle.isLocked()) { + let time_to_next_point = this.distance_to_next_point / 9.7; // 30km/h is 8.3 m/s + if (time_to_next_point > 30) { + Bangle.setGPSPower(false, "gipy"); + setTimeout(function () { + Bangle.setGPSPower(true, "gipy"); + }, time_to_next_point); + } + } if (this.reaching != next_point && this.distance_to_next_point <= 20) { this.reaching = next_point; let reaching_waypoint = this.path.is_waypoint(next_point); @@ -134,10 +144,8 @@ class Status { } } } - // re-display unless locked - if (!Bangle.isLocked() || simulated) { - this.display(); - } + // re-display + this.display(); } remaining_distance() { return ( @@ -610,6 +618,11 @@ function start(fn) { Bangle.setGPSPower(true, "gipy"); Bangle.on("GPS", set_coordinates); + Bangle.on("lock", function (on) { + if (!on) { + Bangle.setGPSPower(true, "gipy"); // activate gps when unlocking + } + }); } }