Skip to content

Commit e8e70ea

Browse files
authored
Merge branch 'espruino:master' into score
2 parents afd132b + 7da2895 commit e8e70ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2072
-739
lines changed

apps/android/ChangeLog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@
3838
0.36: Move from wrapper function to {} and let - faster execution at boot
3939
Allow `calendar-` to take an array of items to remove
4040
0.37: Support Gadgetbridge canned responses
41-
0.38: Don't rewrite settings file on every boot!
41+
0.38: Don't rewrite settings file on every boot!
42+
0.39: Move GB message handling into a library to reduce boot time from 40ms->13ms

apps/android/boot.js

Lines changed: 14 additions & 396 deletions
Large diffs are not rendered by default.

apps/android/lib.js

Lines changed: 388 additions & 0 deletions
Large diffs are not rendered by default.

apps/android/metadata.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "android",
33
"name": "Android Integration",
44
"shortName": "Android",
5-
"version": "0.38",
5+
"version": "0.39",
66
"description": "Display notifications/music/etc sent from the Gadgetbridge app on Android. This replaces the old 'Gadgetbridge' Bangle.js widget.",
77
"icon": "app.png",
88
"tags": "tool,system,messages,notifications,gadgetbridge",
@@ -13,7 +13,8 @@
1313
{"name":"android.app.js","url":"app.js"},
1414
{"name":"android.settings.js","url":"settings.js"},
1515
{"name":"android.img","url":"app-icon.js","evaluate":true},
16-
{"name":"android.boot.js","url":"boot.js"}
16+
{"name":"android.boot.js","url":"boot.js"},
17+
{"name":"android","url":"lib.js"}
1718
],
1819
"data": [{"name":"android.settings.json"}, {"name":"android.calendar.json"}, {"name":"android.cards.json"}],
1920
"sortorder": -8

apps/assistedgps/ChangeLog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
0.03: Select GNSS systems to use for Bangle.js 2
44
0.04: Now turns GPS off after upload
55
0.05: Fix regression in 0.04 that caused AGPS data not to get loaded
6-
0.06: Auto-set GPS output sentences - newer Bangle.js 2 don't include RMC (GPS direction + time) by default
6+
0.06: Auto-set GPS output sentences - newer Bangle.js 2 don't include RMC (GPS direction + time) by default
7+
0.07: Bangle.js 2 now gets estimated time + lat/lon from the browser (~3x faster fix)

apps/assistedgps/custom.html

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ <h2>Assisted GPS</h2>
6060
<script>
6161
var isB1; // is Bangle.js 1?
6262
var isB2; // is Bangle.js 2?
63+
var currentPosition;
6364

