From bf0cbb0484ac45da25be0b62eaf0efb05572fe8e Mon Sep 17 00:00:00 2001 From: Pierre Letousey Date: Thu, 23 Apr 2015 16:20:52 +0200 Subject: [PATCH] Automatic regulation --- bus.c | 6 ++++++ heat.c | 250 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------- heat.h | 3 +++ hvc.c | 1 + main.c | 8 ++++++++ ui.c | 4 ++-- usb.c | 2 +- 7 files changed, 202 insertions(+), 72 deletions(-) diff --git a/bus.c b/bus.c index e03709d..4c5fac1 100644 --- a/bus.c +++ b/bus.c @@ -176,6 +176,12 @@ void processCmd(char* buffer) printx(INFO, BUS, "Processing Auto Heat to 90°C"); processHeat(NULL); } + else if(strcmp(buffer, "stopautoheat") == 0) + { + printx(INFO, BUS, "Auto Heat has been stopped"); + stopAutoHeat(); + } + //printx(DEBUG, BUS, "STRLEN : %d and strcmp ret %d", strlen(buffer), strcmp(buffer, "quit")); } diff --git a/heat.c b/heat.c index 8850221..45efeb9 100644 --- a/heat.c +++ b/heat.c @@ -3,33 +3,27 @@ #include #include "hvc.h" #include "heat.h" +#include "printx.h" -#define TASK_NUMBER 20 -#define T_INIT_THRESH 400 -#define T_STEP_THRESH 860 -#define T_HOLD_THRESH 880 +#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 INIT_HEAT_TIME 15 #define INIT_WAIT_TIME 15 #define STEP_HEAT_TIME 2 -#define STEP_WAIT_TIME 5 +#define STEP_WAIT_TIME 8 //OP is 5 #define HOLD_HEAT_TIME 1 -#define HOLD_WAIT_TIME 2 +#define HOLD_WAIT_TIME 8 //OP is 4 #define HOLD_PUMP_HEAT_TIME 3 -#define HOLD_PUMP_WAIT_TIME 1 +#define HOLD_PUMP_WAIT_TIME 5 //Globals time_t tTask; time_t tNow; -time_t tAct; //Lecture de la température du capteur -bool task[TASK_NUMBER]; //A initialiser (task[0]=true, sinon false) - /*for (int i=0;i INIT_HEAT_TIME ) { setHeatOff(); - task[1] = false; - task[2] = true; + printx(INFO, BUS, "Fin chauffe initiale 1"); + task[2] = false; + task[3] = true; } } - else if (task[2]) + else if (task[3]) + { + tTask = clock(); + task[3] = false; + task[4] = true; + } + + else if (task[4]) { if( ((tNow - tTask) / CLOCKS_PER_SEC) > INIT_WAIT_TIME ) { - task[2] = false; - task[3] = true; + printx(INFO, BUS, "Fin attente %d sec 2", INIT_WAIT_TIME); + task[4] = false; + task[5] = true; } } - //Chauffe par paliers - else if (task[3]) + + //Chauffe par palier + else if (task[5]) + { + tTask = clock(); + task[5] = false; + task[6] = true; + } + + + else if (task[6]) { if (tAct < T_STEP_THRESH) { + printx(INFO, BUS, "Début Chauffe par palier 3"); setHeatOn(); - task[3] = false; - task[4] = true; + task[6] = false; + task[7] = true; } else { - task[3] = false; - task[6] = true; //Numéro de tache début "Maintien au chaud" + task[6] = false; + task[11] = true; //Numéro de tache début "Maintien au chaud" } } - else if (task[4]) + else if (task[7]) + { + tTask = clock(); + task[7] = false; + task[8] = true; + } + + else if (task[8]) { if( ((tNow - tTask) / CLOCKS_PER_SEC) > STEP_HEAT_TIME ) { + printx(INFO, BUS, "Fin de chauffe palier intermédiaire 4"); setHeatOff(); - task[4] = false; - task[5] = true; + task[8] = false; + task[9] = true; } } - else if (task[5]) + else if (task[9]) + { + tTask = clock(); + task[9] = false; + task[10] = true; + } + + else if (task[10]) { if( ((tNow - tTask) / CLOCKS_PER_SEC) > STEP_WAIT_TIME ) { + printx(INFO, BUS, "Fin d'attente palier intermédiaire 5"); + if ( tAct < T_STEP_THRESH ) { - task[5] = false; - task[3] = true; + task[10] = false; + task[5] = true; } else { - task[5] = false; - task[6] = true; + task[10] = false; + task[11] = true; } } } + // Maintien au chaud - else if (task[6]) + else if (task[11]) + { + tTask = clock(); + task[11] = false; + task[12] = true; + } + + else if (task[12]) { + printx(INFO, BUS, "Début Maintien au chaud 6"); heat_ok = true; - task[6]=false; - task[7]=true; + task[12]=false; + task[13]=true; } - else if (task[7]) + else if (task[13]) + { + tTask = clock(); + task[13] = false; + task[14] = true; + } + + else if (task[14]) { if(hold_heat) { - if( (tAct < T_HOLD_THRESH) && !pumpitup) + if( (tAct < T_HOLD_THRESH)) { - setHeatOn(); - task[7] = false; - task[8] = true; - } + if (!pumpitup) + { + printx(INFO, BUS, "Début Chauffe maintien sans pompe 7"); + setHeatOn(); + task[14] = false; + task[15] = true; + } - else if ( (tAct < T_HOLD_THRESH) && pumpitup) - { - setHeatOn(); - task[7]=false; - task[10]=true; //Numéro de tache "T HOLD_HEAT_TIME ) { + printx(INFO, BUS, "Fin chauffe maintien sans pompe 8"); setHeatOff(); - task[8] = false; - task[9] = true; + task[16] = false; + task[17] = true; } } - else if (task[9]) + else if (task[17]) + { + tTask = clock(); + task[17] = false; + task[18] = true; + } + + else if (task[18]) { if( ((tNow - tTask) / CLOCKS_PER_SEC) > HOLD_WAIT_TIME ) { if ( tAct < T_HOLD_THRESH) { - task[9] = false; - task[7] = true; //Retour au début de "Maintien au chaud" + printx(INFO, BUS, "Fin d'attente chauffe intermédiaire maintien 9"); + task[18] = false; + task[11] = true; //Retour au début de "Maintien au chaud" } } } //Maintien au chaud avec pompage - else if (task[10]) + else if (task[19]) + { + tTask = clock(); + task[19] = false; + task[20] = true; + } + + else if (task[20]) { if( ((tNow - tTask) / CLOCKS_PER_SEC) > HOLD_PUMP_HEAT_TIME ) { + printx(INFO, BUS, "Fin chauffe maintien avec pompe 10"); setHeatOff(); - task[10] = false; - task[11] = true; + task[20] = false; + task[21] = true; } } - else if (task[11]) + else if (task[21]) + { + tTask = clock(); + task[21] = false; + task[22] = true; + } + + else if (task[22]) { if( ((tNow - tTask) / CLOCKS_PER_SEC) > HOLD_PUMP_WAIT_TIME ) { if ( tAct < T_HOLD_THRESH) { - task[11] = false; - task[7] = true; //Retour au début de "Maintien au chaud" + printx(INFO, BUS, "Fin d'attente chauffe intermédiaire maintien avec pompe 11"); + task[22] = false; + task[11] = true; //Retour au début de "Maintien au chaud" } } } - + //Fin de maintien au chaud (demandé par l'extérieur) et reboucle quand hold_heat est remis - else if(task[12]) + else if(task[23]) { setHeatOff(); heat_ok=false; if(hold_heat) { - task[12]=false; - task[1]=true; //Retour au début + task[23]=false; + task[0]=true; //Retour au début } } //Mode économie d'énergie - else if(task[13]) + else if(task[24]) { //task[]=false; //task[]=true; diff --git a/heat.h b/heat.h index 549d852..7899135 100644 --- a/heat.h +++ b/heat.h @@ -1,6 +1,9 @@ #ifndef __HEAT_H__ #define __HEAT_H__ +void initProcessHeat(void); void* processHeat(void*); +void actTemp(float); +void stopAutoHeat(void); #endif diff --git a/hvc.c b/hvc.c index 6be249d..db8f408 100644 --- a/hvc.c +++ b/hvc.c @@ -134,6 +134,7 @@ void* processHVC(void* we) data = getData(&hvc_fd); setTemp(data); temp = 25 + (((float)(80*data)))/255; + actTemp(temp); printx(DEBUG, HVC, "TEMP %f\n", temp); if(tHeatTimer > 0) { diff --git a/main.c b/main.c index ba9fbd2..3ce263e 100644 --- a/main.c +++ b/main.c @@ -5,6 +5,7 @@ #include "nfc.h" #include "bus.h" #include "hvc.h" +#include "heat.h" #include @@ -43,8 +44,15 @@ int main(void) printx(ERROR, MAIN, "Unable to start the HVC interface\n"); return 4; } +<<<<<<< Updated upstream pthread_create(&tHVC, NULL, processHVC, NULL);*/ //initProcessHeat(); +======= + pthread_create(&tHVC, NULL, processHVC, NULL); + initProcessHeat(); + setPumpOn(); + processHeat(NULL); +>>>>>>> Stashed changes pthread_join(tUI, NULL); closeLog(); diff --git a/ui.c b/ui.c index a86e61a..de21700 100644 --- a/ui.c +++ b/ui.c @@ -62,7 +62,7 @@ void* drawUI(void* we) { while(!uiStop) { - processScreen(); + //processScreen(); usleep(SCREEN_TIME); } @@ -83,7 +83,7 @@ void initUILog() mainPid = getpid(); uid[0]='\0'; uidDate[0]='\0'; - initUSB(); + //initUSB(); } void setStartTime(char* sT) diff --git a/usb.c b/usb.c index 83335fb..2edc941 100644 --- a/usb.c +++ b/usb.c @@ -108,7 +108,7 @@ bool initUSB(void) return false; } - printf("%d devices detected\n", cnt); + printf("%d devices detected\n", (int)cnt); printf("List of compatible devices detected\n"); for (int i = 0; i < cnt; i++) -- libgit2 0.21.2