-
Notifications
You must be signed in to change notification settings - Fork 0
/
contacts.ino
82 lines (68 loc) · 1.95 KB
/
contacts.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
/*
Modul Contacts for ESP8266
part of Arduino Mega Server project
*/
#ifdef CONTACTS_FEATURE
#define CONT_1_PIN 12
#define CONT_2_PIN 13
#define STATE_NOT_DEFINED 2
#define OPEN 1
#define CLOSE 0
#define CONT_1_OBJECT_NAME "Door1"
#define CONT_2_OBJECT_NAME "Contact2"
#define OPEN_STR "Open"
#define CLOSED_STR "Closed"
#define CONT_2_OPEN_MESS "Down"
#define CONT_2_CLOSE_MESS "Norm"
// states
byte cont1OldState = STATE_NOT_DEFINED; byte cont1ObjState = STATE_NOT_DEFINED;
byte cont2OldState = STATE_NOT_DEFINED; byte cont2ObjState = STATE_NOT_DEFINED;
void contactsInit() {
pinMode(CONT_1_PIN, INPUT);
pinMode(CONT_2_PIN, INPUT);
modulContacts = MODUL_ENABLE;
started("Contacts");
}
void printContactState(char obj[], char mess[]) {
#ifdef EVENTS_CONTACTS
timeStamp();
Serial.print(obj);
Serial.print(": ");
Serial.println(mess);
#endif
}
void contact1Actions(byte state, char mess[], byte major) {
cont1ObjState = state;
printContactState(CONT_1_OBJECT_NAME, mess);
#ifdef MAJORDOMO_FEATURE
sendRequestM(CONT_1_OBJECT_NAME, major);
#endif
}
void contact2Actions(byte state, char mess[], byte major) {
cont2ObjState = state;
printContactState(CONT_2_OBJECT_NAME, mess);
#ifdef MAJORDOMO_FEATURE
sendRequestM(CONT_2_OBJECT_NAME, major);
#endif
}
void contact1Work() {
byte cont1State = digitalRead(CONT_1_PIN);
if (cont1State != cont1OldState) {
if (cont1State == HIGH) {contact1Actions(OPEN, OPEN_STR, OPEN);}
else {contact1Actions(CLOSE, CLOSED_STR, CLOSE);}
cont1OldState = cont1State;
}
}
void contact2Work() {
byte cont2State = digitalRead(CONT_2_PIN);
if (cont2State != cont2OldState) {
if (cont2State == LOW) {contact2Actions(OPEN, CONT_2_OPEN_MESS, OPEN);}
else {contact2Actions(CLOSE, CONT_2_CLOSE_MESS, CLOSE);}
cont2OldState = cont2State;
}
}
void contactsWorks() {
contact1Work();
contact2Work();
}
#endif // CONTACTS_FEATURE