TaskSched
|
TaskSched is a cooperative multitasking scheduler for Arduino processors, designed as a simpler alternative to existing schedulers like TaskScheduler. It provides a flexible and efficient way to manage multiple tasks in Arduino projects, particularly tested on ESP32 and ESP8266 processors.
A cooperative task scheduler is a system that manages the execution of multiple tasks, but with a twist compared to a traditional scheduler. Here's the key difference:
Cooperative: In a cooperative scheme, tasks are responsible for voluntarily giving up control of the processor when they're done or need to wait for something. The scheduler simply provides a starting point and trusts the tasks to behave. This is in contrast to a preemptive scheduler, where the operating system can interrupt a running task and switch to another one.
Here's a breakdown of how cooperative scheduling works:
Pros and Cons:
Use Cases:
To install TaskSched, clone the repository:
Or download the ZIP file.
Tasks are created using the Task
constructor:
TaskCallback
: Function to be called (must accept a Task*
parameter)VoidCallback
: Function to be called (no parameter)interval
: Time between calls milliseconds if integerenabled
: Whether the task starts enablediterations
: Number of times to run (0 for infinite)name
: Descriptive name for the taskrunImmediately
: Whether to run immediately when enabled without waiting for interval to expireKey methods for managing tasks: (https://averageguy.github.io/task-docs/classTask.html)
enable()
: Enable the taskdisable()
: Disable the taskrestart()
: Restart the task with original parameterssetInterval(newInterval)
: Set a new intervalsetIterations(newIterations)
: Set a new iteration countisEnabled()
: Check if the task is enabledisFirstIteration()
: Check if it's the first iterationisLastIteration()
: Check if it's the last iterationThe Sched
class manages multiple tasks:
Key methods in the Sched class (https://averageguy.github.io/task-docs/classSched.html)
enable()
: Enable the schedulerdisable()
: Disable the schedulerbegin()
: Initialize the schedulerrun()
: Loop throught the tasks and run them one at a time, if they are scheduled.getSize()
: Return the number of tasks in the run queuedisplayStatus()
: Returns a String with info about some or all of the tasks in the queue.addTask()
: Adds a task to the queue.isEnabled()
: Returns a true if the scheduler is enabled or false if it is not.getTasks()
: Returns a list of the tasks. See the example/SkedBlink2.ino file for examples of ways to use this list.See the examples
directory for basic examples of blinking an LED using TaskSched and others. Also look at the wiki. It has more examples and explanations.
For detailed API documentation, please refer to the Doxygen-generated documentation https://averageguy.github.io/task-docs/
If you encounter any issues or have feature requests, please open an issue on the GitHub repository.
Contributions to TaskSched are welcome. Please feel free to submit pull requests or open issues to discuss potential improvements.