Quantcast
Channel: openFrameworks - Latest posts
Viewing all articles
Browse latest Browse all 40524

Running a function every 250us (microseconds) on Ras Pi 2

$
0
0

in 0.9 you there's a new class that does exactly this, we use it to control the fps when setting it explictly. ofTimer. on an ofThread threadedFunction call:

class Scheduler: public ofThread{
public:
Scheduler(){
    timer.setPeriodicEvent(250000); // parameter is in nanoseconds
}

private:
ofTimer timer;
void threadedFunction(){
    while(isThreadRunning()){
         timer.waitNext();
         // do your thing here
    }
}
}

the timer will wake up at 250us intervals no matter how long the rest of the task takes, if the last execution took more than 250us it'll wake up right away and execute the next. it also uses the most accurate timming functions on every OS


Viewing all articles
Browse latest Browse all 40524