forked from FOSS/BangleApps
GPS POI Logger - A simple app to log points of interest with their GPS coordinates and read them back onto your PC. Based on the https://www.espruino.com/Bangle.js+Storage tutorial
parent
f4859dc269
commit
cb4df2d7c6
13
apps.json
13
apps.json
|
@ -1918,5 +1918,18 @@
|
|||
{"name":"magnav.img","url":"magnav-icon.js","evaluate":true}
|
||||
],
|
||||
"data":[{"name":"magnav.json"}]
|
||||
},
|
||||
{ "id": "gpspoilog",
|
||||
"name": "GPS POI Logger",
|
||||
"shortName":"GPS POI Log",
|
||||
"icon": "app.png",
|
||||
"version":"0.01",
|
||||
"description": "A simple app to log points of interest with their GPS coordinates and read them back onto your PC. Based on the https://www.espruino.com/Bangle.js+Storage tutorial",
|
||||
"tags": "outdoors",
|
||||
"interface": "interface.html",
|
||||
"storage": [
|
||||
{"name":"gpspoilog.app.js","url":"app.js"},
|
||||
{"name":"gpspoilog.img","url":"app-icon.js","evaluate":true}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
0.01: New App!
|
|
@ -0,0 +1 @@
|
|||
require("heatshrink").decompress(atob("mEwxH+AH4A/AEeGAAwttGMotLGMItPGLwuTGDQuVGDIfHq9RAAgvfDw+AFwtRq4weFZYAIwAvYJIguPSowvavl8F8qpFF6wwSF44AFvl9vo3GF8l80+t1unGAovkvovDvovrAAQvqR4IACR9TviGAovHABIuXF/4vgGAmAFx+AFzDxGACYvVGDAuWF+AwWFzAvwGCguaGCYucF+AwQFzwvwGBwugGBouiF+AwKF0gwJF0wwHF1AvwGAguqGAYusAH4A/AFI="))
|
|
@ -0,0 +1,67 @@
|
|||
var menuItems = {
|
||||
"":{title:"GPS POI Log"},
|
||||
" ":{value:"No Fix"},
|
||||
"Tree" : ()=>addItem("Tree"),
|
||||
"Gate" : ()=>addItem("Gate"),
|
||||
"Flower" : ()=>addItem("Flower"),
|
||||
"Plant" : ()=>addItem("Plant"),
|
||||
"Bus Stop" : ()=>addItem("Bus Stop"),
|
||||
"Pub" : ()=>addItem("Pub")
|
||||
};
|
||||
|
||||
var menu = E.showMenu(menuItems);
|
||||
var gps = { fix : 0};
|
||||
var gpsCount = 0;
|
||||
var file = require("Storage").open("gpspoilog.csv","a");
|
||||
|
||||
function setStatus(msg) {
|
||||
menuItems[" "].value = msg;
|
||||
menu.draw();
|
||||
}
|
||||
|
||||
Bangle.on('GPS',function(g) {
|
||||
gps = g;
|
||||
gpsCount++;
|
||||
var msg;
|
||||
if (g.fix) {
|
||||
msg = g.satellites + " Satellites";
|
||||
} else {
|
||||
msg = "No Fix";
|
||||
}
|
||||
setStatus(msg+" "+"-\\|/"[gpsCount&3]);
|
||||
});
|
||||
|
||||
|
||||
function addItem(name) {
|
||||
if (!gps.fix) {
|
||||
setStatus("Ignored - no fix");
|
||||
return; // don't do anything as no fix
|
||||
}
|
||||
// The fields we want to put in out CSV file
|
||||
var csv = [
|
||||
0|getTime(), // Time to the nearest second
|
||||
gps.lat,
|
||||
gps.lon,
|
||||
gps.alt,
|
||||
name
|
||||
];
|
||||
// Write data here
|
||||
file.write(csv.join(",")+"\n");
|
||||
setStatus("Written");
|
||||
}
|
||||
|
||||
|
||||
Bangle.loadWidgets();
|
||||
Bangle.drawWidgets();
|
||||
Bangle.setGPSPower(1);
|
||||
|
||||
|
||||
|
||||
function getData(callback) {
|
||||
var f = require("Storage").open("gpspoilog.csv","r");
|
||||
var l = f.readLine();
|
||||
while (l!==undefined) {
|
||||
callback(l);
|
||||
l = f.readLine();
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
|
@ -0,0 +1,69 @@
|
|||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="../../css/spectre.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="data"></div>
|
||||
<button class="btn btn-default" id="btnSave">Save</button>
|
||||
<button class="btn btn-default" id="btnDelete">Delete</button>
|
||||
|
||||
<script src="../../lib/interface.js"></script>
|
||||
<script>
|
||||
var dataElement = document.getElementById("data");
|
||||
var csvData = "";
|
||||
|
||||
function getData() {
|
||||
// show loading window
|
||||
Util.showModal("Loading...");
|
||||
// get the data
|
||||
dataElement.innerHTML = "";
|
||||
Util.readStorageFile(`gpspoilog.csv`,data=>{
|
||||
csvData = data.trim();
|
||||
// remove window
|
||||
Util.hideModal();
|
||||
// If no data, report it and exit
|
||||
if (data.length==0) {
|
||||
dataElement.innerHTML = "<b>No data found</b>";
|
||||
return;
|
||||
}
|
||||
// Otherwise parse the data and output it as a table
|
||||
dataElement.innerHTML = `<table>
|
||||
<tr>
|
||||
<th>Time</th>
|
||||
<th>Lat</th>
|
||||
<th>Lon</th>
|
||||
<th>Alt</th>
|
||||
<th>Type</th>
|
||||
</tr>`+data.trim().split("\n").map(l=>{
|
||||
l = l.split(",");
|
||||
return `<tr>
|
||||
<td>${(new Date(l[0]*1000)).toLocaleString()}</td>
|
||||
<td>${l[1]}</td>
|
||||
<td>${l[2]}</td>
|
||||
<td>${l[3]}</td>
|
||||
<td>${l[4]}</td>
|
||||
</tr>`
|
||||
}).join("\n")+"</table>";
|
||||
});
|
||||
}
|
||||
|
||||
// You can call a utility function to save the data
|
||||
document.getElementById("btnSave").addEventListener("click", function() {
|
||||
Util.saveCSV("gpsdata", csvData);
|
||||
});
|
||||
// Or you can also delete the file
|
||||
document.getElementById("btnDelete").addEventListener("click", function() {
|
||||
Util.showModal("Deleting...");
|
||||
Util.eraseStorageFile("gpspoilog.csv", function() {
|
||||
Util.hideModal();
|
||||
getData();
|
||||
});
|
||||
});
|
||||
// Called when app starts
|
||||
function onInit() {
|
||||
getData();
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue