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.

Reply via email to