A scheduled control signal with fibers?
Sebastiaan Koppe
mail at skoppe.eu
Fri Sep 25 13:08:16 UTC 2020
On Friday, 25 September 2020 at 11:58:53 UTC, Ferhat Kurtulmuş
wrote:
> int main(){
> ...
>
> while(true){
>
> int pwmval = getFlameIntensityViaImageProcessing();
>
> sendPWMSignalToValfe(pwmval); // I need this streamed
> ctrl signal to the valfe with a delayed time shift
>
> // a possible solution:
> // enum afterNmilliseconds = 1500;
>
> // schedulePWMSignalToValve(pwmval, afterNmilliseconds
> );
>
> ...
> }
> ...
> }
>
> How can I implement schedulePWMSignalToValve(pwmval,
> afterNmilliseconds ) using fibers?
>
> Thanks in advance.
No need for fibers per se.
You can run 2 threads. One that produces {time: now + 1500.msecs,
value: getFlameIntensityViaImageProcessing} objects and one that
consumes those and basically waits until each's msg.time < now
and then sendPWMSignalToValfe(msg.value). You would basically
rely on std.concurrency's MessageBox to do the queuing. Although
you could do that manually as well.
Could also run it on 1 thread if you don't mind there being a
jitter of however long getFlameIntensityViaImageProcessing takes,
but you will need a queue.
More information about the Digitalmars-d-learn
mailing list