Skip to content

Commit 39f2970

Browse files
committed
fix: reTerminal E1001/E1002 reset button now directly handles WiFi reset
Problem: The checkResetButtonFeedback() function's delay() was blocking the main loop, preventing the library's _handleResetButton() from being called during the LED feedback animation. Solution: Like IoT Button, the reTerminal examples now handle WiFi reset directly in checkResetButtonFeedback(): 1. Detect 6 second hold threshold 2. Give LED rapid blink feedback 3. On button release, directly call ha.clearWiFiCredentials() and ESP.restart() This ensures reliable WiFi reset regardless of the library's internal timing.
1 parent 6364780 commit 39f2970

File tree

2 files changed

+57
-14
lines changed

2 files changed

+57
-14
lines changed

arduino/SeeedHADiscovery/examples/reTerminal_E1001_HASubscribe_Display/reTerminal_E1001_HASubscribe_Display.ino

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,13 @@ void setStatusLED(bool on) {
193193
}
194194

195195
/**
196-
* Check reset button and provide visual feedback
197-
* 检查重置按钮并提供视觉反馈
196+
* Check reset button and handle WiFi reset with visual feedback
197+
* 检查重置按钮并处理 WiFi 重置(带视觉反馈)
198198
*
199-
* This function monitors the reset button to provide LED feedback
200-
* when the button has been held long enough (6 seconds).
201-
* The actual WiFi reset is handled by ha.enableResetButton().
202-
* 此函数监控重置按钮,当按钮按住足够长时间(6秒)时提供 LED 反馈。
203-
* 实际的 WiFi 重置由 ha.enableResetButton() 处理。
199+
* This function monitors the reset button, provides LED feedback at 6 seconds,
200+
* and triggers WiFi reset when button is released after threshold.
201+
* 此函数监控重置按钮,在 6 秒时提供 LED 反馈,
202+
* 并在按钮释放后触发 WiFi 重置。
204203
*/
205204
void checkResetButtonFeedback() {
206205
bool currentState = (digitalRead(PIN_RESET_BUTTON) == LOW); // Button pressed when LOW
@@ -242,14 +241,33 @@ void checkResetButtonFeedback() {
242241

243242
// Button released | 按钮释放
244243
if (!currentState && resetButtonPressed) {
244+
uint32_t holdTime = now - resetButtonPressTime;
245245
resetButtonPressed = false;
246246

247-
// Turn off LED if we gave feedback | 如果给了反馈就关闭 LED
248-
if (resetFeedbackGiven) {
247+
// If held long enough and feedback was given, trigger WiFi reset
248+
// 如果按住足够长时间并且已给反馈,触发 WiFi 重置
249+
if (resetFeedbackGiven && holdTime >= WIFI_RESET_HOLD_TIME) {
250+
Serial1.println();
251+
Serial1.println("=========================================");
252+
Serial1.println(" WiFi Reset triggered!");
253+
Serial1.println(" WiFi 重置已触发!");
254+
Serial1.println("=========================================");
255+
Serial1.println(" Clearing credentials and restarting...");
256+
Serial1.println(" 正在清除凭据并重启...");
257+
249258
setStatusLED(false);
250-
// Note: The actual WiFi reset is handled by ha.enableResetButton()
251-
// 注意:实际的 WiFi 重置由 ha.enableResetButton() 处理
259+
260+
// Clear WiFi credentials and restart
261+
// 清除 WiFi 凭据并重启
262+
ha.clearWiFiCredentials();
263+
Serial1.flush();
264+
delay(500);
265+
ESP.restart();
266+
// Never reaches here | 永远不会到达这里
252267
}
268+
269+
// Turn off LED | 关闭 LED
270+
setStatusLED(false);
253271
resetFeedbackGiven = false;
254272
}
255273
}

arduino/SeeedHADiscovery/examples/reTerminal_E1002_HASubscribe_Display/reTerminal_E1002_HASubscribe_Display.ino

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ void setStatusLED(bool on) {
188188
}
189189

190190
/**
191-
* Check reset button and provide visual feedback
192-
* 检查重置按钮并提供视觉反馈
191+
* Check reset button and handle WiFi reset with visual feedback
192+
* 检查重置按钮并处理 WiFi 重置(带视觉反馈)
193193
*/
194194
void checkResetButtonFeedback() {
195195
bool currentState = (digitalRead(PIN_RESET_BUTTON) == LOW);
@@ -213,6 +213,8 @@ void checkResetButtonFeedback() {
213213
Serial1.println("=========================================");
214214
Serial1.println(" WiFi Reset threshold reached (6s)!");
215215
Serial1.println(" WiFi 重置阈值已达到(6秒)!");
216+
Serial1.println(" Release button to reset WiFi...");
217+
Serial1.println(" 松开按钮以重置 WiFi...");
216218
Serial1.println("=========================================");
217219

218220
// Visual feedback: LED rapid blink | 视觉反馈:LED 快速闪烁
@@ -228,10 +230,33 @@ void checkResetButtonFeedback() {
228230

229231
// Button released | 按钮释放
230232
if (!currentState && resetButtonPressed) {
233+
uint32_t holdTime = now - resetButtonPressTime;
231234
resetButtonPressed = false;
232-
if (resetFeedbackGiven) {
235+
236+
// If held long enough and feedback was given, trigger WiFi reset
237+
// 如果按住足够长时间并且已给反馈,触发 WiFi 重置
238+
if (resetFeedbackGiven && holdTime >= WIFI_RESET_HOLD_TIME) {
239+
Serial1.println();
240+
Serial1.println("=========================================");
241+
Serial1.println(" WiFi Reset triggered!");
242+
Serial1.println(" WiFi 重置已触发!");
243+
Serial1.println("=========================================");
244+
Serial1.println(" Clearing credentials and restarting...");
245+
Serial1.println(" 正在清除凭据并重启...");
246+
233247
setStatusLED(false);
248+
249+
// Clear WiFi credentials and restart
250+
// 清除 WiFi 凭据并重启
251+
ha.clearWiFiCredentials();
252+
Serial1.flush();
253+
delay(500);
254+
ESP.restart();
255+
// Never reaches here | 永远不会到达这里
234256
}
257+
258+
// Turn off LED | 关闭 LED
259+
setStatusLED(false);
235260
resetFeedbackGiven = false;
236261
}
237262
}

0 commit comments

Comments
 (0)