Skip to content

Commit

Permalink
Add power-scale and power-offset CLI options.
Browse files Browse the repository at this point in the history
These can be used to compensate for inaccurate power measurements from
the bike.
  • Loading branch information
ptx2 committed Aug 26, 2020
1 parent 866acdc commit d6c0e4e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export const defaults = {
serverAdapter: 'hci0', // adapter for receiving connections from apps
serverName: 'Gymnasticon', // how the Gymnasticon will appear to apps
serverPingInterval: 6, // send a 0-power 0-cadence update for cadence below 60 rpm

// power adjustment (to compensate for inaccurate power measurements on bike)
powerScale: 1.0, // multiply power by this
powerOffset: 0.0, // add this to power
};

/**
Expand Down Expand Up @@ -64,6 +68,8 @@ export class App {
this.pingInterval = new Timer(opts.serverPingInterval);
this.statsTimeout = new Timer(opts.bikeStatsTimeout, {repeats: false});
this.connectTimeout = new Timer(opts.bikeConnectTimeout, {repeats: false});
this.powerScale = opts.powerScale;
this.powerOffset = opts.powerOffset;

this.pingInterval.on('timeout', this.onPingInterval.bind(this));
this.statsTimeout.on('timeout', this.onBikeStatsTimeout.bind(this));
Expand Down Expand Up @@ -109,6 +115,7 @@ export class App {
}

onBikeStats({ power, cadence }) {
power = power > 0 ? Math.max(0, Math.round(power * this.powerScale + this.powerOffset)) : 0;
this.logger.log(`received stats from bike [power=${power}W cadence=${cadence}rpm]`);
this.statsTimeout.reset();
this.power = power;
Expand Down
11 changes: 11 additions & 0 deletions src/app/cli-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,16 @@ export const options = {
describe: '<seconds> ping app when user not pedaling',
type: 'number',
default: defaults.serverPingInterval,
},

'power-scale': {
describe: '<value> scale watts by this multiplier',
type: 'number',
default: defaults.powerScale,
},
'power-offset': {
describe: '<value> add this value to watts',
type: 'number',
default: defaults.powerOffset,
}
};

0 comments on commit d6c0e4e

Please sign in to comment.