Add wheel circumference setting

master
marko 2020-09-09 15:43:59 -04:00
parent ff74f1eb44
commit d0c284f0d5
3 changed files with 10 additions and 6 deletions

View File

@ -12,4 +12,4 @@ Currently the app displays the following data:
Button 1 resets all measurements. 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), 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.

View File

@ -4,13 +4,17 @@ var gatt;
var service; var service;
var characteristic; var characteristic;
const SETTINGS_FILE = 'cscsensor.json';
class CSCSensor { class CSCSensor {
constructor() { constructor() {
this.movingTime = 0; this.movingTime = 0;
this.lastTime = 0; this.lastTime = 0;
this.lastBangleTime = Date.now(); this.lastBangleTime = Date.now();
this.lastRevs = -1; 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.speedFailed = 0;
this.speed = 0; this.speed = 0;
this.maxSpeed = 0; this.maxSpeed = 0;
@ -29,7 +33,7 @@ class CSCSensor {
this.maxSpeed = 0; this.maxSpeed = 0;
} }
updateScreen() { 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 ddist = Math.round(100*dist)/100;
var dspeed = Math.round(10*this.distFactor*this.speed)/10; var dspeed = Math.round(10*this.distFactor*this.speed)/10;
var dmins = Math.floor(this.movingTime/60).toString(); var dmins = Math.floor(this.movingTime/60).toString();
@ -67,7 +71,7 @@ class CSCSensor {
this.lastTime = wheelTime; this.lastTime = wheelTime;
this.speed = this.lastSpeed; this.speed = this.lastSpeed;
if (dRevs>0 && dT>0) { 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.speedFailed = 0;
this.movingTime += dBT; this.movingTime += dBT;
} }

View File

@ -24,9 +24,9 @@
} }
const menu = { const menu = {
'': { 'title': 'Cycling speed sensor' }, '': { 'title': 'Cycle speed sensor' },
'< Back': back, '< Back': back,
'Wheel diameter (mm)': { 'Wheel circ.(mm)': {
value: s.wheelcirc, value: s.wheelcirc,
min: 800, min: 800,
max: 2400, max: 2400,