diff --git a/apps/cscsensor/README.md b/apps/cscsensor/README.md index 3775b4280..d9284473e 100644 --- a/apps/cscsensor/README.md +++ b/apps/cscsensor/README.md @@ -12,4 +12,4 @@ Currently the app displays the following data: 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 or metric (depending on locale), -and a wheel diameter of 28 inches is assumed. A settings dialog to configure wheel sizes will (hopefully) be added later. +the wheel circumference can be adjusted in the global settings app. diff --git a/apps/cscsensor/cscsensor.app.js b/apps/cscsensor/cscsensor.app.js index 4d2306f30..58fe321a5 100644 --- a/apps/cscsensor/cscsensor.app.js +++ b/apps/cscsensor/cscsensor.app.js @@ -4,13 +4,17 @@ var gatt; var service; var characteristic; +const SETTINGS_FILE = 'cscsensor.json'; + class CSCSensor { constructor() { this.movingTime = 0; this.lastTime = 0; this.lastBangleTime = Date.now(); this.lastRevs = -1; - this.wheelDia = 28.0; + var settings = require('Storage').readJSON(SETTINGS_FILE, 1) || {}; + this.wheelCirc = (settings.wheelcirc || 2230)/25.4; + console.log("wc = " + this.wheelCirc); this.speedFailed = 0; this.speed = 0; this.maxSpeed = 0; @@ -29,7 +33,7 @@ class CSCSensor { this.maxSpeed = 0; } updateScreen() { - var dist = this.distFactor*(this.lastRevs-this.lastRevsStart)*this.wheelDia*Math.PI/63360.0; + var dist = this.distFactor*(this.lastRevs-this.lastRevsStart)*this.wheelCirc/63360.0; var ddist = Math.round(100*dist)/100; var dspeed = Math.round(10*this.distFactor*this.speed)/10; var dmins = Math.floor(this.movingTime/60).toString(); @@ -67,7 +71,7 @@ class CSCSensor { this.lastTime = wheelTime; this.speed = this.lastSpeed; if (dRevs>0 && dT>0) { - this.speed = (dRevs*this.wheelDia*Math.PI/63360.0)*3600/dT; + this.speed = (dRevs*this.wheelCirc/63360.0)*3600/dT; this.speedFailed = 0; this.movingTime += dBT; } diff --git a/apps/cscsensor/settings.js b/apps/cscsensor/settings.js index 95fe28d42..8a1c21de5 100644 --- a/apps/cscsensor/settings.js +++ b/apps/cscsensor/settings.js @@ -24,9 +24,9 @@ } const menu = { - '': { 'title': 'Cycling speed sensor' }, + '': { 'title': 'Cycle speed sensor' }, '< Back': back, - 'Wheel diameter (mm)': { + 'Wheel circ.(mm)': { value: s.wheelcirc, min: 800, max: 2400,