Yes - no problem! It's probably most efficient to think of it like:
Send command 1
When ack received, send command 2
When ack received ....
So you might want something like this:
var ser = Serial1;
var commands = [];
var allSent = true;
function sendCommand(cmd) {
if (allSent) {
// if everything was sent, start again
Serial.write(cmd);
allSent = false;
} else {
// otherwise we're sending - just push the new command onto the end
commands.push(cmd);
}
}
ser.on('data', function(d) {
for (var i in d)
if (d[i]=="\x06") {
if (commands.length) {
// send command off the start of the list
Serial.write(commands.shift());
} else {
// signal we're done
allSent = true;
}
}
});
Then you just call sendCommand with each command, and they get queued up.
I guess you might want some kind of timeout in there as well though?
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi Gerry,
Yes - no problem! It's probably most efficient to think of it like:
So you might want something like this:
Then you just call
sendCommand
with each command, and they get queued up.I guess you might want some kind of timeout in there as well though?