mirror of https://github.com/espruino/BangleApps
misc tweaks for layout/gps time/bootloader
parent
8875e41f2f
commit
fc3ce86009
|
@ -18,7 +18,7 @@
|
||||||
{
|
{
|
||||||
"id": "boot",
|
"id": "boot",
|
||||||
"name": "Bootloader",
|
"name": "Bootloader",
|
||||||
"version": "0.31",
|
"version": "0.32",
|
||||||
"description": "This is needed by Bangle.js to automatically load the clock, menu, widgets and settings",
|
"description": "This is needed by Bangle.js to automatically load the clock, menu, widgets and settings",
|
||||||
"icon": "bootloader.png",
|
"icon": "bootloader.png",
|
||||||
"type": "bootloader",
|
"type": "bootloader",
|
||||||
|
@ -550,11 +550,11 @@
|
||||||
{
|
{
|
||||||
"id": "gpstime",
|
"id": "gpstime",
|
||||||
"name": "GPS Time",
|
"name": "GPS Time",
|
||||||
"version": "0.04",
|
"version": "0.05",
|
||||||
"description": "Update the Bangle.js's clock based on the time from the GPS receiver",
|
"description": "Update the Bangle.js's clock based on the time from the GPS receiver",
|
||||||
"icon": "gpstime.png",
|
"icon": "gpstime.png",
|
||||||
"tags": "tool,gps",
|
"tags": "tool,gps",
|
||||||
"supports": ["BANGLEJS"],
|
"supports": ["BANGLEJS","BANGLEJS2"],
|
||||||
"storage": [
|
"storage": [
|
||||||
{"name":"gpstime.app.js","url":"gpstime.js"},
|
{"name":"gpstime.app.js","url":"gpstime.js"},
|
||||||
{"name":"gpstime.img","url":"gpstime-icon.js","evaluate":true}
|
{"name":"gpstime.img","url":"gpstime-icon.js","evaluate":true}
|
||||||
|
|
|
@ -31,3 +31,6 @@
|
||||||
Fix issues where 'Uncaught Error: Function not found' could happen with multiple .boot.js
|
Fix issues where 'Uncaught Error: Function not found' could happen with multiple .boot.js
|
||||||
0.30: Remove 'Get GPS time' at boot. Latest firmwares keep time through reboots, so this is not needed now
|
0.30: Remove 'Get GPS time' at boot. Latest firmwares keep time through reboots, so this is not needed now
|
||||||
0.31: Add polyfills for g.wrapString, g.imageMetrics, g.stringMetrics
|
0.31: Add polyfills for g.wrapString, g.imageMetrics, g.stringMetrics
|
||||||
|
0.32: Fix single quote error in g.wrapString polyfill
|
||||||
|
improve g.stringMetrics polyfill
|
||||||
|
|
||||||
|
|
|
@ -143,13 +143,14 @@ if (!g.imageMetrics) { // added in 2v11 - this is a limited functionality polyfi
|
||||||
}
|
}
|
||||||
if (!g.stringMetrics) { // added in 2v11 - this is a limited functionality polyfill
|
if (!g.stringMetrics) { // added in 2v11 - this is a limited functionality polyfill
|
||||||
boot += `Graphics.prototype.stringMetrics=function(txt) {
|
boot += `Graphics.prototype.stringMetrics=function(txt) {
|
||||||
return {width:this.stringWidth(txt), height:this.getFontHeight()};
|
txt = txt.toString().split("\\n");
|
||||||
|
return {width:Math.max.apply(null,txt.map(x=>g.stringWidth(x))), height:this.getFontHeight()*txt.length};
|
||||||
};\n`;
|
};\n`;
|
||||||
}
|
}
|
||||||
if (!g.wrapString) { // added in 2v11 - this is a limited functionality polyfill
|
if (!g.wrapString) { // added in 2v11 - this is a limited functionality polyfill
|
||||||
boot += `Graphics.prototype.wrapString=function(str, maxWidth) {
|
boot += `Graphics.prototype.wrapString=function(str, maxWidth) {
|
||||||
var lines = [];
|
var lines = [];
|
||||||
for (var unwrappedLine of str.split("\n")) {
|
for (var unwrappedLine of str.split("\\n")) {
|
||||||
var words = unwrappedLine.split(" ");
|
var words = unwrappedLine.split(" ");
|
||||||
var line = words.shift();
|
var line = words.shift();
|
||||||
for (var word of words) {
|
for (var word of words) {
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
0.03: Fix time output on new firmwares when no GPS time set (fix #104)
|
0.03: Fix time output on new firmwares when no GPS time set (fix #104)
|
||||||
0.04: Fix shown UTC time zone sign
|
0.04: Fix shown UTC time zone sign
|
||||||
|
0.05: Use new 'layout library for Bangle2, fix #764 by adding a back button
|
||||||
|
|
|
@ -1,68 +1,75 @@
|
||||||
var img = require("heatshrink").decompress(atob("mEwghC/AH8A1QWVhWq0AuVAAIuVAAIwT1WinQwTFwMzmQwTCYMjlUqGCIuBlWi0UzC6JdBIoMjC4UDmAuOkYXBPAWgmczLp2ilUiVAUDC4IwLFwIUBLoJ2BFwQwM1WjCgJ1DFwQwLFwJ1B0SQCkQWDGBQXBCgK9BDgKQBAAgwJOwUzRgIDBC54wCkZdGPBwACRgguDBIIwLFxEJBQIwLFxGaBYQwKFxQwLgAWGmQuBcAQwJC48ifYYwJgUidgsyC4L7DGBIXBdohnBCgL7BcYIXIGAqMCIoL7DL5IwERgIUBLoL7BO5QXBGAK7DkWiOxQXGFwOjFoUyFxZhDgBdCCgJ1CCxYxCgBABkcqOwIuNGAQXC0S9BLpgAFXoIwBmYuPAAYwCLp4wHFyYwDFyYwDFygwCCyoA/AFQA="));
|
function satelliteImage() {
|
||||||
|
return require("heatshrink").decompress(atob("mEwxH+AH4A/AH4A/AH4AGnE4F1wvsF34wgFldcLdyMYsoACF1WJF4YxPFzOtF4wxNFzAvKSiIvU1ovIGAkJAAQucF5QxCFwYwbF4QwLrwvjYIVfrwABrtdq9Wqwvkq4oCAAtXmYvi1teE4NXrphCrxoCGAbvdSIoAHNQNeFzQvGeRQvCsowrYYNfF8YwHZQQFCF8QwGF4owjeYovBroHEMERhEF8IwNrtWryYFF8YwCq4vhGBeJF5AwaxIwKwVXFwwvandfMJeJF8M6nZiLGQIvdstfGAVlGBZkCxJeZJQIwCGIRjMFzYACGIc6r/+FsIvGGIYABEzYvPGQYvusovkAH4A/AH4A/ACo="));
|
||||||
|
}
|
||||||
|
|
||||||
|
var fix;
|
||||||
|
|
||||||
Bangle.setLCDPower(1);
|
Bangle.setLCDPower(1);
|
||||||
Bangle.setLCDTimeout(0);
|
Bangle.setLCDTimeout(0);
|
||||||
|
var Layout = require("Layout");
|
||||||
|
Bangle.setGPSPower(1, "app");
|
||||||
|
Bangle.loadWidgets();
|
||||||
|
Bangle.drawWidgets();
|
||||||
|
E.showMessage("Loading..."); // avoid showing rubbish on screen
|
||||||
|
|
||||||
g.clear();
|
function setGPSTime() {
|
||||||
|
if (fix.time!==undefined) {
|
||||||
var fix;
|
setTime(fix.time.getTime()/1000);
|
||||||
Bangle.setGPSPower(1);
|
E.showMessage("System time set", {img:require("heatshrink").decompress(atob("lEo4UBvvv///vEFBYNVAAWq1QFDBAgKGrQJD0oJDtQJD1IICqwGBFoIDByocDwAJBgQeDtWoJwcqDwWq0EAgfAgEKHoQcCBIQeBGAQaBBIQzBytaEwQJDlWlrQmBBIkK0tqBI+ptRNCBIcCBKhECBIh6CAgUL8AJHl/4BI8+3gJRl/8GJH/BI8Ah6MDLIZQB+BjGAAIoBBI84BIaVCAAaVBVIYJEWYLkEXobRDAAbRBcoYACcoT5DEwYJCtQoElWpBINaDwYcB0oJBGQIzCAYIwBDwQGBAAIcCDwYACDgQACBIYIEBQYFDA="))});
|
||||||
Bangle.on('GPS',function(f) {
|
|
||||||
fix = f;
|
|
||||||
g.reset(1);
|
|
||||||
g.setFont("6x8",2);
|
|
||||||
g.setFontAlign(0,0);
|
|
||||||
g.clearRect(90,30,239,90);
|
|
||||||
if (fix.fix) {
|
|
||||||
g.drawString("GPS",170,40);
|
|
||||||
g.drawString("Acquired",170,60);
|
|
||||||
} else {
|
} else {
|
||||||
g.drawString("Waiting for",170,40);
|
E.showMessage("No GPS time to set");
|
||||||
g.drawString("GPS Fix",170,60);
|
|
||||||
}
|
}
|
||||||
g.setFont("6x8");
|
|
||||||
g.drawString(fix.satellites+" satellites",170,80);
|
|
||||||
|
|
||||||
g.clearRect(0,100,239,239);
|
Bangle.removeListener('GPS',onGPS);
|
||||||
var t = ["","","","---",""];
|
setTimeout(function() {
|
||||||
if (fix.time!==undefined)
|
fix = undefined;
|
||||||
|
layout.forgetLazyState(); // redraw all next time
|
||||||
|
Bangle.on('GPS',onGPS);
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
var layout = new Layout( {
|
||||||
|
type:"v", c: [
|
||||||
|
{type:"h", c:[
|
||||||
|
{type:"img", src:satelliteImage },
|
||||||
|
{ type:"v", fillx:1, c: [
|
||||||
|
{type:"txt", font:"6x8:2", label:"Waiting\nfor GPS", id:"status" },
|
||||||
|
{type:"txt", font:"6x8", label:"---", id:"sat" },
|
||||||
|
]},
|
||||||
|
]},
|
||||||
|
{type:"txt", fillx:1, filly:1, font:"6x8:2", label:"---", id:"gpstime" }
|
||||||
|
]},{lazy:true, btns: [
|
||||||
|
{ label : "Set", cb : setGPSTime},
|
||||||
|
{ label : "Back", cb : ()=>load() }
|
||||||
|
]});
|
||||||
|
|
||||||
|
|
||||||
|
function onGPS(f) {
|
||||||
|
if (fix===undefined) {
|
||||||
|
g.clear();
|
||||||
|
Bangle.drawWidgets();
|
||||||
|
}
|
||||||
|
fix = f;
|
||||||
|
if (fix.fix) {
|
||||||
|
layout.status.label = "GPS\nAcquired";
|
||||||
|
} else {
|
||||||
|
layout.status.label = "Waiting\nfor GPS";
|
||||||
|
}
|
||||||
|
layout.sat.label = fix.satellites+" satellites";
|
||||||
|
|
||||||
|
var t = ["","---",""];
|
||||||
|
if (fix.time!==undefined) {
|
||||||
t = fix.time.toString().split(" ");
|
t = fix.time.toString().split(" ");
|
||||||
/*
|
|
||||||
[
|
|
||||||
"Sun",
|
|
||||||
"Nov",
|
|
||||||
"10",
|
|
||||||
"2019",
|
|
||||||
"15:55:35",
|
|
||||||
"GMT+0100"
|
|
||||||
]
|
|
||||||
*/
|
|
||||||
//g.setFont("6x8",2);
|
|
||||||
//g.drawString(t[0],120,110); // day
|
|
||||||
g.setFont("6x8",3);
|
|
||||||
g.drawString(t[1]+" "+t[2],120,135); // date
|
|
||||||
g.setFont("6x8",2);
|
|
||||||
g.drawString(t[3],120,160); // year
|
|
||||||
g.setFont("6x8",3);
|
|
||||||
g.drawString(t[4],120,185); // time
|
|
||||||
if (fix.time) {
|
|
||||||
// timezone
|
|
||||||
var tz = (new Date()).getTimezoneOffset()/-60;
|
var tz = (new Date()).getTimezoneOffset()/-60;
|
||||||
if (tz==0) tz="UTC";
|
if (tz==0) tz="UTC";
|
||||||
else if (tz>0) tz="UTC+"+tz;
|
else if (tz>0) tz="UTC+"+tz;
|
||||||
else 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() {
|
t = [t[1]+" "+t[2],t[3],t[4],t[5],tz];
|
||||||
g.drawImage(img,48,48,{scale:1.5,rotate:Math.sin(getTime()*2)/2});
|
}
|
||||||
},100);
|
|
||||||
setWatch(function() {
|
layout.gpstime.label = t.join("\n");
|
||||||
if (fix.time!==undefined)
|
layout.render();
|
||||||
setTime(fix.time.getTime()/1000);
|
}
|
||||||
}, BTN2, {repeat:true});
|
|
||||||
|
Bangle.on('GPS',onGPS);
|
||||||
|
|
|
@ -169,14 +169,23 @@ function Layout(layout, options) {
|
||||||
Bangle.on('touch',Bangle.touchHandler);
|
Bangle.on('touch',Bangle.touchHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add IDs
|
// recurse over layout doing some fixing up if needed
|
||||||
var ll = this;
|
var ll = this;
|
||||||
function idRecurser(l) {
|
function recurser(l) {
|
||||||
|
// add IDs
|
||||||
if (l.id) ll[l.id] = l;
|
if (l.id) ll[l.id] = l;
|
||||||
|
// fix type up
|
||||||
if (!l.type) l.type="";
|
if (!l.type) l.type="";
|
||||||
if (l.c) l.c.forEach(idRecurser);
|
// FIXME ':'/fsz not needed in new firmwares - Font:12 is handled internally
|
||||||
|
// fix fonts for pre-2v11 firmware
|
||||||
|
if (l.font && l.font.includes(":")) {
|
||||||
|
var f = l.font.split(":");
|
||||||
|
l.font = f[0];
|
||||||
|
l.fsz = f[1];
|
||||||
|
}
|
||||||
|
if (l.c) l.c.forEach(recurser);
|
||||||
}
|
}
|
||||||
idRecurser(layout);
|
recurser(this._l);
|
||||||
this.updateNeeded = true;
|
this.updateNeeded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,12 +361,6 @@ Layout.prototype.update = function() {
|
||||||
"txt" : function(l) {
|
"txt" : function(l) {
|
||||||
if (l.font.endsWith("%"))
|
if (l.font.endsWith("%"))
|
||||||
l.font = "Vector"+Math.round(g.getHeight()*l.font.slice(0,-1)/100);
|
l.font = "Vector"+Math.round(g.getHeight()*l.font.slice(0,-1)/100);
|
||||||
// FIXME ':'/fsz not needed in new firmwares - it's handled internally
|
|
||||||
if (l.font.includes(":")) {
|
|
||||||
var f = l.font.split(":");
|
|
||||||
l.font = f[0];
|
|
||||||
l.fsz = f[1];
|
|
||||||
}
|
|
||||||
if (l.wrap) {
|
if (l.wrap) {
|
||||||
l._h = l._w = 0;
|
l._h = l._w = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue