Download the file
  1. #include "Scheduler.h"
  2.  
  3. bool TimedTask::canRun(uint32_t now) {
  4. return now >= runTime;
  5. }
  6.  
  7.  
  8. TaskScheduler::TaskScheduler(Task **_tasks, uint8_t _numTasks) :
  9. tasks(_tasks),
  10. numTasks(_numTasks) {
  11. }
  12.  
  13. void TaskScheduler::run() {
  14. for(;;) {
  15. uint32_t now = millis();
  16. for (int t = 0; t < numTasks; t++) {
  17. Task *tp = tasks[t];
  18. if (tp->canRun(now)) {
  19. tp->run(now);
  20. break;
  21. }
  22. }
  23. }
  24. }
  25.  
  26. // vim:ft=arduino
  27.