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.
This commit is contained in:
Abász 2023-01-03 10:39:29 +01:00
parent 405bcab55a
commit 35303547e2
1 changed files with 11 additions and 7 deletions

View File

@ -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) {