A cooperative Arduino object oriented, cooperative process scheduler to replace them all.
What is this?
As your Arduino projects get more complicated, you will begin to see the need for multitasking, or at least appear to multitask. Perhaps you want to check if a button was pressed as often as you can, but you only want to update a display once every second. Trying to do this on your own can quickly turn into overwhelming spagetti code involving
ArduinoProcessScheduler seeks to simplify this. Simply create your custom Process that needs to be serviced at certain times, and let the scheduler handle the rest.
Why this one?
Here are some similar popular libraries that inspired this one:
What is wrong with them?
- They all treat processes/tasks as just callback functions.
- Forces you to use ugly global and/or static function variables to track process state.
- Limits you to one instance of a process, or lots of copy & paste.
- Impossible to truly dynamically create new processes, you are really just enabling/disabling a callback function.
- Preemptive schedulers must split stack between all processes
- With 2K or RAM and 8 processes, preemptive scheduler could at most equally give each Process 2k/8 = 256 Bytes of RAM.
- No concurrency protection (not interrupt safe)
- What if an interrupt fires an tries to disable a process while it is running?
- Control over how often a process runs (periodically, iterations, or as often as possible)
- Process priority levels (easily make custom levels as well)
- Dynamically add/remove and enable/disable processes
- Interrupt safe (add, disable, destroy, etc.. processes from interrupt routines)
- Process concurrency protection (Process will always be in a valid state)
- Spawn new processes from within running processes
- Automatic process monitoring statistics (calculates % CPU time for process)
- Truly object oriented (a Process is its own object)
- Exception handling (wait what?!)
- Scheduler can automatically interrupt stuck processes
- ESP8266 (No exception handling or process timeouts)
Install & Usage
NOTE: Don't forget to install this RingBuf library dependency!
I welcome any contributions! Here are some ideas:
- Built in logging
- Built in timers
- Built in process ownership (Library tracks who owns a Process)
- More advanced Process statistics monitoring
- Adding support for additional platforms
- Any Examples!