Skip to content

Commit 82cda71

Browse files
committed
add reset pin disable define
1 parent 65cd57a commit 82cda71

File tree

4 files changed

+37
-20
lines changed

4 files changed

+37
-20
lines changed

src/Arduino_NetworkConfigurator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ void NetworkConfiguratorClass::setStorage(KVStore &kvstore) {
201201
_kvstore = &kvstore;
202202
}
203203

204-
void NetworkConfiguratorClass::setReconfigurePin(uint32_t pin) {
204+
void NetworkConfiguratorClass::setReconfigurePin(int pin) {
205205
_resetInput->setPin(pin);
206206
}
207207

src/Arduino_NetworkConfigurator.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,15 @@ class NetworkConfiguratorClass {
112112
/**
113113
* @brief Sets the pin used for the reconfiguration procedure.
114114
* This must be set before calling the begin() method.
115+
* Use the value DISABLE_PIN to disable the reset pin and
116+
* the reset procedure.
115117
* @param pin The pin number to be used for reconfiguration,
116118
* internally it's mapped to an interrupt with INPUT_PULLUP mode.
119+
* The pin must be in the list of digital pins usable for interrupts.
120+
* Please refer to the Arduino documentation for more details:
121+
* https://docs.arduino.cc/language-reference/en/functions/external-interrupts/attachInterrupt/
117122
*/
118-
void setReconfigurePin(uint32_t pin);
123+
void setReconfigurePin(int pin);
119124

120125
/**
121126
* @brief Adds a callback function to be triggered every time the

src/Utility/ResetInput/ResetInput.cpp

+21-15
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,27 @@ ResetInput &ResetInput::getInstance() {
1616
return instance;
1717
}
1818

19-
ResetInput::ResetInput():
20-
_pin {PIN_RECONFIGURE}
21-
{
22-
_expired = false;
23-
_startPressed = 0;
24-
_fireEvent = false;
25-
_pressedCustomCallback = nullptr;
26-
}
19+
ResetInput::ResetInput() {
20+
_pin = PIN_RECONFIGURE;
21+
_expired = false;
22+
_startPressed = 0;
23+
_fireEvent = false;
24+
_pressedCustomCallback = nullptr;
25+
}
2726

2827
void ResetInput::begin() {
28+
if(_pin == DISABLE_PIN){
29+
return;
30+
}
2931
#ifdef ARDUINO_OPTA
30-
pinMode(PIN_RECONFIGURE, INPUT);
32+
pinMode(_pin, INPUT);
3133
#else
32-
pinMode(PIN_RECONFIGURE, INPUT_PULLUP);
34+
pinMode(_pin, INPUT_PULLUP);
3335
#endif
3436
pinMode(LED_RECONFIGURE, OUTPUT);
3537
digitalWrite(LED_RECONFIGURE, LED_OFF);
3638

37-
attachInterrupt(digitalPinToInterrupt(PIN_RECONFIGURE),_pressedCallback, CHANGE);
39+
attachInterrupt(digitalPinToInterrupt(_pin),_pressedCallback, CHANGE);
3840
}
3941

4042
bool ResetInput::isEventFired() {
@@ -55,15 +57,19 @@ void ResetInput::setPinChangedCallback(ResetInputCallback callback) {
5557
_pressedCustomCallback = callback;
5658
}
5759

58-
void ResetInput::setPin(uint32_t pin) {
59-
_pin = pin;
60+
void ResetInput::setPin(int pin) {
61+
if(pin < 0){
62+
_pin = DISABLE_PIN;
63+
}else {
64+
_pin = pin;
65+
}
6066
}
6167

6268
void ResetInput::_pressedCallback() {
6369
#if defined(ARDUINO_NANO_RP2040_CONNECT)
64-
if(digitalRead(PIN_RECONFIGURE) == HIGH){
70+
if(digitalRead(_pin) == HIGH){
6571
#else
66-
if(digitalRead(PIN_RECONFIGURE) == LOW){
72+
if(digitalRead(_pin) == LOW){
6773
#endif
6874
#if !defined(ARDUINO_NANO_RP2040_CONNECT) && !defined(ARDUINO_SAMD_MKRWIFI1010)
6975
LEDFeedbackClass::getInstance().stop();

src/Utility/ResetInput/ResetInput.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "Arduino.h"
1212
#include <functional>
1313

14+
#define DISABLE_PIN -1
15+
1416
/**
1517
* @class ResetInput
1618
* @brief A singleton class to handle input of the reset functionality with interrupt-based monitoring.
@@ -48,17 +50,21 @@ class ResetInput{
4850
/**
4951
* @brief Set the pin to be monitored for reset events.
5052
* By default, the pin is set as INPUT_PULLUP.
53+
* Use the value DISABLE_PIN to disable the pin and the reset procedure.
5154
* This function must be called before invoking the `begin` method.
52-
* @param pin The pin number to be monitored.
55+
* @param pin The pin number to be monitored. The pin must
56+
* be in the list of digital pins usable for interrupts.
57+
* Please refer to the Arduino documentation for more details:
58+
* https://docs.arduino.cc/language-reference/en/functions/external-interrupts/attachInterrupt/
5359
*/
54-
void setPin(uint32_t pin);
60+
void setPin(int pin);
5561
private:
5662
/**
5763
* @brief Private constructor to enforce the singleton pattern.
5864
*/
5965
ResetInput();
6066
static inline ResetInputCallback _pressedCustomCallback;
61-
uint32_t _pin;
67+
static inline int _pin;
6268
static inline volatile bool _expired;
6369
static inline volatile bool _fireEvent;
6470
static inline volatile uint32_t _startPressed;

0 commit comments

Comments
 (0)