Skip to content

Commit

Permalink
Fix error message on bike disconnect.
Browse files Browse the repository at this point in the history
  • Loading branch information
ptx2 committed Aug 27, 2020
1 parent fb298e4 commit e0d7bd1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class App {
process.exit(0);
}

onBikeDisconnect(address) {
onBikeDisconnect({ address }) {
this.logger.log(`bike disconnected ${address}`);
process.exit(0);
}
Expand Down
21 changes: 10 additions & 11 deletions src/bikes/flywheel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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});
}
}

Expand Down

0 comments on commit e0d7bd1

Please sign in to comment.