From f6f964bfbd5cf25845379d2f72c1b6b6d37c6b71 Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Fri, 6 Sep 2019 14:59:03 +0900 Subject: [PATCH] Fixed encounter the endless loop --- examples/ConfigIP/ConfigIP.ino | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/examples/ConfigIP/ConfigIP.ino b/examples/ConfigIP/ConfigIP.ino index 7dc57e7..9e1fd1f 100644 --- a/examples/ConfigIP/ConfigIP.ino +++ b/examples/ConfigIP/ConfigIP.ino @@ -20,7 +20,7 @@ | | 1K ~ 10K +-+ | - +--> D2 + +--> D2 (for ESP8266, ex: GPIO16 in case of ESP32) | | O --+ @@ -33,9 +33,11 @@ #if defined(ARDUINO_ARCH_ESP8266) #include #include +#define EXTERNAL_SWITCH_PIN D2 #elif defined(ARDUINO_ARCH_ESP32) #include #include +#define EXTERNAL_SWITCH_PIN 16 #endif #include #include @@ -152,7 +154,7 @@ AutoConnectAux auxIPConfig; AutoConnectAux auxRestart; // Pin assignment for an external configuration switch -uint8_t ConfigPin = D2; +uint8_t ConfigPin = EXTERNAL_SWITCH_PIN; uint8_t ActiveLevel = LOW; // EEPROM saving structure @@ -220,7 +222,7 @@ String getConfig(AutoConnectAux& aux, PageArgument& args) { WiFi.macAddress(mac); for (uint8_t i = 0; i < 6; i++) { char buf[3]; - sprintf(buf, "%02x", mac[i]); + sprintf(buf, "%02X", mac[i]); macAddress += buf; if (i < 5) macAddress += ':'; @@ -243,11 +245,11 @@ String getConfig(AutoConnectAux& aux, PageArgument& args) { } // Convert IP address from AutoConnectInput string value -void getIPAddress(AutoConnectInput& input, uint32_t* ip) { +void getIPAddress(String ipString, uint32_t* ip) { IPAddress ipAddress; - if (input.length()) - ipAddress.fromString(input); + if (ipString.length()) + ipAddress.fromString(ipString); *ip = (uint32_t)ipAddress; } @@ -276,8 +278,12 @@ bool senseSW(const uint8_t pin, const uint8_t activeLevel) { bool sw = digitalRead(pin) == activeLevel; if (sw) { // Cut-off the chattering noise - while (digitalRead(pin) == activeLevel) - delay(10); + unsigned long tm = millis(); + while (digitalRead(pin) == activeLevel) { + if (millis() - tm > 1000) + break; + delay(1); + } } return sw; }