forked from audiohacked/OpenCorsairLink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.c
164 lines (134 loc) · 4.49 KB
/
options.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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* This file is part of OpenCorsairLink.
* Copyright (C) 2017 Sean Nelson <[email protected]>
* OpenCorsairLink is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* any later version.
* OpenCorsairLink is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with OpenCorsairLink. If not, see <http://www.gnu.org/licenses/>.
*/
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include "options.h"
#include "print.h"
static struct option long_options[] = {
{"help", no_argument, 0, 0},
{"version", no_argument, 0, 1},
{"debug", no_argument, 0, 2},
{"device", required_argument, 0, 3},
{"firmware", no_argument, 0, 4},
{"print-temperature", no_argument, 0, 5},
{"print-fan-speed", no_argument, 0, 6},
{"led", required_argument, 0, 7},
{"led-warn", required_argument, NULL, 8},
{"led-temp", required_argument, NULL, 9},
{"fan-temps", required_argument, NULL, 10},
{"fan-speeds", required_argument, NULL, 11},
{"pump-mode", required_argument, NULL, 12},
{0, 0, 0, 0}
};
void options_print(void);
#define INIT_WARNING_LED(x) \
x.red = 0xFF; \
x.green = 0x00; \
x.blue = 0x00;
int options_parse(int argc, char **argv,
struct option_flags *flags, int8_t *device_number,
struct option_parse_return *settings)
{
int c, returnCode = 0;
memset(settings, 0, sizeof(struct option_parse_return));
INIT_WARNING_LED(settings->warning_led);
settings->warning_led_temp = 60;
settings->pump_mode = DEFAULT;
while (1) {
int option_index = 0;
c = getopt_long (argc, argv, "", long_options, &option_index);
if (c == -1 || returnCode != 0)
break;
switch (c) {
case 0:
options_print();
break;
case 1: /* program version */
msg_info("OpenCorsairLink Version: %s", VERSION);
break;
case 2:
verbose++;
break;
case 3:
sscanf(optarg, "%hhd", device_number);
break;
case 4:
flags->device_firmware = 1;
break;
case 5:
flags->read_temperature = 1;
break;
case 6:
flags->read_fan_speed = 1;
break;
case 7: /* led color */
sscanf(optarg, "%02hhX%02hhX%02hhX", &settings->led_color.red, &settings->led_color.green, &settings->led_color.blue);
break;
case 8: /* led warning color */
sscanf(optarg, "%02hhX%02hhX%02hhX", &settings->warning_led.red, &settings->warning_led.green, &settings->warning_led.blue);
break;
case 9: /* led warning temperature */
sscanf(optarg, "%hhd", &settings->warning_led_temp);
break;
case 10:
sscanf(optarg, "%hhd,%hhd,%hhd,%hhd,%hhd,%hhd",
&settings->fan1.t1,
&settings->fan1.t2,
&settings->fan1.t3,
&settings->fan1.t4,
&settings->fan1.t5,
&settings->fan1.t6);
break;
case 11:
sscanf(optarg, "%hhd,%hhd,%hhd,%hhd,%hhd,%hhd",
&settings->fan1.s1,
&settings->fan1.s2,
&settings->fan1.s3,
&settings->fan1.s4,
&settings->fan1.s5,
&settings->fan1.s6);
break;
case 12:
sscanf(optarg, "%hhu", &settings->pump_mode);
break;
default:
options_print();
exit(1);
returnCode = 0;
}
}
return returnCode;
}
void options_print() {
msg_info("OpenCorsairLink [options]\n");
msg_info("Options:\n");
msg_info("\t--help :Prints this Message\n");
msg_info("\t--version :Displays version.\n");
msg_info("\t--debug :Displays enhanced Debug Messages.\n");
msg_info("\t--device <Device Number> :Select device.\n");
msg_info("\tLED:\n");
msg_info("\t\t--led <HTML Color Code> :Define Color for LED.\n");
msg_info("\t\t--led-warn <HTML Color Code> :Define Color for Warning Temp.\n");
msg_info("\t\t--led-temp <Temperature in Celsius> :Define Warning Temperature.\n");
msg_info("\tFan:\n");
msg_info("\t\t--fan-temps <CSV of Temperatures> :Define Comma Separated Values of Temperatures for Fan.\n");
msg_info("\t\t--fan-speeds <CSV of Speed Percentage> :Define Comma Separated Values of RPM for Fan.\n");
msg_info("\tPump mode:\n");
msg_info("\t\t--pump-mode <mode> :set to 3 for quiet, and 5 for performance\n");
}