Skip to content

Commit 60596fa

Browse files
committed
improve reset pin logic
1 parent 05b7a69 commit 60596fa

File tree

6 files changed

+27
-35
lines changed

6 files changed

+27
-35
lines changed

examples/NetworkConfiguratorDemo/NetworkConfiguratorDemo.ino

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@
1515
* At startup the NetworkConfigurator library reads the stored network settings from the storage
1616
* and loads them into the ConnectionHandler object.
1717
*
18-
* The NetworkConfigurator library provides a way for wiping out the stored network settings,
19-
* please read the documentation for more information.
18+
* The NetworkConfigurator library provides a way for wiping out the stored network settings.
19+
* Reconfiguration procedure:
20+
* - Arduino Opta: press and hold the user button (BTN_USER) until the led (LED_USER) turns off
21+
* - Arduino MKR WiFi 1010: short the pin 7 to GND until the led turns off
22+
* - Arduino GIGA R1 WiFi: short the pin 7 to GND until the led turns off
23+
* - Arduino Nano RP2040 Connect: short the pin 2 to 3.3V until the led turns off
24+
* - Other boards: short the pin 2 to GND until the led turns off
2025
*
2126
* In this sketch the BLE and Serial interfaces are always enabled and ready for accepting
2227
* a new set of configuration.

src/ANetworkConfigurator_Config.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
#if defined(ARDUINO_PORTENTA_H7_M7)
5959
#define NETWORK_CONFIGURATOR_COMPATIBLE 1
6060
#define ZERO_TOUCH_ENABLED 1
61-
#define PIN_RECONFIGURE 2 //TODO update doc and test
61+
#define PIN_RECONFIGURE 2
6262
#define LED_RECONFIGURE LED_BUILTIN
6363
#define BOARD_HAS_RGB
6464
#define GREEN_LED LEDG
@@ -84,8 +84,8 @@
8484

8585
#if defined(ARDUINO_GIGA)
8686
#define NETWORK_CONFIGURATOR_COMPATIBLE 1
87-
#define PIN_RECONFIGURE 2
88-
#define LED_RECONFIGURE LED_BUILTIN
87+
#define PIN_RECONFIGURE 7
88+
#define LED_RECONFIGURE LEDG
8989
#define BOARD_HAS_RGB
9090
#define GREEN_LED LEDG
9191
#define BLUE_LED LEDB
@@ -110,7 +110,7 @@
110110
#define NETWORK_CONFIGURATOR_COMPATIBLE 1
111111
#define ZERO_TOUCH_ENABLED 1
112112
#define PIN_RECONFIGURE 2
113-
#define LED_RECONFIGURE LED_BUILTIN
113+
#define LED_RECONFIGURE LEDG
114114
#define BOARD_HAS_RGB
115115
#define GREEN_LED LEDG
116116
#define BLUE_LED LEDB

