Skip to content

Commit

Permalink
Faster now
Browse files Browse the repository at this point in the history
  • Loading branch information
lupyuen committed Feb 20, 2024
1 parent b84226b commit c00e056
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
5 changes: 4 additions & 1 deletion docs/blockly/jslinux.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 18 additions & 5 deletions docs/webserial/webserial.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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

0 comments on commit c00e056

Please sign in to comment.