Download the file
  1. #ifndef TASKS_H
  2. #define TASKS_H
  3.  
  4. #include "hsphoto.h"
  5.  
  6. class Task {
  7. public:
  8. virtual bool canRun(uint32_t now) = 0;
  9. virtual void run(uint32_t now) = 0;
  10. };
  11.  
  12. class TimedTask : public Task {
  13. public:
  14. inline TimedTask(uint32_t when) { runTime = when; }
  15. virtual bool canRun(uint32_t now);
  16. inline void setRunTime(uint32_t when) { runTime = when; }
  17. inline void incRunTime(uint32_t inc) { runTime += inc; }
  18. inline uint32_t getRunTime() { return runTime; }
  19. protected:
  20. uint32_t runTime;
  21. };
  22.  
  23. class PeriodicTask : public TimedTask {
  24. public:
  25. inline PeriodicTask(uint32_t period):
  26. TimedTask(millis()),
  27. period(period)
  28. {}
  29. void run(uint32_t now) { do_run(); runTime += period; }
  30. virtual void do_run();
  31. protected:
  32. uint32_t period;
  33. };
  34.  
  35. #endif
  36. // vim:ft=arduino
  37.