From 11824cae11339b6359dc982e45a8471d4bd98412 Mon Sep 17 00:00:00 2001 From: Pierre Letousey Date: Thu, 30 Apr 2015 15:17:53 +0200 Subject: [PATCH] Added automatic pumping --- heat.c | 63 ++++++++++++++++++++++++++++++++++++++------------------------- heat.h | 3 +++ hvc.c | 1 + main.c | 4 +++- pump.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- pump.h | 6 ++++++ 6 files changed, 207 insertions(+), 40 deletions(-) diff --git a/heat.c b/heat.c index 45efeb9..478459b 100644 --- a/heat.c +++ b/heat.c @@ -3,18 +3,19 @@ #include #include "hvc.h" #include "heat.h" +#include "pump.h" #include "printx.h" #define TASK_NUMBER 32 #define T_INIT_THRESH 40 -#define T_STEP_THRESH 80 //OP is 86 -#define T_HOLD_THRESH 82 //OP is 88 +#define T_STEP_THRESH 80 +#define T_HOLD_THRESH 85 //OP is 88 #define INIT_HEAT_TIME 15 #define INIT_WAIT_TIME 15 #define STEP_HEAT_TIME 2 #define STEP_WAIT_TIME 8 //OP is 5 #define HOLD_HEAT_TIME 1 -#define HOLD_WAIT_TIME 8 //OP is 4 +#define HOLD_WAIT_TIME 8 #define HOLD_PUMP_HEAT_TIME 3 #define HOLD_PUMP_WAIT_TIME 5 @@ -22,19 +23,16 @@ //Globals time_t tTask; time_t tNow; -float tAct; //Lecture de la température du capteur +float tAct; bool task[TASK_NUMBER]; bool stop=false; -bool heat_ok=false; bool hold_heat=true; -bool pumpitup=false; //Lecture de l'état de la pompe bool eco_mode=false; bool stopHeat=false; - +bool heat_ok=false; void initProcessHeat(void) { - //Initialisation du tableau task task[0]=true; for (int i_initH=1;i_initH INIT_HEAT_TIME ) { setHeatOff(); - printx(INFO, BUS, "Fin chauffe initiale 1"); + printx(INFO, BUS, "Fin chauffe initiale 1\n"); task[2] = false; task[3] = true; } @@ -105,7 +118,7 @@ void* processHeat(void* arg) { if( ((tNow - tTask) / CLOCKS_PER_SEC) > INIT_WAIT_TIME ) { - printx(INFO, BUS, "Fin attente %d sec 2", INIT_WAIT_TIME); + printx(INFO, BUS, "Fin attente %d sec 2\n", INIT_WAIT_TIME); task[4] = false; task[5] = true; } @@ -125,7 +138,7 @@ void* processHeat(void* arg) { if (tAct < T_STEP_THRESH) { - printx(INFO, BUS, "Début Chauffe par palier 3"); + printx(INFO, BUS, "Début Chauffe par palier 3\n"); setHeatOn(); task[6] = false; task[7] = true; @@ -149,7 +162,7 @@ void* processHeat(void* arg) { if( ((tNow - tTask) / CLOCKS_PER_SEC) > STEP_HEAT_TIME ) { - printx(INFO, BUS, "Fin de chauffe palier intermédiaire 4"); + printx(INFO, BUS, "Fin de chauffe palier intermédiaire 4\n"); setHeatOff(); task[8] = false; task[9] = true; @@ -167,7 +180,7 @@ void* processHeat(void* arg) { if( ((tNow - tTask) / CLOCKS_PER_SEC) > STEP_WAIT_TIME ) { - printx(INFO, BUS, "Fin d'attente palier intermédiaire 5"); + printx(INFO, BUS, "Fin d'attente palier intermédiaire 5\n"); if ( tAct < T_STEP_THRESH ) { @@ -194,8 +207,8 @@ void* processHeat(void* arg) else if (task[12]) { - printx(INFO, BUS, "Début Maintien au chaud 6"); - heat_ok = true; + printx(INFO, BUS, "Début Maintien au chaud 6\n"); + setHeatOk(); task[12]=false; task[13]=true; } @@ -212,10 +225,10 @@ void* processHeat(void* arg) if(hold_heat) { if( (tAct < T_HOLD_THRESH)) - { - if (!pumpitup) + { + if (!isPumpOn()) { - printx(INFO, BUS, "Début Chauffe maintien sans pompe 7"); + printx(INFO, BUS, "Début Chauffe maintien sans pompe 7\n"); setHeatOn(); task[14] = false; task[15] = true; @@ -223,7 +236,7 @@ void* processHeat(void* arg) else { - printx(INFO, BUS, "Début Chauffe maintien avec pompe 7'"); + printx(INFO, BUS, "Début Chauffe maintien avec pompe 7'\n"); setHeatOn(); task[14]=false; task[19]=true; //Numéro de tache "T HOLD_HEAT_TIME ) { - printx(INFO, BUS, "Fin chauffe maintien sans pompe 8"); + printx(INFO, BUS, "Fin chauffe maintien sans pompe 8\n"); setHeatOff(); task[16] = false; task[17] = true; @@ -272,7 +285,7 @@ void* processHeat(void* arg) { if ( tAct < T_HOLD_THRESH) { - printx(INFO, BUS, "Fin d'attente chauffe intermédiaire maintien 9"); + printx(INFO, BUS, "Fin d'attente chauffe intermédiaire maintien 9\n"); task[18] = false; task[11] = true; //Retour au début de "Maintien au chaud" } @@ -291,7 +304,7 @@ void* processHeat(void* arg) { if( ((tNow - tTask) / CLOCKS_PER_SEC) > HOLD_PUMP_HEAT_TIME ) { - printx(INFO, BUS, "Fin chauffe maintien avec pompe 10"); + printx(INFO, BUS, "Fin chauffe maintien avec pompe 10\n"); setHeatOff(); task[20] = false; task[21] = true; @@ -311,7 +324,7 @@ void* processHeat(void* arg) { if ( tAct < T_HOLD_THRESH) { - printx(INFO, BUS, "Fin d'attente chauffe intermédiaire maintien avec pompe 11"); + printx(INFO, BUS, "Fin d'attente chauffe intermédiaire maintien avec pompe 11\n"); task[22] = false; task[11] = true; //Retour au début de "Maintien au chaud" } diff --git a/heat.h b/heat.h index 7899135..1253361 100644 --- a/heat.h +++ b/heat.h @@ -5,5 +5,8 @@ void initProcessHeat(void); void* processHeat(void*); void actTemp(float); void stopAutoHeat(void); +void setHeatOk(void); +void resetHeatOk(void); +bool isHeatOk(void); #endif diff --git a/hvc.c b/hvc.c index db8f408..b067e60 100644 --- a/hvc.c +++ b/hvc.c @@ -14,6 +14,7 @@ #include "printx.h" #include "serial.h" #include "heat.h" +#include "pump.h" #define DEVICE1 "/dev/ttyACM1" #define SPEED B19200 diff --git a/main.c b/main.c index 78225fb..757bb54 100644 --- a/main.c +++ b/main.c @@ -1,13 +1,14 @@ #include #include +#include #include "printx.h" #include "ui.h" #include "nfc.h" #include "bus.h" #include "hvc.h" #include "heat.h" +#include "pump.h" -#include int main(void) { @@ -46,6 +47,7 @@ int main(void) } pthread_create(&tHVC, NULL, processHVC, NULL); initProcessHeat(); + initProcessPump(); setPumpOn(); processHeat(NULL); diff --git a/pump.c b/pump.c index 81bdf21..195dfb5 100644 --- a/pump.c +++ b/pump.c @@ -2,36 +2,178 @@ #include #include #include +#include "printx.h" #include "hvc.h" +#include "heat.h" #include "pump.h" -#define K_DEB 1925 //en imp/L -void* processPump(void* arg) +#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) { - bool stopPump=false; - bool heat_ok=false; - bool coffee_wanted=false; - int volDeb=0; // Volume du débitmetre en impulsion - int volWanted=0; + taskP[0]=true; + for (int i_initP=1;i_initP 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) +{ while (!stopPump) { - if (heat_ok && coffee_wanted) + tNowP = clock(); + + if (taskP[0]) + { + if (coffee_wanted) + { + printx(INFO, BUS, "Demande de café prise en compte 1\n"); + taskP[0]=false; + taskP[1]=true; + } + } + + else if (taskP[1]) { - if (volDeb < volWanted) + if (isHeatOk()) { - setPumpOn(); + printx(INFO, BUS, "Chauffe eau a bonne temperature OK 2\n"); + taskP[1]=false; + taskP[3]=true; } else { - setPumpOff(); - coffee_wanted=false; - volDeb=0; + printx(INFO, BUS, "Attente chauffe eau a bonne temperature 2'\n"); + taskP[1]=false; + taskP[2]=true; + } + } + + else if (taskP[2]) + { + if (isHeatOk()) + { + taskP[2]=false; + taskP[3]=true; + } + } + + else if (taskP[3]) + { + tTaskP = clock(); + printx(INFO, BUS, "Distribution de l'eau Pompe ON 3\n"); + taskP[3]=false; + taskP[4]=true; + } + + else if (taskP[4]) + { + setPumpOn(); + pump_on=true; + + if (volDeb > volWanted) + { + printx(INFO, BUS, "Fin de Distribution de l'eau Pompe OFF 4\n"); + taskP[4]=false; + taskP[5]=true; } + + else if ( ((tNowP - tTaskP) / CLOCKS_PER_SEC) > 60 ) + { + printx(INFO, BUS, "Pompe utilisée depuis plus d'1 min, mise en pause 4'\n"); + taskP[4]=false; + taskP[6]=false; + } + } + + else if (taskP[5]) + { + setPumpOff(); + pump_on=false; + + printx(INFO, BUS, "Cafe servi 5\n"); + volWanted=0; + coffee_wanted=false; + + taskP[5]=false; + taskP[0]=true; } - sleep(1); + + else if (taskP[6]) + { + setPumpOff(); + pump_on=false; + + printx(INFO, BUS, "En pause, Pompe OFF 6"); + + tTaskP = clock(); + taskP[6]=false; + taskP[7]=true; + } + + else if (taskP[7]) + { + if ( ((tNowP - tTaskP) / CLOCKS_PER_SEC) > 60 ) + { + printx(INFO, BUS, "Pause terminée 7\n"); + taskP[7]=false; + taskP[4]=true; + } + } + + sleep(50); } return NULL; diff --git a/pump.h b/pump.h index 51a4a43..624ec89 100644 --- a/pump.h +++ b/pump.h @@ -1,6 +1,12 @@ #ifndef __PUMP_H__ #define __PUMP_H__ +void initProcessPump(void); +void stopAutoPump(void); +void actDeb(int); +void setCoffeeWanted(void); +void setVolWanted(int); +bool isPumpOn(void); void* processPump(void*); #endif -- libgit2 0.21.2