-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvenient_wrapper_functions.c
More file actions
86 lines (75 loc) · 2.81 KB
/
convenient_wrapper_functions.c
File metadata and controls
86 lines (75 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "convenient_wrapper_functions.h"
extern bool verboseFlag;
static double flow_rates[ ] = { 0.0, /* in l/h */
135.0,
270.0,
400.0,
535.0,
670.0,
800.0,
935.0,
1070.0,
1200.0,
1335.0,
1470.0,
1600.0,
1735.0,
1870.0,
2000.0 };
double translate_flow_rate(unsigned int gfr){
return(flow_rates[gfr]);
}
int set_flow_rate( double flow_rate, struct sp_port* port_choice ) {
int fr_index=0;
int i = 0;
if(verboseFlag) {
printf("Requested to change flow rate to %lf\n", flow_rate);
}
if ( flow_rate < 0 ) {
printf("FATAL: flow rate negative!\n");
return(-1) ;
}
if (flow_rate > 2000.0) {
printf("FATAL: flow rate must be below 2000 l/hr\n");
return(-1);
}
for ( i = 1; i < 16; i++ )
if ( flow_rate >= flow_rates[ i - 1 ]
&& flow_rate <= flow_rates[ i ] )
{
if ( flow_rate < 0.5 * ( flow_rates[ i - 1 ] + flow_rates[ i ] ) )
fr_index = i - 1;
else
fr_index = i;
break;
}
if ( flow_rate != 0.0
&& fabs( ( flow_rate - flow_rates[ fr_index ] ) / flow_rate ) > 0.01 )
printf("WARNING: Flow rate had to be adjusted from %.1f l/h to "
"%.1f l/h.\n", flow_rate, flow_rates[ fr_index ] );
bvt3000_set_flow_rate( fr_index , port_choice);
return 0;
}
void checkHeater(struct sp_port* port_choice)
{
if (verboseFlag) { printf("Checking heater state!\n");}
bool result = bvt3000_get_heater_state(port_choice);
if (result == SET) {
if (verboseFlag){printf("Heater is ON\n"); }
printf("***HSC : ON\n");
} else if (result == UNSET) {
printf("***HSC : OFF\n");
if (verboseFlag){printf("Heater is OFF\n"); }
}
}
void setHeaterPowerLimit(float limit, struct sp_port* port_choice){
if (limit < 0.0 || limit > 100.0) {
fprintf(stderr,"FATAL: Invalid power limit, %f not in [0, 100]\n", limit);
} else if (limit >= 0.0 && limit <= 100.0) {
bool result = bvt3000_get_heater_state(port_choice);
if (result == UNSET) {
fprintf(stderr,"WARNING: Heater not currently enabled; limit takes effect in the future.\n");
}
eurotherm902s_set_heater_power_limit( limit, port_choice );
}
}