Ticker and TimedTrigger

Files CCore/inc/task/Ticker.h CCore/src/task/Ticker.cpp

Ticker

The class Ticker is built upon the class TickJob and should be used to schedule a timed job.


class Ticker : public Funchor_nocopy
 {
   ....

  public:
  
   explicit Ticker(Function<void (void)> action_int);
  
   Ticker(Function<void (void)> action_int,MSec delay,MSec period=Nothing);
   
   ~Ticker();
   
   void start(MSec delay,MSec period=Nothing);
   
   void stop();
 };

Constructor takes an action function as the argument. The function will be called in the interrupt context and as such must be a "quick function". The second constructor also starts the object with the given parameters.

Destructor stops the ticker, if it was not stopped.

start() starts or restarts the object with the given parameters. The first argument is a delay before the first action. The second, if it is not zero, specifies the period, actions will be performed with the given periodicity.

stop() stops the ticker.

TimedTrigger

TimedTrigger allows delay and combine actions to reduce the action call frequency.


class TimedTrigger : public Funchor_nocopy
 {
   ....

  public:
  
   TimedTrigger(Function<void (void)> action_int,MSec delay);
   
   ~TimedTrigger();
   
   void trigger();
   
   void stop();
 };

Constructor arguments are: an action function, which is called in the interrupt context and the maximum delay time.

Destructor stops the object.

trigger() "triggers" the action. It will be performed within delay time limit. But if the action was already triggered, the function does nothing. So multiple triggers during a short time period are combined into the single action.

stop() stops the object.