From 35303547e2f633ff78e88b2bf625b1cc2e53fe57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ab=C3=A1sz?= <> Date: Tue, 3 Jan 2023 10:39:29 +0100 Subject: [PATCH] Fix error on simultaneous ANT peripheral startup Move the peripheral startup sequence to an async function to ensure proper startup order and to avoid multiple simultaneous calls to the ANT stick causing app crash. --- app/peripherals/PeripheralManager.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/peripherals/PeripheralManager.js b/app/peripherals/PeripheralManager.js index 1563c6c..349863a 100644 --- a/app/peripherals/PeripheralManager.js +++ b/app/peripherals/PeripheralManager.js @@ -34,9 +34,13 @@ function createPeripheralManager () { let isPeripheralChangeInProgress = false - createBlePeripheral(config.bluetoothMode) - createHrmPeripheral(config.heartRateMode) - createAntPeripheral(config.antplusMode) + setupPeripherals() + + async function setupPeripherals () { + await createBlePeripheral(config.bluetoothMode) + await createHrmPeripheral(config.heartRateMode) + await createAntPeripheral(config.antplusMode) + } function getBlePeripheral () { return blePeripheral @@ -74,13 +78,13 @@ function createPeripheralManager () { } function notifyMetrics (type, metrics) { - if (bleMode !== 'OFF') { blePeripheral.notifyData(type, metrics) } - if (antMode !== 'OFF') { antPeripheral.notifyData(type, metrics) } + if (bleMode !== 'OFF') { blePeripheral?.notifyData(type, metrics) } + if (antMode !== 'OFF') { antPeripheral?.notifyData(type, metrics) } } function notifyStatus (status) { - if (bleMode !== 'OFF') { blePeripheral.notifyStatus(status) } - if (antMode !== 'OFF') { antPeripheral.notifyStatus(status) } + if (bleMode !== 'OFF') { blePeripheral?.notifyStatus(status) } + if (antMode !== 'OFF') { antPeripheral?.notifyStatus(status) } } async function createBlePeripheral (newMode) {