Bangle.loadWidgets(); Bangle.drawWidgets(); var settings = require("Storage").readJSON("gpsrec.json",1)||{}; var qOpenStMap = (require("Storage").list("openstmap.json")>0); function getFN(n) { return ".gpsrc"+n.toString(36); } function updateSettings() { require("Storage").write("gpsrec.json", settings); 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||10, min: 1, max: 120, 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) { menu["Track "+n] = viewTrack.bind(null,n,false); found = true; } } if (!found) menu["No Tracks found"] = function(){}; menu['< Back'] = showMainMenu; return E.showMenu(menu); } function getTrackInfo(fn) { "ram" 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(","); n = +c[1];if(n>maxLat)maxLat=n;if(nmaxLong)maxLong=n;if(nylen ? 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"; } function viewTrack(n, info) { if (!info) { E.showMessage("Loading...","GPS Track "+n); info = getTrackInfo(n); } const menu = { '': { 'title': 'GPS Track '+n } }; 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 Map'] = function() { info.qOSTM = false; plotTrack(info); }; if (qOpenStMap) menu['Plot OpenStMap'] = function() { info.qOSTM = true; plotTrack(info); } menu['Plot Alt.'] = function() { plotGraph(info, "altitude"); }; menu['Plot Speed'] = function() { plotGraph(info, "speed"); }; 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 viewTrack(n, info); }); }; menu['< Back'] = viewTracks; return E.showMenu(menu); } function drawopenstmap(lat, lon, map) { var s = require("Storage"); var cx = g.getWidth()/2; var cy = g.getHeight()/2; var p = Bangle.project({lat:lat,lon:lon}); var ix = (p.x-map.center.x)*4096/map.scale + (map.imgx/2) - cx; var iy = (map.center.y-p.y)*4096/map.scale + (map.imgy/2) - cy; var tx = 0|(ix/map.tilesize); var ty = 0|(iy/map.tilesize); var ox = (tx*map.tilesize)-ix; var oy = (ty*map.tilesize)-iy; for (var x=ox,ttx=tx;x0) infn[i]/=infc[i]; var n = infn[i]; if (n>max) max=n; if (n 8) { grid*=2; } // draw g.clear(1).setFont("6x8",1); var r = require("graph").drawLine(g, infn, { x:4,y:0, width: g.getWidth()-24, height: g.getHeight()-8, axes : true, gridy : grid, gridx : 50, title: title, xlabel : x=>Math.round(x*dur/(60*infn.length))+" min" // minutes }); g.setFont("6x8",2); g.setFontAlign(0,0,3); g.drawString("Back",230,200); setWatch(function() { viewTrack(info.fn, info); }, BTN3); g.flip(); } showMainMenu();