More Bangle.js 2 tweaks
parent
54d98db6c8
commit
87017ce817
|
|
@ -500,9 +500,9 @@
|
||||||
{ "id": "speedo",
|
{ "id": "speedo",
|
||||||
"name": "Speedo",
|
"name": "Speedo",
|
||||||
"icon": "speedo.png",
|
"icon": "speedo.png",
|
||||||
"version":"0.04",
|
"version":"0.05",
|
||||||
"description": "Show the current speed according to the GPS",
|
"description": "Show the current speed according to the GPS",
|
||||||
"tags": "tool,outdoors,gps",
|
"tags": "tool,outdoors,gps,b2",
|
||||||
"storage": [
|
"storage": [
|
||||||
{"name":"speedo.app.js","url":"speedo.js"},
|
{"name":"speedo.app.js","url":"speedo.js"},
|
||||||
{"name":"speedo.img","url":"speedo-icon.js","evaluate":true}
|
{"name":"speedo.img","url":"speedo-icon.js","evaluate":true}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ function redraw() {
|
||||||
m.draw();
|
m.draw();
|
||||||
drawMarker();
|
drawMarker();
|
||||||
if (WIDGETS["gpsrec"] && WIDGETS["gpsrec"].plotTrack) {
|
if (WIDGETS["gpsrec"] && WIDGETS["gpsrec"].plotTrack) {
|
||||||
|
g.flip(); // force immediate draw on double-buffered screens - track will update later
|
||||||
g.setColor(0.75,0.2,0);
|
g.setColor(0.75,0.2,0);
|
||||||
WIDGETS["gpsrec"].plotTrack(m);
|
WIDGETS["gpsrec"].plotTrack(m);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,3 +3,4 @@
|
||||||
0.03: Use offscreen buffer (not doublebuffer)
|
0.03: Use offscreen buffer (not doublebuffer)
|
||||||
Use 'locale' to get internationalised speed
|
Use 'locale' to get internationalised speed
|
||||||
0.04: Start GPS after loading app, just in case widgets affect it (#449)
|
0.04: Start GPS after loading app, just in case widgets affect it (#449)
|
||||||
|
0.05: Use Layout lib for Bangle.js 2 compatibility
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,62 @@
|
||||||
var buf = Graphics.createArrayBuffer(240,120,1,{msb:true});
|
var Layout = require("Layout");
|
||||||
var lastFix = {fix:0,satellites:0};
|
var layout;
|
||||||
|
|
||||||
|
var lastFix = {fix:-1,satellites:0};
|
||||||
|
|
||||||
|
function speedoImage() {
|
||||||
|
return require("heatshrink").decompress(atob("kkdxH+ABteAAwWOECImZDQ2CAQglUD4us2fX68ymQDB1omFESWtDgIACEYYACrolPBwddmWIEZWsmVWJYgiLwXX2YcB1gdDq+BAodWGIWsEhQiDRAWBmQdEAAhGBroFC1ojMC4etERIlDAggkHNIgAWSYYjFVwNWGwgAP5KkBEYoFC1ihBagwAL5W72vKJAxpExCiDABnQ4W12vD6AHBEYxnT4YhB3ghCSIhqDe4SIP3giBM4LfFEYpiMDoQhC3fDCA7+DfBwiCAARmFAAmtEYlYagMywISHEQhEId4UyEYleqwABEZBHERQwABroZBq5rR6BGLNZKzMAAPKRZKzJr2tfaAAKxD7CfgRsD1g1GAAwME2YGDwQjFNgOzwMyCwuCwIAEBg0yHoKODEYmCcYNWCwutAAuzBgg4BCwJGEEgj7JV5r7BIwgjEWrDVCEQYkCWgYAWNYIjF/z8awQfD"));
|
||||||
|
}
|
||||||
|
|
||||||
function onGPS(fix) {
|
function onGPS(fix) {
|
||||||
|
if (lastFix.fix != fix.fix) {
|
||||||
|
// if fix is different, change the layout
|
||||||
|
if (fix.fix) {
|
||||||
|
layout = new Layout( {
|
||||||
|
type:"v", c: [
|
||||||
|
{type:"txt", font:"6x8:2", label:"Speed" },
|
||||||
|
{type:"h", c: [
|
||||||
|
{type:"img", src:speedoImage, pad:4 },
|
||||||
|
{type:"txt", font:"35%", label:"--", fillx:true, id:"speed" },
|
||||||
|
]},
|
||||||
|
{type:"txt", font:"6x8", label:"--", id:"units" },
|
||||||
|
{type:"h", c: [
|
||||||
|
{type:"txt", font:"10%", label:fix.satellites, pad:2, id:"sat" },
|
||||||
|
{type:"txt", font:"6x8", pad:3, label:"Satellites" }
|
||||||
|
]},
|
||||||
|
]},[],{lazy:true});
|
||||||
|
} else {
|
||||||
|
layout = new Layout( {
|
||||||
|
type:"v", c: [
|
||||||
|
{type:"txt", font:"6x8:2", label:"Speed" },
|
||||||
|
{type:"img", src:speedoImage, pad:4 },
|
||||||
|
{type:"txt", font:"6x8", label:"Waiting for GPS" },
|
||||||
|
{type:"h", c: [
|
||||||
|
{type:"txt", font:"10%", label:fix.satellites, pad:2, id:"sat" },
|
||||||
|
{type:"txt", font:"6x8", pad:3, label:"Satellites" }
|
||||||
|
]},
|
||||||
|
]},[],{lazy:true});
|
||||||
|
}
|
||||||
|
g.clearRect(0,24,g.getWidth(),g.getHeight());
|
||||||
|
layout.render();
|
||||||
|
}
|
||||||
lastFix = fix;
|
lastFix = fix;
|
||||||
buf.clear();
|
|
||||||
buf.setFontAlign(0,0);
|
|
||||||
buf.setFont("6x8");
|
|
||||||
buf.drawString(fix.satellites+" satellites",120,6);
|
|
||||||
if (fix.fix) {
|
if (fix.fix) {
|
||||||
|
print(fix.fix);
|
||||||
var speed = require("locale").speed(fix.speed);
|
var speed = require("locale").speed(fix.speed);
|
||||||
var m = speed.match(/([0-9,\.]+)(.*)/); // regex splits numbers from units
|
var m = speed.match(/([0-9,\.]+)(.*)/); // regex splits numbers from units
|
||||||
var txt = (fix.speed<20) ? fix.speed.toFixed(1) : Math.round(fix.speed);
|
var txt = (fix.speed<20) ? fix.speed.toFixed(1) : Math.round(fix.speed);
|
||||||
var value = m[1], units = m[2];
|
layout.speed.label = m[1];
|
||||||
var s = 80;
|
layout.units.label = m[2];
|
||||||
buf.setFontVector(s);
|
|
||||||
buf.drawString(value,120,10+s/2);
|
|
||||||
buf.setFont("6x8",2);
|
|
||||||
buf.drawString(units,120,s+26);
|
|
||||||
} else {
|
|
||||||
buf.setFont("6x8",2);
|
|
||||||
buf.drawString("Waiting for GPS",120,56);
|
|
||||||
}
|
}
|
||||||
g.reset();
|
layout.sat.label = fix.satellites;
|
||||||
g.drawImage({width:buf.getWidth(),height:buf.getHeight(),bpp:1,buffer:buf.buffer},0,70);
|
layout.render();
|
||||||
g.flip();
|
|
||||||
}
|
}
|
||||||
g.clear();
|
g.clear();
|
||||||
onGPS(lastFix);
|
onGPS({fix:0,satellites:0});
|
||||||
|
onGPS({fix:1,satellites:3,speed:200}); // testing
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
||||||
|
|
||||||
Bangle.on('GPS', onGPS);
|
Bangle.on('GPS', onGPS);
|
||||||
Bangle.setGPSPower(1);
|
Bangle.setGPSPower(1, "app");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue