ImFusion SDK 4.3
Debouncer Class Reference

#include <ImFusion/GUI/Debouncer.h>

Class that can be used to limit the frequency of calls to a function. More...

+ Inheritance diagram for Debouncer:

Detailed Description

Class that can be used to limit the frequency of calls to a function.

Every time the debouncer is called, the underlying function is called only if this would not violate the frequency limit, otherwise the call is scheduled as soon as the frequency limit allows. If a call was already scheduled, then no further call is scheduled.

WARNING: Not every call to the debouncer will correspond to a call to the underlying function. WARNING: A Debouncer instance can be called from any thread but the underlying function will always be called in QT Main Thread

This drawing summarizes the behaviour of the class

Call to debouncer X----X------------------X-------------XXX--X-X------
Call to underlying function X--------X--------------X-------------X---------X---
Min wait interval |________|_________| |_________| |_________|

It is possible to specify useScheduling=false in the constructor to use this class as a rate limiter. This mode doesn't use QT to schedule calls but simply drop calls that happen in intervals shorter than minWaitMs This drawing summarizes the behaviour of the class with useScheduling=false

Call to debouncer X----X------------------X-------------XXX--X-X------
Call to underlying function X-----------------------X-------------X-------------
Min wait interval |________| |_________| |_________|

Public Member Functions

 Debouncer (std::function< void()> f, int minWaitMs=15, bool useScheduling=true)
 
bool run (bool forceImmediate=false)
 
void setMinWait (int minWaitMs)
 
void setFpsLimit (int fps)
 
void setFunction (std::function< void()> f)
 

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close