Skip to content

Commit

Permalink
Canned messages: allow GPIO0 with "scan and select" input (meshtastic…
Browse files Browse the repository at this point in the history
…#5838)

* Allow GPIO0; check for conflict with user button

* Guard for no BUTTON_PIN; handle portduino

* Portduino settings: attempt two
We don't really need to #include radio code here just to check if the pin is RADIOLIB_NC. We're only interested if scanAndSelect pin matches user button pin, but they won't match if user button is RADIOLIB_NC.

* Portduino attempt 3: glue
  • Loading branch information
todd-herbert authored Jan 16, 2025
1 parent 262f1d2 commit a48df91
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/input/ScanAndSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include "ScanAndSelect.h"
#include "modules/CannedMessageModule.h"
#include <Throttle.h>
#ifdef ARCH_PORTDUINO // Only to check for pin conflict with user button
#include "platform/portduino/PortduinoGlue.h"
#endif

// Config
static const char name[] = "scanAndSelect"; // should match "allow input source" string
Expand All @@ -30,15 +33,35 @@ bool ScanAndSelectInput::init()
if (strcasecmp(moduleConfig.canned_message.allow_input_source, name) != 0)
return false;

// Use any available inputbroker pin as the button
// Determine which pin to use for the single scan-and-select button
// User can specify this by setting any of the inputbroker pins
// If all values are zero, we'll assume the user *does* want GPIO0
if (moduleConfig.canned_message.inputbroker_pin_press)
pin = moduleConfig.canned_message.inputbroker_pin_press;
else if (moduleConfig.canned_message.inputbroker_pin_a)
pin = moduleConfig.canned_message.inputbroker_pin_a;
else if (moduleConfig.canned_message.inputbroker_pin_b)
pin = moduleConfig.canned_message.inputbroker_pin_b;
else
return false; // Short circuit: no button found
pin = 0; // GPIO 0 then

// Short circuit: if selected pin conficts with the user button
#if defined(ARCH_PORTDUINO)
int pinUserButton = 0;
if (settingsMap.count(user) != 0) {
pinUserButton = settingsMap[user];
}
#elif defined(USERPREFS_BUTTON_PIN)
int pinUserButton = config.device.button_gpio ? config.device.button_gpio : USERPREFS_BUTTON_PIN;
#elif defined(BUTTON_PIN)
int pinUserButton = config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN;
#else
int pinUserButton = config.device.button_gpio;
#endif
if (pin == pinUserButton) {
LOG_ERROR("ScanAndSelect conflict with user button");
return false;
}

// Set-up the button
pinMode(pin, INPUT_PULLUP);
Expand Down

0 comments on commit a48df91

Please sign in to comment.