From 966a867d6082990f0bfba0743f55442ec6dd0aad Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Fri, 13 Jan 2023 13:32:28 +0100 Subject: [PATCH] android - Combine connection handler methods --- apps/android/boot.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/apps/android/boot.js b/apps/android/boot.js index 1d3ef7e3a..2b430b9dc 100644 --- a/apps/android/boot.js +++ b/apps/android/boot.js @@ -178,7 +178,7 @@ },options.timeout||30000)}; }); return promise; - } + }; // Battery monitor function sendBattery() { gbSend({ t: "status", bat: E.getBattery(), chg: Bangle.isCharging()?1:0 }); } @@ -209,20 +209,16 @@ if (settings.overwriteGps) { // if the overwrite option is set../ const origSetGPSPower = Bangle.setGPSPower; // migrate all GPS clients to the other variant on connection events - let handleConnect = () => { - let orig = Bangle._PWR.GPS; - delete Bangle._PWR.GPS; - origSetGPSPower(0); - Bangle._PWR.GPS = orig; + let handleConnection = (state) => { + if (Bangle.isGPSOn()){ + let orig = Bangle._PWR.GPS; + delete Bangle._PWR.GPS; + origSetGPSPower(state); + Bangle._PWR.GPS = orig; + } }; - let handleDisconnect = () => { - let orig = Bangle._PWR.GPS; - delete Bangle._PWR.GPS; - origSetGPSPower(1); - Bangle._PWR.GPS = orig; - }; - NRF.on('connect', handleConnect); - NRF.on('disconnect', handleDisconnect); + NRF.on('connect', ()=>{handleConnection(1);}); + NRF.on('disconnect', ()=>{handleConnection(0);}); // Work around Serial1 for GPS not working when connected to something //