MistyGro API
C++ API for MistyGro's ESP32 controller based on the Arduino framework
scheduler.h
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Myron Rodrigues
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 // Partly created with chat GPT 3.5
18 
19 #ifndef SCHEDULER_H_
20 #define SCHEDULER_H_
21 
22 #include <time.h>
23 
24 #include "timer.h"
25 
33 class Scheduler
34 {
35 public:
36  Scheduler();
37 
44  void create_task(void (*task_func)(), unsigned long interval_sec);
45 
50  void run();
51 
57  void begin(long int timer_sync_interval_ms = 600000); // 10 mins
58 
59 private:
60 
65  struct TaskInfo
66  {
67  void (*task_func)();
68  unsigned long interval;
69  time_t last_execution_time;
70  };
71 
72  static const int MAX_TASKS = 10; // Maximum number of tasks
73  TaskInfo tasks_[MAX_TASKS];
74  int num_tasks_;
75  Timer timer_;
76 };
77 
78 #endif // SCHEDULER_H_
A scheduler for running tasks on the controller, minimum time between events is 1 second based off th...
Definition: scheduler.h:34
void begin(long int timer_sync_interval_ms=600000)
initialise timer
Definition: scheduler.cpp:45
void run()
This needs to be run in the loop function continuously. Best practice is to have a loop function that...
Definition: scheduler.cpp:31
void create_task(void(*task_func)(), unsigned long interval_sec)
Create a task.
Definition: scheduler.cpp:21
Timer that syncs with NTP server.
Definition: timer.h:27