forked from dastcvi/StratoCore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStratoScheduler.h
62 lines (48 loc) · 1.7 KB
/
StratoScheduler.h
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
/*
* StratoScheduler.h
* Author: Alex St. Clair
* Created: June 2019
*
* This file declares a class to perform scheduling through the
* StratoCore based on GPS time from the Zephyr.
*/
#ifndef STRATOSCHEDULER_H
#define STRATOSCHEDULER_H
#include <TimeLib.h>
#include <stdint.h>
#define NO_SCHEDULED_ACTION 0
#define MAX_SCHEDULE_SIZE ((uint8_t) 32) // must be 0-255
// define a struct for use only as a container for scheduled actions
struct ScheduleItem_t {
// data
ScheduleItem_t * prev;
ScheduleItem_t * next;
time_t time;
uint8_t action;
bool exact_time; // scheduled exact or relative?
bool in_use;
};
class StratoScheduler {
public:
// empty constructors and destructors
StratoScheduler();
~StratoScheduler() { };
// returns 0 if no action ready, or the id if one is ready
uint8_t CheckSchedule();
// overloaded method for scheduling actions, returns based on schedule push success
bool AddAction(uint8_t action, time_t seconds_from_now);
bool AddAction(uint8_t action, TimeElements exact_time);
// changes the scheduled times according to a number of seconds to adjust
void UpdateScheduleTime(int32_t seconds_adjustment);
// called after every mode switch
void ClearSchedule();
void PrintSchedule();
private:
ScheduleItem_t * GetFreeItem();
bool SchedulePush(uint8_t action, time_t schedule_time, bool exact);
void SchedulePop(); // remove (and delete!) the first item
ScheduleItem_t item_array[MAX_SCHEDULE_SIZE] = {{0}};
uint8_t schedule_size; // num items in schedule
ScheduleItem_t * schedule_top; // pointer to first element
};
#endif