Advertisement
bipping

TaskManager.h

Jun 28th, 2024
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 KB | Source Code | 0 0
  1. #ifndef C__USERS_BIPPI_ONEDRIVE_DOCUMENTS_ARDUINO_STEPMOTORV3_4_STEPMOTORV3_4_INO_STEPMOTORV3_4_TASKMANAGER_H_
  2. #define C__USERS_BIPPI_ONEDRIVE_DOCUMENTS_ARDUINO_STEPMOTORV3_4_STEPMOTORV3_4_INO_STEPMOTORV3_4_TASKMANAGER_H_
  3.  
  4. // Copyright [2024] <Bipping>
  5.  
  6. #include <avr/sleep.h>
  7. #include <avr/power.h>
  8. #include <avr/interrupt.h>
  9.  
  10. #define MAX_TASKS 10
  11. const uint32_t DEFAULT_MARGIN = 288;
  12.  
  13. uint8_t taskCount;
  14. volatile uint8_t isrCounter;
  15. volatile uint8_t remainingMicros;
  16. uint32_t margin;
  17.  
  18. typedef void (*TaskFunction)(void);
  19.  
  20. struct Task {
  21.     TaskFunction callback;
  22.     uint32_t interval;
  23.     uint32_t lastRun;
  24. };
  25.  
  26. // Enum for sleep modes
  27. enum SleepMode {
  28.     IDLE_MODE,
  29.     POWER_SAVE_MODE,
  30.     EXTENDED_STANDBY_MODE
  31. };
  32.  
  33.  
  34. Task tasks[MAX_TASKS];
  35.  
  36. void addTask(TaskFunction callback, uint32_t interval);
  37. void removeTask(TaskFunction callback);
  38. void changeTaskInterval(TaskFunction callback, uint32_t newInterval);
  39. void setSleepMode(SleepMode mode);
  40. void updateTasks();
  41.  
  42. #endif  // C__USERS_BIPPI_ONEDRIVE_DOCUMENTS_ARDUINO_STEPMOTORV3_4_STEPMOTORV3_4_INO_STEPMOTORV3_4_TASKMANAGER_H_
  43.  
Tags: Arduino
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement