update gpsnav to use locale + add en_NAV
parent
3db0b02f05
commit
85d23d3db9
|
|
@ -65,7 +65,7 @@
|
||||||
{ "id": "locale",
|
{ "id": "locale",
|
||||||
"name": "Languages",
|
"name": "Languages",
|
||||||
"icon": "locale.png",
|
"icon": "locale.png",
|
||||||
"version":"0.07",
|
"version":"0.08",
|
||||||
"description": "Translations for different countries",
|
"description": "Translations for different countries",
|
||||||
"tags": "tool,system,locale,translate",
|
"tags": "tool,system,locale,translate",
|
||||||
"type": "locale",
|
"type": "locale",
|
||||||
|
|
@ -379,13 +379,13 @@
|
||||||
{ "id": "gpsnav",
|
{ "id": "gpsnav",
|
||||||
"name": "GPS Navigation",
|
"name": "GPS Navigation",
|
||||||
"icon": "icon.png",
|
"icon": "icon.png",
|
||||||
"version":"0.04",
|
"version":"0.05",
|
||||||
"description": "Displays GPS Course and Speed, + Directions to waypoint and waypoint recording, now with waypoint editor",
|
"description": "Displays GPS Course and Speed, + Directions to waypoint and waypoint recording, now with waypoint editor",
|
||||||
"tags": "tool,outdoors,gps",
|
"tags": "tool,outdoors,gps",
|
||||||
"readme": "README.md",
|
"readme": "README.md",
|
||||||
"interface":"waypoints.html",
|
"interface":"waypoints.html",
|
||||||
"storage": [
|
"storage": [
|
||||||
{"name":"gpsnav.app.js","url":"app.js"},
|
{"name":"gpsnav.app.js","url":"app.min.js"},
|
||||||
{"name":"waypoints.json","url":"waypoints.json","evaluate":false},
|
{"name":"waypoints.json","url":"waypoints.json","evaluate":false},
|
||||||
{"name":"gpsnav.img","url":"app-icon.js","evaluate":true}
|
{"name":"gpsnav.img","url":"app-icon.js","evaluate":true}
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,5 @@
|
||||||
0.02: Add SCREENACCESS interface
|
0.02: Add SCREENACCESS interface
|
||||||
0.03: Add Waypoint Editor
|
0.03: Add Waypoint Editor
|
||||||
0.04: Fix great circle formula
|
0.04: Fix great circle formula
|
||||||
|
0.05: Use locale for speed and distance + fix Vector font sizes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,19 @@ var buf = Graphics.createArrayBuffer(240,50,2,{msb:true});
|
||||||
var candraw = true;
|
var candraw = true;
|
||||||
|
|
||||||
function flip(b,y) {
|
function flip(b,y) {
|
||||||
g.drawImage({width:240,height:50,bpp:2,buffer:b.buffer, palette:pal2color},0,y);
|
g.drawImage({width:240,height:50,bpp:2,buffer:b.buffer, palette:pal2color},0,y);
|
||||||
b.clear();
|
b.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
var brg=0;
|
var brg=0;
|
||||||
var wpindex=0;
|
var wpindex=0;
|
||||||
const labels = ["N","NE","E","SE","S","SW","W","NW"];
|
const labels = ["N","NE","E","SE","S","SW","W","NW"];
|
||||||
|
var loc = require("locale");
|
||||||
|
|
||||||
function drawCompass(course) {
|
function drawCompass(course) {
|
||||||
if (!candraw) return;
|
if (!candraw) return;
|
||||||
buf.setColor(1);
|
buf.setColor(1);
|
||||||
buf.setFont("Vector",16);
|
buf.setFont("Vector",24);
|
||||||
var start = course-90;
|
var start = course-90;
|
||||||
if (start<0) start+=360;
|
if (start<0) start+=360;
|
||||||
buf.fillRect(28,45,212,49);
|
buf.fillRect(28,45,212,49);
|
||||||
|
|
@ -44,27 +45,21 @@ function drawCompass(course) {
|
||||||
if (bpos>210) bpos = 226;
|
if (bpos>210) bpos = 226;
|
||||||
buf.setColor(2);
|
buf.setColor(2);
|
||||||
buf.fillCircle(bpos,40,8);
|
buf.fillCircle(bpos,40,8);
|
||||||
}
|
}
|
||||||
flip(buf,Yoff);
|
flip(buf,Yoff);
|
||||||
}
|
}
|
||||||
|
|
||||||
//displayed heading
|
//displayed heading
|
||||||
var heading = 0;
|
var heading = 0;
|
||||||
function newHeading(m,h){
|
function newHeading(m,h){
|
||||||
var s = Math.abs(m - h);
|
var s = Math.abs(m - h);
|
||||||
var delta = 1;
|
var delta = (m>h)?1:-1;
|
||||||
if (s<2) return h;
|
if (s>=180){s=360-s; delta = -delta;}
|
||||||
if (m > h){
|
if (s<2) return h;
|
||||||
if (s >= 180) { delta = -1; s = 360 - s;}
|
var hd = h + delta*(1 + Math.round(s/5));
|
||||||
} else if (m <= h){
|
if (hd<0) hd+=360;
|
||||||
if (s < 180) delta = -1;
|
if (hd>360)hd-= 360;
|
||||||
else s = 360 -s;
|
return hd;
|
||||||
}
|
|
||||||
delta = delta * (1 + Math.round(s/15));
|
|
||||||
heading+=delta;
|
|
||||||
if (heading<0) heading += 360;
|
|
||||||
if (heading>360) heading -= 360;
|
|
||||||
return heading;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var course =0;
|
var course =0;
|
||||||
|
|
@ -93,27 +88,28 @@ function bearing(a,b){
|
||||||
}
|
}
|
||||||
|
|
||||||
function distance(a,b){
|
function distance(a,b){
|
||||||
var dsigma = Math.acos(Math.sin(radians(a.lat))*Math.sin(radians(b.lat))+Math.cos(radians(a.lat))*Math.cos(radians(b.lat))*Math.cos(radians(a.lon-b.lon)));
|
var x = radians(a.lon-b.lon) * Math.cos(radians((a.lat+b.lat)/2));
|
||||||
return Math.round(dsigma*6371000);
|
var y = radians(b.lat-a.lat);
|
||||||
|
return Math.round(Math.sqrt(x*x + y*y) * 6371000);
|
||||||
}
|
}
|
||||||
|
|
||||||
var selected = false;
|
var selected = false;
|
||||||
|
|
||||||
function drawN(){
|
function drawN(){
|
||||||
|
var txt = loc.speed(speed);
|
||||||
buf.setColor(1);
|
buf.setColor(1);
|
||||||
buf.setFont("6x8",2);
|
buf.setFont("6x8",2);
|
||||||
buf.drawString("o",100,0);
|
buf.drawString("o",100,0);
|
||||||
buf.setFont("6x8",1);
|
buf.setFont("6x8",1);
|
||||||
buf.drawString("kph",220,40);
|
buf.drawString(txt.substring(txt.length-3),220,40);
|
||||||
buf.setFont("Vector",40);
|
buf.setFont("Vector",48);
|
||||||
var cs = course.toString();
|
var cs = course.toString();
|
||||||
cs = course<10?"00"+cs : course<100 ?"0"+cs : cs;
|
cs = course<10?"00"+cs : course<100 ?"0"+cs : cs;
|
||||||
buf.drawString(cs,10,0);
|
buf.drawString(cs,10,0);
|
||||||
var txt = (speed<10) ? speed.toFixed(1) : Math.round(speed);
|
buf.drawString(txt.substring(0,txt.length-3),140,4);
|
||||||
buf.drawString(txt,140,4);
|
|
||||||
flip(buf,Yoff+70);
|
flip(buf,Yoff+70);
|
||||||
buf.setColor(1);
|
buf.setColor(1);
|
||||||
buf.setFont("Vector",20);
|
buf.setFont("Vector",24);
|
||||||
var bs = brg.toString();
|
var bs = brg.toString();
|
||||||
bs = brg<10?"00"+bs : brg<100 ?"0"+bs : bs;
|
bs = brg<10?"00"+bs : brg<100 ?"0"+bs : bs;
|
||||||
buf.setColor(3);
|
buf.setColor(3);
|
||||||
|
|
@ -123,10 +119,7 @@ function drawN(){
|
||||||
buf.drawString(wp.name,140,0);
|
buf.drawString(wp.name,140,0);
|
||||||
buf.setColor(1);
|
buf.setColor(1);
|
||||||
buf.drawString(bs,60,0);
|
buf.drawString(bs,60,0);
|
||||||
if (dist<1000)
|
buf.drawString(loc.distance(dist),60,30);
|
||||||
buf.drawString(dist.toString()+"m",60,30);
|
|
||||||
else
|
|
||||||
buf.drawString((dist/1000).toFixed(2)+"Km",60,30);
|
|
||||||
flip(buf,Yoff+130);
|
flip(buf,Yoff+130);
|
||||||
g.setFont("6x8",1);
|
g.setFont("6x8",1);
|
||||||
g.setColor(0,0,0);
|
g.setColor(0,0,0);
|
||||||
|
|
@ -165,7 +158,7 @@ function stopdraw() {
|
||||||
function startTimers() {
|
function startTimers() {
|
||||||
candraw=true;
|
candraw=true;
|
||||||
intervalRefSec = setInterval(function() {
|
intervalRefSec = setInterval(function() {
|
||||||
newHeading(course,heading);
|
heading = newHeading(course,heading);
|
||||||
if (course!=heading) drawCompass(heading);
|
if (course!=heading) drawCompass(heading);
|
||||||
},200);
|
},200);
|
||||||
}
|
}
|
||||||
|
|
@ -189,20 +182,20 @@ function setButtons(){
|
||||||
setWatch(nextwp.bind(null,-1), BTN1, {repeat:true,edge:"falling"});
|
setWatch(nextwp.bind(null,-1), BTN1, {repeat:true,edge:"falling"});
|
||||||
setWatch(doselect, BTN2, {repeat:true,edge:"falling"});
|
setWatch(doselect, BTN2, {repeat:true,edge:"falling"});
|
||||||
setWatch(nextwp.bind(null,1), BTN3, {repeat:true,edge:"falling"});
|
setWatch(nextwp.bind(null,1), BTN3, {repeat:true,edge:"falling"});
|
||||||
}
|
};
|
||||||
|
|
||||||
var SCREENACCESS = {
|
var SCREENACCESS = {
|
||||||
withApp:true,
|
withApp:true,
|
||||||
request:function(){
|
request:function(){
|
||||||
this.withApp=false;
|
this.withApp=false;
|
||||||
stopdraw();
|
stopdraw();
|
||||||
clearWatch();
|
clearWatch();
|
||||||
},
|
},
|
||||||
release:function(){
|
release:function(){
|
||||||
this.withApp=true;
|
this.withApp=true;
|
||||||
startdraw();
|
startdraw();
|
||||||
setButtons();
|
setButtons();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Bangle.on('lcdPower',function(on) {
|
Bangle.on('lcdPower',function(on) {
|
||||||
|
|
@ -227,10 +220,10 @@ function nextwp(inc){
|
||||||
}
|
}
|
||||||
|
|
||||||
function doselect(){
|
function doselect(){
|
||||||
if (selected && waypoints[wpindex].lat===undefined && savedfix.fix) {
|
if (selected && wpindex!=0 && waypoints[wpindex].lat===undefined && savedfix.fix) {
|
||||||
waypoints[wpindex] ={name:"@"+wp.name, lat:savedfix.lat, lon:savedfix.lon};
|
waypoints[wpindex] ={name:"@"+wp.name, lat:savedfix.lat, lon:savedfix.lon};
|
||||||
wp = waypoints[wpindex];
|
wp = waypoints[wpindex];
|
||||||
require("Storage").writeJSON("waypoints.json", waypoints);
|
require("Storage").writeJSON("waypoints.json", waypoints);
|
||||||
}
|
}
|
||||||
selected=!selected;
|
selected=!selected;
|
||||||
drawN();
|
drawN();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
var Yoff=40,pal2color=new Uint16Array([0,65535,2047,50712],0,2),buf=Graphics.createArrayBuffer(240,50,2,{msb:!0}),candraw=!0;function flip(a,c){g.drawImage({width:240,height:50,bpp:2,buffer:a.buffer,palette:pal2color},0,c);a.clear()}var brg=0,wpindex=0,labels="N NE E SE S SW W NW".split(" "),loc=require("locale");
|
||||||
|
function drawCompass(a){if(candraw){buf.setColor(1);buf.setFont("Vector",24);var c=a-90;0>c&&(c+=360);buf.fillRect(28,45,212,49);var b=30,d=15-c%15;15>d?b+=d:d=0;for(var e=d;e<=180-d;e+=15){var f=c+e;0==f%90?(buf.drawString(labels[Math.floor(f/45)%8],b-8,0),buf.fillRect(b-2,25,b+2,45)):0==f%45?(buf.drawString(labels[Math.floor(f/45)%8],b-12,0),buf.fillRect(b-2,30,b+2,45)):0==f%15&&buf.fillRect(b,35,b+1,45);b+=15}0!=wpindex&&(a=brg-a,180<a&&(a-=360),-180>a&&(a+=360),a+=120,30>a&&(a=14),210<a&&(a=226),
|
||||||
|
buf.setColor(2),buf.fillCircle(a,40,8));flip(buf,Yoff)}}var heading=0;function newHeading(a,c){var b=Math.abs(a-c),d=a>c?1:-1;180<=b&&(b=360-b,d=-d);if(2>b)return c;b=c+d*(1+Math.round(b/5));0>b&&(b+=360);360<b&&(b-=360);return b}var course=0,speed=0,satellites=0,wp,dist=0;function radians(a){return a*Math.PI/180}function degrees(a){return(180*a/Math.PI+360)%360}
|
||||||
|
function bearing(a,c){var b=radians(c.lon-a.lon),d=radians(a.lat),e=radians(c.lat);return Math.round(degrees(Math.atan2(Math.sin(b)*Math.cos(e),Math.cos(d)*Math.sin(e)-Math.sin(d)*Math.cos(e)*Math.cos(b))))}function distance(a,c){var b=radians(a.lon-c.lon)*Math.cos(radians((a.lat+c.lat)/2)),d=radians(c.lat-a.lat);return Math.round(6371E3*Math.sqrt(b*b+d*d))}var selected=!1;
|
||||||
|
function drawN(){var a=loc.speed(speed);buf.setColor(1);buf.setFont("6x8",2);buf.drawString("o",100,0);buf.setFont("6x8",1);buf.drawString(a.substring(a.length-3),220,40);buf.setFont("Vector",48);var c=course.toString();c=10>course?"00"+c:100>course?"0"+c:c;buf.drawString(c,10,0);buf.drawString(a.substring(0,a.length-3),140,4);flip(buf,Yoff+70);buf.setColor(1);buf.setFont("Vector",24);a=brg.toString();a=10>brg?"00"+a:100>brg?"0"+a:a;buf.setColor(3);buf.drawString("Brg: ",0,0);buf.drawString("Dist: ",
|
||||||
|
0,30);buf.setColor(selected?1:2);buf.drawString(wp.name,140,0);buf.setColor(1);buf.drawString(a,60,0);buf.drawString(loc.distance(dist),60,30);flip(buf,Yoff+130);g.setFont("6x8",1);g.setColor(0,0,0);g.fillRect(10,230,60,239);g.setColor(1,1,1);g.drawString("Sats "+satellites.toString(),10,230)}var savedfix;
|
||||||
|
function onGPS(a){savedfix=a;void 0!==a&&(course=isNaN(a.course)?course:Math.round(a.course),speed=isNaN(a.speed)?speed:a.speed,satellites=a.satellites);candraw&&(void 0!==a&&1==a.fix&&(dist=distance(a,wp),isNaN(dist)&&(dist=0),brg=bearing(a,wp),isNaN(brg)&&(brg=0)),drawN())}var intervalRef;function stopdraw(){candraw=!1;intervalRef&&clearInterval(intervalRef)}
|
||||||
|
function startTimers(){candraw=!0;intervalRefSec=setInterval(function(){heading=newHeading(course,heading);course!=heading&&drawCompass(heading)},200)}function drawAll(){g.setColor(1,.5,.5);g.fillPoly([120,Yoff+50,110,Yoff+70,130,Yoff+70]);g.setColor(1,1,1);drawN();drawCompass(heading)}function startdraw(){g.clear();Bangle.drawWidgets();startTimers();drawAll()}
|
||||||
|
function setButtons(){setWatch(nextwp.bind(null,-1),BTN1,{repeat:!0,edge:"falling"});setWatch(doselect,BTN2,{repeat:!0,edge:"falling"});setWatch(nextwp.bind(null,1),BTN3,{repeat:!0,edge:"falling"})}var SCREENACCESS={withApp:!0,request:function(){this.withApp=!1;stopdraw();clearWatch()},release:function(){this.withApp=!0;startdraw();setButtons()}};Bangle.on("lcdPower",function(a){SCREENACCESS.withApp&&(a?startdraw():stopdraw())});var waypoints=require("Storage").readJSON("waypoints.json")||[{name:"NONE"}];
|
||||||
|
wp=waypoints[0];function nextwp(a){selected&&(wpindex+=a,wpindex>=waypoints.length&&(wpindex=0),0>wpindex&&(wpindex=waypoints.length-1),wp=waypoints[wpindex],drawN())}function doselect(){selected&&0!=wpindex&&void 0===waypoints[wpindex].lat&&savedfix.fix&&(waypoints[wpindex]={name:"@"+wp.name,lat:savedfix.lat,lon:savedfix.lon},wp=waypoints[wpindex],require("Storage").writeJSON("waypoints.json",waypoints));selected=!selected;drawN()}g.clear();Bangle.setLCDBrightness(1);Bangle.loadWidgets();Bangle.drawWidgets();
|
||||||
|
Bangle.setGPSPower(1);drawAll();startTimers();Bangle.on("GPS",onGPS);setButtons();
|
||||||
|
|
@ -7,3 +7,4 @@
|
||||||
0.06: Remove translations if not required
|
0.06: Remove translations if not required
|
||||||
Ensure 'on' is always supplied for translations
|
Ensure 'on' is always supplied for translations
|
||||||
0.07: Improve handling of non-ASCII characters (fix #469)
|
0.07: Improve handling of non-ASCII characters (fix #469)
|
||||||
|
0.08: Added Mavigation units and en_NAV
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,15 @@ const distanceUnits = { // how many meters per X?
|
||||||
"yd": 0.9144,
|
"yd": 0.9144,
|
||||||
"mi": 1609.34,
|
"mi": 1609.34,
|
||||||
"km": 1000,
|
"km": 1000,
|
||||||
"kmi": 1000
|
"kmi": 1000,
|
||||||
|
"nm": 1852
|
||||||
};
|
};
|
||||||
const speedUnits = { // how many kph per X?
|
const speedUnits = { // how many kph per X?
|
||||||
"kmh": 1,
|
"kmh": 1,
|
||||||
"kph": 1,
|
"kph": 1,
|
||||||
"km/h": 1,
|
"km/h": 1,
|
||||||
"mph": 1.60934
|
"mph": 1.60934,
|
||||||
|
"kts": 1.852
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -99,6 +101,24 @@ var locales = {
|
||||||
day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday",
|
day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday",
|
||||||
// No translation for english...
|
// No translation for english...
|
||||||
},
|
},
|
||||||
|
"en_NAV": { // navigation units nautical miles and knots
|
||||||
|
lang: "en_NAV",
|
||||||
|
decimal_point: ".",
|
||||||
|
thousands_sep: ",",
|
||||||
|
currency_symbol: "£", currency_first: true,
|
||||||
|
int_curr_symbol: "GBP",
|
||||||
|
speed: 'kts',
|
||||||
|
distance: { "0": "m", "1": "nm" },
|
||||||
|
temperature: '°C',
|
||||||
|
ampm: { 0: "am", 1: "pm" },
|
||||||
|
timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" },
|
||||||
|
datePattern: { 0: "%b %d %Y", 1: "%d/%m/%Y" }, // Feb 28 2020" // "01/03/2020"(short)
|
||||||
|
abmonth: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec",
|
||||||
|
month: "January,February,March,April,May,June,July,August,September,October,November,December",
|
||||||
|
abday: "Sun,Mon,Tue,Wed,Thu,Fri,Sat",
|
||||||
|
day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday",
|
||||||
|
// No translation for english...
|
||||||
|
},
|
||||||
"de_DE": {
|
"de_DE": {
|
||||||
lang: "de_DE",
|
lang: "de_DE",
|
||||||
decimal_point: ",",
|
decimal_point: ",",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue