-
Notifications
You must be signed in to change notification settings - Fork 1
/
LightPoint.cpp
94 lines (79 loc) · 2.54 KB
/
LightPoint.cpp
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
#include "LightPoint.h"
#include "Const.h"
#include "GeneralOutputStream.h"
LightPoint::LightPoint(int controlButtonPin, int controlOutputPin, const char* name):Point(name) {
this->controlButtonPin = controlButtonPin;
this->controlOutputPin = controlOutputPin;
}
LightPoint::LightPoint(int controlButtonPin, int controlOutputPin, const char* name, ControllerConnector *controllerConnector):Point(name) {
LightPoint(controlButtonPin, controlOutputPin, name);
this->setControllerConnector(controllerConnector);
}
LightPoint::~LightPoint() {
}
void LightPoint::initialize() {
pinMode(this->controlButtonPin, INPUT);
pinMode(this->controlOutputPin, OUTPUT);
}
boolean LightPoint::isControlButtonPressed() {
int buttonNow = digitalRead(this->controlButtonPin);
if (buttonNow != this->buttonPreviousState) {
this->buttonPreviousState = buttonNow;
if(buttonNow == HIGH) {
return true;
};
};
return false;
}
boolean LightPoint::isLightPointOn() {
return this->lightPointState == HIGH;
}
void LightPoint::setLightPointOn() {
setLightPointState(HIGH);
}
void LightPoint::setLightPointOff() {
setLightPointState(LOW);
}
void LightPoint::setLightPointState(int state) {
digitalWrite(this->controlOutputPin, state);
this->lightPointState = state;
}
void LightPoint::verifyControlPoint() {
if (isControlButtonPressed()) {
if (isLightPointOn()) {
setLightPointOff();
} else {
setLightPointOn();
}
sendStateUpdate();
}
}
char* LightPoint::createCommand(int state, char* command) {
if (state == LOW) {
strcpy(command, COMMAND_OFF);
} else {
strcpy(command, COMMAND_ON);
}
return command;
}
char* LightPoint::createCommand(char* command) {
return createCommand(this->lightPointState, command);
}
void LightPoint::executeCommand(const char* remoteName, const char* command) {
if (strcmp(command, COMMAND_ON) == 0) {
setLightPointOn();
} else if (strcmp(command, COMMAND_OFF) == 0) {
setLightPointOff();
} else {
DiagnosticOutputStream.sendln("Unknown action '", command, "' for point ", remoteName);
};
}
void LightPoint::printDiagnosticInfo() {
//LP: name, parent: name, btn: x, out: y, ctr:Y
DiagnosticOutputStream.send("LP parent:", this->parent->getRemoteName(), ", name: ", this->name);
DiagnosticOutputStream.send(", btn:");
DiagnosticOutputStream.send(this->controlButtonPin);
DiagnosticOutputStream.send(", out:");
DiagnosticOutputStream.send(this->controlOutputPin);
DiagnosticOutputStream.sendln(", ctr: ", this->controllerConnector == NULL ? "N" : "Y");
}