-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimerManager.h
More file actions
43 lines (34 loc) · 1.23 KB
/
Copy pathTimerManager.h
File metadata and controls
43 lines (34 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef TIMERMANAGER_H
#define TIMERMANAGER_H
#include <Arduino.h>
#include "uTimerLib.h"
#ifndef MAX_TIMERS
#define MAX_TIMERS 10 // Maximum number of timers
#endif
#define MAX_LEN_TIMER_NAME 20
// Structure to represent a timer event
struct TimerEvent {
unsigned long period; // Interval between events in milliseconds
unsigned long next; // Timestamp when the event should trigger next
void (*callback)(); // Pointer to the callback function for the timer event
bool active; // Flag to indicate if the timer is active
char name[MAX_LEN_TIMER_NAME]; // Timer name
};
// Class to manage multiple timer events using a single hardware timer
class TimerManager {
public:
TimerManager();
void updateTimer();
void addTimer(void (*callback)(), char* name, unsigned long period);
void removeTimer(char* name);
void disableTimer(char* name);
void enableTimer(char* name);
void startAll();
void stopAll();
static void timerCallback();
private:
TimerEvent timers[MAX_TIMERS]; // Array to store timer events
bool enabled;
static TimerManager* instance; // Static instance pointer for the singleton pattern
};
#endif