-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactuator.cpp
105 lines (81 loc) · 2.03 KB
/
actuator.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
95
96
97
98
99
100
101
102
103
104
105
#include "Arduino.h"
#include "actuator.h"
#include <EEPROM.h>
#define ACTUATOR_ADDR 0x100
#define SYSTEM_PORT 39
#define PUMP_PORT 41
#define RESISTOR_PORT 43
#define OXYGEN_PORT 45
#define LIGHT_PORT 47
GPIO_Port::GPIO_Port(const uint8_t& _port, const bool& _initialState) {
port = _port;
pinMode(port, OUTPUT);
set(state);
}
bool GPIO_Port::get() {
return state;
}
void GPIO_Port::set(const bool& value) {
state = 0x01 & value;
if(state)
digitalWrite(port, HIGH);
else
digitalWrite(port, LOW);
}
String GPIO_Port::toString() {
if ( state ){
return "true";
} else {
return "false";
}
}
Actuator::Actuator():system(SYSTEM_PORT, true), pump(PUMP_PORT, true), resistor(RESISTOR_PORT, true), oxygen(OXYGEN_PORT, true), light(LIGHT_PORT, true){}
void Actuator::init(){
Actuator self;
EEPROM.get(ACTUATOR_ADDR, self);
pump.set(self.getPump());
light.set(self.getSystem());
resistor.set(self.getResistor());
oxygen.set(self.getOxygen());
light.set(self.getLight());
}
void Actuator::run() {
}
void Actuator::setPump(const bool& state){
pump.set(state);
EEPROM.put(ACTUATOR_ADDR, (*this));
}
bool Actuator::getPump(){
return pump.get();
}
void Actuator::setResistor(const bool& state){
resistor.set(state);
EEPROM.put(ACTUATOR_ADDR, (*this));
}
bool Actuator::getResistor(){
return resistor.get();
}
void Actuator::setOxygen(const bool& state){
oxygen.set(state);
EEPROM.put(ACTUATOR_ADDR, (*this));
}
bool Actuator::getOxygen(){
return oxygen.get();
}
void Actuator::setLight(const bool& state){
light.set(state);
EEPROM.put(ACTUATOR_ADDR, (*this));
}
bool Actuator::getLight(){
return light.get();
}
void Actuator::setSystem(const bool& state){
system.set(state);
EEPROM.put(ACTUATOR_ADDR, (*this));
}
bool Actuator::getSystem(){
return system.get();
}
String Actuator::toString(){
return "Actuator : system=" + system.toString() + ", pump=" + pump.toString() + ", resistor=" + resistor.toString() + ", oxygen=" + oxygen.toString() + ", light=" + light.toString() + "\n";
}