forked from FOSS/BangleApps
Add reset button
parent
095a06bda5
commit
f83d5e03e7
|
@ -1,3 +1,15 @@
|
|||
# CSCSensor
|
||||
|
||||
TBD
|
||||
Simple app that can read a cycling speed and cadence (CSC) sensor and display the information on the watch.
|
||||
Currently the app displays the following data:
|
||||
|
||||
- moving time
|
||||
- current speed
|
||||
- average speed
|
||||
- maximum speed
|
||||
- distance traveled
|
||||
|
||||
Button 1 resets all measurements.
|
||||
|
||||
I do not have acces to a cadence sensor at the moment, so only the speed part is currently implemented. Values displayed are imperial, and a wheel diameter
|
||||
of 28 inches is assumed. A settings dialog to configure units and wheel sizes will (hopefully) be added later.
|
||||
|
|
|
@ -16,17 +16,23 @@ class CSCSensor {
|
|||
this.maxSpeed = 0;
|
||||
this.lastSpeed = 0;
|
||||
this.qUpdateScreen = true;
|
||||
this.lastRevsStart = -1;
|
||||
}
|
||||
reset() {
|
||||
this.maxSpeed = 0;
|
||||
this.movingTime = 0;
|
||||
this.lastRevsStart = this.lastRevs;
|
||||
this.maxSpeed = 0;
|
||||
}
|
||||
|
||||
updateScreen() {
|
||||
var dist = this.lastRevs*this.wheelDia*Math.PI/63360.0;
|
||||
var dist = (this.lastRevs-this.lastRevsStart)*this.wheelDia*Math.PI/63360.0;
|
||||
var ddist = Math.round(100*dist)/100;
|
||||
var dspeed = Math.round(10*this.speed)/10;
|
||||
var dmins = Math.floor(this.movingTime/60).toString();
|
||||
if (dmins.length<2) dmins = "0"+dmins;
|
||||
var dsecs = (Math.floor(this.movingTime) % 60).toString();
|
||||
if (dsecs.length<2) dsecs = "0"+dsecs;
|
||||
var avespeed = Math.round(10*dist/this.movingTime)/10;
|
||||
var avespeed = (this.movingTime>0 ? Math.round(10*dist/(this.movingTime/3600))/10 : 0);
|
||||
var maxspeed = Math.round(10*this.maxSpeed)/10;
|
||||
g.setFontAlign(1, -1, 0).setFontVector(18).setColor(1, 1, 0);
|
||||
g.drawString("Time:", 86, 60);
|
||||
|
@ -41,7 +47,6 @@ class CSCSensor {
|
|||
g.drawString(maxspeed + " mph", 92, 160);
|
||||
g.drawString(ddist + " miles", 92, 192);
|
||||
}
|
||||
|
||||
updateSensor(event) {
|
||||
var qChanged = false;
|
||||
if (event.target.uuid == "0x2a5b") {
|
||||
|
@ -49,6 +54,7 @@ class CSCSensor {
|
|||
var dRevs = (this.lastRevs>0 ? wheelRevs-this.lastRevs : 0);
|
||||
if (dRevs>0) qChanged = true;
|
||||
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;
|
||||
|
@ -103,7 +109,9 @@ NRF.setScan(parseDevice, { filters: [{services:["1816"]}], timeout: 2000});
|
|||
g.clearRect(0, 60, 239, 239).setFontVector(18).setFontAlign(0, 0, 0).setColor(0, 1, 0);
|
||||
g.drawString("Scanning for CSC sensor...", 120, 120);
|
||||
|
||||
setWatch(function() { mySensor.reset(); mySensor.updateScreen(); }, BTN1);
|
||||
|
||||
Bangle.on('kill',()=>{ if (gatt!=undefined) gatt.disconnect()});
|
||||
|
||||
Bangle.loadWidgets();
|
||||
Bangle.drawWidgets();
|
||||
Bangle.drawWidgets();
|
||||
|
|
Loading…
Reference in New Issue