From e0d7bd1126b86b858939150f512115b24ef5de2a Mon Sep 17 00:00:00 2001 From: ptx2 Date: Thu, 27 Aug 2020 07:59:49 -0400 Subject: [PATCH] Fix error message on bike disconnect. --- src/app/app.js | 2 +- src/bikes/flywheel.js | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/app/app.js b/src/app/app.js index 5f76887..8d5d1c7 100644 --- a/src/app/app.js +++ b/src/app/app.js @@ -128,7 +128,7 @@ export class App { process.exit(0); } - onBikeDisconnect(address) { + onBikeDisconnect({ address }) { this.logger.log(`bike disconnected ${address}`); process.exit(0); } diff --git a/src/bikes/flywheel.js b/src/bikes/flywheel.js index 88760b7..5cda5c9 100644 --- a/src/bikes/flywheel.js +++ b/src/bikes/flywheel.js @@ -55,28 +55,27 @@ export class FlywheelBikeClient extends EventEmitter { this.fixPowerDropout = createPowerDropoutFilter(); // scan - const peripheral = await scan(this.noble, [UART_SERVICE_UUID], this.filters); + this.peripheral = await scan(this.noble, [UART_SERVICE_UUID], this.filters); // connect - peripheral.on('disconnect', this.onDisconnect); - await peripheral.connectAsync(); + this.peripheral.on('disconnect', this.onDisconnect); + await this.peripheral.connectAsync(); // workaround for bluez rejecting connection parameters - await updateConnectionParameters(peripheral, LE_MIN_INTERVAL, LE_MAX_INTERVAL, LE_LATENCY, LE_SUPERVISION_TIMEOUT); // needed for hci bluez + await updateConnectionParameters(this.peripheral, LE_MIN_INTERVAL, LE_MAX_INTERVAL, LE_LATENCY, LE_SUPERVISION_TIMEOUT); // needed for hci bluez // discover services/characteristics - const {characteristics} = await peripheral.discoverSomeServicesAndCharacteristicsAsync( + const {characteristics} = await this.peripheral.discoverSomeServicesAndCharacteristicsAsync( [UART_SERVICE_UUID], [UART_TX_UUID, UART_RX_UUID]); const [tx, rx] = characteristics; + this.tx = tx; + this.rx = rx; // subscribe to receive data - tx.on('read', this.onReceive); - await tx.subscribeAsync(); + this.tx.on('read', this.onReceive); + await this.tx.subscribeAsync(); - this.tx = tx; - this.rx = rx; this.state = 'connected'; - this.peripheral = peripheral; } /** @@ -153,7 +152,7 @@ export class FlywheelBikeClient extends EventEmitter { * @type {object} * @property {string} address - mac address */ - this.emit('disconnect', {address: this.perpiheral.address}); + this.emit('disconnect', {address: this.peripheral.address}); } }