-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclockify_timer.h
More file actions
107 lines (95 loc) · 3.22 KB
/
Copy pathclockify_timer.h
File metadata and controls
107 lines (95 loc) · 3.22 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
enum TimerState {TIMER_STOPPED, TIMER_PENDING, TIMER_STARTING, TIMER_START_SENT, TIMER_RUNNING, TIMER_STOPPING, TIMER_STOP_SENT};
typedef struct {
char id[25];
char sideId[17];
unsigned int start;
char startTime[25];
char endTime[25];
char apiKey[49];
char workspaceId[25];
char projectId[25];
char taskId[25];
char description[65];
TimerState state;
TimerState desiredState;
} ClockifyTimer;
RTC_NOINIT_ATTR ClockifyTimer clockifyTimers[MAX_CLOCKIFY_TIMERS];
String stateToString(TimerState state) {
switch (state) {
case TIMER_STOPPED: {
return "TIMER_STOPPED";
}
case TIMER_PENDING: {
return "TIMER_PENDING";
}
case TIMER_STARTING: {
return "TIMER_STARTING";
}
case TIMER_START_SENT: {
return "TIMER_START_SENT";
}
case TIMER_RUNNING: {
return "TIMER_RUNNING";
}
case TIMER_STOPPING: {
return "TIMER_STOPPING";
}
case TIMER_STOP_SENT: {
return "TIMER_STOP_SENT";
}
}
return "STATE NOT FOUND";
}
void initTimers() {
for (int timerId = 0; timerId < MAX_CLOCKIFY_TIMERS; timerId++) {
if (stateToString(clockifyTimers[timerId].state ) != "STATE NOT FOUND" &&
stateToString(clockifyTimers[timerId].desiredState) != "STATE NOT FOUND") {
continue;
}
memset(&clockifyTimers[timerId], 0, sizeof(ClockifyTimer));
}
}
void printTimer(int timerId) {
#ifdef DEBUG
Serial.print("- id: "); Serial.println(clockifyTimers[timerId].id);
Serial.print("- sideId: "); Serial.println(clockifyTimers[timerId].sideId);
Serial.print("- startTime: "); Serial.println(clockifyTimers[timerId].startTime);
Serial.print("- endTime: "); Serial.println(clockifyTimers[timerId].endTime);
Serial.print("- apiKey: "); Serial.println(clockifyTimers[timerId].apiKey);
Serial.print("- workspaceId: "); Serial.println(clockifyTimers[timerId].workspaceId);
Serial.print("- projectId: "); Serial.println(clockifyTimers[timerId].projectId);
Serial.print("- taskId: "); Serial.println(clockifyTimers[timerId].taskId);
Serial.print("- description: "); Serial.println(clockifyTimers[timerId].description);
Serial.print("- state: "); Serial.println(stateToString(clockifyTimers[timerId].state));
Serial.print("- desiredState: "); Serial.println(stateToString(clockifyTimers[timerId].desiredState));
#endif
}
bool hasUnpersistedTimers = false;
void saveTimers() {
#ifdef DEBUG
Serial.println("saveTimers");
#endif
hasUnpersistedTimers = true;
}
void updateTimerState(int timerId, TimerState newState) {
#ifdef DEBUG
Serial.print("Updating timer ");
Serial.print(timerId); Serial.print(" state from ");
Serial.print(stateToString(clockifyTimers[timerId].state));
Serial.print(" to ");
Serial.println(stateToString(newState));
#endif
clockifyTimers[timerId].state = newState;
saveTimers();
}
void updateTimerDesiredState(int timerId, TimerState newState) {
#ifdef DEBUG
Serial.print("Updating timer ");
Serial.print(timerId); Serial.print(" desiredState from ");
Serial.print(stateToString(clockifyTimers[timerId].desiredState));
Serial.print(" to ");
Serial.println(stateToString(newState));
#endif
clockifyTimers[timerId].desiredState = newState;
saveTimers();
}