Merge pull request #1782 from nxdefiant/master

Changes to gpsautotime / sleepphasealarm
master
Gordon Williams 2022-05-03 09:33:30 +01:00 committed by GitHub
commit a5cb8e6970
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 55 additions and 12 deletions

View File

@ -1,2 +1,3 @@
0.01: New App!
0.02: Set Bangle.js 2 compatible
0.03: Add setting to hide the widget

View File

@ -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"}]
}

View File

@ -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();
}
},
});
})

View File

@ -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
}
})();

View File

@ -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

View File

@ -1,5 +1,7 @@
# Sleep Phase Alarm
The alarm must be in the next 24h.
The display shows:
- the current time

View File

@ -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();
}

View File

@ -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",