Skip to content

Implemented timeout on connect/getPrompt to handle board in strange s… #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions ui/arduino/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,28 @@ async function store(state, emitter) {
state.isConnecting = true
emitter.emit('render')

let timeout_id = setTimeout(() => emitter.emit('connection-timeout'), 5000)
await serial.connect(path)
clearTimeout(timeout_id)

// The following Timeout operation will be cleared after a succesful getPrompt()
// If a board has crashed and/or cannot return a REPL prompt, the connection will fail
// and the user will be prompted to reset the device and try again.
let timeout_id = setTimeout(() => {
let response = win.openDialog({
type: 'question',
buttons: ['OK'],
cancelId: 0,
message: "Could not connect to the board. Reset it and try again."
})
console.log('Reset request acknowledged', response)
emitter.emit('connection-timeout')
}, 3500)
try {
await serial.connect(path)
} catch(e) {
console.error(e)
}
// Stop whatever is going on
// Recover from getting stuck in raw repl
await serial.getPrompt()

clearTimeout(timeout_id)
// Connected and ready
state.isConnecting = false
state.isConnected = true
Expand Down
Loading