diff --git a/Makefile b/Makefile index 1fac1ca..6452778 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ CC_FLAGS=-c -Wall -Werror -std=gnu99 -g CC_LIBS=-pthread INCLUDES= -SOURCES=main.c printx.c ui.c serial.c nfc.c bus.c hvc.c +SOURCES=main.c printx.c ui.c serial.c nfc.c bus.c hvc.c heat.c pump.c OBJECTS=$(SOURCES:.c=.o) OUTPUT=tweekd diff --git a/bus.c b/bus.c index 6d02ee0..e03709d 100644 --- a/bus.c +++ b/bus.c @@ -12,6 +12,8 @@ #include "ui.h" #include "nfc.h" #include "hvc.h" +#include "heat.h" +#include "pump.h" #define CMD_MAX 70 #define KEY 1100 @@ -94,7 +96,8 @@ void P(int i) void V(int i) { PV(i, 1); -} +} + void stopBus() { @@ -132,6 +135,12 @@ void processCmd(char* buffer) printx(INFO, BUS, "Setting HEAT OFF"); setHeatWantedState(false); } + else if(strcmp(buffer, "setheaton2s") == 0) + { + printx(INFO, BUS, "Setting HEAT ON for 2 secs"); + setHeatTimer(2); + setHeatWantedState(true); + } else if(strcmp(buffer, "setheaton5s") == 0) { printx(INFO, BUS, "Setting HEAT ON for 5 secs"); @@ -144,12 +153,29 @@ void processCmd(char* buffer) setHeatTimer(10); setHeatWantedState(true); } + else if(strcmp(buffer, "setheaton15s") == 0) + { + printx(INFO, BUS, "Setting HEAT ON for 15 secs"); + setHeatTimer(15); + setHeatWantedState(true); + } else if(strcmp(buffer, "setpumpon5s") == 0) { printx(INFO, BUS, "Setting PUMP ON for 5 secs"); setPumpTimer(5); setPumpWantedState(true); } + else if(strcmp(buffer, "setpumpon10s") == 0) + { + printx(INFO, BUS, "Setting PUMP ON for 10 secs"); + setPumpTimer(10); + setPumpWantedState(true); + } + else if(strcmp(buffer, "autoheat") == 0) + { + printx(INFO, BUS, "Processing Auto Heat to 90°C"); + processHeat(NULL); + } //printx(DEBUG, BUS, "STRLEN : %d and strcmp ret %d", strlen(buffer), strcmp(buffer, "quit")); } @@ -162,8 +188,6 @@ void* processBus(void* we) while(!busStop) { P(SEM_OUTPUT); - //while(busFree); - //while(!busFree); printx(DEBUG, BUS, "Event receved !\n"); busFree = false; lseek(bus, 0, SEEK_SET); @@ -192,8 +216,6 @@ bool initBus() return false; } - //P(SEM_INPUT); - return true; } diff --git a/heat.c b/heat.c new file mode 100644 index 0000000..44b4519 --- /dev/null +++ b/heat.c @@ -0,0 +1,234 @@ +#include +#include +#include +#include "hvc.h" +#include "heat.h" + +#define TASK_NUMBER 20 +#define T_INIT_THRESH 400 +#define T_STEP_THRESH 860 +#define T_HOLD_THRESH 880 +#define INIT_HEAT_TIME 15 +#define INIT_WAIT_TIME 15 +#define STEP_HEAT_TIME 2 +#define STEP_WAIT_TIME 5 +#define HOLD_HEAT_TIME 1 +#define HOLD_WAIT_TIME 2 +#define HOLD_PUMP_HEAT_TIME 3 +#define HOLD_PUMP_WAIT_TIME 1 + + +//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; + } + } + + else if (task[2]) + { + if( ((tNow - tTask) / CLOCKS_PER_SEC) > INIT_WAIT_TIME ) + { + task[2] = false; + task[3] = true; + } + } + + //Chauffe par paliers + else if (task[3]) + { + if (tAct < T_STEP_THRESH) + { + setHeatOn(); + task[3] = false; + task[4] = true; + } + + else + { + task[3] = false; + task[6] = true; //Numéro de tache début "Maintien au chaud" + } + } + + else if (task[4]) + { + if( ((tNow - tTask) / CLOCKS_PER_SEC) > STEP_HEAT_TIME ) + { + setHeatOff(); + task[4] = false; + task[5] = true; + } + } + + else if (task[5]) + { + if( ((tNow - tTask) / CLOCKS_PER_SEC) > STEP_WAIT_TIME ) + { + if ( tAct < T_STEP_THRESH ) + { + task[5] = false; + task[3] = true; + } + + else + { + task[5] = false; + task[6] = true; + } + } + } + + // Maintien au chaud + else if (task[6]) + { + heat_ok = true; + task[6]=false; + task[7]=true; + } + + else if (task[7]) + { + if(hold_heat) + { + if( (tAct < T_HOLD_THRESH) && !pumpitup) + { + setHeatOn(); + task[7] = false; + task[8] = true; + } + + else if ( (tAct < T_HOLD_THRESH) && pumpitup) + { + setHeatOn(); + task[7]=false; + task[10]=true; //Numéro de tache "T HOLD_HEAT_TIME ) + { + setHeatOff(); + task[8] = false; + task[9] = true; + } + } + + else if (task[9]) + { + 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" + } + } + } + + //Maintien au chaud avec pompage + else if (task[10]) + { + if( ((tNow - tTask) / CLOCKS_PER_SEC) > HOLD_PUMP_HEAT_TIME ) + { + setHeatOff(); + task[10] = false; + task[11] = true; + } + } + + else if (task[11]) + { + 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" + } + } + } + + //Fin de maintien au chaud (demandé par l'extérieur) et reboucle quand hold_heat est remis + else if(task[12]) + { + setHeatOff(); + heat_ok=false; + + if(hold_heat) + { + task[12]=false; + task[1]=true; //Retour au début + } + } + + + //Mode économie d'énergie + else if(task[13]) + { + //task[]=false; + //task[]=true; + } + + + } + + +return NULL; +} diff --git a/heat.h b/heat.h new file mode 100644 index 0000000..549d852 --- /dev/null +++ b/heat.h @@ -0,0 +1,6 @@ +#ifndef __HEAT_H__ +#define __HEAT_H__ + +void* processHeat(void*); + +#endif diff --git a/hvc.c b/hvc.c index f212970..1299afc 100644 --- a/hvc.c +++ b/hvc.c @@ -13,6 +13,7 @@ #include "hvc.h" #include "printx.h" #include "serial.h" +#include "heat.h" #define DEVICE1 "/dev/ttyACM1" #define SPEED B19200 @@ -31,6 +32,7 @@ int hvc_fd = -1; bool hvcStop = false; bool sPump = false; bool sHeat = false; +bool autoHeat = false; struct termios hvcSaveterm; bool wHeat = false; bool wPump = false; @@ -40,6 +42,7 @@ double tHeatTimer; time_t tPumpStart; double tPumpTimer; time_t tPumpStop; +int tempCons; void stopHVC() { @@ -70,6 +73,11 @@ void setHeatTimer(double t) tHeatTimer = t; } +void setAutoHeat(bool s) +{ + autoHeat = s; +} + bool initHVC() { unsigned char data; @@ -97,6 +105,7 @@ bool initHVC() void* processHVC(void* we) { uint8_t data; + float temp; while(!hvcStop) { @@ -104,7 +113,8 @@ void* processHVC(void* we) sendData(&hvc_fd, GET_TEMP); data = getData(&hvc_fd); setTemp(data); - printx(DEBUG, HVC, "TEMP %f\n", 25 + (((float)(80*data)))/255); + temp = 25 + (((float)(80*data)))/255; + printx(DEBUG, HVC, "TEMP %f\n", temp); if(tHeatTimer > 0) { tHeatStop = clock(); @@ -113,7 +123,6 @@ void* processHVC(void* we) wHeat = false; tHeatTimer = 0; } - } if(tPumpTimer > 0) diff --git a/nfc.c b/nfc.c index 6707c21..dd7ed9b 100644 --- a/nfc.c +++ b/nfc.c @@ -68,7 +68,7 @@ bool isTagPresent(char* tag) if(data == PROFESSOR_TAG) { sendData(&nfc_fd, GET_TAG_DETAILS); - //printx(INFO, NFC, "Professor Tag Detected %02x\n", data); + printx(INFO, NFC, "Professor Tag Detected %02x\n", data); //return (read(serial_fd, tag, 6) == 6); } else if(data == STUDENT_TAG) diff --git a/printx.c b/printx.c index 9c4b029..6f515fb 100644 --- a/printx.c +++ b/printx.c @@ -57,11 +57,11 @@ void printx(severity s, msgfrom from, char* str, ...) char buffer1[MAX_BUFFER]; char buffer2[MAX_BUFFER]; va_list arglist; - //float now = clock(); + float now = clock(); va_start(arglist, str); vsprintf(buffer1, str, arglist); - //fprintf(logfile, "[%6f] : %s", (now - start)/CLOCKS_PER_SEC, buffer1); - //fflush(logfile); + fprintf(logfile, "[%6f] : %s", (now - start)/CLOCKS_PER_SEC, buffer1); + fflush(logfile); sprintf(buffer2, "[%s] %s%s%s", f_name[from], s_color[s], buffer1, S_RESET); removeCharFromString('\n', buffer2); addToLog(buffer2); diff --git a/pump.c b/pump.c new file mode 100644 index 0000000..b6bcad7 --- /dev/null +++ b/pump.c @@ -0,0 +1,37 @@ +#include +#include +#include +#include "hvc.h" +#include "pump.h" + +#define K_DEB 1925 //en imp/L + + +//Globals +bool stop=false; +bool heat_ok=false; +bool coffee_wanted=false; +int volDeb=0; // Volume du débitmetre en impulsion +int volWanted=0; + +void* processHeat(void* arg) +{ + while (!stop) + { + if (heat_ok && coffee_wanted) + { + if (volDeb < volWanted) + { + setPumpOn(); + } + + else + { + setPumpOff(); + coffee_wanted=false; + volDeb=0; + } + } + sleep(1); + } +} diff --git a/pump.h b/pump.h new file mode 100644 index 0000000..51a4a43 --- /dev/null +++ b/pump.h @@ -0,0 +1,6 @@ +#ifndef __PUMP_H__ +#define __PUMP_H__ + +void* processPump(void*); + +#endif diff --git a/ui.c b/ui.c index b8a14d5..d634e89 100644 --- a/ui.c +++ b/ui.c @@ -225,6 +225,6 @@ void displayUI() sprintf(buffer, "\u2503> %s", cmd); printf("%s\u2503\n", fillStatusWithSpaces(buffer, buffer)); printf("\u2517\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u251B\n"); - printf("\x1b[2A\x1b[%dC", strlen(cmd) + 3); + printf("\x1b[2A\x1b[%dC",(int)(strlen(cmd)) + 3); fflush(stdout); } -- libgit2 0.21.2