From d990bbb07ea7b5ad3e822ebd0ac29a2d0ebec88b Mon Sep 17 00:00:00 2001
From: Khoi Hoang <57012152+khoih-prog@users.noreply.github.com>
Date: Thu, 24 Nov 2022 22:26:43 -0500
Subject: [PATCH] Update `README.md` and use `allman` astyle
---
CONTRIBUTING.md | 23 +-
README.md | 31 +--
changelog.md | 8 +-
.../ConfigOnDRD_ESP32_minimal.ino | 83 +++++--
.../ConfigOnDRD_ESP8266_minimal.ino | 77 +++++--
.../ConfigOnDoubleReset.ino | 215 ++++++++++--------
examples/checkWaitingDRD/checkWaitingDRD.ino | 20 +-
examples/minimal/minimal.ino | 12 +-
library.json | 1 +
src/ESP_DoubleResetDetector.h | 95 ++++----
utils/astyle_library.conf | 70 ++++++
utils/restyle.sh | 6 +
12 files changed, 430 insertions(+), 211 deletions(-)
create mode 100644 utils/astyle_library.conf
create mode 100644 utils/restyle.sh
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 705d0d3..ce1fb4f 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -29,10 +29,10 @@ Please ensure to specify the following:
Arduino IDE version: 1.8.19
ESP8266 Core Version 3.0.2
OS: Ubuntu 20.04 LTS
-Linux xy-Inspiron-3593 5.15.0-46-generic #49~20.04.1-Ubuntu SMP Thu Aug 4 19:15:44 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
+Linux xy-Inspiron-3593 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Context:
-I encountered a non-response while trying to press the reset button twice.
+I encountered a crash while using this library
Steps to reproduce:
1. ...
@@ -40,14 +40,33 @@ Steps to reproduce:
3. ...
4. ...
```
+
+---
+
### Sending Feature Requests
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/ESP_DoubleResetDetector/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
+---
+
### Sending Pull Requests
Pull Requests with changes and fixes are also welcome!
+Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)
+
+1. Change directory to the library GitHub
+
+```
+xy@xy-Inspiron-3593:~$ cd Arduino/xy/ESP_DoubleResetDetector_GitHub/
+xy@xy-Inspiron-3593:~/Arduino/xy/ESP_DoubleResetDetector_GitHub$
+```
+
+2. Issue astyle command
+
+```
+xy@xy-Inspiron-3593:~/Arduino/xy/ESP_DoubleResetDetector_GitHub$ bash utils/restyle.sh
+```
diff --git a/README.md b/README.md
index c30d5da..898c72a 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-## ESP_DoubleResetDetector
+## ESP_DoubleResetDetector Library
[![arduino-library-badge](https://www.ardu-badge.com/badge/ESP_DoubleResetDetector.svg?)](https://www.ardu-badge.com/ESP_DoubleResetDetector)
[![GitHub release](https://img.shields.io/github/release/khoih-prog/ESP_DoubleResetDetector.svg)](https://github.com/khoih-prog/ESP_DoubleResetDetector/releases)
@@ -6,8 +6,11 @@
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/ESP_DoubleResetDetector.svg)](http://github.com/khoih-prog/ESP_DoubleResetDetector/issues)
+
+
+
---
---
@@ -81,16 +84,16 @@
#### Features
-[**ESP_DoubleResetDetector**](https://github.com/khoih-prog/ESP_DoubleResetDetector) is a library for the **ESP8266 and ESP32** boards to detects a double reset, within configurable timeout (default 10s) seconds, so that an alternative start-up mode can be used. Example use cases are to allow re-configuration of a device's WiFi / MQTT / Blynk credentials.
+[**ESP_DoubleResetDetector**](https://github.com/khoih-prog/ESP_DoubleResetDetector) is a library for the **ESP8266 and ESP32** boards to detects a `double reset`, within configurable timeout (default 10s) seconds, so that an alternative start-up mode can be used. Example use cases are to allow re-configuration of a device's WiFi / MQTT / Blynk credentials.
-This library is based on, modified, bug-fixed and improved from [`Stephen Denne's DoubleResetDetector`](https://github.com/datacute/DoubleResetDetector) to add support to ESP8266 and ESP32 using EEPROM, SPIFFS and LittleFS besides original RTC.
+This library is based on, modified, bug-fixed and improved from [`Stephen Denne's DoubleResetDetector`](https://github.com/datacute/DoubleResetDetector) to add support to ESP8266 and ESP32 using `EEPROM`, `SPIFFS` or `LittleFS` besides original `RTC`.
Currently, [`DoubleResetDetector`](https://github.com/datacute/DoubleResetDetector) only supports ESP8266 using RTC memory.
-This library can be used to detect a double reset within a predetermined time to force the program to enter a special operation such as Config Portal, Clear Default Data, etc., using :
+This library can be used to detect a `double reset within a predetermined time` to force the program to enter a special operation such as Config Portal, Clear Default Data, etc., using :
-1. EEPROM, SPIFFS or LittleFS for ESP8266 and ESP32 boards.
-2. RTC memory for ESP8266 boards (unadvised).
+1. `EEPROM`, `SPIFFS` or `LittleFS` for ESP8266 and ESP32 boards.
+2. `RTC` memory for ESP8266 boards (unadvised).
#### Currently supported Boards
@@ -105,7 +108,7 @@ This [**ESP_DoubleResetDetector** library](https://github.com/khoih-prog/ESP_Dou
## Prerequisites
1. [`Arduino IDE 1.8.19+` for Arduino](https://github.com/arduino/Arduino). [![GitHub release](https://img.shields.io/github/release/arduino/Arduino.svg)](https://github.com/arduino/Arduino/releases/latest)
-2. [`ESP32 Core 2.0.4+`](https://github.com/espressif/arduino-esp32) for ESP32-based boards. [![Latest release](https://img.shields.io/github/release/espressif/arduino-esp32.svg)](https://github.com/espressif/arduino-esp32/releases/latest/)
+2. [`ESP32 Core 2.0.5+`](https://github.com/espressif/arduino-esp32) for ESP32-based boards. [![Latest release](https://img.shields.io/github/release/espressif/arduino-esp32.svg)](https://github.com/espressif/arduino-esp32/releases/latest/)
3. [`ESP8266 Core 3.0.2+`](https://github.com/esp8266/Arduino) for ESP8266-based boards. [![Latest release](https://img.shields.io/github/release/esp8266/Arduino.svg)](https://github.com/esp8266/Arduino/releases/latest/). SPIFFS is deprecated from ESP8266 core 2.7.1+, to use LittleFS.
4. [`LittleFS_esp32 v1.0.6+`](https://github.com/lorol/LITTLEFS) for ESP32-based boards using LittleFS with ESP32 core **v1.0.5-**. To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/LittleFS_esp32.svg?)](https://www.ardu-badge.com/LittleFS_esp32). **Notice**: This [`LittleFS_esp32 library`](https://github.com/lorol/LITTLEFS) has been integrated to Arduino [ESP32 core v1.0.6+](https://github.com/espressif/arduino-esp32/tree/master/libraries/LITTLEFS) and **you don't need to install it if using ESP32 core v1.0.6+**
@@ -287,7 +290,7 @@ This is terminal debug output when running [ESP32_FSWebServer_DRD](https://githu
```cpp
Starting ESP32_FSWebServer_DRD with DoubleResetDetect using SPIFFS on ESP32_DEV
-ESP_WiFiManager v1.11.0
+ESP_WiFiManager v1.12.1
ESP_DoubleResetDetector v1.3.2
FS File: /ConfigSW.json, size: 150B
FS File: /CanadaFlag_1.png, size: 40.25KB
@@ -351,9 +354,9 @@ HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH
This is terminal debug output when running [ConfigOnDoubleReset](https://github.com/khoih-prog/ESP_WiFiManager/tree/master/examples/ConfigOnDoubleReset) on **ESP32 ESP32_DEV.**. Config Portal was requested by DRD to input and save Credentials.
-```
+```cpp
Starting ConfigOnDoubleReset with DoubleResetDetect using LittleFS on ESP32_DEV
-ESP_WiFiManager v1.11.0
+ESP_WiFiManager v1.12.1
ESP_DoubleResetDetector v1.3.2
[WM] RFC925 Hostname = ConfigOnDoubleReset
[WM] Set CORS Header to : Your Access-Control-Allow-Origin
@@ -397,7 +400,7 @@ load:0x40080400,len:6352
entry 0x400806b8
Starting ConfigOnDoubleReset with DoubleResetDetect using LittleFS on ESP32_DEV
-ESP_WiFiManager v1.11.0
+ESP_WiFiManager v1.12.1
ESP_DoubleResetDetector v1.3.2
[WM] RFC925 Hostname = ConfigOnDoubleReset
[WM] Set CORS Header to : Your Access-Control-Allow-Origin
@@ -428,7 +431,7 @@ Starting configuration portal.
This is terminal debug output when running [ESPAsync_WiFi](https://github.com/khoih-prog/ESPAsync_WiFiManager_Lite/tree/master/examples/ESPAsync_WiFi) on **ESP32 ESP32S3_DEV.**. Config Portal was requested by DRD to input and save Credentials.
-```
+```cpp
Starting ESPAsync_WiFi using LittleFS on ESP32S3_DEV
ESPAsync_WiFiManager_Lite v1.9.0
ESP_DoubleResetDetector v1.3.2
@@ -542,7 +545,7 @@ Submit issues to: [ESP_DoubleResetDetector issues](https://github.com/khoih-prog
5. Add waitingForDRD() function to signal in DRD waiting period
6. Fix ESP32 chipID for example`ConfigOnDoubleReset`
7. Remove dependency on `LittleFS_esp32` library to prevent PIO error when using new ESP32 core v1.0.6+
-
+8. Add astyle using `allman` style. Restyle the library
---
---
@@ -580,6 +583,6 @@ If you want to contribute to this project:
### Copyright
-Copyright 2019- Khoi Hoang
+Copyright (c) 2019- Khoi Hoang
diff --git a/changelog.md b/changelog.md
index 1717575..45429fe 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,4 +1,4 @@
-## ESP_DoubleResetDetector
+## ESP_DoubleResetDetector Library
[![arduino-library-badge](https://www.ardu-badge.com/badge/ESP_DoubleResetDetector.svg?)](https://www.ardu-badge.com/ESP_DoubleResetDetector)
[![GitHub release](https://img.shields.io/github/release/khoih-prog/ESP_DoubleResetDetector.svg)](https://github.com/khoih-prog/ESP_DoubleResetDetector/releases)
@@ -6,6 +6,12 @@
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/ESP_DoubleResetDetector.svg)](http://github.com/khoih-prog/ESP_DoubleResetDetector/issues)
+
+
+
+
+
+
---
---
diff --git a/examples/ConfigOnDRD_ESP32_minimal/ConfigOnDRD_ESP32_minimal.ino b/examples/ConfigOnDRD_ESP32_minimal/ConfigOnDRD_ESP32_minimal.ino
index c568111..eafd67a 100644
--- a/examples/ConfigOnDRD_ESP32_minimal/ConfigOnDRD_ESP32_minimal.ino
+++ b/examples/ConfigOnDRD_ESP32_minimal/ConfigOnDRD_ESP32_minimal.ino
@@ -7,8 +7,8 @@
#if defined(ESP32)
#define USE_SPIFFS true
#define ESP_DRD_USE_EEPROM true
-#else
- #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting.
+#else
+ #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting.
#endif
#include //https://github.com/khoih-prog/ESP_WiFiManager
#define DRD_TIMEOUT 10
@@ -18,27 +18,74 @@ DoubleResetDetector* drd;
const int PIN_LED = 2;
bool initialConfig = false;
-void setup() {
+void setup()
+{
pinMode(PIN_LED, OUTPUT);
- Serial.begin(115200); while (!Serial); delay(200);
- Serial.print(F("\nStarting ConfigOnDoubleReset_minimal on ")); Serial.println(ARDUINO_BOARD);
- Serial.println(ESP_WIFIMANAGER_VERSION);
+ Serial.begin(115200);
+
+ while (!Serial)
+ ;
+
+ delay(200);
+ Serial.print(F("\nStarting ConfigOnDoubleReset_minimal on "));
+ Serial.println(ARDUINO_BOARD);
+ Serial.println(ESP_WIFIMANAGER_VERSION);
drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
- if (drd->detectDoubleReset()) { Serial.println(F("DRD")); initialConfig = true; }
+
+ if (drd->detectDoubleReset())
+ {
+ Serial.println(F("DRD"));
+ initialConfig = true;
+ }
+
ESP_WiFiManager ESP_wifiManager("ConfigOnDoubleReset");
- if (ESP_wifiManager.WiFi_SSID() == "") { Serial.println(F("No AP credentials")); initialConfig = true; }
- if (initialConfig) {
- Serial.println(F("Starting Config Portal")); digitalWrite(PIN_LED, HIGH);
- if (!ESP_wifiManager.startConfigPortal()) { Serial.println(F("Not connected to WiFi")); }
- else { Serial.println(F("connected")); }
+
+ if (ESP_wifiManager.WiFi_SSID() == "")
+ {
+ Serial.println(F("No AP credentials"));
+ initialConfig = true;
}
- else { WiFi.mode(WIFI_STA); WiFi.begin(); }
+
+ if (initialConfig)
+ {
+ Serial.println(F("Starting Config Portal"));
+ digitalWrite(PIN_LED, HIGH);
+
+ if (!ESP_wifiManager.startConfigPortal())
+ {
+ Serial.println(F("Not connected to WiFi"));
+ }
+ else
+ {
+ Serial.println(F("connected"));
+ }
+ }
+ else
+ {
+ WiFi.mode(WIFI_STA);
+ WiFi.begin();
+ }
+
unsigned long startedAt = millis();
- digitalWrite(PIN_LED, LOW); Serial.print(F("After waiting "));
+ digitalWrite(PIN_LED, LOW);
+ Serial.print(F("After waiting "));
int connRes = WiFi.waitForConnectResult();
float waited = (millis() - startedAt);
- Serial.print(waited / 1000); Serial.print(F(" secs , Connection result is ")); Serial.println(connRes);
- if (WiFi.status() != WL_CONNECTED) { Serial.println(F("Failed to connect")); }
- else { Serial.print(F("Local IP: ")); Serial.println(WiFi.localIP()); }
+ Serial.print(waited / 1000);
+ Serial.print(F(" secs , Connection result is "));
+ Serial.println(connRes);
+
+ if (WiFi.status() != WL_CONNECTED)
+ {
+ Serial.println(F("Failed to connect"));
+ }
+ else
+ {
+ Serial.print(F("Local IP: "));
+ Serial.println(WiFi.localIP());
+ }
+}
+void loop()
+{
+ drd->loop();
}
-void loop() { drd->loop(); }
diff --git a/examples/ConfigOnDRD_ESP8266_minimal/ConfigOnDRD_ESP8266_minimal.ino b/examples/ConfigOnDRD_ESP8266_minimal/ConfigOnDRD_ESP8266_minimal.ino
index 9b09b38..e68a4ef 100644
--- a/examples/ConfigOnDRD_ESP8266_minimal/ConfigOnDRD_ESP8266_minimal.ino
+++ b/examples/ConfigOnDRD_ESP8266_minimal/ConfigOnDRD_ESP8266_minimal.ino
@@ -7,8 +7,8 @@
#if defined(ESP8266)
#define USE_LITTLEFS true
#define ESP_DRD_USE_LITTLEFS true
-#else
- #error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting.
+#else
+ #error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting.
#endif
#include //https://github.com/khoih-prog/ESP_WiFiManager
#define DRD_TIMEOUT 10
@@ -18,27 +18,70 @@ DoubleResetDetector* drd;
const int PIN_LED = 2;
bool initialConfig = false;
-void setup() {
+void setup()
+{
pinMode(PIN_LED, OUTPUT);
- Serial.begin(115200); while (!Serial); delay(200);
- Serial.print(F("\nStarting ConfigOnDoubleReset_minimal on ")); Serial.println(ARDUINO_BOARD);
- Serial.println(ESP_WIFIMANAGER_VERSION);
- if (WiFi.SSID() == "") { Serial.println(F("No AP credentials")); initialConfig = true; }
+ Serial.begin(115200);
+
+ while (!Serial)
+ ;
+
+ delay(200);
+ Serial.print(F("\nStarting ConfigOnDoubleReset_minimal on "));
+ Serial.println(ARDUINO_BOARD);
+ Serial.println(ESP_WIFIMANAGER_VERSION);
+
+ if (WiFi.SSID() == "")
+ {
+ Serial.println(F("No AP credentials"));
+ initialConfig = true;
+ }
+
drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
- if (drd->detectDoubleReset()) { Serial.println(F("DRD")); initialConfig = true; }
- if (initialConfig) {
- Serial.println(F("Starting Config Portal")); digitalWrite(PIN_LED, LOW);
+
+ if (drd->detectDoubleReset())
+ {
+ Serial.println(F("DRD"));
+ initialConfig = true;
+ }
+
+ if (initialConfig)
+ {
+ Serial.println(F("Starting Config Portal"));
+ digitalWrite(PIN_LED, LOW);
ESP_WiFiManager ESP_wifiManager("ConfigOnDoubleReset");
ESP_wifiManager.setConfigPortalTimeout(0);
- if (!ESP_wifiManager.startConfigPortal()) { Serial.println(F("Not connected to WiFi")); }
- else { Serial.println(F("connected")); }
+
+ if (!ESP_wifiManager.startConfigPortal())
+ {
+ Serial.println(F("Not connected to WiFi"));
+ }
+ else
+ {
+ Serial.println(F("connected"));
+ }
}
- digitalWrite(PIN_LED, HIGH); Serial.print(F("After waiting ")); //WiFi.mode(WIFI_STA);
+
+ digitalWrite(PIN_LED, HIGH);
+ Serial.print(F("After waiting ")); //WiFi.mode(WIFI_STA);
unsigned long startedAt = millis();
int connRes = WiFi.waitForConnectResult();
float waited = (millis() - startedAt);
- Serial.print(waited / 1000); Serial.print(F(" secs , Connection result is ")); Serial.println(connRes);
- if (WiFi.status() != WL_CONNECTED) { Serial.println(F("Failed to connect")); }
- else { Serial.print(F("Local IP: ")); Serial.println(WiFi.localIP()); }
+ Serial.print(waited / 1000);
+ Serial.print(F(" secs , Connection result is "));
+ Serial.println(connRes);
+
+ if (WiFi.status() != WL_CONNECTED)
+ {
+ Serial.println(F("Failed to connect"));
+ }
+ else
+ {
+ Serial.print(F("Local IP: "));
+ Serial.println(WiFi.localIP());
+ }
+}
+void loop()
+{
+ drd->loop();
}
-void loop() { drd->loop(); }
diff --git a/examples/ConfigOnDoubleReset/ConfigOnDoubleReset.ino b/examples/ConfigOnDoubleReset/ConfigOnDoubleReset.ino
index bf29fba..0f1db05 100644
--- a/examples/ConfigOnDoubleReset/ConfigOnDoubleReset.ino
+++ b/examples/ConfigOnDoubleReset/ConfigOnDoubleReset.ino
@@ -21,7 +21,7 @@
Save data in
a) EEPROM from address 256, size 512 bytes (both configurable)
b) SPIFFS
-
+
For LittleFS or SPIFFS, file name is "/drd.dat"
So when the device starts up it checks this region of ram for a flag to see if it has been recently reset.
@@ -55,7 +55,7 @@
#include
#include
#include
-
+
// From v1.1.0
#include
WiFiMulti wifiMulti;
@@ -80,10 +80,10 @@
#if (_WIFIMGR_LOGLEVEL_ > 3)
#warning Using ESP32 Core 1.0.6 or 2.0.0+
#endif
-
+
// The library has been merged into esp32 core from release 1.0.6
#include // https://github.com/espressif/arduino-esp32/tree/master/libraries/LittleFS
-
+
FS* filesystem = &LittleFS;
#define FileFS LittleFS
#define FS_Name "LittleFS"
@@ -91,15 +91,15 @@
#if (_WIFIMGR_LOGLEVEL_ > 3)
#warning Using ESP32 Core 1.0.5-. You must install LITTLEFS library
#endif
-
+
// The library has been merged into esp32 core from release 1.0.6
#include // https://github.com/lorol/LITTLEFS
-
+
FS* filesystem = &LITTLEFS;
#define FileFS LITTLEFS
#define FS_Name "LittleFS"
#endif
-
+
#elif USE_SPIFFS
#include
FS* filesystem = &SPIFFS;
@@ -112,24 +112,24 @@
#define FileFS FFat
#define FS_Name "FFat"
#endif
- //////
-
-#define LED_BUILTIN 2
-#define LED_ON HIGH
-#define LED_OFF LOW
+ //////
+
+ #define LED_BUILTIN 2
+ #define LED_ON HIGH
+ #define LED_OFF LOW
#else
#include //https://github.com/esp8266/Arduino
//needed for library
#include
#include
-
+
// From v1.1.0
#include
ESP8266WiFiMulti wifiMulti;
-
+
#define USE_LITTLEFS true
-
+
#if USE_LITTLEFS
#include
FS* filesystem = &LittleFS;
@@ -141,9 +141,9 @@
#define FS_Name "SPIFFS"
#endif
//////
-
+
#define ESP_getChipId() (ESP.getChipId())
-
+
#define LED_ON LOW
#define LED_OFF HIGH
#endif
@@ -187,7 +187,7 @@
#define ESP_DRD_USE_LITTLEFS false
#define ESP_DRD_USE_SPIFFS true
#endif
-
+
#define ESP_DRD_USE_EEPROM false
#define ESP8266_DRD_USE_RTC false
#endif
@@ -305,28 +305,28 @@ bool initialConfig = false;
#if ( USE_DHCP_IP )
// Use DHCP
-
+
#if (_WIFIMGR_LOGLEVEL_ > 3)
#warning Using DHCP IP
#endif
-
+
IPAddress stationIP = IPAddress(0, 0, 0, 0);
IPAddress gatewayIP = IPAddress(192, 168, 2, 1);
IPAddress netMask = IPAddress(255, 255, 255, 0);
-
+
#else
// Use static IP
-
+
#if (_WIFIMGR_LOGLEVEL_ > 3)
#warning Using static IP
#endif
-
+
#ifdef ESP32
IPAddress stationIP = IPAddress(192, 168, 2, 232);
#else
IPAddress stationIP = IPAddress(192, 168, 2, 186);
#endif
-
+
IPAddress gatewayIP = IPAddress(192, 168, 2, 1);
IPAddress netMask = IPAddress(255, 255, 255, 0);
#endif
@@ -367,25 +367,25 @@ uint8_t connectMultiWiFi();
///////////////////////////////////////////
// New in v1.4.0
/******************************************
- * // Defined in ESP_WiFiManager.h
-typedef struct
-{
+ // Defined in ESP_WiFiManager.h
+ typedef struct
+ {
IPAddress _ap_static_ip;
IPAddress _ap_static_gw;
IPAddress _ap_static_sn;
-} WiFi_AP_IPConfig;
+ } WiFi_AP_IPConfig;
-typedef struct
-{
+ typedef struct
+ {
IPAddress _sta_static_ip;
IPAddress _sta_static_gw;
IPAddress _sta_static_sn;
-#if USE_CONFIGURABLE_DNS
+ #if USE_CONFIGURABLE_DNS
IPAddress _sta_static_dns1;
IPAddress _sta_static_dns2;
-#endif
-} WiFi_STA_IPConfig;
+ #endif
+ } WiFi_STA_IPConfig;
******************************************/
WiFi_AP_IPConfig WM_AP_IPconfig;
@@ -403,7 +403,7 @@ void initSTAIPConfigStruct(WiFi_STA_IPConfig &in_WM_STA_IPconfig)
in_WM_STA_IPconfig._sta_static_ip = stationIP;
in_WM_STA_IPconfig._sta_static_gw = gatewayIP;
in_WM_STA_IPconfig._sta_static_sn = netMask;
-#if USE_CONFIGURABLE_DNS
+#if USE_CONFIGURABLE_DNS
in_WM_STA_IPconfig._sta_static_dns1 = dns1IP;
in_WM_STA_IPconfig._sta_static_dns2 = dns2IP;
#endif
@@ -420,13 +420,14 @@ void displayIPConfigStruct(WiFi_STA_IPConfig in_WM_STA_IPconfig)
void configWiFi(WiFi_STA_IPConfig in_WM_STA_IPconfig)
{
- #if USE_CONFIGURABLE_DNS
- // Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5
- WiFi.config(in_WM_STA_IPconfig._sta_static_ip, in_WM_STA_IPconfig._sta_static_gw, in_WM_STA_IPconfig._sta_static_sn, in_WM_STA_IPconfig._sta_static_dns1, in_WM_STA_IPconfig._sta_static_dns2);
- #else
- // Set static IP, Gateway, Subnetmask, Use auto DNS1 and DNS2.
- WiFi.config(in_WM_STA_IPconfig._sta_static_ip, in_WM_STA_IPconfig._sta_static_gw, in_WM_STA_IPconfig._sta_static_sn);
- #endif
+#if USE_CONFIGURABLE_DNS
+ // Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5
+ WiFi.config(in_WM_STA_IPconfig._sta_static_ip, in_WM_STA_IPconfig._sta_static_gw, in_WM_STA_IPconfig._sta_static_sn,
+ in_WM_STA_IPconfig._sta_static_dns1, in_WM_STA_IPconfig._sta_static_dns2);
+#else
+ // Set static IP, Gateway, Subnetmask, Use auto DNS1 and DNS2.
+ WiFi.config(in_WM_STA_IPconfig._sta_static_ip, in_WM_STA_IPconfig._sta_static_gw, in_WM_STA_IPconfig._sta_static_sn);
+#endif
}
///////////////////////////////////////////
@@ -436,15 +437,15 @@ uint8_t connectMultiWiFi()
#if ESP32
// For ESP32, this better be 0 to shorten the connect time.
// For ESP32-S2/C3, must be > 500
- #if ( USING_ESP32_S2 || USING_ESP32_C3 )
- #define WIFI_MULTI_1ST_CONNECT_WAITING_MS 500L
- #else
- // For ESP32 core v1.0.6, must be >= 500
- #define WIFI_MULTI_1ST_CONNECT_WAITING_MS 800L
- #endif
+#if ( USING_ESP32_S2 || USING_ESP32_C3 )
+#define WIFI_MULTI_1ST_CONNECT_WAITING_MS 500L
+#else
+ // For ESP32 core v1.0.6, must be >= 500
+#define WIFI_MULTI_1ST_CONNECT_WAITING_MS 800L
+#endif
#else
// For ESP8266, this better be 2200 to enable connect the 1st time
- #define WIFI_MULTI_1ST_CONNECT_WAITING_MS 2200L
+#define WIFI_MULTI_1ST_CONNECT_WAITING_MS 2200L
#endif
#define WIFI_MULTI_CONNECT_WAITING_MS 500L
@@ -465,7 +466,8 @@ uint8_t connectMultiWiFi()
for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++)
{
// Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8)
- if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != "") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) )
+ if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != "")
+ && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) )
{
LOGERROR3(F("* Additional SSID = "), WM_config.WiFi_Creds[i].wifi_ssid, F(", PW = "), WM_config.WiFi_Creds[i].wifi_pw );
}
@@ -482,7 +484,7 @@ uint8_t connectMultiWiFi()
#endif
int i = 0;
-
+
status = wifiMulti.run();
delay(WIFI_MULTI_1ST_CONNECT_WAITING_MS);
@@ -508,12 +510,12 @@ uint8_t connectMultiWiFi()
// To avoid unnecessary DRD
drd->loop();
-
-#if ESP8266
+
+#if ESP8266
ESP.reset();
#else
ESP.restart();
-#endif
+#endif
}
return status;
@@ -525,26 +527,28 @@ void printLocalTime()
{
#if ESP8266
static time_t now;
-
+
now = time(nullptr);
-
+
if ( now > 1451602800 )
{
Serial.print("Local Date/Time: ");
Serial.print(ctime(&now));
}
+
#else
struct tm timeinfo;
getLocalTime( &timeinfo );
- // Valid only if year > 2000.
+ // Valid only if year > 2000.
// You can get from timeinfo : tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec
if (timeinfo.tm_year > 100 )
{
Serial.print("Local Date/Time: ");
Serial.print( asctime( &timeinfo ) );
}
+
#endif
}
@@ -571,7 +575,8 @@ void heartBeatPrint()
{
Serial.print(F(" "));
}
-#endif
+
+#endif
}
void check_WiFi()
@@ -593,9 +598,9 @@ void check_status()
#define WIFICHECK_INTERVAL 1000L
#if USE_ESP_WIFIMANAGER_NTP
- #define HEARTBEAT_INTERVAL 60000L
+#define HEARTBEAT_INTERVAL 60000L
#else
- #define HEARTBEAT_INTERVAL 10000L
+#define HEARTBEAT_INTERVAL 10000L
#endif
current_millis = millis();
@@ -618,7 +623,7 @@ void check_status()
int calcChecksum(uint8_t* address, uint16_t sizeToCalc)
{
uint16_t checkSum = 0;
-
+
for (uint16_t index = 0; index < sizeToCalc; index++)
{
checkSum += * ( ( (byte*) address ) + index);
@@ -652,10 +657,10 @@ bool loadConfigData()
if ( WM_config.checksum != calcChecksum( (uint8_t*) &WM_config, sizeof(WM_config) - sizeof(WM_config.checksum) ) )
{
LOGERROR(F("WM_config checksum wrong"));
-
+
return false;
}
-
+
// New in v1.4.0
displayIPConfigStruct(WM_STA_IPconfig);
//////
@@ -678,7 +683,7 @@ void saveConfigData()
if (file)
{
WM_config.checksum = calcChecksum( (uint8_t*) &WM_config, sizeof(WM_config) - sizeof(WM_config.checksum) );
-
+
file.write((uint8_t*) &WM_config, sizeof(WM_config));
displayIPConfigStruct(WM_STA_IPconfig);
@@ -703,21 +708,26 @@ void setup()
pinMode(PIN_LED, OUTPUT);
Serial.begin(115200);
+
while (!Serial);
delay(200);
- Serial.print(F("\nStarting ConfigOnDoubleReset with DoubleResetDetect using ")); Serial.print(FS_Name);
- Serial.print(F(" on ")); Serial.println(ARDUINO_BOARD);
+ Serial.print(F("\nStarting ConfigOnDoubleReset with DoubleResetDetect using "));
+ Serial.print(FS_Name);
+ Serial.print(F(" on "));
+ Serial.println(ARDUINO_BOARD);
Serial.println(ESP_WIFIMANAGER_VERSION);
Serial.println(ESP_DOUBLE_RESET_DETECTOR_VERSION);
#if defined(ESP_WIFIMANAGER_VERSION_MIN)
+
if (ESP_WIFIMANAGER_VERSION_INT < ESP_WIFIMANAGER_VERSION_MIN)
{
Serial.print("Warning. Must use this example on Version equal or later than : ");
Serial.println(ESP_WIFIMANAGER_VERSION_MIN_TARGET);
}
+
#endif
Serial.setDebugOutput(false);
@@ -727,6 +737,7 @@ void setup()
// Format FileFS if not yet
#ifdef ESP32
+
if (!FileFS.begin(true))
#else
if (!FileFS.begin())
@@ -737,12 +748,12 @@ void setup()
#endif
Serial.println(F("SPIFFS/LittleFS failed! Already tried formatting."));
-
+
if (!FileFS.begin())
- {
+ {
// prevents debug info from the library to hide err message.
delay(100);
-
+
#if USE_LITTLEFS
Serial.println(F("LittleFS failed!. Please use SPIFFS or EEPROM. Stay forever"));
#else
@@ -785,16 +796,16 @@ void setup()
ESP_wifiManager.setConfigPortalChannel(0);
//////
-#if !USE_DHCP_IP
- // Set (static IP, Gateway, Subnetmask, DNS1 and DNS2) or (IP, Gateway, Subnetmask). New in v1.0.5
- // New in v1.4.0
- ESP_wifiManager.setSTAStaticIPConfig(WM_STA_IPconfig);
- //////
+#if !USE_DHCP_IP
+ // Set (static IP, Gateway, Subnetmask, DNS1 and DNS2) or (IP, Gateway, Subnetmask). New in v1.0.5
+ // New in v1.4.0
+ ESP_wifiManager.setSTAStaticIPConfig(WM_STA_IPconfig);
+ //////
#endif
// New from v1.1.1
#if USING_CORS_FEATURE
- ESP_wifiManager.setCORSHeader("Your Access-Control-Allow-Origin");
+ ESP_wifiManager.setCORSHeader("Your Access-Control-Allow-Origin");
#endif
// We can't use WiFi.SSID() in ESP32 as it's only valid after connected.
@@ -821,30 +832,32 @@ void setup()
ESP_wifiManager.setConfigPortalTimeout(120); //If no access point name has been previously entered disable timeout.
Serial.println(F("Got ESP Self-Stored Credentials. Timeout 120s for Config Portal"));
}
-
+
if (loadConfigData())
{
configDataLoaded = true;
-
+
ESP_wifiManager.setConfigPortalTimeout(120); //If no access point name has been previously entered disable timeout.
- Serial.println(F("Got stored Credentials. Timeout 120s for Config Portal"));
+ Serial.println(F("Got stored Credentials. Timeout 120s for Config Portal"));
+
+#if USE_ESP_WIFIMANAGER_NTP
-#if USE_ESP_WIFIMANAGER_NTP
if ( strlen(WM_config.TZ_Name) > 0 )
{
LOGERROR3(F("Current TZ_Name ="), WM_config.TZ_Name, F(", TZ = "), WM_config.TZ);
- #if ESP8266
- configTime(WM_config.TZ, "pool.ntp.org");
- #else
+#if ESP8266
+ configTime(WM_config.TZ, "pool.ntp.org");
+#else
//configTzTime(WM_config.TZ, "pool.ntp.org" );
configTzTime(WM_config.TZ, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org");
- #endif
+#endif
}
else
{
Serial.println(F("Current Timezone is not set. Enter Config Portal to set."));
- }
+ }
+
#endif
}
else
@@ -866,17 +879,18 @@ void setup()
if (initialConfig)
{
Serial.print(F("Starting configuration portal @ "));
-
-#if USE_CUSTOM_AP_IP
+
+#if USE_CUSTOM_AP_IP
Serial.print(APStaticIP);
#else
Serial.print(F("192.168.4.1"));
#endif
#if defined(HTTP_PORT_TO_USE)
- Serial.print(F(":")); Serial.print(HTTP_PORT_TO_USE);
+ Serial.print(F(":"));
+ Serial.print(HTTP_PORT_TO_USE);
#endif
-
+
Serial.print(F(", SSID = "));
Serial.print(ssid);
Serial.print(F(", PWD = "));
@@ -916,14 +930,15 @@ void setup()
strncpy(WM_config.WiFi_Creds[i].wifi_pw, tempPW.c_str(), sizeof(WM_config.WiFi_Creds[i].wifi_pw) - 1);
// Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8)
- if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != "") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) )
+ if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != "")
+ && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) )
{
LOGERROR3(F("* Add SSID = "), WM_config.WiFi_Creds[i].wifi_ssid, F(", PW = "), WM_config.WiFi_Creds[i].wifi_pw );
wifiMulti.addAP(WM_config.WiFi_Creds[i].wifi_ssid, WM_config.WiFi_Creds[i].wifi_pw);
}
}
-#if USE_ESP_WIFIMANAGER_NTP
+#if USE_ESP_WIFIMANAGER_NTP
String tempTZ = ESP_wifiManager.getTimezoneName();
if (strlen(tempTZ.c_str()) < sizeof(WM_config.TZ_Name) - 1)
@@ -932,33 +947,34 @@ void setup()
strncpy(WM_config.TZ_Name, tempTZ.c_str(), sizeof(WM_config.TZ_Name) - 1);
const char * TZ_Result = ESP_wifiManager.getTZ(WM_config.TZ_Name);
-
+
if (strlen(TZ_Result) < sizeof(WM_config.TZ) - 1)
strcpy(WM_config.TZ, TZ_Result);
else
strncpy(WM_config.TZ, TZ_Result, sizeof(WM_config.TZ_Name) - 1);
-
+
if ( strlen(WM_config.TZ_Name) > 0 )
{
LOGERROR3(F("Saving current TZ_Name ="), WM_config.TZ_Name, F(", TZ = "), WM_config.TZ);
- #if ESP8266
- configTime(WM_config.TZ, "pool.ntp.org");
- #else
+#if ESP8266
+ configTime(WM_config.TZ, "pool.ntp.org");
+#else
//configTzTime(WM_config.TZ, "pool.ntp.org" );
configTzTime(WM_config.TZ, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org");
- #endif
+#endif
}
else
{
LOGERROR(F("Current Timezone Name is not set. Enter Config Portal to set."));
}
+
#endif
// New in v1.4.0
ESP_wifiManager.getSTAStaticIPConfig(WM_STA_IPconfig);
//////
-
+
saveConfigData();
}
@@ -975,17 +991,18 @@ void setup()
for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++)
{
// Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8)
- if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != "") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) )
+ if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != "")
+ && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) )
{
LOGERROR3(F("* Add SSID = "), WM_config.WiFi_Creds[i].wifi_ssid, F(", PW = "), WM_config.WiFi_Creds[i].wifi_pw );
wifiMulti.addAP(WM_config.WiFi_Creds[i].wifi_ssid, WM_config.WiFi_Creds[i].wifi_pw);
}
}
- if ( WiFi.status() != WL_CONNECTED )
+ if ( WiFi.status() != WL_CONNECTED )
{
Serial.println(F("ConnectMultiWiFi in setup"));
-
+
connectMultiWiFi();
}
}
diff --git a/examples/checkWaitingDRD/checkWaitingDRD.ino b/examples/checkWaitingDRD/checkWaitingDRD.ino
index 86849e2..d7d9ffc 100644
--- a/examples/checkWaitingDRD/checkWaitingDRD.ino
+++ b/examples/checkWaitingDRD/checkWaitingDRD.ino
@@ -34,7 +34,7 @@
#include //https://github.com/khoih-prog/ESP_DoubleResetDetector
-// Number of seconds after reset during which a
+// Number of seconds after reset during which a
// subsequent reset will be considered a double reset.
#define DRD_TIMEOUT 10
@@ -82,13 +82,13 @@ void check_status()
{
digitalWrite(LED_BUILTIN, LEDState);
- LEDState = !LEDState;
+ LEDState = !LEDState;
}
else
{
digitalWrite(LED_BUILTIN, LED_OFF);
}
-
+
checkstatus_timeout = current_millis + DRD_CHECK_INTERVAL;
}
}
@@ -96,24 +96,26 @@ void check_status()
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
-
+
Serial.begin(115200);
+
while (!Serial);
delay(200);
- Serial.print("\nStarting checkWaitingDRD on"); Serial.println(ARDUINO_BOARD);
+ Serial.print("\nStarting checkWaitingDRD on");
+ Serial.println(ARDUINO_BOARD);
Serial.println(ESP_DOUBLE_RESET_DETECTOR_VERSION);
-
+
drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
- if (drd->detectDoubleReset())
+ if (drd->detectDoubleReset())
{
Serial.println("Double Reset Detected");
digitalWrite(LED_BUILTIN, LED_ON);
DRD_Detected = true;
- }
- else
+ }
+ else
{
Serial.println("No Double Reset Detected");
digitalWrite(LED_BUILTIN, LED_OFF);
diff --git a/examples/minimal/minimal.ino b/examples/minimal/minimal.ino
index 8876704..bc857f1 100644
--- a/examples/minimal/minimal.ino
+++ b/examples/minimal/minimal.ino
@@ -30,7 +30,7 @@
#include //https://github.com/khoih-prog/ESP_DoubleResetDetector
-// Number of seconds after reset during which a
+// Number of seconds after reset during which a
// subseqent reset will be considered a double reset.
#define DRD_TIMEOUT 10
@@ -60,18 +60,18 @@ DoubleResetDetector* drd;
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
-
+
Serial.begin(115200);
Serial.println("\nStarting minimal example for ESP_DoubleResetDetector");
-
+
drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
- if (drd->detectDoubleReset())
+ if (drd->detectDoubleReset())
{
Serial.println("Double Reset Detected");
digitalWrite(LED_BUILTIN, LED_ON);
- }
- else
+ }
+ else
{
Serial.println("No Double Reset Detected");
digitalWrite(LED_BUILTIN, LED_OFF);
diff --git a/library.json b/library.json
index 0274edb..76a7c62 100644
--- a/library.json
+++ b/library.json
@@ -25,6 +25,7 @@
"dependencies":
[
],
+ "license": "MIT",
"frameworks": "arduino",
"platforms": [ "espressif32", "espressif8266" ],
"examples": "examples/*/*/*.ino",
diff --git a/src/ESP_DoubleResetDetector.h b/src/ESP_DoubleResetDetector.h
index 94029ef..44f189b 100644
--- a/src/ESP_DoubleResetDetector.h
+++ b/src/ESP_DoubleResetDetector.h
@@ -44,7 +44,7 @@
#ifndef ESP_DOUBLE_RESET_DETECTOR_VERSION
#define ESP_DOUBLE_RESET_DETECTOR_VERSION "ESP_DoubleResetDetector v1.3.2"
-
+
#define ESP_DOUBLE_RESET_DETECTOR_VERSION_MAJOR 1
#define ESP_DOUBLE_RESET_DETECTOR_VERSION_MINOR 3
#define ESP_DOUBLE_RESET_DETECTOR_VERSION_PATCH 2
@@ -61,11 +61,11 @@
#ifdef ESP32
#if (!ESP_DRD_USE_EEPROM && !ESP_DRD_USE_SPIFFS && !ESP_DRD_USE_LITTLEFS)
-
+
#if (DOUBLERESETDETECTOR_DEBUG)
#warning Neither EEPROM, SPIFFS nor LittleFS selected. Default to EEPROM
#endif
-
+
#ifdef ESP_DRD_USE_EEPROM
#undef ESP_DRD_USE_EEPROM
#define ESP_DRD_USE_EEPROM true
@@ -77,8 +77,8 @@
#if (!ESP8266_DRD_USE_RTC && !ESP_DRD_USE_EEPROM && !ESP_DRD_USE_SPIFFS && !ESP_DRD_USE_LITTLEFS)
#if (DOUBLERESETDETECTOR_DEBUG)
#warning Neither RTC, EEPROM, LITTLEFS nor SPIFFS selected. Default to EEPROM
- #endif
-
+ #endif
+
#ifdef ESP_DRD_USE_EEPROM
#undef ESP_DRD_USE_EEPROM
#define ESP_DRD_USE_EEPROM true
@@ -102,55 +102,55 @@
#elif ( ESP_DRD_USE_LITTLEFS || ESP_DRD_USE_SPIFFS )
-#include
+ #include
-#ifdef ESP32
+ #ifdef ESP32
- #if ESP_DRD_USE_LITTLEFS
- // Check cores/esp32/esp_arduino_version.h and cores/esp32/core_version.h
- //#if ( ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0) ) //(ESP_ARDUINO_VERSION_MAJOR >= 2)
- #if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 2) )
- #if (DOUBLERESETDETECTOR_DEBUG)
- #warning Using ESP32 Core 1.0.6 or 2.0.0+
- #endif
-
- // The library has been merged into esp32 core from release 1.0.6
- #include
-
- #define FileFS LittleFS
- #define FS_Name "LittleFS"
+ #if ESP_DRD_USE_LITTLEFS
+ // Check cores/esp32/esp_arduino_version.h and cores/esp32/core_version.h
+ //#if ( ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0) ) //(ESP_ARDUINO_VERSION_MAJOR >= 2)
+ #if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 2) )
+ #if (DOUBLERESETDETECTOR_DEBUG)
+ #warning Using ESP32 Core 1.0.6 or 2.0.0+
+ #endif
+
+ // The library has been merged into esp32 core from release 1.0.6
+ #include
+
+ #define FileFS LittleFS
+ #define FS_Name "LittleFS"
+ #else
+ #if (DOUBLERESETDETECTOR_DEBUG)
+ #warning Using ESP32 Core 1.0.5-. You must install LITTLEFS library
+ #endif
+
+ // The library has been merged into esp32 core from release 1.0.6
+ #include // https://github.com/lorol/LITTLEFS
+
+ #define FileFS LITTLEFS
+ #define FS_Name "LittleFS"
+ #endif
#else
- #if (DOUBLERESETDETECTOR_DEBUG)
- #warning Using ESP32 Core 1.0.5-. You must install LITTLEFS library
- #endif
-
- // The library has been merged into esp32 core from release 1.0.6
- #include // https://github.com/lorol/LITTLEFS
-
- #define FileFS LITTLEFS
- #define FS_Name "LittleFS"
+ #include "SPIFFS.h"
+ // ESP32 core 1.0.4 still uses SPIFFS
+ #define FileFS SPIFFS
#endif
- #else
- #include "SPIFFS.h"
- // ESP32 core 1.0.4 still uses SPIFFS
- #define FileFS SPIFFS
- #endif
-#else
- // From ESP8266 core 2.7.1
- #include
-
- #if ESP_DRD_USE_LITTLEFS
- #define FileFS LittleFS
#else
- #define FileFS SPIFFS
- #endif
+ // From ESP8266 core 2.7.1
+ #include
+
+ #if ESP_DRD_USE_LITTLEFS
+ #define FileFS LittleFS
+ #else
+ #define FileFS SPIFFS
+ #endif
-#endif // #if ESP_DRD_USE_EEPROM
+ #endif // #if ESP_DRD_USE_EEPROM
-#define DRD_FILENAME "/drd.dat"
+ #define DRD_FILENAME "/drd.dat"
#endif //#if ESP_DRD_USE_EEPROM
@@ -171,6 +171,7 @@ class DoubleResetDetector
EEPROM.begin(EEPROM_SIZE);
#elif ( ESP_DRD_USE_LITTLEFS || ESP_DRD_USE_SPIFFS )
+
// LittleFS / SPIFFS code
if (!FileFS.begin())
{
@@ -184,6 +185,7 @@ class DoubleResetDetector
#endif
}
+
#else
#ifdef ESP8266
//RTC only for ESP8266
@@ -221,7 +223,7 @@ class DoubleResetDetector
return doubleResetDetected;
};
-
+
bool waitingForDRD()
{
return waitingForDoubleReset;
@@ -264,6 +266,7 @@ class DoubleResetDetector
Serial.printf("EEPROM Flag read = 0x%X\n", DOUBLERESETDETECTOR_FLAG);
#endif
#elif ( ESP_DRD_USE_LITTLEFS || ESP_DRD_USE_SPIFFS )
+
// LittleFS / SPIFFS code
if (FileFS.exists(DRD_FILENAME))
{
@@ -292,6 +295,7 @@ class DoubleResetDetector
file.close();
}
+
#else
#ifdef ESP8266
//RTC only for ESP8266
@@ -340,6 +344,7 @@ class DoubleResetDetector
Serial.println("Saving config file failed");
#endif
}
+
#else
#ifdef ESP8266
//RTC only for ESP8266
diff --git a/utils/astyle_library.conf b/utils/astyle_library.conf
new file mode 100644
index 0000000..8a73bc2
--- /dev/null
+++ b/utils/astyle_library.conf
@@ -0,0 +1,70 @@
+# Code formatting rules for Arduino libraries, modified from for KH libraries:
+#
+# https://github.com/arduino/Arduino/blob/master/build/shared/examples_formatter.conf
+#
+
+# astyle --style=allman -s2 -t2 -C -S -xW -Y -M120 -f -p -xg -H -xb -c --xC120 -xL *.h *.cpp *.ino
+
+--mode=c
+--lineend=linux
+--style=allman
+
+# -r or -R
+#--recursive
+
+# -c => Converts tabs into spaces
+convert-tabs
+
+# -s2 => 2 spaces indentation
+--indent=spaces=2
+
+# -t2 => tab =2 spaces
+#--indent=tab=2
+
+# -C
+--indent-classes
+
+# -S
+--indent-switches
+
+# -xW
+--indent-preproc-block
+
+# -Y => indent classes, switches (and cases), comments starting at column 1
+--indent-col1-comments
+
+# -M120 => maximum of 120 spaces to indent a continuation line
+--max-continuation-indent=120
+
+# -xC120 => max‑code‑length will break a line if the code exceeds # characters
+--max-code-length=120
+
+# -f =>
+--break-blocks
+
+# -p => put a space around operators
+--pad-oper
+
+# -xg => Insert space padding after commas
+--pad-comma
+
+# -H => put a space after if/for/while
+pad-header
+
+# -xb => Break one line headers (e.g. if/for/while)
+--break-one-line-headers
+
+# -c => Converts tabs into spaces
+#--convert-tabs
+
+# if you like one-liners, keep them
+#keep-one-line-statements
+
+# -xV
+--attach-closing-while
+
+#unpad-paren
+
+# -xp
+remove-comment-prefix
+
diff --git a/utils/restyle.sh b/utils/restyle.sh
new file mode 100644
index 0000000..bcd846f
--- /dev/null
+++ b/utils/restyle.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+for dir in . ; do
+ find $dir -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.ino" \) -exec astyle --suffix=none --options=./utils/astyle_library.conf \{\} \;
+done
+