6465
// When the 'upload' button is clicked...
6566
document.getElementById("upload").addEventListener("click", function() {
@@ -120,6 +121,7 @@ <h2>Assisted GPS</h2>
120121
}
121122

122123
// =================================================== Bangle.js 2 CASIC
124+
// https://www.espruino.com/Bangle.js2+Technical#gps
123125

124126
function CASIC_CHECKSUM(cmd) {
125127
var cs = 0;
@@ -128,6 +130,61 @@ <h2>Assisted GPS</h2>
128130
return cmd+"*"+cs.toString(16).toUpperCase().padStart(2, '0');
129131
}
130132

133+
// Send a binary CASIC packet, eg: {classId:6, messageId:0, payload:[]}
134+
function CASIC_PKT(pkt) {
135+
pkt.payload = pkt.payload || [];
136+
var plen = pkt.payload.length;
137+
var msg = new Uint8Array(10+pkt.payload.length);
138+
msg.set([0xBA,0xCE,
139+
plen, // LENGTH
140+
0x00,
141+
pkt.classId, // CLASS ID
142+
pkt.messageId]); // MESSAGE ID
143+
msg.set(pkt.payload, 6);
144+
var dv = new DataView(msg.buffer);
145+
// checksum
146+
var ckSum = 0;
147+
for (i = -4; i < plen; i+=4)
148+
ckSum = 0|(ckSum+dv.getUint32(6+i, true));
149+
dv.setUint32(6+plen, ckSum, true);
150+
return msg;
151+
}
152+
153+
// Send AID_INI message, {lat,lon,alt}
154+
function AID_INI(pos) {
155+
var msg = new Uint8Array(56);
156+
var dv = new DataView(msg.buffer);
157+
/*
158+
double xOrLat, yOrLon, zOrAlt;
159+
double tow; // 24
160+
float df; // 32
161+
float posAcc; // 36
162+
float tAcc; // 40
163+
float fAcc; // 44
164+
unsigned int res; // 48
165+
unsigned short int wn; // 52
166+
unsigned char timeSource; // 54
167+
unsigned char flags; // 55
168+
*/
169+
var ms = Date.now();
170+
var wk = (ms-new Date("1980-01-06T00:00:00Z")) / 604800000;
171+
var wn = Math.floor(wk); // week number
172+
var tow = (wk-wn) * 604800; // seconds in week
173+
dv.setFloat64(0, pos.lat, true); // xOrLat
174+
dv.setFloat64(8, pos.lon, true); // yOrLon
175+
dv.setFloat64(16, pos.alt, true); // zOrAlt
176+
dv.setFloat64(24, tow, true); // tow
177+
dv.setFloat32(32, 0, true); // df
178+
dv.setFloat32(36, 0, true); // posAcc
179+
dv.setFloat32(40, 0, true); // tAcc
180+
dv.setFloat32(44, 0, true); // fAcc
181+
dv.setUint32(48, 0, true); // res
182+
dv.setUint16(52, wn, true); // wn
183+
dv.setUint8(54,0); // timeSource
184+
dv.setUint8(55, 0x23); // flags ( lat/lon and clock valid, no drift data )
185+
return CASIC_PKT({classId:0x0B, messageId:0x01, payload:msg});
186+
}
187+
131188
// ===================================================
132189

133190
function jsFromBase64(b64) {
@@ -140,7 +197,6 @@ <h2>Assisted GPS</h2>
140197
js += `\x10Serial1.write(atob("${btoa(String.fromCharCode.apply(null,UBX_MGA_INI_TIME_UTC()))}"))\n`; // set GPS time
141198
}
142199
if (isB2) { // CASIC
143-
144200
// Select what GNSS System to use for decreased fix time.
145201
var radios = document.getElementsByName('gnss_select');
146202
var gnss_select="1";
@@ -150,11 +206,11 @@ <h2>Assisted GPS</h2>
150206
js += `\x10var t=getTime()+0.5;while (getTime()<t);\n`; // This is nasty - but we just wait here until the GPS has had time to boot
151207
js += `\x10Serial1.println("${CASIC_CHECKSUM("$PCAS04,"+gnss_select)}")\n`; // set GNSS mode
152208
js += `\x10Serial1.println("${CASIC_CHECKSUM("$PCAS03,1,0,0,1,1,0,0,0")}")\n`; // enable GGA,GSV,RMC packets (new Bangle.js 2 GPS firmwares don't include RMC by default!)
209+
// If the browser let us have the current location, give it to the GPS chip to get a faster fix
210+
if (currentPosition) {
211+
js += `\x10Serial1.write([${AID_INI(currentPosition).join(",")}])\n`;
212+
}
153213
// Serial1.println("$PCAS06,0*1B") gets the current firmware version
154-
// What about:
155-
// NAV-TIMEUTC (0x01 0x10)
156-
// NAV-PV (0x01 0x03)
157-
// or AGPS.zip uses AID-INI (0x0B 0x01)
158214
}
159215

160216
for (var i=0;i<bin.length;i+=chunkSize) {
@@ -184,8 +240,20 @@ <h2>Assisted GPS</h2>
184240
document.getElementById("banglejs1-info").style = isB1?"":"display:none";
185241
document.getElementById("banglejs2-info").style = isB2?"":"display:none";
186242
document.getElementById("upload-wrap").style = "";
243+
244+
if (isB2) {
245+
// get current position for AGPS improvement
246+
navigator.geolocation.getCurrentPosition(function(position) {
247+
currentPosition = {
248+
lat : position.coords.latitude,
249+
lon : position.coords.longitude,
250+
alt : 0|position.coords.altitude
251+
};
252+
});
253+
}
187254
}
188255

256+
189257
</script>
190258
</body>
191259
</html>

apps/assistedgps/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "assistedgps",
33
"name": "Assisted GPS Updater (AGPS)",
44
"shortName": "AGPS",
5-
"version": "0.06",
5+
"version": "0.07",
66
"description": "Downloads assisted GPS (AGPS) data to Bangle.js for faster GPS startup and more accurate fixes. **No app will be installed**, this just uploads new data to the GPS chip.",
77
"sortorder": -1,
88
"icon": "app.png",

apps/banglebridge/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
0.01: New app!
22
0.02: Minor code improvements
3+
0.03: Remove clearing of the screen (will break running apps) and fix lint errors

apps/banglebridge/metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"id": "banglebridge",
33
"name": "BangleBridge",
44
"shortName": "BangleBridge",
5-
"version": "0.02",
6-
"description": "Widget that allows Bangle Js to record pair and end data using Bluetooth Low Energy in combination with the BangleBridge Android App",
5+
"version": "0.03",
6+
"description": "Widget that allows Bangle.js to record pair and end data using Bluetooth Low Energy in combination with the BangleBridge Android App (**Note:** this has nothing to do with Gadgetbridge)",
77
"icon": "widget.png",
88
"type": "widget",
99
"tags": "widget",

apps/banglebridge/widget.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
(() => {
22
/**
33
* Widget measurements
4-
* Description:
4+
* Description:
55
* name: connection.wid.js
66
*icon: conectionIcon.icon
7-
*
7+
*
88
*/
99

1010
//Font
@@ -24,7 +24,7 @@
2424

2525
//Sensors code
2626
/**
27-
*
27+
*
2828
* @author Jorge
2929
*/
3030
function accel() {
@@ -35,8 +35,7 @@
3535
});
3636

3737
setInterval(function () {
38-
39-
acclS = accelN.x + "##" + accelN.y + "##" + accelN.z + "\n" + accelN.diff + "##" + accelN.mag;
38+
//acclS = accelN.x + "##" + accelN.y + "##" + accelN.z + "\n" + accelN.diff + "##" + accelN.mag;
4039
data[3] = accelN;
4140
}, 2 * 1000);
4241

@@ -45,8 +44,7 @@
4544
function btt() {
4645

4746
setInterval(function () {
48-
49-
bttS = E.getBattery(); //return String
47+
//bttS = E.getBattery(); //return String
5048
data[2] = E.getBattery();
5149
}, 15 * 1000);
5250

@@ -65,9 +63,9 @@
6563

6664
setInterval(function () {
6765

68-
compssS = "A: " + compssN.x + " ## " + compssN.y + " ## " + compssN.z + "\n" +
66+
/*compssS = "A: " + compssN.x + " ## " + compssN.y + " ## " + compssN.z + "\n" +
6967
"B: " + compssN.dx + " ## " + compssN.dy + " ## " + compssN.dz + " ## " + "\n" +
70-
"C: " + compssN.heading; //return String
68+
"C: " + compssN.heading; *///return String
7169
data[4] = compssN;
7270
}, 2 * 1000);
7371

@@ -86,8 +84,8 @@
8684

8785
setInterval(function () {
8886

89-
gpsS = "A: " + gpsN.lat + " ## " + gpsN.lon + " ## " + gpsN.alt + "\n" + "B: " + gpsN.speed + " ## " + gpsN.course + " ## " + gpsN.time + "\n" +
90-
"C: " + gpsN.satellites + " ## " + gpsN.fix; //return String
87+
/*gpsS = "A: " + gpsN.lat + " ## " + gpsN.lon + " ## " + gpsN.alt + "\n" + "B: " + gpsN.speed + " ## " + gpsN.course + " ## " + gpsN.time + "\n" +
88+
"C: " + gpsN.satellites + " ## " + gpsN.fix; *///return String
9189
// work out how to display the current time
9290
var d = new Date();
9391
var year = d.getFullYear();
@@ -150,7 +148,7 @@
150148
//console.log("Index ==> "+ index);
151149
msr[indexFinal] = nueva;
152150

153-
item = nueva;
151+
//item = nueva;
154152
lastInsert = indexFinal;
155153

156154
}
@@ -180,7 +178,7 @@
180178

181179
hrmN = normalize(hrmN);
182180
var roundedRate = parseFloat(hrmN).toFixed(2);
183-
hrmS = String.valueOf(roundedRate); //return String
181+
//hrmS = String.valueOf(roundedRate); //return String
184182
//console.log("array----->" + msr);
185183
data[0] = roundedRate;
186184

@@ -205,7 +203,7 @@
205203

206204
setInterval(function () {
207205

208-
stepS = String.valueOf(stepN); //return String
206+
//stepS = String.valueOf(stepN); //return String
209207
data[1] = stepN;
210208
}, 2 * 1000);
211209

@@ -240,12 +238,11 @@
240238
g.setFont("Vector", 45);
241239
g.drawString(prueba,100,200);*/
242240
if (flip == 1) { //when off
243-
241+
244242
flip = 0;
245243
//Bangle.buzz(1000);
246-
g.clear();
247244
} else { //when on
248-
245+
249246
flip = 1;
250247
g.setFont("Vector", 30);
251248
g.drawString(data[0], 65, 180);
@@ -283,7 +280,7 @@
283280
com: data[4],
284281
gps: data[5]
285282
};
286-
/* g.clear();
283+
/*
287284
g.drawString(compssS,100,200);
288285
*/
289286

@@ -293,7 +290,7 @@
293290
//draw();
294291

295292
}, 5 * 1000);
296-
293+
297294
WIDGETS["banglebridge"]={
298295
area: "tl",
299296
width: 10,

0 commit comments

Comments
 (0)