diff --git a/docs/blockly/jslinux.js b/docs/blockly/jslinux.js index 9254db3..783f8de 100644 --- a/docs/blockly/jslinux.js +++ b/docs/blockly/jslinux.js @@ -529,9 +529,12 @@ function start_vm(user, pwd) send_str = send_str.substring(1); window.setTimeout(()=>{ send_command(null); }, 10); } + // Send a command to serial port. Newlines become Carriage Returns. + const code = window.localStorage.getItem("runCode") + .split('\n').join('\r'); const cmd = [ `qjs`, - window.localStorage.getItem("runCode"), + code, `` ].join("\r"); window.setTimeout(()=>{ send_command(cmd); }, 5000); diff --git a/docs/webserial/webserial.js b/docs/webserial/webserial.js index 21e214b..4750c09 100644 --- a/docs/webserial/webserial.js +++ b/docs/webserial/webserial.js @@ -660,11 +660,13 @@ async function control_device() { console.log("NSH Spotted!"); nshSpotted = true; - // Send a command to serial port + // Send a command to serial port. Newlines become Carriage Returns. + const code = window.localStorage.getItem("runCode") + .split('\n').join('\r'); const cmd = [ `qjs`, - window.localStorage.getItem("runCode"), - ` ` + code, + `` ].join("\r"); window.setTimeout(()=>{ send_command(writer, cmd); }, 1000); } @@ -675,8 +677,19 @@ let send_str = ""; async function send_command(writer, cmd) { if (cmd !== null) { send_str = cmd; } if (send_str.length == 0) { return; } - await writer.write(send_str.substring(0, 1)); + + // Get the next character + const ch = send_str.substring(0, 1); send_str = send_str.substring(1); - window.setTimeout(()=>{ send_command(writer, null); }, 1000); + + // Slow down at the end of each line + const timeout = (ch === "\r") + ? 2000 + : 10; + console.log({ch, timeout}); + + // Send the character + await writer.write(ch); + window.setTimeout(()=>{ send_command(writer, null); }, timeout); } //// End Test