Merge branch 'espruino:master' into master

master
Ronin0000 2021-09-27 16:15:07 -07:00 committed by GitHub
commit bb5fcdaafc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 108 additions and 49 deletions

View File

@ -2508,7 +2508,7 @@
"name": "Cycling speed sensor", "name": "Cycling speed sensor",
"shortName":"CSCSensor", "shortName":"CSCSensor",
"icon": "icons8-cycling-48.png", "icon": "icons8-cycling-48.png",
"version":"0.04", "version":"0.05",
"description": "Read BLE enabled cycling speed and cadence sensor and display readings on watch", "description": "Read BLE enabled cycling speed and cadence sensor and display readings on watch",
"tags": "outdoors,exercise,ble,bluetooth", "tags": "outdoors,exercise,ble,bluetooth",
"readme": "README.md", "readme": "README.md",
@ -3543,7 +3543,8 @@
"icon": "app.png", "icon": "app.png",
"version":"0.01", "version":"0.01",
"description": "A simple clock using the bold Anton font.", "description": "A simple clock using the bold Anton font.",
"tags": "clock,b2", "tags":"clock,b2",
"type":"clock",
"storage": [ "storage": [
{"name":"antonclk.app.js","url":"app.js"}, {"name":"antonclk.app.js","url":"app.js"},
{"name":"antonclk.img","url":"app-icon.js","evaluate":true} {"name":"antonclk.img","url":"app-icon.js","evaluate":true}
@ -3554,7 +3555,8 @@
"icon": "app.png", "icon": "app.png",
"version":"0.01", "version":"0.01",
"description": "A clock using a wave image by [Lillith May](https://www.instagram.com/_lilustrations_/). **Note: This requires a bugfix for #2049 on Bangle.js 1**", "description": "A clock using a wave image by [Lillith May](https://www.instagram.com/_lilustrations_/). **Note: This requires a bugfix for #2049 on Bangle.js 1**",
"tags": "clock,b2", "tags":"clock,b2",
"type":"clock",
"storage": [ "storage": [
{"name":"waveclk.app.js","url":"app.js"}, {"name":"waveclk.app.js","url":"app.js"},
{"name":"waveclk.img","url":"app-icon.js","evaluate":true} {"name":"waveclk.img","url":"app-icon.js","evaluate":true}

View File

@ -1 +1 @@
require("heatshrink").decompress(atob("mEwge27dtAX4C+/dt+wFB/wCECIu3/dvBYNv34RC7/tCIu//99EYN9C4IpB74jG3379ovDFIIRBEYxHD/47D2wjHCIX+AQJHBCIIXBNZt/+5QBEZIgBAQX///9EZRWBBARHDEwhlC/9/EAJoBDQIOBNwyPCEYYCDJQ4CJSQ4CB0O2lojL2lwBIXFiwsK0f/KgUbuwRJo6cBPAO34cUmJHH7U/97tBgEGBIODEY/RXoOw7cAgHbtlxoojGx7hCjAjD20ANA1378MEIIAB4d0u5HGNAPYCAYAB2n2SQSPDjv3CIsF2lxEYto//+CoOGCIUt0O3EYtHvqMBvlw4UAgJQBqIjERgQDBsO+7FAhaMH64DB+4qB+3AgARG9uhIgQJD4dghd+7dLBQZoBaISwC4cArf27dpCIf/23f9uHCIQABhoNClsl20ttuwgYKBEAIAChOmCIOH/vx9ttwB2BDgMBAoIRBmnbpkbtk2ltsgAMCJQOwAgMBk+eq3AhiSBsE2GAX//4WCAAOBAoVbtt8mCJBgHHfYMHdgoRBott+zmDsEAn/tEwkC7UAVoYACgPbv4REAASTBEYY0BPIPwCJAjEu3Dvq8BCAnbsEwGgm2jbAC8EAjFvEAQREjuwDQXbvvx7cd2K/EgEb9oRCAoLOBjEAgk/A=")) require("heatshrink").decompress(atob("mEwgX/AH4A/AAf+14BBAoPq/Wq1QFB+EP+kLAoNA+CdB3//yEP6ALB/sABYf8gEMgALB6ALJqoLB+tVgH//kQhkQhUABYImCIwPwh3whcA94UCgJHD+AXB/4LCcQQLCKYQLB+EDBZQFCBY/Qh4LJ4ALLl4LFioLCgE/KZMAv4XFBYimBC4/+BYw7DRwQLIV4ILWTQQLDOIUA/ALDAC+t1uv/263/6/Pq/YLC3vv//vM4Oq33rBYP6/u//2/C4Pr1YXC12vBwO+BYO69XmJDQA/ACIA=="))

View File

@ -2,4 +2,4 @@
0.02: Add wheel circumference settings dialog 0.02: Add wheel circumference settings dialog
0.03: Save total distance traveled 0.03: Save total distance traveled
0.04: Add sensor battery level indicator 0.04: Add sensor battery level indicator
0.05: Add cadence sensor support

View File

@ -13,6 +13,6 @@ Currently the app displays the following data:
Button 1 resets all measurements except total distance traveled. The latter gets preserved by being written to storage every 0.1 miles and upon exiting the app. Button 1 resets all measurements except total distance traveled. The latter gets preserved by being written to storage every 0.1 miles and upon exiting the app.
If the watch app has not received an update from the sensor for at least 10 seconds, pushing button 3 will attempt to reconnect to the sensor. If the watch app has not received an update from the sensor for at least 10 seconds, pushing button 3 will attempt to reconnect to the sensor.
Button 2 switches between the display for cycling speed and cadence.
I do not have access to a cadence sensor at the moment, so only the speed part is currently implemented. Values displayed are imperial or metric (depending on locale), Values displayed are imperial or metric (depending on locale), cadence is in RPM, the wheel circumference can be adjusted in the global settings app.
the wheel circumference can be adjusted in the global settings app.

View File

@ -28,6 +28,10 @@ class CSCSensor {
this.distFactor = this.qMetric ? 1.609344 : 1; this.distFactor = this.qMetric ? 1.609344 : 1;
this.screenInit = true; this.screenInit = true;
this.batteryLevel = -1; this.batteryLevel = -1;
this.lastCrankTime = 0;
this.lastCrankRevs = 0;
this.showCadence = false;
this.cadence = 0;
} }
reset() { reset() {
@ -40,6 +44,11 @@ class CSCSensor {
this.screenInit = true; this.screenInit = true;
} }
toggleDisplayCadence() {
this.showCadence = !this.showCadence;
this.screenInit = true;
}
setBatteryLevel(level) { setBatteryLevel(level) {
if (level!=this.batteryLevel) { if (level!=this.batteryLevel) {
this.batteryLevel = level; this.batteryLevel = level;
@ -62,7 +71,7 @@ class CSCSensor {
else g.setFontVector(14).setFontAlign(0, 0, 0).setColor(0xffff).drawString("?", 16, 66); else g.setFontVector(14).setFontAlign(0, 0, 0).setColor(0xffff).drawString("?", 16, 66);
} }
updateScreen() { updateScreenRevs() {
var dist = this.distFactor*(this.lastRevs-this.lastRevsStart)*this.wheelCirc/63360.0; var dist = this.distFactor*(this.lastRevs-this.lastRevsStart)*this.wheelCirc/63360.0;
var ddist = Math.round(100*dist)/100; var ddist = Math.round(100*dist)/100;
var tdist = Math.round(this.distFactor*this.totaldist*10)/10; var tdist = Math.round(this.distFactor*this.totaldist*10)/10;
@ -109,44 +118,87 @@ class CSCSensor {
g.setColor(0xffff).drawString(tdist + " " + this.distUnit, 92, 226); g.setColor(0xffff).drawString(tdist + " " + this.distUnit, 92, 226);
} }
updateScreenCadence() {
if (this.screenInit) {
for (var i=0; i<2; ++i) {
if ((i&1)==0) g.setColor(0, 0, 0);
else g.setColor(0x30cd);
g.fillRect(0, 48+i*32, 86, 48+(i+1)*32);
if ((i&1)==1) g.setColor(0);
else g.setColor(0x30cd);
g.fillRect(87, 48+i*32, 239, 48+(i+1)*32);
g.setColor(0.5, 0.5, 0.5).drawRect(87, 48+i*32, 239, 48+(i+1)*32).drawLine(0, 239, 239, 239);//.drawRect(0, 48, 87, 239);
g.moveTo(0, 80).lineTo(30, 80).lineTo(30, 48).lineTo(87, 48).lineTo(87, 239).lineTo(0, 239).lineTo(0, 80);
}
g.setFontAlign(1, 0, 0).setFontVector(19).setColor(1, 1, 0);
g.drawString("Cadence:", 87, 98);
this.drawBatteryIcon();
this.screenInit = false;
}
g.setFontAlign(-1, 0, 0).setFontVector(26);
g.setColor(0).fillRect(88, 81, 238, 111);
g.setColor(0xffff).drawString(Math.round(this.cadence), 92, 98);
}
updateScreen() {
if (!this.showCadence) {
this.updateScreenRevs();
} else {
this.updateScreenCadence();
}
}
updateSensor(event) { updateSensor(event) {
var qChanged = false; var qChanged = false;
if (event.target.uuid == "0x2a5b") { if (event.target.uuid == "0x2a5b") {
var wheelRevs = event.target.value.getUint32(1, true); if (event.target.value.getUint8(0, true) & 0x2) {
var dRevs = (this.lastRevs>0 ? wheelRevs-this.lastRevs : 0); // crank revolution
if (dRevs>0) { const crankRevs = event.target.value.getUint16(1, true);
qChanged = true; const crankTime = event.target.value.getUint16(3, true);
this.totaldist += dRevs*this.wheelCirc/63360.0; if (crankTime > this.lastCrankTime) {
if ((this.totaldist-this.settings.totaldist)>0.1) { this.cadence = (crankRevs-this.lastCrankRevs)/(crankTime-this.lastCrankTime)*(60*1024);
this.settings.totaldist = this.totaldist; qChanged = true;
storage.writeJSON(SETTINGS_FILE, this.settings);
} }
} this.lastCrankRevs = crankRevs;
this.lastRevs = wheelRevs; this.lastCrankTime = crankTime;
if (this.lastRevsStart<0) this.lastRevsStart = wheelRevs; } else {
var wheelTime = event.target.value.getUint16(5, true); // wheel revolution
var dT = (wheelTime-this.lastTime)/1024; var wheelRevs = event.target.value.getUint32(1, true);
var dBT = (Date.now()-this.lastBangleTime)/1000; var dRevs = (this.lastRevs>0 ? wheelRevs-this.lastRevs : 0);
this.lastBangleTime = Date.now(); if (dRevs>0) {
if (dT<0) dT+=64; qChanged = true;
if (Math.abs(dT-dBT)>3) dT = dBT; this.totaldist += dRevs*this.wheelCirc/63360.0;
this.lastTime = wheelTime; if ((this.totaldist-this.settings.totaldist)>0.1) {
this.speed = this.lastSpeed; this.settings.totaldist = this.totaldist;
if (dRevs>0 && dT>0) { storage.writeJSON(SETTINGS_FILE, this.settings);
this.speed = (dRevs*this.wheelCirc/63360.0)*3600/dT; }
this.speedFailed = 0;
this.movingTime += dT;
}
else {
this.speedFailed++;
qChanged = false;
if (this.speedFailed>3) {
this.speed = 0;
qChanged = (this.lastSpeed>0);
} }
this.lastRevs = wheelRevs;
if (this.lastRevsStart<0) this.lastRevsStart = wheelRevs;
var wheelTime = event.target.value.getUint16(5, true);
var dT = (wheelTime-this.lastTime)/1024;
var dBT = (Date.now()-this.lastBangleTime)/1000;
this.lastBangleTime = Date.now();
if (dT<0) dT+=64;
if (Math.abs(dT-dBT)>3) dT = dBT;
this.lastTime = wheelTime;
this.speed = this.lastSpeed;
if (dRevs>0 && dT>0) {
this.speed = (dRevs*this.wheelCirc/63360.0)*3600/dT;
this.speedFailed = 0;
this.movingTime += dT;
}
else {
this.speedFailed++;
qChanged = false;
if (this.speedFailed>3) {
this.speed = 0;
qChanged = (this.lastSpeed>0);
}
}
this.lastSpeed = this.speed;
if (this.speed>this.maxSpeed && (this.movingTime>3 || this.speed<20) && this.speed<50) this.maxSpeed = this.speed;
} }
this.lastSpeed = this.speed;
if (this.speed>this.maxSpeed && (this.movingTime>3 || this.speed<20) && this.speed<50) this.maxSpeed = this.speed;
} }
if (qChanged && this.qUpdateScreen) this.updateScreen(); if (qChanged && this.qUpdateScreen) this.updateScreen();
} }
@ -199,6 +251,7 @@ connection_setup();
setWatch(function() { mySensor.reset(); g.clearRect(0, 48, 239, 239); mySensor.updateScreen(); }, BTN1, {repeat:true, debounce:20}); setWatch(function() { mySensor.reset(); g.clearRect(0, 48, 239, 239); mySensor.updateScreen(); }, BTN1, {repeat:true, debounce:20});
E.on('kill',()=>{ if (gatt!=undefined) gatt.disconnect(); mySensor.settings.totaldist = mySensor.totaldist; storage.writeJSON(SETTINGS_FILE, mySensor.settings); }); E.on('kill',()=>{ if (gatt!=undefined) gatt.disconnect(); mySensor.settings.totaldist = mySensor.totaldist; storage.writeJSON(SETTINGS_FILE, mySensor.settings); });
setWatch(function() { if (Date.now()-mySensor.lastBangleTime>10000) connection_setup(); }, BTN3, {repeat:true, debounce:20}); setWatch(function() { if (Date.now()-mySensor.lastBangleTime>10000) connection_setup(); }, BTN3, {repeat:true, debounce:20});
setWatch(function() { mySensor.toggleDisplayCadence(); g.clearRect(0, 48, 239, 239); mySensor.updateScreen(); }, BTN2, {repeat:true, debounce:20});
NRF.on('disconnect', connection_setup); NRF.on('disconnect', connection_setup);
Bangle.loadWidgets(); Bangle.loadWidgets();

View File

@ -1 +1 @@
require("heatshrink").decompress(atob("mEwgX/AH4A/AAf+14BBAoPq/Wq1QFB+EP+kLAoNA+CdB3//yEP6ALB/sABYf8gEMgALB6ALJqoLB+tVgH//kQhkQhUABYImCIwPwh3whcA94UCgJHD+AXB/4LCcQQLCKYQLB+EDBZQFCBY/Qh4LJ4ALLl4LFioLCgE/KZMAv4XFBYimBC4/+BYw7DRwQLIV4ILWTQQLDOIUA/ALDAC+t1uv/263/6/Pq/YLC3vv//vM4Oq33rBYP6/u//2/C4Pr1YXC12vBwO+BYO69XmJDQA/ACIA==")) require("heatshrink").decompress(atob("mEwge27dtAX4C+/dt+wFB/wCECIu3/dvBYNv34RC7/tCIu//99EYN9C4IpB74jG3379ovDFIIRBEYxHD/47D2wjHCIX+AQJHBCIIXBNZt/+5QBEZIgBAQX///9EZRWBBARHDEwhlC/9/EAJoBDQIOBNwyPCEYYCDJQ4CJSQ4CB0O2lojL2lwBIXFiwsK0f/KgUbuwRJo6cBPAO34cUmJHH7U/97tBgEGBIODEY/RXoOw7cAgHbtlxoojGx7hCjAjD20ANA1378MEIIAB4d0u5HGNAPYCAYAB2n2SQSPDjv3CIsF2lxEYto//+CoOGCIUt0O3EYtHvqMBvlw4UAgJQBqIjERgQDBsO+7FAhaMH64DB+4qB+3AgARG9uhIgQJD4dghd+7dLBQZoBaISwC4cArf27dpCIf/23f9uHCIQABhoNClsl20ttuwgYKBEAIAChOmCIOH/vx9ttwB2BDgMBAoIRBmnbpkbtk2ltsgAMCJQOwAgMBk+eq3AhiSBsE2GAX//4WCAAOBAoVbtt8mCJBgHHfYMHdgoRBott+zmDsEAn/tEwkC7UAVoYACgPbv4REAASTBEYY0BPIPwCJAjEu3Dvq8BCAnbsEwGgm2jbAC8EAjFvEAQREjuwDQXbvvx7cd2K/EgEb9oRCAoLOBjEAgk/A="))

View File

@ -154,16 +154,20 @@ function touchHandler(l,e) {
if (l.c) l.c.forEach(n => touchHandler(n,e)); if (l.c) l.c.forEach(n => touchHandler(n,e));
} }
function prepareLazyRender(l, rectsToClear, drawList, rects, bgCol) { function prepareLazyRender(l, rectsToClear, drawList, rects, parentBg) {
if ((l.bgCol != null && l.bgCol != bgCol) || l.type == "txt" || l.type == "btn" || l.type == "img" || l.type == "custom") { var bgCol = l.bgCol == null ? parentBg : g.toColor(l.bgCol);
if (bgCol != parentBg || l.type == "txt" || l.type == "btn" || l.type == "img" || l.type == "custom") {
// Hash the layoutObject without including its children // Hash the layoutObject without including its children
let c = l.c; var c = l.c;
delete l.c; delete l.c;
let hash = "H"+E.CRC32(E.toJS(l)); // String keys maintain insertion order var hash = "H"+E.CRC32(E.toJS(l)); // String keys maintain insertion order
if (c) l.c = c; if (c) l.c = c;
if (!delete rectsToClear[hash]) { if (!delete rectsToClear[hash]) {
rects[hash] = {bg: bgCol, r: [l.x,l.y,l.x+l.w-1,l.y+l.h-1]}; rects[hash] = {
bg: parentBg == null ? g.theme.bg : parentBg,
r: [l.x,l.y,l.x+l.w-1,l.y+l.h-1]
};
if (drawList) { if (drawList) {
drawList.push(l); drawList.push(l);
drawList = null; // Prevent children from being redundantly added to the drawList drawList = null; // Prevent children from being redundantly added to the drawList
@ -171,7 +175,7 @@ function prepareLazyRender(l, rectsToClear, drawList, rects, bgCol) {
} }
} }
if (l.c) for (let ch of l.c) prepareLazyRender(ch, rectsToClear, drawList, rects, l.bgCol == null ? bgCol : l.bgCol); if (l.c) for (var ch of l.c) prepareLazyRender(ch, rectsToClear, drawList, rects, bgCol);
} }
Layout.prototype.render = function (l) { Layout.prototype.render = function (l) {
@ -220,7 +224,7 @@ Layout.prototype.render = function (l) {
if (!this.rects) this.rects = {}; if (!this.rects) this.rects = {};
var rectsToClear = this.rects.clone(); var rectsToClear = this.rects.clone();
var drawList = []; var drawList = [];
prepareLazyRender(l, rectsToClear, drawList, this.rects, g.getBgColor()); prepareLazyRender(l, rectsToClear, drawList, this.rects, null);
for (var h in rectsToClear) delete this.rects[h]; for (var h in rectsToClear) delete this.rects[h];
var clearList = Object.keys(rectsToClear).map(k=>rectsToClear[k]).reverse(); // Rects are cleared in reverse order so that the original bg color is restored var clearList = Object.keys(rectsToClear).map(k=>rectsToClear[k]).reverse(); // Rects are cleared in reverse order so that the original bg color is restored
for (var r of clearList) g.setBgColor(r.bg).clearRect.apply(g, r.r); for (var r of clearList) g.setBgColor(r.bg).clearRect.apply(g, r.r);