Added gpsautotime widget

pull/510/head
Erik Andresen 2020-06-22 20:48:08 +02:00
parent e295f91bc4
commit a8f52da803
3 changed files with 45 additions and 0 deletions

View File

@ -1974,5 +1974,17 @@
"data": [
{"name":"one_button_presses.csv","storageFile": true}
]
},
{ "id": "gpsautotime",
"name": "GPS auto time",
"shortName":"GPS auto time",
"icon": "widget.png",
"version":"0.01",
"description": "A widget that automatically updates the Bangle.js time to the GPS time whenever there is a valid GPS fix.",
"tags": "widget,gps",
"type": "widget",
"storage": [
{"name":"gps_auto_time.wid.js","url":"widget.js"}
]
}
]

View File

@ -0,0 +1,33 @@
(() => {
var lastTimeSet = 0;
Bangle.on('GPS',function(fix) {
if (fix.fix) {
var curTime = fix.time.getTime()/1000;
setTime(curTime);
lastTimeSet = curTime;
WIDGETS["gpsAutoTime"].draw(WIDGETS["gpsAutoTime"]);
}
});
// 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
draw: function() {
g.reset(); // reset the graphics context to defaults (color/font/etc)
g.setFont("6x8");
if ((getTime() - lastTimeSet) <= 60) {
// time is uptodate
g.setColor('#00ff00'); // green
}
g.drawString("auto", this.x, this.y);
g.drawString("time", this.x, this.y+10);
}
};
setInterval(function() {
WIDGETS["gpsAutoTime"].draw(WIDGETS["gpsAutoTime"]);
}, 1*60000); // update every minute
})()

BIN
apps/gpsautotime/widget.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB