File tree Expand file tree Collapse file tree 4 files changed +31
-0
lines changed Expand file tree Collapse file tree 4 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,8 @@ const state = {
6161 isWriting : false
6262} ;
6363
64+ const delay = async ( n ) => await new Promise ( ( resolve ) => setTimeout ( resolve , n ) ) ;
65+
6466function setErrorMsg ( msg ) {
6567 errMsg . innerText = msg ;
6668 setScene ( scenes . error ) ;
@@ -200,6 +202,7 @@ async function writePassword(value) {
200202 throw new Error ( `Device acknowledged password length doesn't match (want: ${ value . length } , got: ${ val } )` ) ;
201203 }
202204
205+ await delay ( 500 ) ;
203206 setScene ( scenes . finish ) ;
204207 setTimeout ( ( ) => setScene ( scenes . start ) , 3000 ) ;
205208 } finally {
Original file line number Diff line number Diff line change @@ -20,5 +20,6 @@ uint16_t getPasswdLen();
2020void readPasswdStr (uint16_t len , uint8_t * dst );
2121void savePasswd (uint16_t len , uint8_t * data );
2222void wipePasswd ();
23+ void reset ();
2324
2425#endif
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ class SetupSaga : public Saga {
5555 PromptReader m_reader;
5656 unsigned long m_prevMillis = 0 ;
5757 bool m_ledEnabled = false ;
58+ bool m_changed = false ;
5859
5960 void updateLedState (bool state) {
6061 m_prevMillis = millis ();
@@ -95,6 +96,7 @@ class SetupSaga : public Saga {
9596 Serial.println ();
9697#endif
9798
99+ m_changed = true ;
98100 savePasswd (result.len , result.data );
99101 state.pwdLen = result.len ;
100102 if (state.pwdData != nullptr ) {
@@ -108,11 +110,21 @@ class SetupSaga : public Saga {
108110 void enter (BoardState& state) override {
109111 Serial.begin (9600 );
110112 updateLedState (true );
113+ m_changed = true ;
111114 m_reader.reset ();
112115 }
113116
114117 void leave (BoardState& state) override {
118+ Serial.flush ();
115119 Serial.end ();
120+
121+ if (m_changed) {
122+ // HACK: for some reason, board stuck in indeterminate state after a couple of sequential setup cycles.
123+ // Rebooting device helps.
124+ delay (250 );
125+ reset ();
126+ }
127+
116128 m_reader.reset ();
117129 digitalWrite (PIN_LED_SETUP, LOW);
118130 }
Original file line number Diff line number Diff line change 1+ #include < avr/wdt.h>
12#include < Arduino.h>
23#include < EEPROM.h>
34#include " config.h"
@@ -61,3 +62,17 @@ void wipePasswd() {
6162 EEPROM.update (i, 0xFF );
6263 }
6364}
65+
66+ void reset () {
67+ #if defined(__AVR__)
68+ wdt_disable ();
69+ wdt_enable (WDTO_15MS);
70+ while (1 ) {}
71+ #elif defined(ESP32) || defined(ESP8266)
72+ ESP.restart ();
73+ #else
74+ // Fallback for other architectures
75+ void (*resetFunc)(void ) = 0 ;
76+ resetFunc ();
77+ #endif
78+ }
You can’t perform that action at this time.
0 commit comments