diff --git a/apps/gpsautotime/ChangeLog b/apps/gpsautotime/ChangeLog index 2827c9e5c..97b80ecdf 100644 --- a/apps/gpsautotime/ChangeLog +++ b/apps/gpsautotime/ChangeLog @@ -1,2 +1,3 @@ 0.01: New App! 0.02: Set Bangle.js 2 compatible +0.03: Add setting to hide the widget diff --git a/apps/gpsautotime/metadata.json b/apps/gpsautotime/metadata.json index 766961276..217a27931 100644 --- a/apps/gpsautotime/metadata.json +++ b/apps/gpsautotime/metadata.json @@ -2,13 +2,15 @@ "id": "gpsautotime", "name": "GPS auto time", "shortName": "GPS auto time", - "version": "0.02", + "version": "0.03", "description": "A widget that automatically updates the Bangle.js time to the GPS time whenever there is a valid GPS fix.", "icon": "widget.png", "type": "widget", "tags": "widget,gps", "supports": ["BANGLEJS","BANGLEJS2"], "storage": [ - {"name":"gpsautotime.wid.js","url":"widget.js"} - ] + {"name":"gpsautotime.wid.js","url":"widget.js"}, + {"name":"gpsautotime.settings.js","url":"settings.js"} + ], + "data": [{"name":"gpsautotime.json"}] } diff --git a/apps/gpsautotime/settings.js b/apps/gpsautotime/settings.js new file mode 100644 index 000000000..dbdd121d1 --- /dev/null +++ b/apps/gpsautotime/settings.js @@ -0,0 +1,25 @@ +(function(back) { + var FILE = "gpsautotime.json"; + // Load settings + var settings = Object.assign({ + show: true, + }, require('Storage').readJSON(FILE, true) || {}); + + function writeSettings() { + require('Storage').writeJSON(FILE, settings); + } + + // Show the menu + E.showMenu({ + "" : { "title" : "GPS auto time" }, + "< Back" : () => back(), + 'Show widget?': { + value: !!settings.show, // !! converts undefined to false + format: v => v?"Show":"Hide", + onchange: v => { + settings.show = v; + writeSettings(); + } + }, + }); +}) diff --git a/apps/gpsautotime/widget.js b/apps/gpsautotime/widget.js index a1d1b2b08..a21c14619 100644 --- a/apps/gpsautotime/widget.js +++ b/apps/gpsautotime/widget.js @@ -1,6 +1,13 @@ (() => { var lastTimeSet = 0; + var settings = Object.assign({ + // default values + show: true, + }, require('Storage').readJSON("gpsautotime.json", true) || {}); + const show = settings.show; + delete settings; + Bangle.on('GPS',function(fix) { if (fix.fix) { var curTime = fix.time.getTime()/1000; @@ -14,8 +21,9 @@ // add your widget WIDGETS["gpsAutoTime"]={ area:"tl", // tl (top left), tr (top right), bl (bottom left), br (bottom right) - width: 28, // width of the widget + width: show ? 4*6+2 : 0, // width of the widget draw: function() { + if (!show) return; g.reset(); // reset the graphics context to defaults (color/font/etc) g.setFont("6x8"); if ((getTime() - lastTimeSet) <= 60) { @@ -27,7 +35,9 @@ } }; - setInterval(function() { - WIDGETS["gpsAutoTime"].draw(WIDGETS["gpsAutoTime"]); - }, 1*60000); // update every minute -})() + if (show) { + setInterval(function() { + WIDGETS["gpsAutoTime"].draw(WIDGETS["gpsAutoTime"]); + }, 1*60000); // update every minute + } +})(); diff --git a/apps/sleepphasealarm/ChangeLog b/apps/sleepphasealarm/ChangeLog index 53c993376..ec3fe3a23 100644 --- a/apps/sleepphasealarm/ChangeLog +++ b/apps/sleepphasealarm/ChangeLog @@ -5,3 +5,4 @@ 0.05: Refactor decodeTime() to scheduling library 0.06: Add logging use Layout library and display ETA +0.07: Add check for day of week diff --git a/apps/sleepphasealarm/README.md b/apps/sleepphasealarm/README.md index 04388194f..c33c9c807 100644 --- a/apps/sleepphasealarm/README.md +++ b/apps/sleepphasealarm/README.md @@ -1,5 +1,7 @@ # Sleep Phase Alarm +The alarm must be in the next 24h. + The display shows: - the current time diff --git a/apps/sleepphasealarm/app.js b/apps/sleepphasealarm/app.js index 9bde85452..8ccd43eb2 100644 --- a/apps/sleepphasealarm/app.js +++ b/apps/sleepphasealarm/app.js @@ -51,8 +51,10 @@ active.forEach(alarm => { if (dateAlarm < now) { // dateAlarm in the past, add 24h dateAlarm.setTime(dateAlarm.getTime() + (24*60*60*1000)); } - if (nextAlarm === undefined || dateAlarm < nextAlarm) { - nextAlarm = dateAlarm; + if ((alarm.dow >> dateAlarm.getDay()) & 1) { // check valid day of week + if (nextAlarm === undefined || dateAlarm < nextAlarm) { + nextAlarm = dateAlarm; + } } }); @@ -80,7 +82,7 @@ function drawApp() { layout.date.label = locale.time(now, BANGLEJS2 && Bangle.isLocked() ? 1 : 0); // hide seconds on bangle 2 const diff = nextAlarm - now; const diffHour = Math.floor((diff % 86400000) / 3600000).toString(); - const diffMinutes = Math.round(((diff % 86400000) % 3600000) / 60000).toString(); + const diffMinutes = Math.floor(((diff % 86400000) % 3600000) / 60000).toString(); layout.eta.label = "ETA: -"+ diffHour + ":" + diffMinutes.padStart(2, '0'); layout.render(); } diff --git a/apps/sleepphasealarm/metadata.json b/apps/sleepphasealarm/metadata.json index f55854f35..d74590704 100644 --- a/apps/sleepphasealarm/metadata.json +++ b/apps/sleepphasealarm/metadata.json @@ -2,7 +2,7 @@ "id": "sleepphasealarm", "name": "SleepPhaseAlarm", "shortName": "SleepPhaseAlarm", - "version": "0.06", + "version": "0.07", "description": "Uses the accelerometer to estimate sleep and wake states with the principle of Estimation of Stationary Sleep-segments (ESS, see https://ubicomp.eti.uni-siegen.de/home/datasets/ichi14/index.html.en). This app will read the next alarm from the alarm application and will wake you up to 30 minutes early at the best guessed time when you are almost already awake.", "icon": "app.png", "tags": "alarm",