Skip to content

Commit 9f56d75

Browse files
authored
Merge pull request #150 from arduino/fix/timeout-getprompt-alert
Implemented timeout on connect/getPrompt to handle board in strange s…
2 parents 6febfac + fa37c89 commit 9f56d75

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

Diff for: ui/arduino/store.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,28 @@ async function store(state, emitter) {
122122
state.isConnecting = true
123123
emitter.emit('render')
124124

125-
let timeout_id = setTimeout(() => emitter.emit('connection-timeout'), 5000)
126-
await serial.connect(path)
127-
clearTimeout(timeout_id)
128-
125+
// The following Timeout operation will be cleared after a succesful getPrompt()
126+
// If a board has crashed and/or cannot return a REPL prompt, the connection will fail
127+
// and the user will be prompted to reset the device and try again.
128+
let timeout_id = setTimeout(() => {
129+
let response = win.openDialog({
130+
type: 'question',
131+
buttons: ['OK'],
132+
cancelId: 0,
133+
message: "Could not connect to the board. Reset it and try again."
134+
})
135+
console.log('Reset request acknowledged', response)
136+
emitter.emit('connection-timeout')
137+
}, 3500)
138+
try {
139+
await serial.connect(path)
140+
} catch(e) {
141+
console.error(e)
142+
}
129143
// Stop whatever is going on
130144
// Recover from getting stuck in raw repl
131145
await serial.getPrompt()
132-
146+
clearTimeout(timeout_id)
133147
// Connected and ready
134148
state.isConnecting = false
135149
state.isConnected = true

0 commit comments

Comments
 (0)