1
0
Fork 0

Update speedo to use localised speed

master
Gordon Williams 2020-05-07 08:21:12 +01:00
parent 139b7cb6d6
commit e8d5394ee5
3 changed files with 26 additions and 15 deletions

View File

@ -303,7 +303,7 @@
{ "id": "speedo",
"name": "Speedo",
"icon": "speedo.png",
"version":"0.02",
"version":"0.03",
"description": "Show the current speed according to the GPS",
"tags": "tool,outdoors,gps",
"storage": [
@ -1470,7 +1470,7 @@
"shortName":"Round Clock",
"icon": "app.png",
"version":"0.02",
"description": "Designed round clock with ticks for minutes and seconds",
"description": "Designed round clock with ticks for minutes and seconds and heart rate indication",
"tags": "clock",
"type": "clock",
"storage": [

4
apps/speedo/ChangeLog Normal file
View File

@ -0,0 +1,4 @@
0.01: New App!
0.02: Add widgets to app
0.03: Use offscreen buffer (not doublebuffer)
Use 'locale' to get internationalised speed

View File

@ -1,26 +1,33 @@
Bangle.loadWidgets();
Bangle.setGPSPower(1);
Bangle.setLCDMode("doublebuffered");
var buf = Graphics.createArrayBuffer(240,120,1,{msb:true});
var lastFix = {fix:0,satellites:0};
function onGPS(fix) {
lastFix = fix;
g.clear();
Bangle.drawWidgets();
g.setFontAlign(0,0);
g.setFont("6x8");
g.drawString(fix.satellites+" satellites",120,36);
buf.clear();
buf.setFontAlign(0,0);
buf.setFont("6x8");
buf.drawString(fix.satellites+" satellites",120,6);
if (fix.fix) {
var speed = require("locale").speed(fix.speed);
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 value = m[1], units = m[2];
var s = 80;
g.setFontVector(s);
g.drawString(txt,120,80);
g.setFont("6x8",2);
g.drawString("km/h",120,80+16+s/2);
buf.setFontVector(s);
buf.drawString(value,120,10+s/2);
buf.setFont("6x8",2);
buf.drawString(units,120,s+26);
} else {
g.setFont("6x8",2);
g.drawString("Waiting for GPS",120,80);
buf.setFont("6x8",2);
buf.drawString("Waiting for GPS",120,56);
}
g.reset();
g.drawImage({width:buf.getWidth(),height:buf.getHeight(),bpp:1,buffer:buf.buffer},0,70);
g.flip();
}
g.clear();
onGPS(lastFix);
Bangle.loadWidgets();
Bangle.drawWidgets();
Bangle.on('GPS', onGPS);