2020-02-07 17:16:45 +00:00
|
|
|
Bangle.loadWidgets();
|
|
|
|
Bangle.drawWidgets();
|
|
|
|
|
2020-02-28 17:02:26 +00:00
|
|
|
var settings = require("Storage").readJSON("gpsrec.json",1)||{};
|
2020-02-07 17:16:45 +00:00
|
|
|
|
|
|
|
function getFN(n) {
|
|
|
|
return ".gpsrc"+n.toString(36);
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateSettings() {
|
2020-02-28 11:44:25 +00:00
|
|
|
require("Storage").write("gpsrec.json", settings);
|
2020-02-07 17:16:45 +00:00
|
|
|
if (WIDGETS["gpsrec"])
|
|
|
|
WIDGETS["gpsrec"].reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
function showMainMenu() {
|
|
|
|
const mainmenu = {
|
|
|
|
'': { 'title': 'GPS Record' },
|
|
|
|
'RECORD': {
|
|
|
|
value: !!settings.recording,
|
|
|
|
format: v=>v?"On":"Off",
|
|
|
|
onchange: v => {
|
|
|
|
settings.recording = v;
|
|
|
|
updateSettings();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'File #': {
|
|
|
|
value: settings.file|0,
|
|
|
|
min: 0,
|
|
|
|
max: 35,
|
|
|
|
step: 1,
|
|
|
|
onchange: v => {
|
|
|
|
settings.recording = false;
|
|
|
|
settings.file = v;
|
|
|
|
updateSettings();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'Time Period': {
|
|
|
|
value: settings.period||1,
|
|
|
|
min: 1,
|
|
|
|
max: 60,
|
|
|
|
step: 1,
|
|
|
|
onchange: v => {
|
|
|
|
settings.recording = false;
|
|
|
|
settings.period = v;
|
|
|
|
updateSettings();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'View Tracks': viewTracks,
|
|
|
|
'< Back': ()=>{load();}
|
|
|
|
};
|
|
|
|
return E.showMenu(mainmenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
function viewTracks() {
|
|
|
|
const menu = {
|
|
|
|
'': { 'title': 'GPS Tracks' }
|
|
|
|
};
|
|
|
|
var found = false;
|
|
|
|
for (var n=0;n<36;n++) {
|
|
|
|
var f = require("Storage").open(getFN(n),"r");
|
|
|
|
if (f.readLine()!==undefined) {
|
2020-05-08 20:58:55 +00:00
|
|
|
menu["Track "+n] = viewTrack.bind(null,n,false);
|
2020-02-07 17:16:45 +00:00
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
menu["No Tracks found"] = function(){};
|
|
|
|
menu['< Back'] = showMainMenu;
|
|
|
|
return E.showMenu(menu);
|
|
|
|
}
|
|
|
|
|
2020-04-15 12:39:50 +00:00
|
|
|
function getTrackInfo(fn) {
|
2020-05-08 20:58:55 +00:00
|
|
|
"ram"
|
2020-04-15 12:39:50 +00:00
|
|
|
var filename = getFN(fn);
|
|
|
|
var minLat = 90;
|
|
|
|
var maxLat = -90;
|
|
|
|
var minLong = 180;
|
|
|
|
var maxLong = -180;
|
|
|
|
var starttime, duration=0;
|
|
|
|
var f = require("Storage").open(filename,"r");
|
|
|
|
if (f===undefined) return;
|
|
|
|
var l = f.readLine(f);
|
|
|
|
var nl = 0, c, n;
|
|
|
|
if (l!==undefined) {
|
|
|
|
c = l.split(",");
|
|
|
|
starttime = parseInt(c[0]);
|
|
|
|
}
|
|
|
|
// pushed this loop together to try and bump loading speed a little
|
|
|
|
while(l!==undefined) {
|
|
|
|
++nl;c=l.split(",");
|
2020-05-08 20:58:55 +00:00
|
|
|
n = +c[1];if(n>maxLat)maxLat=n;if(n<minLat)minLat=n;
|
|
|
|
n = +c[2];if(n>maxLong)maxLong=n;if(n<minLong)minLong=n;
|
2020-04-15 12:39:50 +00:00
|
|
|
l = f.readLine(f);
|
|
|
|
}
|
|
|
|
if (c) duration = parseInt(c[0]) - starttime;
|
|
|
|
var lfactor = Math.cos(minLat*Math.PI/180);
|
|
|
|
var ylen = (maxLat-minLat);
|
|
|
|
var xlen = (maxLong-minLong)* lfactor;
|
|
|
|
var scale = xlen>ylen ? 200/xlen : 200/ylen;
|
|
|
|
return {
|
|
|
|
fn : fn,
|
|
|
|
filename : filename,
|
|
|
|
time : new Date(starttime),
|
|
|
|
records : nl,
|
|
|
|
minLat : minLat, maxLat : maxLat,
|
|
|
|
minLong : minLong, maxLong : maxLong,
|
|
|
|
lfactor : lfactor,
|
|
|
|
scale : scale,
|
|
|
|
duration : Math.round(duration/1000)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function asTime(v){
|
|
|
|
var mins = Math.floor(v/60);
|
|
|
|
var secs = v-mins*60;
|
|
|
|
return ""+mins.toString()+"m "+secs.toString()+"s";
|
|
|
|
}
|
|
|
|
|
2020-05-08 20:58:55 +00:00
|
|
|
function viewTrack(n, info) {
|
|
|
|
if (!info) {
|
|
|
|
E.showMessage("Loading...","GPS Track "+n);
|
|
|
|
info = getTrackInfo(n);
|
|
|
|
}
|
2020-02-07 17:16:45 +00:00
|
|
|
const menu = {
|
|
|
|
'': { 'title': 'GPS Track '+n }
|
|
|
|
};
|
2020-04-15 12:39:50 +00:00
|
|
|
if (info.time)
|
|
|
|
menu[info.time.toISOString().substr(0,16).replace("T"," ")] = function(){};
|
|
|
|
menu["Duration"] = { value : asTime(info.duration)};
|
|
|
|
menu["Records"] = { value : ""+info.records };
|
|
|
|
menu['Plot'] = function() {
|
|
|
|
plotTrack(info);
|
|
|
|
};
|
2020-02-07 17:16:45 +00:00
|
|
|
menu['Erase'] = function() {
|
|
|
|
E.showPrompt("Delete Track?").then(function(v) {
|
|
|
|
if (v) {
|
|
|
|
settings.recording = false;
|
|
|
|
updateSettings();
|
|
|
|
var f = require("Storage").open(getFN(n),"r");
|
|
|
|
f.erase();
|
|
|
|
viewTracks();
|
|
|
|
} else
|
2020-05-08 20:58:55 +00:00
|
|
|
viewTrack(n, info);
|
2020-02-07 17:16:45 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
menu['< Back'] = viewTracks;
|
|
|
|
return E.showMenu(menu);
|
|
|
|
}
|
|
|
|
|
2020-04-15 12:39:50 +00:00
|
|
|
function plotTrack(info) {
|
2020-05-08 20:58:55 +00:00
|
|
|
"ram"
|
2020-04-15 12:39:50 +00:00
|
|
|
|
|
|
|
function radians(a) {
|
|
|
|
return a*Math.PI/180;
|
|
|
|
}
|
|
|
|
|
|
|
|
function distance(lat1,long1,lat2,long2){
|
|
|
|
var x = radians(long1-long2) * Math.cos(radians((lat1+lat2)/2));
|
|
|
|
var y = radians(lat2-lat1);
|
|
|
|
return Math.sqrt(x*x + y*y) * 6371000;
|
|
|
|
}
|
|
|
|
|
|
|
|
E.showMenu(); // remove menu
|
|
|
|
g.setColor(1,0.5,0.5);
|
|
|
|
g.setFont("Vector",16);
|
|
|
|
g.fillRect(9,80,11,120);
|
|
|
|
g.fillPoly([9,60,19,80,0,80]);
|
|
|
|
g.setColor(1,1,1);
|
|
|
|
g.drawString("N",2,40);
|
|
|
|
g.drawString("Track"+info.fn.toString()+" - Loading",10,220);
|
|
|
|
g.setColor(0,0,0);
|
|
|
|
g.fillRect(0,220,239,239);
|
|
|
|
g.setColor(1,1,1);
|
|
|
|
g.drawString(asTime(info.duration),10,220);
|
|
|
|
var f = require("Storage").open(info.filename,"r");
|
|
|
|
if (f===undefined) return;
|
|
|
|
var l = f.readLine(f);
|
|
|
|
var ox=0;
|
|
|
|
var oy=0;
|
|
|
|
var olat,olong,dist=0;
|
|
|
|
var i=0;
|
2020-05-08 20:58:55 +00:00
|
|
|
var c = l.split(",");
|
|
|
|
var lat = +c[1];
|
|
|
|
var long = +c[2];
|
|
|
|
var x = 30 + Math.round((long-info.minLong)*info.lfactor*info.scale);
|
|
|
|
var y = 210 - Math.round((lat - info.minLat)*info.scale);
|
|
|
|
g.moveTo(x,y);
|
|
|
|
g.setColor(0,1,0);
|
|
|
|
g.fillCircle(x,y,5);
|
|
|
|
g.setColor(1,1,1);
|
|
|
|
l = f.readLine(f);
|
2020-04-15 12:39:50 +00:00
|
|
|
while(l!==undefined) {
|
2020-05-08 20:58:55 +00:00
|
|
|
c = l.split(",");
|
|
|
|
lat = +c[1];
|
|
|
|
long = +c[2];
|
|
|
|
x = 30 + Math.round((long-info.minLong)*info.lfactor*info.scale);
|
|
|
|
y = 210 - Math.round((lat - info.minLat)*info.scale);
|
|
|
|
g.lineTo(x,y);
|
|
|
|
var d = distance(olat,olong,lat,long);
|
|
|
|
if (!isNaN(d)) dist+=d;
|
2020-04-15 12:39:50 +00:00
|
|
|
olat = lat;
|
|
|
|
olong = long;
|
|
|
|
ox = x;
|
|
|
|
oy = y;
|
|
|
|
l = f.readLine(f);
|
|
|
|
}
|
|
|
|
g.setColor(1,0,0);
|
|
|
|
g.fillCircle(ox,oy,5);
|
|
|
|
g.setColor(1,1,1);
|
|
|
|
g.drawString(require("locale").distance(dist),120,220);
|
|
|
|
g.setFont("6x8",2);
|
|
|
|
g.setFontAlign(0,0,3);
|
|
|
|
g.drawString("Back",230,200);
|
|
|
|
setWatch(function() {
|
2020-05-08 20:58:55 +00:00
|
|
|
viewTrack(info.fn, info);
|
2020-04-15 12:39:50 +00:00
|
|
|
}, BTN3);
|
|
|
|
}
|
|
|
|
|
2020-02-07 17:16:45 +00:00
|
|
|
showMainMenu();
|