Commit 5dd66ab0f1e0a661fa266c8e514944556c570769

Authored by henyxia
1 parent ac0ae6b0

Added timer option to HVC

Showing 4 changed files with 65 additions and 0 deletions   Show diff stats
... ... @@ -53,6 +53,18 @@ void processCmd(char* buffer)
53 53 printx(INFO, BUS, "Setting HEAT OFF");
54 54 setHeatWantedState(false);
55 55 }
  56 + else if(strcmp(buffer, "setheaton5s") == 0)
  57 + {
  58 + printx(INFO, BUS, "Setting HEAT ON for 5 secs");
  59 + setHeatTimer(5);
  60 + setHeatWantedState(true);
  61 + }
  62 + else if(strcmp(buffer, "setpumpon5s") == 0)
  63 + {
  64 + printx(INFO, BUS, "Setting PUMP ON for 5 secs");
  65 + setPumpTimer(5);
  66 + setPumpWantedState(true);
  67 + }
56 68  
57 69 //printx(DEBUG, BUS, "STRLEN : %d and strcmp ret %d", strlen(buffer), strcmp(buffer, "quit"));
58 70 }
... ...
... ... @@ -8,6 +8,7 @@
8 8 #include <fcntl.h>
9 9 #include <strings.h>
10 10 #include <inttypes.h>
  11 +#include <time.h>
11 12 #include "ui.h"
12 13 #include "hvc.h"
13 14 #include "printx.h"
... ... @@ -33,6 +34,12 @@ bool sHeat = false;
33 34 struct termios hvcSaveterm;
34 35 bool wHeat = false;
35 36 bool wPump = false;
  37 +time_t tHeatStart;
  38 +time_t tHeatStop;
  39 +double tHeatTimer;
  40 +time_t tPumpStart;
  41 +double tPumpTimer;
  42 +time_t tPumpStop;
36 43  
37 44 void stopHVC()
38 45 {
... ... @@ -41,14 +48,28 @@ void stopHVC()
41 48  
42 49 void setPumpWantedState(bool s)
43 50 {
  51 + tPumpStart = clock();
  52 + tPumpStop = clock();
44 53 wPump = s;
45 54 }
46 55  
47 56 void setHeatWantedState(bool s)
48 57 {
  58 + tHeatStart = clock();
  59 + tHeatStop = clock();
49 60 wHeat = s;
50 61 }
51 62  
  63 +void setPumpTimer(double t)
  64 +{
  65 + tPumpTimer = t;
  66 +}
  67 +
  68 +void setHeatTimer(double t)
  69 +{
  70 + tHeatTimer = t;
  71 +}
  72 +
52 73 bool initHVC()
53 74 {
54 75 unsigned char data;
... ... @@ -84,11 +105,34 @@ void* processHVC(void* we)
84 105 data = getData(&hvc_fd);
85 106 setTemp(data);
86 107  
  108 + if(tHeatTimer > 0)
  109 + {
  110 + tHeatStop = clock();
  111 + if(((double)(tHeatStop - tHeatStart) / CLOCKS_PER_SEC) > tHeatTimer)
  112 + {
  113 + wHeat = false;
  114 + tHeatTimer = 0;
  115 + }
  116 +
  117 + }
  118 +
  119 + if(tPumpTimer > 0)
  120 + {
  121 + tPumpStop = clock();
  122 + if(((double)(tPumpStop - tPumpStart) / CLOCKS_PER_SEC) > tPumpTimer)
  123 + {
  124 + wPump = false;
  125 + tPumpTimer = 0;
  126 + }
  127 + }
  128 +
87 129 if(wHeat ^ sHeat)
88 130 {
89 131 sendData(&hvc_fd, wHeat ? SET_HEAT_ON : SET_HEAT_OFF);
90 132 sHeat = wHeat;
91 133 setHeat(sHeat);
  134 + if(sHeat)
  135 + tHeatStart = clock();
92 136 }
93 137  
94 138 if(wPump ^ sPump)
... ... @@ -96,6 +140,8 @@ void* processHVC(void* we)
96 140 sendData(&hvc_fd, wPump ? SET_PUMP_ON : SET_PUMP_OFF);
97 141 sPump = wPump;
98 142 setPump(sPump);
  143 + if(sPump)
  144 + tPumpStart = clock();
99 145 }
100 146  
101 147 usleep(HVC_POLLING_TIME);
... ...
... ... @@ -8,5 +8,7 @@ void* processHVC();
8 8 void stopHVC();
9 9 void setPumpWantedState(bool);
10 10 void setHeatWantedState(bool);
  11 +void setPumpTimer(double);
  12 +void setHeatTimer(double);
11 13  
12 14 #endif
... ...
... ... @@ -195,6 +195,11 @@ void displayUI()
195 195 sprintf(buffer, "%c", bufferO[0]);
196 196 strcat(cmd, buffer);
197 197 }
  198 + else if(bufferO[0] >= 48 && bufferO[0] <= 57)
  199 + {
  200 + sprintf(buffer, "%c", bufferO[0]);
  201 + strcat(cmd, buffer);
  202 + }
198 203 else if(bufferO[0] == 32)
199 204 {
200 205 sprintf(buffer, "%c", bufferO[0]);
... ...