forked from espruino/BangleApps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpstrack.js
78 lines (73 loc) · 1.73 KB
/
gpstrack.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// unfinished GPS Track recorder
g.clear();
var gpsTrack = require("Storage").open(".track","w");
var gpsTrackLen = 0;
var recording = false;
var inMenu = false;
var currentFix;
function drawIcons() {
g.clearRect(220,110,240,130);
if (recording) {
g.fillRect(225,115,235,125);
} else {
g.setColor(1,0,0);
g.fillCircle(230,120,10);
g.setColor(1,1,1);
}
g.setFont("6x8");
g.setFontAlign(0,0);
g.drawString("X",230,220);
}
setWatch(() => {
if (inMenu) return;
recording = !recording;
drawIcons();
}, BTN2, {repeat:true});
setWatch(() => {
if (inMenu) return;
inMenu = true;
g.flip();
E.showPrompt("Erase GPS Trace?").then(r=>{
inMenu = false;
if (r) {
gpsTrack.erase();
gpsTrack = require("Storage").open(".track","w");
gpsTrackLen = 0;
}
});
}, BTN3, {repeat:true});
function onGPS(fix) {
currentFix = fix;
if (!inMenu) {
g.setFont("6x8");
g.setFontAlign(0,0);
g.drawString(" "+fix.satellites+" Satellites ",120,4,true/*solid bg*/);
g.drawString(fix.fix ? "FIX Acquired":" NO FIX ",120,12,true/*solid bg*/);
drawIcons();
}
if (!fix.fix) return;
if (recording) {
gpsTrack.write([
fix.time.toISOString().slice(0,-5),
fix.lat.toFixed(5),
fix.lon.toFixed(5),
fix.alt
].join(",")+"\n");
gpsTrackLen++;
}
if (!inMenu) {
g.drawString(" TRACK LENGTH "+gpsTrackLen+" ",120,236,true/*solid bg*/);
}
// TODO: Use Bangle.project to map this out onto the Screen?
}
Bangle.on('GPS',onGPS);
Bangle.setGPSPower(true);
// Write the contents of the track out to the console
function dumpTrack() {
var f = require("Storage").open(".track","r");
var l;
do {
l = f.readLine();
if (l) console.log(l);
} while (l);
}