/
cHeating.cpp
221 lines (200 loc) · 4.99 KB
/
cHeating.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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include "cHeating.h"
cHeating::cHeating(void):
WarmWater(),
Rooms(&WarmWater),
Boiler(&Rooms, &WarmWater),
TransferStation(),
Solar(),
Pool(&(Boiler.Pump))
// Initialize and activate WarmWater Circulation Heating system
{
pinMode(PinPumpCirculation, OUTPUT);
digitalWrite(PinPumpCirculation, LOW);
}
void cHeating::Circulation(void){
time_t dt = elapsedSecsToday(now());
time_t dt1 = hoursToTime_t(7);
time_t dt2 = hoursToTime_t(9) + minutesToTime_t(20);
time_t dt3 = hoursToTime_t(18);
time_t dt4 = hoursToTime_t(19) + minutesToTime_t(55);
if ((( (dt1<dt) && (dt<dt2) ) || ( (dt3<dt) && (dt<dt4) ))&&(WarmWater.Period.get()))
digitalWrite(PinPumpCirculation, HIGH);
else
digitalWrite(PinPumpCirculation, LOW);
// digitalWrite(PinPumpCirculation, HIGH); //activate, if permanent Circulation required
}
void cHeating::Control(void) {
WarmWater.Control();
Circulation();
checkSinks();
checkSources();
if (needSource || needSink) {
selectSink(Sink);
selectSource(Source);
}
else {
selectSink(SiOff);
selectSource(SoOff);
}
}
void cHeating::checkSinks(void)
{
// Aggregate needs of heat sinks according to priority
// #0 Determine need to charge warm water and Rooms Heating
if (Boiler.needChargeWarmWater() && Rooms.bAct) {
Sink = SiCombined;
SpTempSource = Boiler.SpTemp();
needSource = true;
}
// #1 Determine need to charge warm water
else if (Boiler.needChargeWarmWater()) {
Sink = SiChargeWarmWater;
SpTempSource = Boiler.SpTemp();
needSource = true;
}
// #2 Determine whether Rooms Heating is requested
else if (Rooms.bAct) {
Sink = SiChargeRooms;
SpTempSource = Rooms.SpTemp();
needSource = true;
}
// #3 Charge into boiler
else if (Boiler.shouldCharge()) {
Sink = SiChargeHeating;
SpTempSource = Boiler.SpTemp();
needSource = false;
}
// #4 Charge the pool
else if ((Pool.shouldCharge()) && (Boiler.hasMinHeat() || Pool.forceChargePool())) {
Sink = SiChargePool;
SpTempSource = Pool.SpTemp();
if (SpTempSource >= 55)
needSource = true;
else
needSource = false;
}
// Else Charge into boiler anyway
else {
Sink = SiChargeHeating;
SpTempSource = Boiler.SpTemp();
needSource = false;
}
}
void cHeating::checkSources(void)
{
// Priority of Heat sources:
// #1 Solar
if (Solar.hasHeat(SpTempSource)) {
Source = SoSolar;
TempSource = Solar.TempSource();
needSink = true;
}
// #3 Boiler
else if ((! Boiler.needChargeWarmWater()) && (Boiler.Hot()) && (! Pool.shouldCharge())) {
Source = SoBoiler;
TempSource = Boiler.TempReserve1.get();
needSink = false;
}
// #4 TransferStation
else if (needSource) {
Source = SoTransferStation;
TempSource = TransferStation.TempSource();
// Check for sufficient/residual heat
needSink = false;
}
// #5 Off
else {
Source = SoOff;
TempSource = (0.0);
needSink = false;
}
}
void cHeating::selectSource(int Source)
{
switch (Source) {
case SoSolar: {
TransferStation.tap(SpTempSource, false, true);
Boiler.discharge(false);
break;
}
case SoBoiler: {
if (TransferStation.tap(SpTempSource, false)) //remaining heat modus
Boiler.discharge(false);
else
Boiler.discharge(true);
break;
}
case SoTransferStation: {
TransferStation.tap(SpTempSource, needSource);
Boiler.discharge(false);
break;
}
case SoOff: default: {
TransferStation.tap(SpTempSource, false);
Boiler.discharge(false);
break;
}
}
Solar.harvest(SpTempSource);
}
void cHeating::selectSink( int Sink )
{
boolean boilerMayCharge = false;
boolean poolMayCharge = false;
boolean roomsMayCharge = false;
switch (Sink) {
case SiCombined: {
roomsMayCharge = true;
boilerMayCharge = true;
poolMayCharge = false;
break;
}
case SiChargeWarmWater: {
roomsMayCharge = false;
boilerMayCharge = true;
poolMayCharge = false;
break;
}
case SiChargeRooms: {
roomsMayCharge = true;
if (Solar.sufficientHeat && (Solar.TempToSystem.getRaw() > Boiler.TempReserve1.get()))
boilerMayCharge = true;
else
boilerMayCharge = false;
poolMayCharge = false;
break;
}
case SiChargeHeating: {
roomsMayCharge = false;
boilerMayCharge = true;
poolMayCharge = false;
break;
}
case SiChargePool: {
roomsMayCharge = false;
boilerMayCharge = false;
poolMayCharge = true;
break;
}
case SiOff: default: {
roomsMayCharge = false;
boilerMayCharge = false;
poolMayCharge = false;
break;
}
}
boolean controlByRoomsMixer = ((TransferStation.GetMode()!=AUTOMATIC) || (Boiler.needChargeWarmWater() && Rooms.bAct));
Rooms.charge(roomsMayCharge,controlByRoomsMixer);
boolean bBoilerCharging = Boiler.charge(boilerMayCharge,TempSource,needSink);
boolean bPoolCharging = Pool.charge(poolMayCharge, TempSource);
if (!bBoilerCharging && !bPoolCharging)
Boiler.Pump.run(); //stop charge pump
}
void cHeating::getData( JsonObject& root )
{
root["SOTs"] = SpTempSource;
root["nSO"] = static_cast<int>(needSource);
root["nSI"] = static_cast<int>(needSink);
root["SO"] = static_cast<int>(Source);
root["SI"] = static_cast<int>(Sink);
}