How to carry out functions in a sequential manner #469
Replies: 5 comments
-
Posted at 2015-10-22 by @gfwilliams 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 I guess you might want some kind of timeout in there as well though? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-22 by @allObjects Is the ack something you receive serially / over RX from the module? If so, use serial.onData(callback) with callback function receiving the ack and triggering the next command... For use in application logic, this is of course a bit cumbersome... Therefore, you may use a FIFO with some triggering methods inbetween your app and the display which takes care of feeding the display module with the comands in a timely correct manner/sequence, where as the application just pushes to the FIFO without having to be time aware. The FIFO is of course a buffer and could over-grow if you have a run-away in your application. Some code 'in the rough':
This code has no error handling (over flow, out of synch, etc.) in place. For examples:
A first enhancement is to leave the command in the fifo (using The Can you share the code how you got your display initially working? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-22 by @allObjects @gordon, what is the reason to go for a loop in the callback, since it is serialized anyway (at best one ack for every cmd and only ack can/should trigger the next cmd)? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-22 by GKeely Hi regards Gerry |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-23 by @gfwilliams @allObjects true - I could just check with indexOf. I was assuming that there might be other characers sent - but if not, you could just use the occurrence of more data to trigger sending the next command. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-22 by GKeely
Hi
I'm new to Javascript/Espruino and trying to get a 4D Systems oled gmd-128 Display (serial connection) to work.
After each command is sent the display responds with an ack(0x06) if successful and next command should not be sent until ack is received.
I have managed to get the display working by using the setTimeout('func',td);
but this is not the most efficient way.
I would appreciate any info has to how to "force" sequential operation ie
Send command 1
wait for ack
Send command 2
wait for ack
etc
regards
Gerry
ps hope this makes sense !
Beta Was this translation helpful? Give feedback.
All reactions