-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStateChange01.h
More file actions
56 lines (39 loc) · 1.63 KB
/
StateChange01.h
File metadata and controls
56 lines (39 loc) · 1.63 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
#ifndef StateChange_h
#define StateChange_h
#include <Arduino.h>
#include <functional>
#include <Runnable.h>
//StateControll
class StateChange : public Runnable {
private:
bool state = 0;
bool changed = 0;
ulong tChanged = 0;
ulong tChangedOld = 0;
void setChanged() { changed = true; tChangedOld = tChanged; tChanged = millis();
callback( state );
}
typedef std::function<void(bool)> callback_t;
callback_t callback;
public:
StateChange() {} // Constructor
void setup() {}
void loop() { changed = false; } //EndOf loop
bool isActive() { return( state ); }
bool isChanged() { return( changed ); } // 1CicleTimeMemory
bool isChToActive() { return( changed && isActive() ); }
bool isChToNotActive() { return( changed && !isActive() ); }
ulong getTChanged() { return( tChanged ); }
ulong getDTChanged() { return( tChanged -tChangedOld ); }
void setActive( bool activeNew ) {
if( state != activeNew ) {
if( activeNew ) Serial.print("1");
else Serial.print("0");
state = activeNew; setChanged();
}
}
void setCallBack( callback_t callback_ ) {
callback = callback_;
}
};
#endif