forked from audiohacked/OpenCorsairLink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.c
196 lines (167 loc) · 6.04 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
* 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},
{"dump", no_argument, 0, 3},
{"device", required_argument, 0, 4},
{"firmware", no_argument, 0, 5},
{"print-temperature", no_argument, 0, 6},
{"print-fan-speed", no_argument, 0, 7},
{"led", required_argument, 0, 8},
{"led-warn", required_argument, NULL, 9},
{"led-temp", required_argument, NULL, 10},
{"fan", required_argument, NULL, 11},
{"fan-mode", required_argument, NULL, 12},
{"fan-pwm", required_argument, NULL, 13},
{"fan-rpm", required_argument, NULL, 14},
{"fan-temps", required_argument, NULL, 15},
{"fan-speeds", required_argument, NULL, 16},
{"pump-mode", required_argument, NULL, 17},
{0, 0, 0, 0}
};
void options_print(void);
#define INIT_WARNING_LED(xx) \
xx.red = 0xFF; \
xx.green = 0x00; \
xx.blue = 0x00;
int options_parse(int argc, char **argv,
struct option_flags *flags, int8_t *device_number,
struct option_parse_return *settings)
{
int cc, 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;
cc = getopt_long (argc, argv, "", long_options, &option_index);
if (cc == -1 || returnCode != 0)
break;
switch (cc) {
case 0:
options_print();
break;
case 1: /* program version */
msg_info("OpenCorsairLink Version: %s", VERSION);
break;
case 3:
verbose++;
case 2:
verbose++;
break;
case 4:
sscanf(optarg, "%hhd", device_number);
break;
case 5:
flags->device_firmware = 1;
break;
case 6:
flags->read_temperature = 1;
break;
case 7:
flags->read_fan_speed = 1;
break;
case 8: /* led color */
sscanf(optarg, "%02hhX%02hhX%02hhX", &settings->led_color.red, &settings->led_color.green, &settings->led_color.blue);
break;
case 9: /* led warning color */
sscanf(optarg, "%02hhX%02hhX%02hhX", &settings->warning_led.red, &settings->warning_led.green, &settings->warning_led.blue);
break;
case 10: /* led warning temperature */
sscanf(optarg, "%hhd", &settings->warning_led_temp);
break;
case 11:
sscanf(optarg, "%hhd", &settings->fan);
break;
case 12:
sscanf(optarg, "%hhd", &settings->fan_mode);
break;
case 13:
sscanf(optarg, "%hhd", &settings->fan_data);
break;
case 14:
sscanf(optarg, "%d", &settings->fan_data);
break;
case 15:
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 16:
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 17:
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\t\t\t\t:Prints this Message\n");
msg_info("\t--version\t\t\t:Displays version.\n");
msg_info("\t--debug\t\t\t\t:Displays enhanced Debug Messages.\n");
msg_info("\t--dump\t\t\t\t:Implies --debug. Dump the raw data recieved from the device.\n");
msg_info("\t--device <Device Number>\t:Select device.\n");
msg_info("\n\tLED:\n");
msg_info("\t--led <HTML Color Code>\t\t\t:Define Color for LED.\n");
msg_info("\t--led-warn <HTML Color Code>\t\t:Define Color for Warning Temp.\n");
msg_info("\t--led-temp <Temperature in Celsius>\t:Define Warning Temperature.\n");
msg_info("\n\tFan:\n");
msg_info("\t--fan <fan number> :Selects a fan to setup. Accepted values are 1, 2, 3 or 4.\n");
msg_info("\t--fan-mode <fan mode> :Sets the mode for the selected fan\n");
msg_info("\t\tModes:\n");
msg_info("\t\t 0 - Fixed PWM (requires to specify the PWM)\n");
msg_info("\t\t 1 - Fixed RPM (requires to specify the RPM)\n");
msg_info("\t\t 2 - Default\n");
msg_info("\t\t 3 - Quiet\n");
msg_info("\t\t 4 - Balanced\n");
msg_info("\t\t 5 - Performance\n");
msg_info("\t\t 6 - Custom Curve\n");
msg_info("\t--fan-pwm <fan PWM> :The desired PWM speed for the selected fan. NOTE: it only works when fan mode is set to Fixed PWM\n");
msg_info("\t--fan-rpm <fan RPM> :The desired RPM for the selected fan. NOTE: it works only when fan mode is set to Fixed RPM\n");
msg_info("\t--fan-temps <CSV of Temperatures>\t:Define Comma Separated Values of Temperatures for Fan.\n");
msg_info("\t--fan-speeds <CSV of Speed Percentage>\t:Define Comma Separated Values of RPM Percentage for Fan.\n");
msg_info("\n\tPump mode:\n");
msg_info("\t--pump-mode <mode>\t:set to 3 for quiet, and 5 for performance\n");
msg_info("\n Without options, OpenCorsairLink will show the status of any detected Corsair Link device.\n");
}