From f3efada35463f0fb60a802b2ec5a231462b81f39 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Mon, 24 Feb 2020 17:04:01 +0000 Subject: [PATCH] 0.03: Fix time output on new firmwares when no GPS time set (fix #104) --- apps.json | 2 +- apps/gpstime/ChangeLog | 1 + apps/gpstime/gpstime.js | 38 +++++++++++++++++++++----------------- 3 files changed, 23 insertions(+), 18 deletions(-) create mode 100644 apps/gpstime/ChangeLog diff --git a/apps.json b/apps.json index ae96a5740..36a1d0757 100644 --- a/apps.json +++ b/apps.json @@ -212,7 +212,7 @@ { "id": "gpstime", "name": "GPS Time", "icon": "gpstime.png", - "version":"0.02", + "version":"0.03", "description": "Update the Bangle.js's clock based on the time from the GPS receiver", "tags": "tool,gps", "storage": [ diff --git a/apps/gpstime/ChangeLog b/apps/gpstime/ChangeLog new file mode 100644 index 000000000..e91b36f52 --- /dev/null +++ b/apps/gpstime/ChangeLog @@ -0,0 +1 @@ +0.03: Fix time output on new firmwares when no GPS time set (fix #104) diff --git a/apps/gpstime/gpstime.js b/apps/gpstime/gpstime.js index 285fb64ba..97487ac85 100644 --- a/apps/gpstime/gpstime.js +++ b/apps/gpstime/gpstime.js @@ -5,11 +5,11 @@ Bangle.setLCDTimeout(0); g.clear(); - - var fix; +Bangle.setGPSPower(1); Bangle.on('GPS',function(f) { fix = f; + g.reset(1); g.setFont("6x8",2); g.setFontAlign(0,0); g.clearRect(90,30,239,90); @@ -22,9 +22,12 @@ Bangle.on('GPS',function(f) { } g.setFont("6x8"); g.drawString(fix.satellites+" satellites",170,80); - + g.clearRect(0,100,239,239); - var t = fix.time.toString().split(" ");/* + var t = ["","","","---",""]; + if (fix.time!==undefined) + t = fix.time.toString().split(" "); + /* [ "Sun", "Nov", @@ -42,23 +45,24 @@ Bangle.on('GPS',function(f) { g.drawString(t[3],120,160); // year g.setFont("6x8",3); g.drawString(t[4],120,185); // time - // timezone - var tz = (new Date()).getTimezoneOffset()/60; - if (tz==0) tz="UTC"; - else if (tz>0) tz="UTC+"+tz; - else tz="UTC"+tz; - g.setFont("6x8",2); - g.drawString(tz,120,210); // gmt - g.setFontAlign(0,0,3); - g.drawString("Set",230,120); - g.setFontAlign(0,0); + if (fix.time) { + // timezone + var tz = (new Date()).getTimezoneOffset()/60; + if (tz==0) tz="UTC"; + else if (tz>0) tz="UTC+"+tz; + else tz="UTC"+tz; + g.setFont("6x8",2); + g.drawString(tz,120,210); // gmt + g.setFontAlign(0,0,3); + g.drawString("Set",230,120); + g.setFontAlign(0,0); + } }); setInterval(function() { g.drawImage(img,48,48,{scale:1.5,rotate:Math.sin(getTime()*2)/2}); },100); setWatch(function() { - setTime(fix.time.getTime()/1000); + if (fix.time!==undefined) + setTime(fix.time.getTime()/1000); }, BTN2, {repeat:true}); - -Bangle.setGPSPower(1)