mirror of https://github.com/espruino/BangleApps
Handle 'RAM' as filename to allow direct uploads
Add ability to upload assisted GPS datapull/563/head
parent
811611c51e
commit
063929f750
|
@ -241,7 +241,8 @@ and which gives information about the app for the Launcher.
|
||||||
// add an icon to allow your app to be tested
|
// add an icon to allow your app to be tested
|
||||||
|
|
||||||
"storage": [ // list of files to add to storage
|
"storage": [ // list of files to add to storage
|
||||||
{"name":"appid.js", // filename to use in storage
|
{"name":"appid.js", // filename to use in storage.
|
||||||
|
// If name=='RAM', the code is sent directly to Bangle.js and is not saved to a file
|
||||||
"url":"", // URL of file to load (currently relative to apps/)
|
"url":"", // URL of file to load (currently relative to apps/)
|
||||||
"content":"..." // if supplied, this content is loaded directly
|
"content":"..." // if supplied, this content is loaded directly
|
||||||
"evaluate":true // if supplied, data isn't quoted into a String before upload
|
"evaluate":true // if supplied, data isn't quoted into a String before upload
|
||||||
|
|
11
apps.json
11
apps.json
|
@ -895,6 +895,17 @@
|
||||||
{"name":"gpsinfo.img","url": "gps-info-icon.js","evaluate": true}
|
{"name":"gpsinfo.img","url": "gps-info-icon.js","evaluate": true}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{ "id": "assistedgps",
|
||||||
|
"name": "Assisted GPS Update",
|
||||||
|
"icon": "app.png",
|
||||||
|
"version":"0.01",
|
||||||
|
"description": "Downloads assisted GPS data to Bangle.js for faster GPS startup and more accurate fixes",
|
||||||
|
"custom": "custom.html",
|
||||||
|
"tags": "tool,outdoors",
|
||||||
|
"readme": "README.md",
|
||||||
|
"storage": [
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "pomodo",
|
"id": "pomodo",
|
||||||
"name":"Pomodoro",
|
"name":"Pomodoro",
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
0.01: New App!
|
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
|
@ -0,0 +1,113 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" href="../../css/spectre.min.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h2>Assisted GPS</h2>
|
||||||
|
<p>GPS can take a long time (~5 minutes) to get an accurate position the first time it is used.
|
||||||
|
AGPS uploads a few hints to the GPS receiver about satellite positions that allow it
|
||||||
|
to get a faster, more accurate fix - however they are only valid for a short period of time.</p>
|
||||||
|
<p>You can upload data that covers a longer period of time, but the upload will take longer.</p>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="form-label">AGPS Validity time</label>
|
||||||
|
<label class="form-radio">
|
||||||
|
<input type="radio" name="agpsperiod" value="1d" checked><i class="form-icon"></i> 1 day (8kB)
|
||||||
|
</label>
|
||||||
|
<label class="form-radio">
|
||||||
|
<input type="radio" name="agpsperiod" value="2d"><i class="form-icon"></i> 2 days (14kB)
|
||||||
|
</label>
|
||||||
|
<label class="form-radio">
|
||||||
|
<input type="radio" name="agpsperiod" value="3d"><i class="form-icon"></i> 3 days (20kB)
|
||||||
|
</label>
|
||||||
|
<label class="form-radio">
|
||||||
|
<input type="radio" name="agpsperiod" value="1wk"><i class="form-icon"></i> 1 week (46kB)
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<p>Click <button id="upload" class="btn btn-primary">Upload</button></p>
|
||||||
|
|
||||||
|
<script src="../../core/lib/customize.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// When the 'upload' button is clicked...
|
||||||
|
document.getElementById("upload").addEventListener("click", function() {
|
||||||
|
var radios = document.getElementsByName('agpsperiod');
|
||||||
|
var url = "https://www.espruino.com/agps/assistnow_1d.base64";
|
||||||
|
for (var i=0; i<radios.length; i++)
|
||||||
|
if (radios[i].checked)
|
||||||
|
url = "https://www.espruino.com/agps/assistnow_"+radios[i].value+".base64";
|
||||||
|
console.log("Sending...");
|
||||||
|
//var text = document.getElementById("agpsperiod").value;
|
||||||
|
get(url, function(b64) {
|
||||||
|
var js = jsFromBase64(b64);
|
||||||
|
sendCustomizedApp({
|
||||||
|
storage:[
|
||||||
|
{name:"RAM", content:js},
|
||||||
|
]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function UBX_CMD(cmd) {
|
||||||
|
var d = [0xB5,0x62]; // sync chars
|
||||||
|
d = d.concat(cmd);
|
||||||
|
var a=0,b=0;
|
||||||
|
for (var i=2;i<d.length;i++) {
|
||||||
|
a += d[i];
|
||||||
|
b += a;
|
||||||
|
}
|
||||||
|
d.push(a&255,b&255);
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
function UBX_MGA_INI_TIME_UTC() {
|
||||||
|
var a = new Uint8Array(4+24);
|
||||||
|
a.set([0x13,0x40,24,0]);
|
||||||
|
a.set([ 0x10, // 0: type
|
||||||
|
0, // 1: version
|
||||||
|
0, // 2: ref - none
|
||||||
|
0x80] ); // 3: leapsecs - unknown
|
||||||
|
var d = new Date();
|
||||||
|
d.setTime(d.getTime()+d.getTimezoneOffset()*60000); // get as UTC
|
||||||
|
var dv = new DataView(a.buffer, 4);
|
||||||
|
dv.setUint16(4, d.getFullYear());
|
||||||
|
dv.setUint8(6, d.getMonth()+1);
|
||||||
|
dv.setUint8(7, d.getDate());
|
||||||
|
dv.setUint8(8, d.getHours());
|
||||||
|
dv.setUint8(9, d.getMinutes());
|
||||||
|
dv.setUint8(10, d.getSeconds());
|
||||||
|
dv.setUint16(16, 10*60); // seconds part of accuracy - 10 minutes
|
||||||
|
return UBX_CMD([].slice.call(a));
|
||||||
|
}
|
||||||
|
|
||||||
|
function jsFromBase64(b64) {
|
||||||
|
var bin = atob(b64);
|
||||||
|
var chunkSize = 128;
|
||||||
|
var js = "\x10Bangle.setGPSPower(1);\n"; // turn GPS on
|
||||||
|
//js += `\x10Bangle.on('GPS-raw',function (d) { if (d.startsWith("\\xB5\\x62\\x05\\x01")) Terminal.println("GPS ACK"); else if (d.startsWith("\\xB5\\x62\\x05\\x00")) Terminal.println("GPS NACK"); })\n`;
|
||||||
|
js += "\x10E.showMessage('Uploading...','AGPS');function p(n) {g.fillRect(0,g.getHeight()-80,g.getWidth()*n,g.getHeight()-60);}";
|
||||||
|
//js += "\x10var t=getTime()+1;while(t>getTime());\n"; // wait 1 sec
|
||||||
|
js += `\x10Serial1.write(atob("${btoa(String.fromCharCode.apply(null,UBX_MGA_INI_TIME_UTC()))}"))\n`; // set GPS time
|
||||||
|
|
||||||
|
for (var i=0;i<bin.length;i+=chunkSize) {
|
||||||
|
var chunk = bin.substr(i,chunkSize);
|
||||||
|
js += `\x10p(${Math.round(100*i/bin.length)/100});Serial1.write(atob("${btoa(chunk)}"))\n`;
|
||||||
|
}
|
||||||
|
js += "\x10p(1);\n"; // finish progress bar
|
||||||
|
return js;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get(url,callback) {
|
||||||
|
console.log("Loading "+url);
|
||||||
|
var oReq = new XMLHttpRequest();
|
||||||
|
oReq.addEventListener("load", function() {
|
||||||
|
var b64 = this.responseText;
|
||||||
|
console.log("Response received...");
|
||||||
|
callback(b64);
|
||||||
|
});
|
||||||
|
oReq.open("GET", url);
|
||||||
|
oReq.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
2
core
2
core
|
@ -1 +1 @@
|
||||||
Subproject commit c99967381280f483877c3f11ae7b0d4dc8c53e0e
|
Subproject commit 1b66c4ce1ba71036bcb612a2f16bbd7fbc2c66de
|
|
@ -16,7 +16,7 @@ function writeGPScmd(cmd) {
|
||||||
a += d[i];
|
a += d[i];
|
||||||
b += a;
|
b += a;
|
||||||
}
|
}
|
||||||
d.push(a,b);
|
d.push(a&255,b&255);
|
||||||
Serial1.write(d);
|
Serial1.write(d);
|
||||||
}
|
}
|
||||||
function readGPScmd(cmd, callback) {
|
function readGPScmd(cmd, callback) {
|
||||||
|
@ -131,7 +131,7 @@ function setUBX_MGA_INI_TIME_UTC() {
|
||||||
dv.setUint8(9, d.getMinutes());
|
dv.setUint8(9, d.getMinutes());
|
||||||
dv.setUint8(10, d.getSeconds());
|
dv.setUint8(10, d.getSeconds());
|
||||||
dv.setUint16(16, 10*60); // seconds part of accuracy - 10 minutes
|
dv.setUint16(16, 10*60); // seconds part of accuracy - 10 minutes
|
||||||
writeGPScmd(a.slice());
|
writeGPScmd([].slice.call(a));
|
||||||
}
|
}
|
||||||
|
|
||||||
setUBX_MGA_INI_TIME_UTC();
|
setUBX_MGA_INI_TIME_UTC();
|
||||||
|
|
Loading…
Reference in New Issue