-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathThreadLite.h
More file actions
56 lines (37 loc) · 1.13 KB
/
ThreadLite.h
File metadata and controls
56 lines (37 loc) · 1.13 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
// Created by Ivan Seidel Gomes, March, 2013. Released into the public domain.
// Copyright © 2018 Stanislav Hnatiuk. All rights reserved.
#ifndef THREADLITE_H
#define THREADLITE_H
#include <Arduino.h>
using time_int = uint16_t;
constexpr time_int time_over = (1 << (sizeof (time_int) * 8 - 1));
class Thread{
protected:
// Desired interval between runs
time_int interval;
// Last runned time in Ms
time_int last_run;
// Scheduled run in Ms (MUST BE CACHED)
time_int _cached_next_run;
/*
IMPORTANT! Run after all calls to run()
Updates last_run and cache next run.
NOTE: This MUST be called if extending
this class and implementing run() method
*/
// Default is to mark it runned "now"
void runned();
// Callback for run() if not implemented
void (*_onRun)(void);
public:
Thread(void (*callback)(void), time_int _interval);
// Set the desired interval for calls, and update _cached_next_run
void setInterval(time_int _interval);
// Default is to check whether it should run "now"
bool shouldRun();
// Runs Thread if should be it
void run();
// Execute Thread
void execute();
};
#endif // THREADLITE_H