fixes a problem, that caused ANT+ not to work wit newer ANT+ usb sticks

This commit is contained in:
Lars Berning 2021-04-24 10:51:21 +02:00
parent d385ad78d7
commit d1f7a80c9a
1 changed files with 8 additions and 9 deletions

View File

@ -17,18 +17,17 @@ function createAntManager () {
const emitter = new EventEmitter() const emitter = new EventEmitter()
const antStick = new Ant.GarminStick2() const antStick = new Ant.GarminStick2()
const antStick3 = new Ant.GarminStick3() const antStick3 = new Ant.GarminStick3()
// it seems that we have to use two separate heart rate sensors to support both old and new
// ant sticks, since the library requires them to be bound before open is called
const heartrateSensor = new Ant.HeartRateSensor(antStick) const heartrateSensor = new Ant.HeartRateSensor(antStick)
const heartrateSensor3 = new Ant.HeartRateSensor(antStick3)
heartrateSensor.on('hbData', (data) => { heartrateSensor.on('hbData', (data) => {
emitter.emit('heartrateMeasurement', { heartrate: data.ComputedHeartRate, batteryLevel: data.BatteryLevel }) emitter.emit('heartrateMeasurement', { heartrate: data.ComputedHeartRate, batteryLevel: data.BatteryLevel })
}) })
heartrateSensor.on('attached', () => { heartrateSensor3.on('hbData', (data) => {
log.info('heart rate sensor attached') emitter.emit('heartrateMeasurement', { heartrate: data.ComputedHeartRate, batteryLevel: data.BatteryLevel })
})
heartrateSensor.on('detached', () => {
log.info('heart rate sensor detached')
}) })
antStick.on('startup', () => { antStick.on('startup', () => {
@ -38,7 +37,7 @@ function createAntManager () {
antStick3.on('startup', () => { antStick3.on('startup', () => {
log.info('mini ANT+ stick found') log.info('mini ANT+ stick found')
heartrateSensor.attach(0, 0) heartrateSensor3.attach(0, 0)
}) })
antStick.on('shutdown', () => { antStick.on('shutdown', () => {
@ -50,11 +49,11 @@ function createAntManager () {
}) })
if (!antStick.open()) { if (!antStick.open()) {
log.debug('classic ANT+ stick not found') log.debug('classic ANT+ stick NOT found')
} }
if (!antStick3.open()) { if (!antStick3.open()) {
log.debug('mini ANT+ stick not found') log.debug('mini ANT+ stick NOT found')
} }
return Object.assign(emitter, { return Object.assign(emitter, {