Skip to content

Commit

Permalink
refactor(bluetooth): add more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mKeRix committed Nov 1, 2020
1 parent 22cc010 commit a7b61aa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ export class BluetoothLowEnergyService
this.companionAppTags.set(tag.id, null);

try {
this.logger.log(`Attempting app discovery for tag ${tag.id}`);
const appId = await this.discoverCompanionAppId(tag);
this.companionAppTags.set(tag.id, appId);

Expand Down
12 changes: 12 additions & 0 deletions src/integrations/bluetooth/bluetooth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,17 @@ export class BluetoothService {
* @param adapterId - HCI Device ID of the adapter to lock
*/
lockAdapter(adapterId: number): void {
this.logger.debug(`Locking adapter ${adapterId}`);

switch (this.adapterStates.get(adapterId)) {
case 'inquiry':
throw new Error(
`Trying to lock adapter ${adapterId} even though it is already locked`
);
case 'scan':
this.logger.debug(
`Stop scanning for BLE peripherals on adapter ${this.lowEnergyAdapterId}`
);
noble.stopScanning();
}

Expand All @@ -232,6 +237,7 @@ export class BluetoothService {
* @param adapterId - HCI Device ID of the adapter to unlock
*/
async unlockAdapter(adapterId: number): Promise<void> {
this.logger.debug(`Unlocking adapter ${adapterId}`);
this.adapterStates.set(adapterId, 'inactive');

if (adapterId == this.lowEnergyAdapterId) {
Expand Down Expand Up @@ -263,9 +269,15 @@ export class BluetoothService {
private async handleAdapterStateChange(state: string): Promise<void> {
if (this.adapterStates.get(this.lowEnergyAdapterId) != 'inquiry') {
if (state === 'poweredOn') {
this.logger.debug(
`Start scanning for BLE peripherals on adapter ${this.lowEnergyAdapterId}`
);
await noble.startScanningAsync([], true);
this.adapterStates.set(this.lowEnergyAdapterId, 'scan');
} else {
this.logger.debug(
`Stop scanning for BLE peripherals on adapter ${this.lowEnergyAdapterId}`
);
await noble.stopScanning();
this.adapterStates.set(this.lowEnergyAdapterId, 'inactive');
}
Expand Down

0 comments on commit a7b61aa

Please sign in to comment.