Skip to content

New define for disabling the reset pin and the reset procedure #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/NetworkConfiguratorDemo/NetworkConfiguratorDemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ void setup() {
/* Add the interfaces that are enabled for configuring the network*/
NetworkConfigurator.addAgent(BLEAgent);
NetworkConfigurator.addAgent(SerialAgent);

//Uncomment this for disabling the reconfiguration pin and the reconfiguration procedure
//NetworkConfigurator.setReconfigurePin(DISABLE_PIN);

/* Uncomment and specify your preferred pin for changing the default reconfiguration pin
* The pin must be in the list of digital pins usable for interrupts.
* Please refer to the Arduino documentation for more details:
* https://docs.arduino.cc/language-reference/en/functions/external-interrupts/attachInterrupt/
*/
//NetworkConfigurator.setReconfigurePin(your_pin);

/* Add a custom callback function to be invoked every time the interrupt on reconfiguration pin is fired*/
NetworkConfigurator.addReconfigurePinCallback(onResetPinInterrupt);
/* Start the network configurator */
Expand Down
2 changes: 1 addition & 1 deletion src/Arduino_NetworkConfigurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void NetworkConfiguratorClass::setStorage(KVStore &kvstore) {
_kvstore = &kvstore;
}

void NetworkConfiguratorClass::setReconfigurePin(uint32_t pin) {
void NetworkConfiguratorClass::setReconfigurePin(int pin) {
_resetInput->setPin(pin);
}

Expand Down
7 changes: 6 additions & 1 deletion src/Arduino_NetworkConfigurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,15 @@ class NetworkConfiguratorClass {
/**
* @brief Sets the pin used for the reconfiguration procedure.
* This must be set before calling the begin() method.
* Use the value DISABLE_PIN to disable the reset pin and
* the reset procedure.
* @param pin The pin number to be used for reconfiguration,
* internally it's mapped to an interrupt with INPUT_PULLUP mode.
* The pin must be in the list of digital pins usable for interrupts.
* Please refer to the Arduino documentation for more details:
* https://docs.arduino.cc/language-reference/en/functions/external-interrupts/attachInterrupt/
*/
void setReconfigurePin(uint32_t pin);
void setReconfigurePin(int pin);

/**
* @brief Adds a callback function to be triggered every time the
Expand Down
36 changes: 21 additions & 15 deletions src/Utility/ResetInput/ResetInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,27 @@ ResetInput &ResetInput::getInstance() {
return instance;
}

ResetInput::ResetInput():
_pin {PIN_RECONFIGURE}
{
_expired = false;
_startPressed = 0;
_fireEvent = false;
_pressedCustomCallback = nullptr;
}
ResetInput::ResetInput() {
_pin = PIN_RECONFIGURE;
_expired = false;
_startPressed = 0;
_fireEvent = false;
_pressedCustomCallback = nullptr;
}

void ResetInput::begin() {
if(_pin == DISABLE_PIN){
return;
}
#ifdef ARDUINO_OPTA
pinMode(PIN_RECONFIGURE, INPUT);
pinMode(_pin, INPUT);
#else
pinMode(PIN_RECONFIGURE, INPUT_PULLUP);
pinMode(_pin, INPUT_PULLUP);
#endif
pinMode(LED_RECONFIGURE, OUTPUT);
digitalWrite(LED_RECONFIGURE, LED_OFF);

attachInterrupt(digitalPinToInterrupt(PIN_RECONFIGURE),_pressedCallback, CHANGE);
attachInterrupt(digitalPinToInterrupt(_pin),_pressedCallback, CHANGE);
}

bool ResetInput::isEventFired() {
Expand All @@ -55,15 +57,19 @@ void ResetInput::setPinChangedCallback(ResetInputCallback callback) {
_pressedCustomCallback = callback;
}

void ResetInput::setPin(uint32_t pin) {
_pin = pin;
void ResetInput::setPin(int pin) {
if(pin < 0){
_pin = DISABLE_PIN;
}else {
_pin = pin;
}
}

void ResetInput::_pressedCallback() {
#if defined(ARDUINO_NANO_RP2040_CONNECT)
if(digitalRead(PIN_RECONFIGURE) == HIGH){
if(digitalRead(_pin) == HIGH){
#else
if(digitalRead(PIN_RECONFIGURE) == LOW){
if(digitalRead(_pin) == LOW){
#endif
#if !defined(ARDUINO_NANO_RP2040_CONNECT) && !defined(ARDUINO_SAMD_MKRWIFI1010)
LEDFeedbackClass::getInstance().stop();
Expand Down
12 changes: 9 additions & 3 deletions src/Utility/ResetInput/ResetInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "Arduino.h"
#include <functional>

#define DISABLE_PIN -1

/**
* @class ResetInput
* @brief A singleton class to handle input of the reset functionality with interrupt-based monitoring.
Expand Down Expand Up @@ -48,17 +50,21 @@ class ResetInput{
/**
* @brief Set the pin to be monitored for reset events.
* By default, the pin is set as INPUT_PULLUP.
* Use the value DISABLE_PIN to disable the pin and the reset procedure.
* This function must be called before invoking the `begin` method.
* @param pin The pin number to be monitored.
* @param pin The pin number to be monitored. The pin must
* be in the list of digital pins usable for interrupts.
* Please refer to the Arduino documentation for more details:
* https://docs.arduino.cc/language-reference/en/functions/external-interrupts/attachInterrupt/
*/
void setPin(uint32_t pin);
void setPin(int pin);
private:
/**
* @brief Private constructor to enforce the singleton pattern.
*/
ResetInput();
static inline ResetInputCallback _pressedCustomCallback;
uint32_t _pin;
static inline int _pin;
static inline volatile bool _expired;
static inline volatile bool _fireEvent;
static inline volatile uint32_t _startPressed;
Expand Down
Loading