-
Notifications
You must be signed in to change notification settings - Fork 0
/
Brain.cpp
87 lines (67 loc) · 1.7 KB
/
Brain.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
#include <iostream>
#include "Brain.h"
Brain::Brain(){}
Brain::~Brain() {}
void Brain::setConfiguration(bool openW){
if (openW){
sensor.openWindow();
} else {
sensor.closeWindow();
}
}
void Brain::check(){
config.getConfiguration();
update();
act();
}
void Brain::update(){
rain = sensor.isRaining();
if (rain)
std::cout << "It's Raining!!" << std::endl;
else
std::cout << "It's NOT Raining!!!!" << std::endl;
day = sensor.isDay();
if (day)
std::cout << "It's Day!!" << std::endl;
else
std::cout << "It's Night!!" << std::endl;
std::cout << "Getting Temperature..." << std::endl;
temperatureNow = sensor.getTemperature();
std::cout << "Temperature: " << temperatureNow << std::endl;
automaticOn = isAutomatic();
}
void Brain::act(){
if(automaticOn){
if(sensor.isWindowOpen()){ //Window is open?
if((rain) || (config.getMinTemp() > temperatureNow)){
sensor.closeWindow();
std::cout << "Close the window!" << std::endl;
} else {
std::cout << "Keep Open!" << std::endl;
}
}else if(sensor.isWindowClose()){ //Window is closed.
if(config.getMaxTemp() < temperatureNow && !rain){
sensor.openWindow();
std::cout << "Open the window!" << std::endl;
} else {
std::cout << "Keep Closed!" << std::endl;
}
}
}
else{
std::cout << "Está manual!!" << std::endl;
}
}
bool Brain::isAutomatic(){
if(day){ //is it day?
if(config.isAutomaticDay()){// Automatic on day is on?
return true;//It's on automatic mode
}
return false;//It's on manual mode
}else{ //it's night.
if(config.isAutomaticNight()){//Automatic on night is on?
return true;//It's on automatic mode
}
return false;//It's on manual mode
}
}