From d32cdecc06b973d58f87eb34f75399774592a0ce Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 22 Jun 2024 07:00:48 -0500 Subject: [PATCH] Pause BLE logging during want_config flow (#4162) --- src/RedirectablePrint.cpp | 2 +- src/main.cpp | 1 + src/main.h | 2 ++ src/mesh/PhoneAPI.cpp | 4 ++++ src/mesh/PhoneAPI.h | 2 -- 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/RedirectablePrint.cpp b/src/RedirectablePrint.cpp index 2110761ffc..b77720d85d 100644 --- a/src/RedirectablePrint.cpp +++ b/src/RedirectablePrint.cpp @@ -169,7 +169,7 @@ size_t RedirectablePrint::log(const char *logLevel, const char *format, ...) isContinuationMessage = !hasNewline; - if (config.bluetooth.device_logging_enabled) { + if (config.bluetooth.device_logging_enabled && !pauseBluetoothLogging) { bool isBleConnected = false; #ifdef ARCH_ESP32 isBleConnected = nimbleBluetooth && nimbleBluetooth->isActive() && nimbleBluetooth->isConnected(); diff --git a/src/main.cpp b/src/main.cpp index 725e3499db..9ec4fa82de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -154,6 +154,7 @@ bool isVibrating = false; bool eink_found = true; uint32_t serialSinceMsec; +bool pauseBluetoothLogging = false; bool pmu_found; diff --git a/src/main.h b/src/main.h index 2ef7edb3a9..ea2d80f94a 100644 --- a/src/main.h +++ b/src/main.h @@ -85,6 +85,8 @@ extern uint32_t serialSinceMsec; // This will suppress the current delay and instead try to run ASAP. extern bool runASAP; +extern bool pauseBluetoothLogging; + void nrf52Setup(), esp32Setup(), nrf52Loop(), esp32Loop(), rp2040Setup(), clearBonds(), enterDfuMode(); meshtastic_DeviceMetadata getDeviceMetadata(); diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index 26d0d9525a..404666877c 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -46,6 +46,7 @@ void PhoneAPI::handleStartConfig() // even if we were already connected - restart our state machine state = STATE_SEND_MY_INFO; + pauseBluetoothLogging = true; LOG_INFO("Starting API client config\n"); nodeInfoForPhone.num = 0; // Don't keep returning old nodeinfos @@ -352,9 +353,11 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf) fromRadioScratch.config_complete_id = config_nonce; config_nonce = 0; state = STATE_SEND_PACKETS; + pauseBluetoothLogging = false; break; case STATE_SEND_PACKETS: + pauseBluetoothLogging = false; // Do we have a message from the mesh or packet from the local device? LOG_INFO("getFromRadio=STATE_SEND_PACKETS\n"); if (queueStatusPacketForPhone) { @@ -398,6 +401,7 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf) void PhoneAPI::handleDisconnect() { + pauseBluetoothLogging = false; LOG_INFO("PhoneAPI disconnect\n"); } diff --git a/src/mesh/PhoneAPI.h b/src/mesh/PhoneAPI.h index 49bf0e292b..668f9c1f3c 100644 --- a/src/mesh/PhoneAPI.h +++ b/src/mesh/PhoneAPI.h @@ -98,8 +98,6 @@ class PhoneAPI bool isConnected() { return state != STATE_SEND_NOTHING; } - void setInitialState() { state = STATE_SEND_MY_INFO; } - protected: /// Our fromradio packet while it is being assembled meshtastic_FromRadio fromRadioScratch = {};