From ac611c4b6262ae54336317c9e4167827ba6edd78 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Wed, 4 Feb 2026 14:47:44 -0600 Subject: [PATCH] Add agc reset attempt (#8163) * Add agc reset attempt * Add radioLibInterface include * Trunk * AGC reset don't crash, don't naively call * Update src/main.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Use Throttle function --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/main.cpp | 9 +++++++++ src/main.h | 1 + src/mesh/RadioLibInterface.cpp | 2 ++ 3 files changed, 12 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 1e0ec041e..08b6707fb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,6 +7,7 @@ #include "NodeDB.h" #include "PowerFSM.h" #include "PowerMon.h" +#include "RadioLibInterface.h" #include "ReliableRouter.h" #include "airtime.h" #include "buzz.h" @@ -193,6 +194,8 @@ bool kb_found = false; // global bool to record that on-screen keyboard (OSK) is present bool osk_found = false; +unsigned long last_listen = 0; + // The I2C address of the RTC Module (if found) ScanI2C::DeviceAddress rtc_found = ScanI2C::ADDRESS_NONE; // The I2C address of the Accelerometer (if found) @@ -1166,6 +1169,12 @@ void loop() #endif power->powerCommandsCheck(); + if (RadioLibInterface::instance != nullptr && !Throttle::isWithinTimespanMs(last_listen, 1000 * 60) && + !(RadioLibInterface::instance->isSending() || RadioLibInterface::instance->isActivelyReceiving())) { + RadioLibInterface::instance->startReceive(); + LOG_DEBUG("attempting AGC reset"); + } + #ifdef DEBUG_STACK static uint32_t lastPrint = 0; if (!Throttle::isWithinTimespanMs(lastPrint, 10 * 1000L)) { diff --git a/src/main.h b/src/main.h index 91e27951f..619eb184e 100644 --- a/src/main.h +++ b/src/main.h @@ -33,6 +33,7 @@ extern ScanI2C::DeviceAddress cardkb_found; extern uint8_t kb_model; extern bool kb_found; extern bool osk_found; +extern unsigned long last_listen; extern ScanI2C::DeviceAddress rtc_found; extern ScanI2C::DeviceAddress accelerometer_found; extern ScanI2C::FoundDevice rgb_found; diff --git a/src/mesh/RadioLibInterface.cpp b/src/mesh/RadioLibInterface.cpp index 80e51b8bc..6716109b6 100644 --- a/src/mesh/RadioLibInterface.cpp +++ b/src/mesh/RadioLibInterface.cpp @@ -514,6 +514,8 @@ void RadioLibInterface::handleReceiveInterrupt() void RadioLibInterface::startReceive() { + // Note the updated timestamp, to avoid unneeded AGC resets + last_listen = millis(); isReceiving = true; powerMon->setState(meshtastic_PowerMon_State_Lora_RXOn); }