From fa37c89eac548a1b1c2e64d6d5b26ba50dff3c01 Mon Sep 17 00:00:00 2001 From: ubi de feo Date: Thu, 5 Dec 2024 15:40:56 +0100 Subject: [PATCH] Implemented timeout on connect/getPrompt to handle board in strange state (crash). Signed-off-by: ubi de feo --- ui/arduino/store.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/ui/arduino/store.js b/ui/arduino/store.js index 2c93a7e..c748905 100644 --- a/ui/arduino/store.js +++ b/ui/arduino/store.js @@ -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