Skip to content

Commit

Permalink
Add failsafe, logging to getAvailableDevices()
Browse files Browse the repository at this point in the history
  • Loading branch information
JovannMC committed Jul 25, 2024
1 parent 28204b0 commit 63c3a45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/HaritoraX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,11 @@ export default class HaritoraX extends EventEmitter {
let com = new COM("wireless"); // variable doesn't matter, just need to initialize it to get the available devices
let bluetooth = new Bluetooth();

console.log("Checking if any COM devices is available")
if (await com.isDeviceAvailable()) {
log("COM devices available")
const devices = await com.getAvailableDevices();
log(`Got COM devices: ${devices}`);
// for each device, add the device name to the available devices
devices.forEach((device) => {
if (device === "HaritoraX 1.0" || device === "HaritoraX 1.1" || device === "HaritoraX 1.1b") {
Expand All @@ -790,7 +793,9 @@ export default class HaritoraX extends EventEmitter {
}
});
}
log("Checking if Bluetooth & HaritoraX Wireless are available")
if (await bluetooth.isDeviceAvailable()) {
log("Bluetooth & HaritoraX Wireless devices available")
availableDevices.push("Bluetooth");
availableDevices.push("HaritoraX Wireless");
}
Expand Down
5 changes: 5 additions & 0 deletions src/mode/bluetooth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ export default class Bluetooth extends EventEmitter {
resolve(false);
}
});

// Fail-safe if noble never initializes properly (no "stateChange" event fired)
setTimeout(() => {
resolve(false);
}, 3500);
});
}

Expand Down

0 comments on commit 63c3a45

Please sign in to comment.