From 31bcb2ae0aae69becbf88989dc33fbd2be952099 Mon Sep 17 00:00:00 2001 From: uyseali <111198793+uyseali@users.noreply.github.com> Date: Sun, 18 Oct 2026 23:38:28 +0000 Subject: [PATCH] Fix RF95 optional pins and CannedMessage initialization (#11913) * Fix RF95 optional pins and CannedMessage initialization * style: clang-format CannedMessageModule else branch --------- Co-authored-by: Tom <116762865+NomDeTom@users.noreply.github.com> Co-authored-by: caveman99 Co-authored-by: Jonathan Bennett --- src/mesh/RF95Interface.cpp | 16 ++++++++-------- src/modules/CannedMessageModule.cpp | 17 ++++++++++++----- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/mesh/RF95Interface.cpp b/src/mesh/RF95Interface.cpp index e7a8b72331..8ebc5829a9 100644 --- a/src/mesh/RF95Interface.cpp +++ b/src/mesh/RF95Interface.cpp @@ -91,7 +91,7 @@ RF95Interface::RF95Interface(LockingArduinoHal *hal, RADIOLIB_PIN_TYPE cs, RADIO /** Some boards require GPIO control of tx vs rx paths */ void RF95Interface::setTransmitEnable(bool txon) { -#ifdef RF95_TXEN +#if defined(RF95_TXEN) && (RF95_TXEN != RADIOLIB_NC) digitalWrite(RF95_TXEN, txon ? 1 : 0); #elif ARCH_PORTDUINO if (portduino_config.lora_txen_pin.pin != RADIOLIB_NC) { @@ -99,7 +99,7 @@ void RF95Interface::setTransmitEnable(bool txon) } #endif -#ifdef RF95_RXEN +#if defined(RF95_RXEN) && (RF95_RXEN != RADIOLIB_NC) digitalWrite(RF95_RXEN, txon ? 0 : 1); #elif ARCH_PORTDUINO if (portduino_config.lora_rxen_pin.pin != RADIOLIB_NC) { @@ -113,7 +113,7 @@ void RF95Interface::setTransmitEnable(bool txon) /// \return true if initialisation succeeded. bool RF95Interface::init() { -#ifdef RF95_POWER_EN +#if defined(RF95_POWER_EN) && (RF95_POWER_EN != RADIOLIB_NC) pinMode(RF95_POWER_EN, OUTPUT); digitalWrite(RF95_POWER_EN, HIGH); #endif @@ -153,17 +153,17 @@ bool RF95Interface::init() #define RF95_RXEN (23) // If defined, this pin should be set high prior to receive (controls an external analog switch) */ -#ifdef RF95_TXEN +#if defined(RF95_TXEN) && (RF95_TXEN != RADIOLIB_NC) pinMode(RF95_TXEN, OUTPUT); digitalWrite(RF95_TXEN, 0); #endif -#ifdef RF95_FAN_EN +#if defined(RF95_FAN_EN) && (RF95_FAN_EN != RADIOLIB_NC) pinMode(RF95_FAN_EN, OUTPUT); digitalWrite(RF95_FAN_EN, 1); #endif -#ifdef RF95_RXEN +#if defined(RF95_RXEN) && (RF95_RXEN != RADIOLIB_NC) pinMode(RF95_RXEN, OUTPUT); digitalWrite(RF95_RXEN, 1); #endif @@ -420,11 +420,11 @@ bool RF95Interface::sleep() (void)trySetStandby(); // First cancel any active receiving/sending - going to sleep, a failure must not crash lora->sleep(); -#ifdef RF95_POWER_EN +#if defined(RF95_POWER_EN) && (RF95_POWER_EN != RADIOLIB_NC) digitalWrite(RF95_POWER_EN, LOW); #endif -#ifdef RF95_FAN_EN +#if defined(RF95_FAN_EN) && (RF95_FAN_EN != RADIOLIB_NC) digitalWrite(RF95_FAN_EN, 0); #endif diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index 634e1ee0a5..b2bd5073dd 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -74,6 +74,10 @@ CannedMessageModule::CannedMessageModule() LOG_INFO("CannedMessage: none configured, disabled"); this->updateState(CANNED_MESSAGE_RUN_STATE_DISABLED); disable(); + } else if (!inputBroker) { + LOG_INFO("CannedMessage: no InputBroker, disabled"); + this->updateState(CANNED_MESSAGE_RUN_STATE_DISABLED); + disable(); } else { LOG_INFO("CannedMessageModule is enabled"); moduleConfig.canned_message.enabled = true; @@ -544,12 +548,15 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event) void CannedMessageModule::updateState(cannedMessageModuleRunState newState, bool shouldRequestFocus) { runState = newState; - if (runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) { - inputBroker->menuMode = - false; // Allow any key input to be sent to the message composer instead of being interpreted as menu navigation - } else { - inputBroker->menuMode = true; // Re-enable menu navigation for destination selection + if (inputBroker) { + if (runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) { + inputBroker->menuMode = + false; // Allow any key input to be sent to the message composer instead of being interpreted as menu navigation + } else { + inputBroker->menuMode = true; // Re-enable menu navigation for destination selection + } } + if (shouldRequestFocus) { requestFocus(); }