Figure everyone in this forum is very 'node' savvy, so that is why I am asking here. I am trying to drive a MAX7219 controlled display. Writing an updated node library for it. I have it done but for one basic problem. I need to write to the display, wait a specific time, and write again, etc. This is to support a ticker-tape mode node. This has to be a sync stream of writes and waits, it can't be async. To using setInterval, setTimeout, promise methods don't seem to work, using await cannot be used. Every time my code writes to the display for the first message, it works, but the next message write steps on it, because the sync blocking is really async based. Got to love node/JavaScript for this one!
For example...
node input 1... write to display... right to left shifting one character at a time, so write wait write wait etc...
Buffer is...
"012345678 This is o test!"
Display...
" "
Wait...
Display...
" 0"
Wait...
Display...
" 01"
Wait...
Display...
" 012"
Wait...
Display...
" 0123"
I trust you get the idea?
No matter what method I have tried, timeout, promise, interval, etc. The inputs overlap, by whatever the initial delay offset is between the first and second input.
I can't use sleep, per my understanding because it blocks the entire node js event loop? But the basic sleep module works, my MAX7219 write routine does not return until the entire first message is displayed correct.
I have spent several hours reading on Google, trying different methods, but non seeme to do a true current thread block quite the way I need it. Or I am just not implementing the various methods right?
Hope someone with more node js (JavaScript) knowledge knows of a method to do a sync wait that actually works, that does not do something evil to anything else. Or maybe there is another way altogether that would work, I am just not finding or know of?
I realize this is a unique issue for node js given its core nature is async.
Oh, I tried using a trigger node in NR, but because my write routine returns too fast... the trigger fires to soon, so I get the next input message too fast, and I end up with the overlap again. Same with a delay or rate limit, either the rest comes to fast, or the total time is not known so rate limit does not work for this. I tried using simple queue, and a couple of other NR queue modules, but always come back to the fact that my write routine is coming back too soon, while the display is still working on the current message.