| @@ -8,6 +8,7 @@ |
| @@ -8,6 +8,7 @@ |
8
| #include <fcntl.h> |
8
| #include <fcntl.h> |
9
| #include <strings.h> |
9
| #include <strings.h> |
10
| #include <inttypes.h> |
10
| #include <inttypes.h> |
| |
11
| +#include <time.h> |
11
| #include "ui.h" |
12
| #include "ui.h" |
12
| #include "hvc.h" |
13
| #include "hvc.h" |
13
| #include "printx.h" |
14
| #include "printx.h" |
| @@ -33,6 +34,12 @@ bool sHeat = false; |
| @@ -33,6 +34,12 @@ bool sHeat = false; |
33
| struct termios hvcSaveterm; |
34
| struct termios hvcSaveterm; |
34
| bool wHeat = false; |
35
| bool wHeat = false; |
35
| bool wPump = false; |
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
| void stopHVC() |
44
| void stopHVC() |
38
| { |
45
| { |
| @@ -41,14 +48,28 @@ void stopHVC() |
| @@ -41,14 +48,28 @@ void stopHVC() |
41
| |
48
| |
42
| void setPumpWantedState(bool s) |
49
| void setPumpWantedState(bool s) |
43
| { |
50
| { |
| |
51
| + tPumpStart = clock(); |
| |
52
| + tPumpStop = clock(); |
44
| wPump = s; |
53
| wPump = s; |
45
| } |
54
| } |
46
| |
55
| |
47
| void setHeatWantedState(bool s) |
56
| void setHeatWantedState(bool s) |
48
| { |
57
| { |
| |
58
| + tHeatStart = clock(); |
| |
59
| + tHeatStop = clock(); |
49
| wHeat = s; |
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
| bool initHVC() |
73
| bool initHVC() |
53
| { |
74
| { |
54
| unsigned char data; |
75
| unsigned char data; |
| @@ -84,11 +105,34 @@ void* processHVC(void* we) |
| @@ -84,11 +105,34 @@ void* processHVC(void* we) |
84
| data = getData(&hvc_fd); |
105
| data = getData(&hvc_fd); |
85
| setTemp(data); |
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
| if(wHeat ^ sHeat) |
129
| if(wHeat ^ sHeat) |
88
| { |
130
| { |
89
| sendData(&hvc_fd, wHeat ? SET_HEAT_ON : SET_HEAT_OFF); |
131
| sendData(&hvc_fd, wHeat ? SET_HEAT_ON : SET_HEAT_OFF); |
90
| sHeat = wHeat; |
132
| sHeat = wHeat; |
91
| setHeat(sHeat); |
133
| setHeat(sHeat); |
| |
134
| + if(sHeat) |
| |
135
| + tHeatStart = clock(); |
92
| } |
136
| } |
93
| |
137
| |
94
| if(wPump ^ sPump) |
138
| if(wPump ^ sPump) |
| @@ -96,6 +140,8 @@ void* processHVC(void* we) |
| @@ -96,6 +140,8 @@ void* processHVC(void* we) |
96
| sendData(&hvc_fd, wPump ? SET_PUMP_ON : SET_PUMP_OFF); |
140
| sendData(&hvc_fd, wPump ? SET_PUMP_ON : SET_PUMP_OFF); |
97
| sPump = wPump; |
141
| sPump = wPump; |
98
| setPump(sPump); |
142
| setPump(sPump); |
| |
143
| + if(sPump) |
| |
144
| + tPumpStart = clock(); |
99
| } |
145
| } |
100
| |
146
| |
101
| usleep(HVC_POLLING_TIME); |
147
| usleep(HVC_POLLING_TIME); |