Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions app/ble/ftms/FitnessMachineControlPointCharacteristic.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,35 @@ export default class FitnessMachineControlPointCharacteristic extends bleno.Char
break

case ControlPointOpCode.stopOrPause: {
const controlParameter = data.readUInt8(1)
if (controlParameter === 1) {
this.handleSimpleCommand(ControlPointOpCode.stopOrPause, 'stop', callback)
} else if (controlParameter === 2) {
this.handleSimpleCommand(ControlPointOpCode.stopOrPause, 'pause', callback)
if (data.length < 2) {
log.error('stopOrPause requires a parameter byte')
callback(this.buildResponse(opCode, ResultCode.invalidParameter))
} else {
log.error(`stopOrPause with invalid controlParameter: ${controlParameter}`)
const controlParameter = data.readUInt8(1)
if (controlParameter === 1) {
this.handleSimpleCommand(ControlPointOpCode.stopOrPause, 'stop', callback)
} else if (controlParameter === 2) {
this.handleSimpleCommand(ControlPointOpCode.stopOrPause, 'pause', callback)
} else {
log.error(`stopOrPause with invalid controlParameter: ${controlParameter}`)
callback(this.buildResponse(opCode, ResultCode.invalidParameter))
}
}
break
}

// todo: Most tested bike apps use these to simulate a bike ride. Not sure how we can use these in our rower
// since there is no adjustable resistance on the rowing machine
case ControlPointOpCode.setIndoorBikeSimulationParameters: {
const windspeed = data.readInt16LE(1) * 0.001
const grade = data.readInt16LE(3) * 0.01
const crr = data.readUInt8(5) * 0.0001
const cw = data.readUInt8(6) * 0.01
if (this.controlPointCallback({ name: 'setIndoorBikeSimulationParameters', value: { windspeed, grade, crr, cw } })) {
callback(this.buildResponse(opCode, ResultCode.success))
if (data.length < 7) {
log.error('setIndoorBikeSimulationParameters requires 7 bytes')
callback(this.buildResponse(opCode, ResultCode.invalidParameter))
} else {
callback(this.buildResponse(opCode, ResultCode.operationFailed))
const windspeed = data.readInt16LE(1) * 0.001
const grade = data.readInt16LE(3) * 0.01
const crr = data.readUInt8(5) * 0.0001
const cw = data.readUInt8(6) * 0.01
this.handleSimParameters(opCode, windspeed, grade, crr, cw, callback)
}
break
}
Expand All @@ -136,6 +143,19 @@ export default class FitnessMachineControlPointCharacteristic extends bleno.Char
}
}

handleSimParameters (opCode, windspeed, grade, crr, cw, callback) {
if (this.controlled) {
if (this.controlPointCallback({ name: 'setIndoorBikeSimulationParameters', value: { windspeed, grade, crr, cw } })) {
callback(this.buildResponse(opCode, ResultCode.success))
} else {
callback(this.buildResponse(opCode, ResultCode.operationFailed))
}
} else {
log.info(`initiating command 'setIndoorBikeSimulationParameters' requires 'requestControl'`)
callback(this.buildResponse(opCode, ResultCode.controlNotPermitted))
}
}

// build the response message as defined by the spec
buildResponse (opCode, resultCode) {
const buffer = Buffer.alloc(3)
Expand Down
Loading