diff --git a/examples/NetworkConfiguratorDemo/NetworkConfiguratorDemo.ino b/examples/NetworkConfiguratorDemo/NetworkConfiguratorDemo.ino index e0ee949..d832a2a 100644 --- a/examples/NetworkConfiguratorDemo/NetworkConfiguratorDemo.ino +++ b/examples/NetworkConfiguratorDemo/NetworkConfiguratorDemo.ino @@ -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 */ diff --git a/src/Arduino_NetworkConfigurator.cpp b/src/Arduino_NetworkConfigurator.cpp index 25e583f..8983d91 100644 --- a/src/Arduino_NetworkConfigurator.cpp +++ b/src/Arduino_NetworkConfigurator.cpp @@ -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); } diff --git a/src/Arduino_NetworkConfigurator.h b/src/Arduino_NetworkConfigurator.h index 2e8cfe2..781dc47 100644 --- a/src/Arduino_NetworkConfigurator.h +++ b/src/Arduino_NetworkConfigurator.h @@ -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 diff --git a/src/Utility/ResetInput/ResetInput.cpp b/src/Utility/ResetInput/ResetInput.cpp index b8751b8..ddfc1f2 100644 --- a/src/Utility/ResetInput/ResetInput.cpp +++ b/src/Utility/ResetInput/ResetInput.cpp @@ -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() { @@ -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(); diff --git a/src/Utility/ResetInput/ResetInput.h b/src/Utility/ResetInput/ResetInput.h index 8608168..a9700ee 100644 --- a/src/Utility/ResetInput/ResetInput.h +++ b/src/Utility/ResetInput/ResetInput.h @@ -11,6 +11,8 @@ #include "Arduino.h" #include +#define DISABLE_PIN -1 + /** * @class ResetInput * @brief A singleton class to handle input of the reset functionality with interrupt-based monitoring. @@ -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;