8dca7aeb
henyxia
Automatic Pumping...
|
1
2
3
|
#include <stdio.h>
#include <time.h>
#include <stdbool.h>
|
bb8c2799
henyxia
Fixed version
|
4
|
#include <unistd.h>
|
11824cae
Pierre Letousey
Added automatic p...
|
5
|
#include "printx.h"
|
8dca7aeb
henyxia
Automatic Pumping...
|
6
|
#include "hvc.h"
|
11824cae
Pierre Letousey
Added automatic p...
|
7
|
#include "heat.h"
|
8dca7aeb
henyxia
Automatic Pumping...
|
8
9
|
#include "pump.h"
|
8dca7aeb
henyxia
Automatic Pumping...
|
10
|
|
11824cae
Pierre Letousey
Added automatic p...
|
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
#define K_DEB 1925 //en imp/L
#define VOL_IMP_SHORT_COFFEE 97 //pour 5cl
#define VOL_IMP_LONG_COFFEE 231 //pour 12cl
#define TASK_NUMBER_PUMP 16
//Globals
bool stopPump=false;
bool coffee_wanted=false;
bool pump_on=false;
int volDeb=0; // Lecture volume du débitmetre en impulsion
int volWanted=0;
bool taskP[TASK_NUMBER_PUMP];
time_t tTaskP;
time_t tNowP;
void initProcessPump(void)
|
8dca7aeb
henyxia
Automatic Pumping...
|
29
|
{
|
11824cae
Pierre Letousey
Added automatic p...
|
30
31
32
33
|
taskP[0]=true;
for (int i_initP=1;i_initP<TASK_NUMBER_PUMP;i_initP++)
taskP[i_initP]=false;
}
|
bb8c2799
henyxia
Fixed version
|
34
|
|
11824cae
Pierre Letousey
Added automatic p...
|
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
|
void stopAutoPump(void)
{
stopPump = true;
}
void setCoffeeWanted(void)
{
coffee_wanted = true;
}
//Determine le volume en fonction de l'entier reçu (1 pour café court, 2 pour long, si autre : volume personalisé en cl)
void setVolWanted (int v)
{
if (v == 1)
volWanted = VOL_IMP_SHORT_COFFEE;
else if (v == 2)
volWanted = VOL_IMP_LONG_COFFEE;
else if ((v > 5) && (v <= 20))
volWanted = (v*K_DEB)/100;
else
volWanted = 0;
}
void actDeb(int v)
{
volDeb = v;
}
bool isPumpOn(void)
{
return pump_on;
}
void* processPump(void* arg)
{
|
bb8c2799
henyxia
Fixed version
|
73
|
while (!stopPump)
|
8dca7aeb
henyxia
Automatic Pumping...
|
74
|
{
|
11824cae
Pierre Letousey
Added automatic p...
|
75
76
77
78
79
80
|
tNowP = clock();
if (taskP[0])
{
if (coffee_wanted)
{
|
717e403d
henyxia
Sperated output
|
81
|
printx(INFO, PUMP, "Demande de café prise en compte 1\n");
|
11824cae
Pierre Letousey
Added automatic p...
|
82
83
84
85
86
87
|
taskP[0]=false;
taskP[1]=true;
}
}
else if (taskP[1])
|
8dca7aeb
henyxia
Automatic Pumping...
|
88
|
{
|
11824cae
Pierre Letousey
Added automatic p...
|
89
|
if (isHeatOk())
|
8dca7aeb
henyxia
Automatic Pumping...
|
90
|
{
|
717e403d
henyxia
Sperated output
|
91
|
printx(INFO, PUMP, "Chauffe eau a bonne temperature OK 2\n");
|
11824cae
Pierre Letousey
Added automatic p...
|
92
93
|
taskP[1]=false;
taskP[3]=true;
|
8dca7aeb
henyxia
Automatic Pumping...
|
94
95
96
97
|
}
else
{
|
717e403d
henyxia
Sperated output
|
98
|
printx(INFO, PUMP, "Attente chauffe eau a bonne temperature 2'\n");
|
11824cae
Pierre Letousey
Added automatic p...
|
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
taskP[1]=false;
taskP[2]=true;
}
}
else if (taskP[2])
{
if (isHeatOk())
{
taskP[2]=false;
taskP[3]=true;
}
}
else if (taskP[3])
{
tTaskP = clock();
|
717e403d
henyxia
Sperated output
|
116
|
printx(INFO, PUMP, "Distribution de l'eau Pompe ON 3\n");
|
11824cae
Pierre Letousey
Added automatic p...
|
117
118
119
120
121
122
123
124
125
126
127
|
taskP[3]=false;
taskP[4]=true;
}
else if (taskP[4])
{
setPumpOn();
pump_on=true;
if (volDeb > volWanted)
{
|
717e403d
henyxia
Sperated output
|
128
|
printx(INFO, PUMP, "Fin de Distribution de l'eau Pompe OFF 4\n");
|
11824cae
Pierre Letousey
Added automatic p...
|
129
130
|
taskP[4]=false;
taskP[5]=true;
|
8dca7aeb
henyxia
Automatic Pumping...
|
131
|
}
|
11824cae
Pierre Letousey
Added automatic p...
|
132
133
134
|
else if ( ((tNowP - tTaskP) / CLOCKS_PER_SEC) > 60 )
{
|
717e403d
henyxia
Sperated output
|
135
|
printx(INFO, PUMP, "Pompe utilisée depuis plus d'1 min, mise en pause 4'\n");
|
11824cae
Pierre Letousey
Added automatic p...
|
136
137
138
139
140
141
142
143
144
145
|
taskP[4]=false;
taskP[6]=false;
}
}
else if (taskP[5])
{
setPumpOff();
pump_on=false;
|
717e403d
henyxia
Sperated output
|
146
|
printx(INFO, PUMP, "Cafe servi 5\n");
|
11824cae
Pierre Letousey
Added automatic p...
|
147
148
149
150
151
|
volWanted=0;
coffee_wanted=false;
taskP[5]=false;
taskP[0]=true;
|
8dca7aeb
henyxia
Automatic Pumping...
|
152
|
}
|
11824cae
Pierre Letousey
Added automatic p...
|
153
154
155
156
157
158
|
else if (taskP[6])
{
setPumpOff();
pump_on=false;
|
717e403d
henyxia
Sperated output
|
159
|
printx(INFO, PUMP, "En pause, Pompe OFF 6");
|
11824cae
Pierre Letousey
Added automatic p...
|
160
161
162
163
164
165
166
167
168
169
|
tTaskP = clock();
taskP[6]=false;
taskP[7]=true;
}
else if (taskP[7])
{
if ( ((tNowP - tTaskP) / CLOCKS_PER_SEC) > 60 )
{
|
717e403d
henyxia
Sperated output
|
170
|
printx(INFO, PUMP, "Pause terminée 7\n");
|
11824cae
Pierre Letousey
Added automatic p...
|
171
172
173
174
175
|
taskP[7]=false;
taskP[4]=true;
}
}
|
e912f423
henyxia
Urgent fix
|
176
|
sleep(1);
|
8dca7aeb
henyxia
Automatic Pumping...
|
177
|
}
|
bb8c2799
henyxia
Fixed version
|
178
179
|
return NULL;
|
8dca7aeb
henyxia
Automatic Pumping...
|
180
|
}
|