src/NetworkConfigurator.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ NetworkConfiguratorStates NetworkConfiguratorClass::update() {
108108

109109
/* Reconfiguration procedure:
110110
* - Arduino Opta: press and hold the user button (BTN_USER) until the led (LED_USER) turns off
111-
* - Arduino Nano 33 IOT: short the pin 2 to GND until the led turns off
112-
* - Arduino Uno R4 WiFi: short the pin 2 to GND until the led turns off
111+
* - Arduino MKR WiFi 1010: short the pin 7 to GND until the led turns off
112+
* - Arduino GIGA R1 WiFi: short the pin 7 to GND until the led turns off
113113
* - Arduino Nano RP2040 Connect: short the pin 2 to 3.3V until the led turns off
114-
* - Other boards: short the pin 7 to GND until the led turns off
114+
* - Other boards: short the pin 2 to GND until the led turns off
115115
*/
116116

117117
if(_resetInput->isEventFired()) {
@@ -600,7 +600,7 @@ void NetworkConfiguratorClass::printNetworkSettings() {
600600
DEBUG_INFO("WIFI");
601601
DEBUG_INFO("SSID: %s", _networkSetting.wifi.ssid);
602602
#if DEBUG_NETWORK_CREDENTIALS
603-
DEBUG_INFO("PSW: %s", _networkSetting.wifi.ssid, _networkSetting.wifi.pwd);
603+
DEBUG_INFO("PSW: %s", _networkSetting.wifi.pwd);
604604
#endif
605605
break;
606606
#endif

src/NetworkConfigurator.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ enum class NetworkConfiguratorStates { ZERO_TOUCH_CONFIG,
4141
* the restart of the BLE interface if turned off.
4242
* Reconfiguration procedure:
4343
* - Arduino Opta: press and hold the user button (BTN_USER) until the led (LED_USER) turns off
44-
* - Arduino Nano 33 IOT: short the pin 2 to GND until the led turns off
45-
* - Arduino Uno R4 WiFi: short the pin 2 to GND until the led turns off
44+
* - Arduino MKR WiFi 1010: short the pin 7 to GND until the led turns off
45+
* - Arduino GIGA R1 WiFi: short the pin 7 to GND until the led turns off
4646
* - Arduino Nano RP2040 Connect: short the pin 2 to 3.3V until the led turns off
47-
* - Other boards: short the pin 7 to GND until the led turns off
47+
* - Other boards: short the pin 2 to GND until the led turns off
4848
*
4949
*/
5050
class NetworkConfiguratorClass {

src/Utility/ResetInput/ResetInput.cpp

+8-21
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ResetInput &ResetInput::getInstance() {
1919
ResetInput::ResetInput():
2020
_pin {PIN_RECONFIGURE}
2121
{
22-
_pressed = false;
22+
_expired = false;
2323
_startPressed = 0;
2424
_fireEvent = false;
2525
_pressedCustomCallback = nullptr;
@@ -32,21 +32,19 @@ void ResetInput::begin() {
3232
pinMode(PIN_RECONFIGURE, INPUT_PULLUP);
3333
#endif
3434
pinMode(LED_RECONFIGURE, OUTPUT);
35+
digitalWrite(LED_RECONFIGURE, LED_OFF);
3536

3637
attachInterrupt(digitalPinToInterrupt(PIN_RECONFIGURE),_pressedCallback, CHANGE);
3738
}
3839

3940
bool ResetInput::isEventFired() {
40-
if(_pressed){
41+
if(_startPressed != 0){
4142
#if defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_SAMD_MKRWIFI1010)
4243
LEDFeedbackClass::getInstance().stop();
4344
#endif
4445
if(micros() - _startPressed > RESET_HOLD_TIME){
45-
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_GIGA)
46-
digitalWrite(LED_RECONFIGURE, HIGH);
47-
#else
48-
digitalWrite(LED_RECONFIGURE, LOW);
49-
#endif
46+
digitalWrite(LED_RECONFIGURE, LED_OFF);
47+
_expired = true;
5048
}
5149
}
5250

@@ -71,21 +69,10 @@ void ResetInput::_pressedCallback() {
7169
LEDFeedbackClass::getInstance().stop();
7270
#endif
7371
_startPressed = micros();
74-
_pressed = true;
75-
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_GIGA)
76-
digitalWrite(LED_RECONFIGURE, LOW);
77-
#else
78-
digitalWrite(LED_RECONFIGURE, HIGH);
79-
#endif
72+
digitalWrite(LED_RECONFIGURE, LED_ON);
8073
} else {
81-
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_GIGA)
82-
digitalWrite(LED_RECONFIGURE, HIGH);
83-
#else
84-
digitalWrite(LED_RECONFIGURE, LOW);
85-
#endif
86-
87-
_pressed = false;
88-
if(_startPressed != 0 && micros() - _startPressed > RESET_HOLD_TIME){
74+
digitalWrite(LED_RECONFIGURE, LED_OFF);
75+
if(_startPressed != 0 && _expired){
8976
_fireEvent = true;
9077
}else{
9178
LEDFeedbackClass::getInstance().restart();

src/Utility/ResetInput/ResetInput.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ResetInput{
2727
ResetInput();
2828
static inline ResetInputCallback _pressedCustomCallback;
2929
uint32_t _pin;
30-
static inline volatile bool _pressed;
30+
static inline volatile bool _expired;
3131
static inline volatile bool _fireEvent;
3232
static inline volatile uint32_t _startPressed;
3333
static void _pressedCallback();

0 commit comments

Comments
 (0)