Commit 11824cae11339b6359dc982e45a8471d4bd98412
1 parent
c0152e3d
Added automatic pumping
Showing
6 changed files
with
207 additions
and
40 deletions
Show diff stats
... | ... | @@ -3,18 +3,19 @@ |
3 | 3 | #include <stdbool.h> |
4 | 4 | #include "hvc.h" |
5 | 5 | #include "heat.h" |
6 | +#include "pump.h" | |
6 | 7 | #include "printx.h" |
7 | 8 | |
8 | 9 | #define TASK_NUMBER 32 |
9 | 10 | #define T_INIT_THRESH 40 |
10 | -#define T_STEP_THRESH 80 //OP is 86 | |
11 | -#define T_HOLD_THRESH 82 //OP is 88 | |
11 | +#define T_STEP_THRESH 80 | |
12 | +#define T_HOLD_THRESH 85 //OP is 88 | |
12 | 13 | #define INIT_HEAT_TIME 15 |
13 | 14 | #define INIT_WAIT_TIME 15 |
14 | 15 | #define STEP_HEAT_TIME 2 |
15 | 16 | #define STEP_WAIT_TIME 8 //OP is 5 |
16 | 17 | #define HOLD_HEAT_TIME 1 |
17 | -#define HOLD_WAIT_TIME 8 //OP is 4 | |
18 | +#define HOLD_WAIT_TIME 8 | |
18 | 19 | #define HOLD_PUMP_HEAT_TIME 3 |
19 | 20 | #define HOLD_PUMP_WAIT_TIME 5 |
20 | 21 | |
... | ... | @@ -22,19 +23,16 @@ |
22 | 23 | //Globals |
23 | 24 | time_t tTask; |
24 | 25 | time_t tNow; |
25 | -float tAct; //Lecture de la température du capteur | |
26 | +float tAct; | |
26 | 27 | bool task[TASK_NUMBER]; |
27 | 28 | bool stop=false; |
28 | -bool heat_ok=false; | |
29 | 29 | bool hold_heat=true; |
30 | -bool pumpitup=false; //Lecture de l'état de la pompe | |
31 | 30 | bool eco_mode=false; |
32 | 31 | bool stopHeat=false; |
33 | - | |
32 | +bool heat_ok=false; | |
34 | 33 | |
35 | 34 | void initProcessHeat(void) |
36 | 35 | { |
37 | - //Initialisation du tableau task | |
38 | 36 | task[0]=true; |
39 | 37 | for (int i_initH=1;i_initH<TASK_NUMBER;i_initH++) |
40 | 38 | task[i_initH]=false; |
... | ... | @@ -50,6 +48,21 @@ void stopAutoHeat(void) |
50 | 48 | stopHeat = true; |
51 | 49 | } |
52 | 50 | |
51 | +void setHeatOk(void) | |
52 | +{ | |
53 | + heat_ok=true; | |
54 | +} | |
55 | + | |
56 | +void resetHeatOk(void) | |
57 | +{ | |
58 | + heat_ok=false; | |
59 | +} | |
60 | + | |
61 | +bool isHeatOk(void) | |
62 | +{ | |
63 | + return heat_ok; | |
64 | +} | |
65 | + | |
53 | 66 | void* processHeat(void* arg) |
54 | 67 | { |
55 | 68 | while(!stopHeat) |
... | ... | @@ -64,7 +77,7 @@ void* processHeat(void* arg) |
64 | 77 | if (tAct < T_INIT_THRESH) |
65 | 78 | { |
66 | 79 | setHeatOn(); |
67 | - printx(INFO, BUS, "Début chauffe initiale 0"); | |
80 | + printx(INFO, BUS, "Début chauffe initiale 0\n"); | |
68 | 81 | task[0] = false; |
69 | 82 | task[1] = true; |
70 | 83 | } |
... | ... | @@ -88,7 +101,7 @@ void* processHeat(void* arg) |
88 | 101 | if( ((tNow - tTask) / CLOCKS_PER_SEC) > INIT_HEAT_TIME ) |
89 | 102 | { |
90 | 103 | setHeatOff(); |
91 | - printx(INFO, BUS, "Fin chauffe initiale 1"); | |
104 | + printx(INFO, BUS, "Fin chauffe initiale 1\n"); | |
92 | 105 | task[2] = false; |
93 | 106 | task[3] = true; |
94 | 107 | } |
... | ... | @@ -105,7 +118,7 @@ void* processHeat(void* arg) |
105 | 118 | { |
106 | 119 | if( ((tNow - tTask) / CLOCKS_PER_SEC) > INIT_WAIT_TIME ) |
107 | 120 | { |
108 | - printx(INFO, BUS, "Fin attente %d sec 2", INIT_WAIT_TIME); | |
121 | + printx(INFO, BUS, "Fin attente %d sec 2\n", INIT_WAIT_TIME); | |
109 | 122 | task[4] = false; |
110 | 123 | task[5] = true; |
111 | 124 | } |
... | ... | @@ -125,7 +138,7 @@ void* processHeat(void* arg) |
125 | 138 | { |
126 | 139 | if (tAct < T_STEP_THRESH) |
127 | 140 | { |
128 | - printx(INFO, BUS, "Début Chauffe par palier 3"); | |
141 | + printx(INFO, BUS, "Début Chauffe par palier 3\n"); | |
129 | 142 | setHeatOn(); |
130 | 143 | task[6] = false; |
131 | 144 | task[7] = true; |
... | ... | @@ -149,7 +162,7 @@ void* processHeat(void* arg) |
149 | 162 | { |
150 | 163 | if( ((tNow - tTask) / CLOCKS_PER_SEC) > STEP_HEAT_TIME ) |
151 | 164 | { |
152 | - printx(INFO, BUS, "Fin de chauffe palier intermédiaire 4"); | |
165 | + printx(INFO, BUS, "Fin de chauffe palier intermédiaire 4\n"); | |
153 | 166 | setHeatOff(); |
154 | 167 | task[8] = false; |
155 | 168 | task[9] = true; |
... | ... | @@ -167,7 +180,7 @@ void* processHeat(void* arg) |
167 | 180 | { |
168 | 181 | if( ((tNow - tTask) / CLOCKS_PER_SEC) > STEP_WAIT_TIME ) |
169 | 182 | { |
170 | - printx(INFO, BUS, "Fin d'attente palier intermédiaire 5"); | |
183 | + printx(INFO, BUS, "Fin d'attente palier intermédiaire 5\n"); | |
171 | 184 | |
172 | 185 | if ( tAct < T_STEP_THRESH ) |
173 | 186 | { |
... | ... | @@ -194,8 +207,8 @@ void* processHeat(void* arg) |
194 | 207 | |
195 | 208 | else if (task[12]) |
196 | 209 | { |
197 | - printx(INFO, BUS, "Début Maintien au chaud 6"); | |
198 | - heat_ok = true; | |
210 | + printx(INFO, BUS, "Début Maintien au chaud 6\n"); | |
211 | + setHeatOk(); | |
199 | 212 | task[12]=false; |
200 | 213 | task[13]=true; |
201 | 214 | } |
... | ... | @@ -212,10 +225,10 @@ void* processHeat(void* arg) |
212 | 225 | if(hold_heat) |
213 | 226 | { |
214 | 227 | if( (tAct < T_HOLD_THRESH)) |
215 | - { | |
216 | - if (!pumpitup) | |
228 | + { | |
229 | + if (!isPumpOn()) | |
217 | 230 | { |
218 | - printx(INFO, BUS, "Début Chauffe maintien sans pompe 7"); | |
231 | + printx(INFO, BUS, "Début Chauffe maintien sans pompe 7\n"); | |
219 | 232 | setHeatOn(); |
220 | 233 | task[14] = false; |
221 | 234 | task[15] = true; |
... | ... | @@ -223,7 +236,7 @@ void* processHeat(void* arg) |
223 | 236 | |
224 | 237 | else |
225 | 238 | { |
226 | - printx(INFO, BUS, "Début Chauffe maintien avec pompe 7'"); | |
239 | + printx(INFO, BUS, "Début Chauffe maintien avec pompe 7'\n"); | |
227 | 240 | setHeatOn(); |
228 | 241 | task[14]=false; |
229 | 242 | task[19]=true; //Numéro de tache "T<Thold && pumpitup" |
... | ... | @@ -234,7 +247,7 @@ void* processHeat(void* arg) |
234 | 247 | |
235 | 248 | else |
236 | 249 | { |
237 | - printx(INFO, BUS, "Maintien au chaud annulé 7 ' ' Go etape de fin"); | |
250 | + printx(INFO, BUS, "Maintien au chaud annulé 7 ' ' Go etape de fin\n"); | |
238 | 251 | task[14]=false; |
239 | 252 | task[23]=true; //Sinon go étape d'attente fin |
240 | 253 | } |
... | ... | @@ -252,7 +265,7 @@ void* processHeat(void* arg) |
252 | 265 | { |
253 | 266 | if( ((tNow - tTask) / CLOCKS_PER_SEC) > HOLD_HEAT_TIME ) |
254 | 267 | { |
255 | - printx(INFO, BUS, "Fin chauffe maintien sans pompe 8"); | |
268 | + printx(INFO, BUS, "Fin chauffe maintien sans pompe 8\n"); | |
256 | 269 | setHeatOff(); |
257 | 270 | task[16] = false; |
258 | 271 | task[17] = true; |
... | ... | @@ -272,7 +285,7 @@ void* processHeat(void* arg) |
272 | 285 | { |
273 | 286 | if ( tAct < T_HOLD_THRESH) |
274 | 287 | { |
275 | - printx(INFO, BUS, "Fin d'attente chauffe intermédiaire maintien 9"); | |
288 | + printx(INFO, BUS, "Fin d'attente chauffe intermédiaire maintien 9\n"); | |
276 | 289 | task[18] = false; |
277 | 290 | task[11] = true; //Retour au début de "Maintien au chaud" |
278 | 291 | } |
... | ... | @@ -291,7 +304,7 @@ void* processHeat(void* arg) |
291 | 304 | { |
292 | 305 | if( ((tNow - tTask) / CLOCKS_PER_SEC) > HOLD_PUMP_HEAT_TIME ) |
293 | 306 | { |
294 | - printx(INFO, BUS, "Fin chauffe maintien avec pompe 10"); | |
307 | + printx(INFO, BUS, "Fin chauffe maintien avec pompe 10\n"); | |
295 | 308 | setHeatOff(); |
296 | 309 | task[20] = false; |
297 | 310 | task[21] = true; |
... | ... | @@ -311,7 +324,7 @@ void* processHeat(void* arg) |
311 | 324 | { |
312 | 325 | if ( tAct < T_HOLD_THRESH) |
313 | 326 | { |
314 | - printx(INFO, BUS, "Fin d'attente chauffe intermédiaire maintien avec pompe 11"); | |
327 | + printx(INFO, BUS, "Fin d'attente chauffe intermédiaire maintien avec pompe 11\n"); | |
315 | 328 | task[22] = false; |
316 | 329 | task[11] = true; //Retour au début de "Maintien au chaud" |
317 | 330 | } | ... | ... |
1 | 1 | #include <stdio.h> |
2 | 2 | #include <pthread.h> |
3 | +#include <unistd.h> | |
3 | 4 | #include "printx.h" |
4 | 5 | #include "ui.h" |
5 | 6 | #include "nfc.h" |
6 | 7 | #include "bus.h" |
7 | 8 | #include "hvc.h" |
8 | 9 | #include "heat.h" |
10 | +#include "pump.h" | |
9 | 11 | |
10 | -#include <unistd.h> | |
11 | 12 | |
12 | 13 | int main(void) |
13 | 14 | { |
... | ... | @@ -46,6 +47,7 @@ int main(void) |
46 | 47 | } |
47 | 48 | pthread_create(&tHVC, NULL, processHVC, NULL); |
48 | 49 | initProcessHeat(); |
50 | + initProcessPump(); | |
49 | 51 | setPumpOn(); |
50 | 52 | processHeat(NULL); |
51 | 53 | ... | ... |
... | ... | @@ -2,36 +2,178 @@ |
2 | 2 | #include <time.h> |
3 | 3 | #include <stdbool.h> |
4 | 4 | #include <unistd.h> |
5 | +#include "printx.h" | |
5 | 6 | #include "hvc.h" |
7 | +#include "heat.h" | |
6 | 8 | #include "pump.h" |
7 | 9 | |
8 | -#define K_DEB 1925 //en imp/L | |
9 | 10 | |
10 | -void* processPump(void* arg) | |
11 | +#define K_DEB 1925 //en imp/L | |
12 | +#define VOL_IMP_SHORT_COFFEE 97 //pour 5cl | |
13 | +#define VOL_IMP_LONG_COFFEE 231 //pour 12cl | |
14 | +#define TASK_NUMBER_PUMP 16 | |
15 | + | |
16 | + | |
17 | +//Globals | |
18 | +bool stopPump=false; | |
19 | +bool coffee_wanted=false; | |
20 | +bool pump_on=false; | |
21 | +int volDeb=0; // Lecture volume du débitmetre en impulsion | |
22 | +int volWanted=0; | |
23 | +bool taskP[TASK_NUMBER_PUMP]; | |
24 | +time_t tTaskP; | |
25 | +time_t tNowP; | |
26 | + | |
27 | + | |
28 | +void initProcessPump(void) | |
11 | 29 | { |
12 | - bool stopPump=false; | |
13 | - bool heat_ok=false; | |
14 | - bool coffee_wanted=false; | |
15 | - int volDeb=0; // Volume du débitmetre en impulsion | |
16 | - int volWanted=0; | |
30 | + taskP[0]=true; | |
31 | + for (int i_initP=1;i_initP<TASK_NUMBER_PUMP;i_initP++) | |
32 | + taskP[i_initP]=false; | |
33 | +} | |
17 | 34 | |
35 | +void stopAutoPump(void) | |
36 | +{ | |
37 | + stopPump = true; | |
38 | +} | |
39 | + | |
40 | +void setCoffeeWanted(void) | |
41 | +{ | |
42 | + coffee_wanted = true; | |
43 | +} | |
44 | + | |
45 | +//Determine le volume en fonction de l'entier reçu (1 pour café court, 2 pour long, si autre : volume personalisé en cl) | |
46 | +void setVolWanted (int v) | |
47 | +{ | |
48 | + if (v == 1) | |
49 | + volWanted = VOL_IMP_SHORT_COFFEE; | |
50 | + | |
51 | + else if (v == 2) | |
52 | + volWanted = VOL_IMP_LONG_COFFEE; | |
53 | + | |
54 | + else if ((v > 5) && (v <= 20)) | |
55 | + volWanted = (v*K_DEB)/100; | |
56 | + | |
57 | + else | |
58 | + volWanted = 0; | |
59 | +} | |
60 | + | |
61 | +void actDeb(int v) | |
62 | +{ | |
63 | + volDeb = v; | |
64 | +} | |
65 | + | |
66 | +bool isPumpOn(void) | |
67 | +{ | |
68 | + return pump_on; | |
69 | +} | |
70 | + | |
71 | +void* processPump(void* arg) | |
72 | +{ | |
18 | 73 | while (!stopPump) |
19 | 74 | { |
20 | - if (heat_ok && coffee_wanted) | |
75 | + tNowP = clock(); | |
76 | + | |
77 | + if (taskP[0]) | |
78 | + { | |
79 | + if (coffee_wanted) | |
80 | + { | |
81 | + printx(INFO, BUS, "Demande de café prise en compte 1\n"); | |
82 | + taskP[0]=false; | |
83 | + taskP[1]=true; | |
84 | + } | |
85 | + } | |
86 | + | |
87 | + else if (taskP[1]) | |
21 | 88 | { |
22 | - if (volDeb < volWanted) | |
89 | + if (isHeatOk()) | |
23 | 90 | { |
24 | - setPumpOn(); | |
91 | + printx(INFO, BUS, "Chauffe eau a bonne temperature OK 2\n"); | |
92 | + taskP[1]=false; | |
93 | + taskP[3]=true; | |
25 | 94 | } |
26 | 95 | |
27 | 96 | else |
28 | 97 | { |
29 | - setPumpOff(); | |
30 | - coffee_wanted=false; | |
31 | - volDeb=0; | |
98 | + printx(INFO, BUS, "Attente chauffe eau a bonne temperature 2'\n"); | |
99 | + taskP[1]=false; | |
100 | + taskP[2]=true; | |
101 | + } | |
102 | + } | |
103 | + | |
104 | + else if (taskP[2]) | |
105 | + { | |
106 | + if (isHeatOk()) | |
107 | + { | |
108 | + taskP[2]=false; | |
109 | + taskP[3]=true; | |
110 | + } | |
111 | + } | |
112 | + | |
113 | + else if (taskP[3]) | |
114 | + { | |
115 | + tTaskP = clock(); | |
116 | + printx(INFO, BUS, "Distribution de l'eau Pompe ON 3\n"); | |
117 | + taskP[3]=false; | |
118 | + taskP[4]=true; | |
119 | + } | |
120 | + | |
121 | + else if (taskP[4]) | |
122 | + { | |
123 | + setPumpOn(); | |
124 | + pump_on=true; | |
125 | + | |
126 | + if (volDeb > volWanted) | |
127 | + { | |
128 | + printx(INFO, BUS, "Fin de Distribution de l'eau Pompe OFF 4\n"); | |
129 | + taskP[4]=false; | |
130 | + taskP[5]=true; | |
32 | 131 | } |
132 | + | |
133 | + else if ( ((tNowP - tTaskP) / CLOCKS_PER_SEC) > 60 ) | |
134 | + { | |
135 | + printx(INFO, BUS, "Pompe utilisée depuis plus d'1 min, mise en pause 4'\n"); | |
136 | + taskP[4]=false; | |
137 | + taskP[6]=false; | |
138 | + } | |
139 | + } | |
140 | + | |
141 | + else if (taskP[5]) | |
142 | + { | |
143 | + setPumpOff(); | |
144 | + pump_on=false; | |
145 | + | |
146 | + printx(INFO, BUS, "Cafe servi 5\n"); | |
147 | + volWanted=0; | |
148 | + coffee_wanted=false; | |
149 | + | |
150 | + taskP[5]=false; | |
151 | + taskP[0]=true; | |
33 | 152 | } |
34 | - sleep(1); | |
153 | + | |
154 | + else if (taskP[6]) | |
155 | + { | |
156 | + setPumpOff(); | |
157 | + pump_on=false; | |
158 | + | |
159 | + printx(INFO, BUS, "En pause, Pompe OFF 6"); | |
160 | + | |
161 | + tTaskP = clock(); | |
162 | + taskP[6]=false; | |
163 | + taskP[7]=true; | |
164 | + } | |
165 | + | |
166 | + else if (taskP[7]) | |
167 | + { | |
168 | + if ( ((tNowP - tTaskP) / CLOCKS_PER_SEC) > 60 ) | |
169 | + { | |
170 | + printx(INFO, BUS, "Pause terminée 7\n"); | |
171 | + taskP[7]=false; | |
172 | + taskP[4]=true; | |
173 | + } | |
174 | + } | |
175 | + | |
176 | + sleep(50); | |
35 | 177 | } |
36 | 178 | |
37 | 179 | return NULL; | ... | ... |