arduinoesp8266arduino-idearduino-esp8266

parameters of Task in TaskScehduler Arduino


What are the different parameters used in the Task class of TaskScheduler Arduino Library?

   #include <TaskScheduler.h>
   Scheduler runner;
   Task t2(3000, TASK_FOREVER, &t2Callback, &runner, true)

What are the different callbacks that be used in Task Scheduler?

ThankYou


Solution

  • The API of the library is well documented in the wiki on GitHub. The corresponding section is the following:

    Task(unsigned long aInterval, long aIterations, void (*aCallback)(), Scheduler* aScheduler, bool aEnable, bool (*aOnEnable)(), void (*aOnDisable)(), bool aSelfdestruct);
    // OR
    Task(unsigned long aInterval, long aIterations, TaskCallback aCallback, Scheduler* aScheduler, bool aEnable, TaskOnEnable aOnEnable, TaskOnDisable aOnDisable, bool aSelfdestruct);
    

    Constructor with parameters.
    Creates a task that is scheduled to run every <aInterval> milliseconds, <aIterations> times, executing <aCallback> method on every pass.

    1. aInterval is in milliseconds (or microseconds) (default = 0 or TASK_IMMEDIATE)
    2. aIteration in number of times, -1 or TASK_FOREVER for indefinite execution (default = 0)
      Note: Tasks remember the number of iteration set initially, and could be restarted. After the iterations are done, the internal iteration counter is 0. If you need to perform a different set of iterations, you need to set the number of iterations explicitly.
      Note: Tasks which performed all their iterations will be disabled during next scheduling run.
    3. aCallback is a pointer to a void callback method without parameters (default = NULL)
    4. aScheduler – optional reference to existing scheduler. If supplied (not NULL) this task will be appended to the task chain of the current scheduler). (default = NULL)
    5. aEnable – optional. Value of true will create task enabled. (default = false)
    6. aOnEnable is a pointer to a bool callback method without parameters, invoked when task is enabled. If OnEnable method returns true, task is enabled. If OnEnable method return false, task remains disabled (default = NULL)
    7. aOnDisable is a pointer to a void callback method without parameters, invoked when task is disabled (default = NULL)

    All tasks are created disabled by default (unless aEnable = true). You have to explicitly enable the task for execution.