-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControlUVC.cpp
122 lines (94 loc) · 2.28 KB
/
ControlUVC.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "ControlUVC.h"
ControlUVC::ControlUVC() {
init();
}
void ControlUVC::init(void) {
if (!loadVolumen())
__volumen = 0.0;
__ciclos = 0.0;
if (!loadTuboUVC())
__tubo_UVC = 0;
}
void ControlUVC::setVolumen(float volumen) {
__volumen = volumen;
updateVolumen();
}
float ControlUVC::getVolumen(void) {
return __volumen;
}
bool ControlUVC::loadVolumen(void) {
File myFile = SPIFFS.open("/volumen.txt", "r");
if (myFile) {
while (myFile.available()) {
String line = myFile.readStringUntil('\n');
if (line != "") {
//Serial.printf("\r\nloadVolumen: %s\r\n", line.c_str());
__volumen = line.toFloat();
} else
return false;
}
myFile.close();
return true;
} else
return false;
}
bool ControlUVC::updateVolumen() {
File myFile = SPIFFS.open("/volumen.txt", "w");
if (myFile) {
//Serial.printf("\r\nsaveVolumen: %.2f\r\n", __volumen);
myFile.println(__volumen);
myFile.close();
return true;
} else
return false;
}
double ControlUVC::getCiclos(uint32_t segundos) {
double segundosCiclo;
if (__volumen > 0.0) {
segundosCiclo = __volumen / VOLUMEN_AIRE_SEGUNDO;
__ciclos = segundos / segundosCiclo;
}
return __ciclos;
}
double ControlUVC::getCiclos(void) {
return __ciclos;
}
void ControlUVC::setTuboUVC(uint32_t segundos) {
__tubo_UVC = segundos;
updateTuboUVC(segundos);
}
uint32_t ControlUVC::getTuboUVC(void) {
return __tubo_UVC;
}
bool ControlUVC::loadTuboUVC(void) {
File myFile = SPIFFS.open("/tiempo.txt", "r");
if (myFile) {
while (myFile.available()) {
String line = myFile.readStringUntil('\n');
if (line != "") {
//Serial.printf("\r\nloadTuboUVC: %s\r\n", line.c_str());
__tubo_UVC = line.toInt();
} else
return false;
}
myFile.close();
return true;
} else
return false;
}
bool ControlUVC::updateTuboUVC(uint32_t segundos) {
File myFile = SPIFFS.open("/tiempo.txt", "w");
if (myFile) {
//Serial.printf("\r\nupdateTuboUVC: %u\r\n", segundos);
myFile.println(segundos);
myFile.close();
return true;
} else
return false;
}
bool ControlUVC::isValidTuboUVC() {
if (__tubo_UVC < VIDA_UTIL_TUBO_UVC)
return true;
else
return false;
}