diff --git a/src/Observer.h b/src/Observer.h index 555dcd1e9..6e1ec44c8 100644 --- a/src/Observer.h +++ b/src/Observer.h @@ -10,12 +10,12 @@ template class Observable; */ template class Observer { - std::list *> observed; + std::list *> observables; public: virtual ~Observer(); - /// Stop watching the obserable + /// Stop watching the observable void unobserve(Observable *o); /// Start watching a specified observable @@ -86,21 +86,21 @@ template class Observable template Observer::~Observer() { - for (typename std::list *>::const_iterator iterator = observed.begin(); iterator != observed.end(); + for (typename std::list *>::const_iterator iterator = observables.begin(); iterator != observables.end(); ++iterator) { (*iterator)->removeObserver(this); } - observed.clear(); + observables.clear(); } template void Observer::unobserve(Observable *o) { o->removeObserver(this); - observed.remove(o); + observables.remove(o); } template void Observer::observe(Observable *o) { - observed.push_back(o); + observables.push_back(o); o->addObserver(this); -} +} \ No newline at end of file diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 9101712d1..db0dd88ec 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -108,8 +108,9 @@ void MeshService::loop() (void)sendQueueStatusToPhone(qs, 0, 0); } if (oldFromNum != fromNum) { // We don't want to generate extra notifies for multiple new packets - fromNumChanged.notifyObservers(fromNum); - oldFromNum = fromNum; + int result = fromNumChanged.notifyObservers(fromNum); + if (result == 0) // If any observer returns non-zero, we will try again + oldFromNum = fromNum; } } diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index 10e8ac2dc..270bf613f 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -62,15 +62,17 @@ void PhoneAPI::close() } } -void PhoneAPI::checkConnectionTimeout() +bool PhoneAPI::checkConnectionTimeout() { if (isConnected()) { bool newContact = checkIsConnected(); if (!newContact) { LOG_INFO("Lost phone connection\n"); close(); + return true; } } + return false; } /** @@ -461,8 +463,8 @@ bool PhoneAPI::handleToRadioPacket(meshtastic_MeshPacket &p) /// If the mesh service tells us fromNum has changed, tell the phone int PhoneAPI::onNotify(uint32_t newValue) { - checkConnectionTimeout(); // a handy place to check if we've heard from the phone (since the BLE version doesn't call this - // from idle) + bool timeout = checkConnectionTimeout(); // a handy place to check if we've heard from the phone (since the BLE version + // doesn't call this from idle) if (state == STATE_SEND_PACKETS) { LOG_INFO("Telling client we have new packets %u\n", newValue); @@ -471,5 +473,5 @@ int PhoneAPI::onNotify(uint32_t newValue) LOG_DEBUG("(Client not yet interested in packets)\n"); } - return 0; + return timeout ? -1 : 0; // If we timed out, MeshService should stop iterating through observers as we just removed one } \ No newline at end of file diff --git a/src/mesh/PhoneAPI.h b/src/mesh/PhoneAPI.h index 65a06bc6b..450649d7b 100644 --- a/src/mesh/PhoneAPI.h +++ b/src/mesh/PhoneAPI.h @@ -108,8 +108,8 @@ class PhoneAPI /// Hookable to find out when connection changes virtual void onConnectionChanged(bool connected) {} - /// If we haven't heard from the other side in a while then say not connected - void checkConnectionTimeout(); + /// If we haven't heard from the other side in a while then say not connected. Returns true if timeout occurred + bool checkConnectionTimeout(); /// Check the current underlying physical link to see if the client is currently connected virtual bool checkIsConnected() = 0; @@ -142,4 +142,4 @@ class PhoneAPI /// If the mesh service tells us fromNum has changed, tell the phone virtual int onNotify(uint32_t newValue) override; -}; +}; \ No newline at end of file diff --git a/variants/rak11310/platformio.ini b/variants/rak11310/platformio.ini index a69b18c1a..6495278bf 100644 --- a/variants/rak11310/platformio.ini +++ b/variants/rak11310/platformio.ini @@ -10,4 +10,6 @@ build_flags = ${rp2040_base.build_flags} -DDEBUG_RP2040_PORT=Serial -L "${platformio.libdeps_dir}/${this.__env__}/BSEC2 Software Library/src/cortex-m0plus" lib_deps = - ${rp2040_base.lib_deps} \ No newline at end of file + ${rp2040_base.lib_deps} +debug_build_flags = ${rp2040_base.build_flags} +debug_tool = cmsis-dap ; for e.g. Picotool \ No newline at end of file diff --git a/variants/rpipico/platformio.ini b/variants/rpipico/platformio.ini index 727a1cab6..9537694ec 100644 --- a/variants/rpipico/platformio.ini +++ b/variants/rpipico/platformio.ini @@ -11,4 +11,6 @@ build_flags = ${rp2040_base.build_flags} -DHW_SPI1_DEVICE -L "${platformio.libdeps_dir}/${this.__env__}/BSEC2 Software Library/src/cortex-m0plus" lib_deps = - ${rp2040_base.lib_deps} \ No newline at end of file + ${rp2040_base.lib_deps} +debug_build_flags = ${rp2040_base.build_flags} +debug_tool = cmsis-dap ; for e.g. Picotool \ No newline at end of file diff --git a/variants/rpipicow/platformio.ini b/variants/rpipicow/platformio.ini index 4c8cf992d..29b5c8bcb 100644 --- a/variants/rpipicow/platformio.ini +++ b/variants/rpipicow/platformio.ini @@ -14,4 +14,6 @@ build_flags = ${rp2040_base.build_flags} build_src_filter = ${rp2040_base.build_src_filter} + lib_deps = ${rp2040_base.lib_deps} - ${networking_base.lib_deps} \ No newline at end of file + ${networking_base.lib_deps} +debug_build_flags = ${rp2040_base.build_flags} +debug_tool = cmsis-dap ; for e.g. Picotool \ No newline at end of file