-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeed.c
57 lines (42 loc) · 793 Bytes
/
speed.c
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
#include <stdio.h>
#include <stdlib.h>
#include "flowmaster.h"
double read_arg(const char *arg);
int main(int argc, char *argv[])
{
flowmaster *fm;
int rc;
double speed = 0;
#ifdef _WIN32
const char port[] = "COM3";
#else
const char port[] = "/dev/ttyUSB1";
#endif
if(argc >= 2){
speed = read_arg(argv[1]);
}
else {
fprintf(stderr,"Speed not given!\n");
return 0;
}
fm = fm_create();
rc = fm_connect(fm, port);
if(rc != FM_OK){
fprintf(stderr,"Error opening com port!\n");
fm_destroy(fm);
return 0;
}
rc = fm_set_fan_speed(fm,speed);
if(rc != 0){
fprintf(stderr,"Failed to set speed: %d\n",rc);
}
fm_disconnect(fm);
fm_destroy(fm);
return 0;
}
double read_arg(const char *arg)
{
int result;
sscanf(arg,"%d",&result);
return result / 100.0;
}