Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit 3c90445

Browse files
authored
Update README.md and use allman astyle
1 parent 56a1b8f commit 3c90445

File tree

12 files changed

+1055
-681
lines changed

12 files changed

+1055
-681
lines changed

CONTRIBUTING.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
1515
Please ensure to specify the following:
1616

1717
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
18-
* `SAMD` Core Version (e.g. Arduino SAMD core v1.8.13, Adafruit SAMD core v1.7.9, Seeed Studio SAMD v1.8.2)
18+
* `SAMD` Core Version (e.g. Arduino SAMD core v1.8.13, Adafruit SAMD core v1.7.11, Seeed Studio SAMD v1.8.3)
1919
* Contextual information (e.g. what you were trying to achieve)
2020
* Simplest possible steps to reproduce
2121
* Anything that might be relevant in your opinion, such as:
@@ -29,10 +29,10 @@ Please ensure to specify the following:
2929
Arduino IDE version: 1.8.19
3030
Arduino SAMD Core Version 1.8.13
3131
OS: Ubuntu 20.04 LTS
32-
Linux kh-Inspiron-3593 5.4.0-100-generic #113-Ubuntu SMP Thu Feb 3 18:43:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
32+
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
3333
3434
Context:
35-
I encountered an endless loop while trying to connect to Local WiFi.
35+
I encountered a crash while using this library
3636
3737
Steps to reproduce:
3838
1. ...
@@ -41,13 +41,34 @@ Steps to reproduce:
4141
4. ...
4242
```
4343

44+
---
45+
4446
### Sending Feature Requests
4547

4648
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
4749

4850
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/DoubleResetDetector_Generic/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
4951

52+
---
53+
5054
### Sending Pull Requests
5155

5256
Pull Requests with changes and fixes are also welcome!
5357

58+
Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)
59+
60+
1. Change directory to the library GitHub
61+
62+
```
63+
xy@xy-Inspiron-3593:~$ cd Arduino/xy/DoubleResetDetector_Generic_GitHub/
64+
xy@xy-Inspiron-3593:~/Arduino/xy/DoubleResetDetector_Generic_GitHub$
65+
```
66+
67+
2. Issue astyle command
68+
69+
```
70+
xy@xy-Inspiron-3593:~/Arduino/xy/DoubleResetDetector_Generic_GitHub$ bash utils/restyle.sh
71+
```
72+
73+
74+

README.md

Lines changed: 132 additions & 49 deletions
Large diffs are not rendered by default.

changelog.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
## DoubleResetDetector_Generic
1+
## DoubleResetDetector_Generic Library
22

33
[![arduino-library-badge](https://www.ardu-badge.com/badge/DoubleResetDetector_Generic.svg?)](https://www.ardu-badge.com/DoubleResetDetector_Generic)
44
[![GitHub release](https://img.shields.io/github/release/khoih-prog/DoubleResetDetector_Generic.svg)](https://github.com/khoih-prog/DoubleResetDetector_Generic/releases)
55
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/DoubleResetDetector_Generic/blob/master/LICENSE)
66
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
77
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/DoubleResetDetector_Generic.svg)](http://github.com/khoih-prog/DoubleResetDetector_Generic/issues)
88

9+
10+
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Donate to my libraries using BuyMeACoffee" style="height: 50px !important;width: 181px !important;" ></a>
11+
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donate-orange.svg?logo=buy-me-a-coffee&logoColor=FFDD00" style="height: 20px !important;width: 200px !important;" ></a>
12+
<a href="https://profile-counter.glitch.me/khoih-prog/count.svg" title="Total khoih-prog Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog/count.svg" style="height: 30px;width: 200px;"></a>
13+
<a href="https://profile-counter.glitch.me/khoih-prog-DoubleResetDetector_Generic/count.svg" title="DoubleResetDetector_Generic Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog-DoubleResetDetector_Generic/count.svg" style="height: 30px;width: 200px;"></a>
14+
915
---
1016
---
1117

examples/checkWaitingDRD/checkWaitingDRD.ino

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868

6969
#include <DoubleResetDetector_Generic.h> //https://github.com/khoih-prog/DoubleResetDetector_Generic
7070

71-
// Number of seconds after reset during which a
71+
// Number of seconds after reset during which a
7272
// subsequent reset will be considered a double reset.
7373
#define DRD_TIMEOUT 10
7474

@@ -108,44 +108,46 @@ void check_status()
108108
{
109109
digitalWrite(LED_BUILTIN, LEDState);
110110

111-
LEDState = !LEDState;
111+
LEDState = !LEDState;
112112
}
113113
else
114114
{
115115
digitalWrite(LED_BUILTIN, LED_OFF);
116116
}
117-
117+
118118
checkstatus_timeout = current_millis + DRD_CHECK_INTERVAL;
119119
}
120120
}
121121

122122
void setup()
123123
{
124124
pinMode(LED_BUILTIN, OUTPUT);
125-
125+
126126
Serial.begin(115200);
127+
127128
while (!Serial);
128129

129130
delay(200);
130131

131132
#if defined(BOARD_NAME)
132-
Serial.print(F("\nStarting checkWaitingDRD on")); Serial.println(BOARD_NAME);
133+
Serial.print(F("\nStarting checkWaitingDRD on"));
134+
Serial.println(BOARD_NAME);
133135
#else
134136
Serial.print(F("\nStarting checkWaitingDRD"));
135-
#endif
137+
#endif
136138

137139
Serial.println(DOUBLERESETDETECTOR_GENERIC_VERSION);
138140
Serial.println("-----------------------------------");
139-
141+
140142
drd = new DoubleResetDetector_Generic(DRD_TIMEOUT, DRD_ADDRESS);
141143

142-
if (drd->detectDoubleReset())
144+
if (drd->detectDoubleReset())
143145
{
144146
Serial.println("Double Reset Detected");
145147
digitalWrite(LED_BUILTIN, LED_ON);
146148
DRD_Detected = true;
147-
}
148-
else
149+
}
150+
else
149151
{
150152
Serial.println("No Double Reset Detected");
151153
digitalWrite(LED_BUILTIN, LED_OFF);
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/****************************************************************************************************************************
2+
checkWaitingDRD.ino
3+
DoubleResetDetector_Generic.h
4+
For AVR Mega, Teensy, STM32, nRF52, SAM DUE, SAMD21, SAMD51 boards
5+
6+
DoubleResetDetector_Generic is a library for the Arduino AVR, Teensy, SAM-DUE, SAMD, STM32. etc. boards
7+
to enable trigger configure mode by resetting the boards twice within configurable timeout seconds.
8+
9+
Based on and modified from DataCute https://github.com/datacute/DoubleResetDetector and
10+
https://github.com/khoih-prog/ESP_DoubleResetDetector
11+
12+
Built by Khoi Hoang https://github.com/khoih-prog/DoubleResetDetector_Generic
13+
Licensed under MIT license
14+
*****************************************************************************************************************************/
15+
16+
/****************************************************************************************************************************
17+
This example will open a configuration portal when the reset button is pressed twice.
18+
This method works well on Wemos boards which have a single reset button on board. It avoids using a pin for launching the configuration portal.
19+
20+
How It Works
21+
1) AVR Mega, Teensy
22+
Save data in EPPROM from address 1020, size 1024 bytes (both configurable)
23+
Note: Teensy 4.0 has only 1080 bytes of EEPROM-simulated Flash
24+
2) SAMD
25+
Save data in EEPROM-simulated FlashStorage from address 0 (configurable to avoid conflict)
26+
3) SAM DUE
27+
Save data in DueFlashStorage from address 1020 (configurable to avoid conflict)
28+
4) Adafruit nRF52-based boards
29+
Save data in InternalFS, fle "/drd.dat" location 0
30+
5) RTL8720
31+
Save data in FlashStorage from address 0 (configurable to avoid conflict)
32+
6) STM32
33+
Save data in EEPROM-simulated FlashStorage from address 0 (configurable to avoid conflict)
34+
35+
So when the device starts up it checks the InternalFS file "/drd.dat", EEPROM or (Due)FlashStorage for a flag to see if it has been
36+
recently reset within the configurable timeout seconds
37+
It'll then set a flag, and display a message to signal if the DR is detected
38+
39+
Settings
40+
There are two values to be set in the sketch.
41+
42+
DRD_TIMEOUT - Number of seconds to wait for the second reset. Set to 10s in the example.
43+
DRD_ADDRESS - The address in ESP8266 RTC RAM to store the flag. This memory must not be used for other purposes in the same sketch. Set to 0 in the example.
44+
45+
This example, originally relied on the Double Reset Detector library from https://github.com/datacute/DoubleResetDetector
46+
To support ESP32, use ESP_DoubleResetDetector library from https://github.com/khoih-prog/ESP_DoubleResetDetector
47+
To support AVR, Teensy, SAM DUE, SAMD and STM32, etc., use this DoubleResetDetector_Generic from //https://github.com/khoih-prog/DoubleResetDetector_Generic
48+
*****************************************************************************************************************************/
49+
50+
51+
// These defines must be put before #include <DoubleResetDetector_Generic.h>
52+
// to select where to store DoubleResetDetector's variable.
53+
// For ESP32, You must select one to be true (EEPROM or SPIFFS)
54+
// For ESP8266, You must select one to be true (RTC, EEPROM, LITTLEFS or SPIFFS)
55+
// Otherwise, library will use default EEPROM storage
56+
57+
// This example demonstrates how to use new function waitingForDRD() to signal the stage of DRD
58+
// waitingForDRD() returns true if in DRD_TIMEOUT, false when out of DRD_TIMEOUT
59+
// In this example, LED_BUILTIN will blink in DRD_TIMEOUT period, ON when DR has been detected, OFF otherwise
60+
61+
#define DEBUG_ETHERNET_GENERIC_PORT SerialDebug
62+
63+
#define DRD_GENERIC_DEBUG true //false
64+
65+
// You have to select true for the first time for any board
66+
#define FORCE_REFORMAT false
67+
68+
// Uncomment to have debug
69+
//#define DOUBLERESETDETECTOR_DEBUG true
70+
71+
#include <DoubleResetDetector_Generic.h> //https://github.com/khoih-prog/DoubleResetDetector_Generic
72+
73+
// Number of seconds after reset during which a
74+
// subsequent reset will be considered a double reset.
75+
#define DRD_TIMEOUT 10
76+
77+
// RTC Memory Address for the DoubleResetDetector to use
78+
#define DRD_ADDRESS 0
79+
80+
DoubleResetDetector_Generic* drd;
81+
82+
// Change according to your board
83+
#ifndef LED_BUILTIN
84+
// Generic boards following LED at pin 13
85+
#define LED_BUILTIN 13
86+
#endif
87+
88+
// Change according to your board
89+
#define LED_OFF LOW
90+
#define LED_ON HIGH
91+
92+
bool DRD_Detected = false;
93+
94+
void check_status()
95+
{
96+
static unsigned long checkstatus_timeout = 0;
97+
static bool LEDState = LED_OFF;
98+
99+
static unsigned long current_millis;
100+
101+
#define DRD_CHECK_INTERVAL 500L
102+
103+
current_millis = millis();
104+
105+
// If DRD_Detected, don't need to blink, just keep LED_BUILTIN ON
106+
if ( !DRD_Detected && ((current_millis > checkstatus_timeout) || (checkstatus_timeout == 0)) )
107+
{
108+
// If in DRD checking loop, blinking the LED_BUILTIN
109+
if ( drd->waitingForDRD() )
110+
{
111+
digitalWrite(LED_BUILTIN, LEDState);
112+
113+
LEDState = !LEDState;
114+
}
115+
else
116+
{
117+
digitalWrite(LED_BUILTIN, LED_OFF);
118+
}
119+
120+
checkstatus_timeout = current_millis + DRD_CHECK_INTERVAL;
121+
}
122+
}
123+
124+
void setup()
125+
{
126+
pinMode(LED_BUILTIN, OUTPUT);
127+
128+
SerialDebug.begin(115200);
129+
130+
while (!SerialDebug);
131+
132+
delay(200);
133+
134+
#if defined(BOARD_NAME)
135+
SerialDebug.print(F("\nStarting checkWaitingDRD on"));
136+
SerialDebug.println(BOARD_NAME);
137+
#else
138+
SerialDebug.println(F("\nStarting checkWaitingDRD"));
139+
#endif
140+
141+
SerialDebug.println(DOUBLERESETDETECTOR_GENERIC_VERSION);
142+
SerialDebug.println("-----------------------------------");
143+
144+
drd = new DoubleResetDetector_Generic(DRD_TIMEOUT, DRD_ADDRESS);
145+
146+
if (drd->detectDoubleReset())
147+
{
148+
SerialDebug.println("Double Reset Detected");
149+
digitalWrite(LED_BUILTIN, LED_ON);
150+
DRD_Detected = true;
151+
}
152+
else
153+
{
154+
SerialDebug.println("No Double Reset Detected");
155+
digitalWrite(LED_BUILTIN, LED_OFF);
156+
}
157+
}
158+
159+
void loop()
160+
{
161+
// Call the double reset detector loop method every so often,
162+
// so that it can recognise when the timeout expires.
163+
// You can also call drd.stop() when you wish to no longer
164+
// consider the next reset as a double reset.
165+
drd->loop();
166+
167+
check_status();
168+
}

examples/minimal/minimal.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
To support AVR, Teensy, SAM DUE, SAMD and STM32, etc., use this DoubleResetDetector_Generic from //https://github.com/khoih-prog/DoubleResetDetector_Generic
4747
*****************************************************************************************************************************/
4848

49-
#define DRD_GENERIC_DEBUG false
49+
#define DRD_GENERIC_DEBUG true //false
5050

5151
// You have to select true for the first time for any board
5252
#define FORCE_REFORMAT false
@@ -72,12 +72,14 @@ void setup()
7272
pinMode(LED_BUILTIN, OUTPUT);
7373

7474
Serial.begin(115200);
75+
7576
while (!Serial);
7677

7778
Serial.println();
7879

7980
#if defined(BOARD_NAME)
80-
Serial.print(F("DoubleResetDetector minimal Example Program on ")); Serial.println(BOARD_NAME);
81+
Serial.print(F("DoubleResetDetector minimal Example Program on "));
82+
Serial.println(BOARD_NAME);
8183
#else
8284
Serial.println(F("DoubleResetDetector minimal Example Program"));
8385
#endif

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ DoubleResetDetector_Generic
1111
# Methods and Functions (KEYWORD2)
1212
#######################################
1313
detectDoubleReset KEYWORD2
14+
waitingForDRD KEYWORD2
1415
loop KEYWORD2
1516
stop KEYWORD2
1617

platformio/platformio.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ upload_speed = 921600
3737

3838
; Checks for the compatibility with frameworks and dev/platforms
3939
lib_compat_mode = strict
40+
lib_ldf_mode = chain+
41+
;lib_ldf_mode = deep+
4042

4143
lib_deps =
4244
; PlatformIO 4.x

0 commit comments

Comments
 (0)