-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathEnvironmentController.java
More file actions
160 lines (131 loc) · 3.22 KB
/
EnvironmentController.java
File metadata and controls
160 lines (131 loc) · 3.22 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
* Created by rosanna_corvino on 6/14/16.
*/
public class EnvironmentController implements EnvironmentInterface{
private HVAC hvac;
private Integer minTemp;
private Integer maxTemp;
public boolean heatStatus;
public boolean coolStatus;
public boolean fanStatus;
public int heatOnCount;
public int heatOffCount;
public int coolOnCount;
public int coolOffCount;
public EnvironmentController(HVAC hvac, Integer minTemp, Integer maxTemp){
this.hvac = hvac;
this.minTemp = minTemp;
this.maxTemp = maxTemp;
heatStatus = false;
coolStatus = false;
fanStatus = false;
heatOnCount = 0;
heatOffCount = 0;
coolOnCount = 0;
coolOffCount = 0;
}
public void tick(){
if (hvac.temp() < minTemp){
turnOnHeat();
}
if (hvac.temp() > maxTemp){
turnOnCool();
}
}
private void turnOnHeat(){
hvac.heat(true);
hvac.fan(true);
turnOffCool();
heatOnCheckHeatStatusAdjustCount();
heatStatus = true;
}
private void turnOnCool(){
hvac.cool(true);
hvac.fan(true);
turnOffHeat();
coolOnCheckCoolStatusAdjustCount();
coolStatus = true;
}
private void turnOffHeat(){
hvac.heat(false);
heatOffCheckHeatStatusAdjustCount();
heatStatus = false;
if (heatOffCount <= 5){
turnFanOff();
}
else{
turnFanOn();
}
}
private void turnOffCool(){
hvac.cool(false);
coolOffCheckStatusAdjustCount();
coolStatus = false;
if (coolOffCount <= 3){
turnFanOff();
}
else{
turnFanOn();
}
}
private void turnFanOn(){
hvac.fan(true);
fanStatus = true;
}
private void turnFanOff(){
hvac.fan(false);
fanStatus = false;
}
private void heatOnCheckHeatStatusAdjustCount(){
if (heatStatus == false){
heatOnCount = 1;
heatOffCount = 0;
}
else{
heatOnCount = heatOnCount + 1;
}
}
private void coolOnCheckCoolStatusAdjustCount(){
if (coolStatus == false){
coolOnCount = 1;
coolOffCount = 0;
turnFanOff();
}
else{
coolOnCount = coolOnCount + 1;
}
}
private void heatOffCheckHeatStatusAdjustCount(){
if (heatStatus == true){
heatOnCount = 0;
heatOffCount = 1;
turnFanOff();
}
else{
heatOffCount = heatOffCount + 1;
}
}
private void coolOffCheckStatusAdjustCount(){
if (coolStatus == true){
coolOnCount = 0;
coolOffCount = 1;
}
else{
coolOffCount = coolOffCount + 1;
}
}
public Integer getMinTemp() {
return minTemp;
}
public Integer getMaxTemp() {
return maxTemp;
}
@Override
public void setMinTemp(int minTemp) {
this.minTemp = minTemp;
}
@Override
public void setMaxTemp(int maxTemp) {
this.maxTemp = maxTemp;
}
}