-
Notifications
You must be signed in to change notification settings - Fork 1
/
logic.ino
140 lines (132 loc) · 5.34 KB
/
logic.ino
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
bool pushLogic() {
// THIS STUFF ONLY REALLY USED IN HIGH SPEED CASES
if (strcmp(config.highSpeed, "t") == 0) { //only if enabled
Serial.println("High Speed Mode");
if (contactLatchClosed && contactLatchOpen) {
Serial.println("BOTH Latches were triggered - must have opened//closed real fast");
Serial.println("Going to send first contact position first, then oposite");
if (digitalRead(contactStatusPin)) {//is open now, so will send closed first
contactLatchOpen = false;
}
else {
contactLatchClosed = false;
}
contactStatusClosed = !contactStatusClosed;//just so we make sure to send opposite next reboot
} else { //maybe something else weird covered here
if (contactLatchOpen && contactStatusClosed) { //latched open, status is closed?
if (timerWake) { //we're going to ignore this
Serial.println("treating like a timer wake");
contactLatchOpen = false;
contactLatchClosed = false;
} else {
Serial.println("Latch Status mismatch, thought opened, but really closed");
contactLatchOpen = true;
contactLatchClosed = false;
Serial.println("Going to send first contact position first, then oposite");
contactStatusClosed = !contactStatusClosed;
}
}
if (contactLatchClosed && !contactStatusClosed) { //latched closed, status is open?
if (timerWake) { //we're going to ignore this
Serial.println("treating like a timer wake");
contactLatchOpen = false;
contactLatchClosed = false;
} else {
Serial.println("Latch Status mismatch, thought closed, but really open");
contactLatchOpen = false;
contactLatchClosed = true;
Serial.println("Going to send first contact position first, then oposite");
contactStatusClosed = !contactStatusClosed;
}
}
}
} else {
//slow normal speed
Serial.println("Normal Mode");
if (timerWake) { //timer wake, then do nothing with contact latches
contactLatchOpen = false;
contactLatchClosed = false;
} else {
if (contactStatusClosed) {
contactLatchClosed = true;
contactLatchOpen = false;
} else {
contactLatchClosed = false;
contactLatchOpen = true;
}
}
}
//check to see if we need wifi for anything
// mqtt or ifttt or pushsafer or pushover, udp is a private network configured separately
if (strcmp(config.iftttEnable, "t") == 0 || strcmp(config.mqttEnable, "t") == 0 || strcmp(config.pushSaferEnable, "t") == 0 || strcmp(config.pushOverEnable, "t") == 0) {
wiFiNeeded = true;
}
//**************************************
if (buttonWasPressed) {
Serial.println(F("BUTTON"));
sprintf(pushMessage, "%s, %sV", config.buttonMessage, batCharString);
rtcInit(config.timerCountDown, true);//reset timer
return true;
}
//**************************************
if (strcmp(config.trigSelect, "Close") == 0 && contactLatchClosed) {
Serial.println(F("CONTACT CLOSE"));
sprintf(pushMessage, "%s, %sV", config.triggerClosesMessage, batCharString);
rtcInit(config.timerCountDown, true);//reset timer - this is set to true so that when the door opens/closes, you start fresh
return true;
}
//**************************************
if (strcmp(config.trigSelect, "Open") == 0 && contactLatchOpen) {
Serial.println(F("CONTACT OPEN"));
sprintf(pushMessage, "%s, %sV", config.triggerOpensMessage, batCharString);
rtcInit(config.timerCountDown, true);//reset timer
return true;
}
//**************************************
if (strcmp(config.trigSelect, "Both") == 0) {
if (contactLatchOpen) {
Serial.println(F("CONTACT OPEN"));
sprintf(pushMessage, "%s, %sV", config.triggerOpensMessage, batCharString);
rtcInit(config.timerCountDown, true);//reset timer
return true;
}
if (contactLatchClosed) {
Serial.println(F("CONTACT CLOSE"));
sprintf(pushMessage, "%s, %sV", config.triggerClosesMessage, batCharString);
rtcInit(config.timerCountDown, true);//reset timer
return true;
}
}
//**************************************
if (timerWake && lowBattery) { //priority
Serial.println(F("TIMER + LOW BAT"));
sprintf(pushMessage, "LOW BATTERY!, %sV", batCharString);
return true;
}
//**************************************
if (timerWake && strcmp(config.timerSelect, "Closed") == 0 && contactStatusClosed) {
Serial.println(F("TIMER + CONTACT CLOSED"));
sprintf(pushMessage, "%s, %sV", config.StillClosedMessage, batCharString);
return true;
}
//**************************************
if (timerWake && strcmp(config.timerSelect, "Open") == 0 && !contactStatusClosed) {
Serial.println(F("TIMER + CONTACT OPEN"));
sprintf(pushMessage, "%s, %sV", config.StillOpenMessage, batCharString);
return true;
}
//**************************************
if (timerWake && strcmp(config.timerSelect, "Either") == 0) {
if (contactStatusClosed) {
Serial.println(F("TIMER + CONTACT CLOSE"));
sprintf(pushMessage, "%s, %sV", config.StillClosedMessage, batCharString);
return true;
}
else {
Serial.println(F("TIMER + CONTACT OPEN"));
sprintf(pushMessage, "%s, %sV", config.StillOpenMessage, batCharString);
return true;
}
}
return false;
}