Skip to content

Commit 8f7c0ee

Browse files
committed
split options.h
1 parent 23144b2 commit 8f7c0ee

4 files changed

Lines changed: 219 additions & 141 deletions

File tree

include/logic/options.h

Lines changed: 2 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,8 @@
2424
#include <getopt.h>
2525
#include <stdint.h>
2626

27-
struct color {
28-
uint8_t red;
29-
uint8_t green;
30-
uint8_t blue;
31-
};
32-
33-
struct led_temperatures {
34-
uint8_t temp1;
35-
uint8_t temp2;
36-
uint8_t temp3;
37-
};
38-
39-
enum led_modes {
40-
STATIC = 0,
41-
BLINK = 1,
42-
PULSE = 2,
43-
SHIFT = 3,
44-
RAINBOW = 4,
45-
TEMPERATURE = 5,
46-
};
47-
48-
struct temp_speed_pair {
49-
/** temperature */
50-
int8_t temperature;
51-
52-
/** fan speed PWM */
53-
int8_t speed;
54-
};
55-
56-
enum motor_modes {
57-
PWM = 0,
58-
RPM = 1,
59-
DEFAULT = 2,
60-
QUIET = 3,
61-
BALANCED = 4,
62-
PERFORMANCE = 5,
63-
CUSTOM = 6,
64-
UNDEFINED = 7,
65-
};
27+
#include "logic/support.h"
28+
#include "logic/suboptions.h"
6629

6730
struct option_flags {
6831
// flags
@@ -73,47 +36,6 @@ struct option_flags {
7336
unsigned int set_pump : 1;
7437
};
7538

76-
struct led_control {
77-
uint8_t channel;
78-
enum led_modes mode;
79-
struct color led_colors[7];
80-
uint16_t temperatures[3];
81-
uint8_t speed;
82-
uint8_t count;
83-
uint8_t led_type; // commanderpro
84-
uint8_t direction; // commanderpro
85-
uint8_t change_style; // commanderpro
86-
};
87-
88-
struct fan_control {
89-
uint8_t channel;
90-
enum motor_modes mode;
91-
struct temp_speed_pair table[7];
92-
93-
// data returns
94-
uint8_t fan_count;
95-
uint8_t fan_type;
96-
uint8_t temp_sensor_id;
97-
uint16_t data;
98-
uint16_t speed;
99-
uint8_t speed_pwm;
100-
uint16_t speed_rpm;
101-
uint16_t max_speed;
102-
char mode_string[64];
103-
};
104-
105-
struct pump_control {
106-
uint8_t channel;
107-
enum motor_modes mode;
108-
struct temp_speed_pair table[6];
109-
110-
// data returns
111-
uint16_t speed;
112-
uint8_t speed_pwm;
113-
uint16_t speed_rpm;
114-
uint16_t max_speed;
115-
};
116-
11739
struct option_parse_return {
11840
struct led_control led_ctrl;
11941
struct fan_control fan_ctrl;
@@ -177,66 +99,6 @@ static struct option long_options[] = {
17799
xx[6].green = 0x00; \
178100
xx[6].blue = 0xff;
179101

180-
enum {
181-
SUBOPTION_FAN_CHANNEL = 0,
182-
SUBOPTION_FAN_MODE,
183-
SUBOPTION_FAN_PWM,
184-
SUBOPTION_FAN_RPM,
185-
SUBOPTION_FAN_TEMPERATURES,
186-
SUBOPTION_FAN_SPEEDS,
187-
SUBOPTION_FAN_LIST_END,
188-
};
189-
190-
enum {
191-
SUBOPTION_LED_CHANNEL = 0,
192-
SUBOPTION_LED_MODE,
193-
SUBOPTION_LED_SPEED,
194-
SUBOPTION_LED_COLORS,
195-
SUBOPTION_LED_WARN,
196-
SUBOPTION_LED_TEMPERATURES,
197-
SUBOPTION_LED_LIST_END,
198-
};
199-
200-
enum {
201-
SUBOPTION_PUMP_MODE = 0,
202-
SUBOPTION_PUMP_PWM,
203-
SUBOPTION_PUMP_RPM,
204-
SUBOPTION_PUMP_TEMPERATURES,
205-
SUBOPTION_PUMP_SPEEDS,
206-
SUBOPTION_PUMP_LIST_END,
207-
};
208-
209-
static char *fan_options[] = {[SUBOPTION_FAN_CHANNEL] = "channel",
210-
[SUBOPTION_FAN_MODE] = "mode",
211-
[SUBOPTION_FAN_PWM] = "pwm",
212-
[SUBOPTION_FAN_RPM] = "rpm",
213-
[SUBOPTION_FAN_TEMPERATURES] = "temps",
214-
[SUBOPTION_FAN_SPEEDS] = "speeds",
215-
[SUBOPTION_FAN_LIST_END] = 0};
216-
217-
static char *led_options[] = {[SUBOPTION_LED_CHANNEL] = "channel",
218-
[SUBOPTION_LED_MODE] = "mode",
219-
[SUBOPTION_LED_SPEED] = "speed",
220-
[SUBOPTION_LED_COLORS] = "colors",
221-
[SUBOPTION_LED_WARN] = "warning_color",
222-
[SUBOPTION_LED_TEMPERATURES] = "temps",
223-
[SUBOPTION_LED_LIST_END] = 0};
224-
225-
static char *pump_options[] = {[SUBOPTION_PUMP_MODE] = "mode",
226-
[SUBOPTION_PUMP_PWM] = "pwm",
227-
[SUBOPTION_PUMP_RPM] = "rpm",
228-
[SUBOPTION_PUMP_TEMPERATURES] = "temps",
229-
[SUBOPTION_PUMP_SPEEDS] = "speeds",
230-
[SUBOPTION_PUMP_LIST_END] = 0};
231-
232-
void fan_suboptions_parse(char *subopts, struct fan_control *settings);
233-
void led_suboptions_parse(char *subopts, struct led_control *settings);
234-
void pump_suboptions_parse(char *subopts, struct pump_control *settings);
235-
236-
void fan_control_init(struct fan_control *settings);
237-
void led_control_init(struct led_control *settings);
238-
void pump_control_init(struct pump_control *settings);
239-
240102
void options_print(void);
241103

242104
int options_parse(int argc, char **argv, struct option_flags *flags,

include/logic/suboptions.h

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* This file is part of OpenCorsairLink.
3+
* Copyright (C) 2017-2019 Sean Nelson <audiohacked@gmail.com>
4+
5+
* OpenCorsairLink is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 2 of the License, or
8+
* any later version.
9+
10+
* OpenCorsairLink is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
15+
* You should have received a copy of the GNU General Public License
16+
* along with OpenCorsairLink. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#ifndef _SUBOPTIONS_H
20+
#define _SUBOPTIONS_H
21+
22+
enum {
23+
SUBOPTION_FAN_CHANNEL = 0,
24+
SUBOPTION_FAN_MODE,
25+
SUBOPTION_FAN_PWM,
26+
SUBOPTION_FAN_RPM,
27+
SUBOPTION_FAN_TEMPERATURES,
28+
SUBOPTION_FAN_SPEEDS,
29+
SUBOPTION_FAN_LIST_END,
30+
};
31+
32+
enum {
33+
SUBOPTION_LED_CHANNEL = 0,
34+
SUBOPTION_LED_MODE,
35+
SUBOPTION_LED_SPEED,
36+
SUBOPTION_LED_COLORS,
37+
SUBOPTION_LED_WARN,
38+
SUBOPTION_LED_TEMPERATURES,
39+
SUBOPTION_LED_LIST_END,
40+
};
41+
42+
enum {
43+
SUBOPTION_PUMP_MODE = 0,
44+
SUBOPTION_PUMP_PWM,
45+
SUBOPTION_PUMP_RPM,
46+
SUBOPTION_PUMP_TEMPERATURES,
47+
SUBOPTION_PUMP_SPEEDS,
48+
SUBOPTION_PUMP_LIST_END,
49+
};
50+
51+
struct led_control {
52+
uint8_t channel;
53+
enum led_modes mode;
54+
struct color led_colors[7];
55+
uint16_t temperatures[3];
56+
uint8_t speed;
57+
uint8_t count;
58+
};
59+
60+
struct fan_control {
61+
uint8_t channel;
62+
enum motor_modes mode;
63+
struct temp_speed_pair table[7];
64+
65+
// data returns
66+
uint8_t fan_count;
67+
uint8_t fan_type;
68+
uint8_t temp_sensor_id;
69+
uint16_t data;
70+
uint16_t speed;
71+
uint8_t speed_pwm;
72+
uint16_t speed_rpm;
73+
uint16_t max_speed;
74+
char mode_string[64];
75+
};
76+
77+
struct pump_control {
78+
uint8_t channel;
79+
enum motor_modes mode;
80+
struct temp_speed_pair table[6];
81+
82+
// data returns
83+
uint16_t speed;
84+
uint8_t speed_pwm;
85+
uint16_t speed_rpm;
86+
uint16_t max_speed;
87+
};
88+
89+
static char *fan_options[] = {[SUBOPTION_FAN_CHANNEL] = "channel",
90+
[SUBOPTION_FAN_MODE] = "mode",
91+
[SUBOPTION_FAN_PWM] = "pwm",
92+
[SUBOPTION_FAN_RPM] = "rpm",
93+
[SUBOPTION_FAN_TEMPERATURES] = "temps",
94+
[SUBOPTION_FAN_SPEEDS] = "speeds",
95+
[SUBOPTION_FAN_LIST_END] = 0};
96+
97+
static char *led_options[] = {[SUBOPTION_LED_CHANNEL] = "channel",
98+
[SUBOPTION_LED_MODE] = "mode",
99+
[SUBOPTION_LED_SPEED] = "speed",
100+
[SUBOPTION_LED_COLORS] = "colors",
101+
[SUBOPTION_LED_WARN] = "warning_color",
102+
[SUBOPTION_LED_TEMPERATURES] = "temps",
103+
[SUBOPTION_LED_LIST_END] = 0};
104+
105+
static char *pump_options[] = {[SUBOPTION_PUMP_MODE] = "mode",
106+
[SUBOPTION_PUMP_PWM] = "pwm",
107+
[SUBOPTION_PUMP_RPM] = "rpm",
108+
[SUBOPTION_PUMP_TEMPERATURES] = "temps",
109+
[SUBOPTION_PUMP_SPEEDS] = "speeds",
110+
[SUBOPTION_PUMP_LIST_END] = 0};
111+
112+
void fan_suboptions_parse(char *subopts, struct fan_control *settings);
113+
void led_suboptions_parse(char *subopts, struct led_control *settings);
114+
void pump_suboptions_parse(char *subopts, struct pump_control *settings);
115+
116+
void fan_control_init(struct fan_control *settings);
117+
void led_control_init(struct led_control *settings);
118+
void pump_control_init(struct pump_control *settings);
119+
120+
#endif

include/logic/support.h

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* This file is part of OpenCorsairLink.
3+
* Copyright (C) 2017-2019 Sean Nelson <audiohacked@gmail.com>
4+
5+
* OpenCorsairLink is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 2 of the License, or
8+
* any later version.
9+
10+
* OpenCorsairLink is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
15+
* You should have received a copy of the GNU General Public License
16+
* along with OpenCorsairLink. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#ifndef _SUPPORT_H
20+
#define _SUPPORT_H
21+
22+
struct color {
23+
uint8_t red;
24+
uint8_t green;
25+
uint8_t blue;
26+
};
27+
28+
struct led_temperatures {
29+
uint8_t temp1;
30+
uint8_t temp2;
31+
uint8_t temp3;
32+
};
33+
34+
enum led_modes {
35+
STATIC = 0,
36+
BLINK = 1,
37+
PULSE = 2,
38+
SHIFT = 3,
39+
RAINBOW = 4,
40+
TEMPERATURE = 5,
41+
};
42+
43+
struct temp_speed_pair {
44+
/** temperature */
45+
int8_t temperature;
46+
47+
/** fan speed PWM */
48+
int8_t speed;
49+
};
50+
51+
enum motor_modes {
52+
PWM = 0,
53+
RPM = 1,
54+
DEFAULT = 2,
55+
QUIET = 3,
56+
BALANCED = 4,
57+
PERFORMANCE = 5,
58+
CUSTOM = 6,
59+
UNDEFINED = 7,
60+
};
61+
62+
#define INIT_WARNING_LED(xx) \
63+
xx.red = 0xFF; \
64+
xx.green = 0x00; \
65+
xx.blue = 0x00;
66+
67+
#define INIT_DEFAULT_LED(xx) \
68+
xx.red = 0xFF; \
69+
xx.green = 0xFF; \
70+
xx.blue = 0x00;
71+
72+
#define INIT_RAINBOW_LED(xx) \
73+
xx[0].red = 0xff; \
74+
xx[0].green = 0x00; \
75+
xx[0].blue = 0x00; \
76+
xx[1].red = 0xff; \
77+
xx[1].green = 0x80; \
78+
xx[1].blue = 0x00; \
79+
xx[2].red = 0xff; \
80+
xx[2].green = 0xff; \
81+
xx[2].blue = 0x00; \
82+
xx[3].red = 0x00; \
83+
xx[3].green = 0xff; \
84+
xx[3].blue = 0x00; \
85+
xx[4].red = 0x00; \
86+
xx[4].green = 0x00; \
87+
xx[4].blue = 0xff; \
88+
xx[5].red = 0x4b; \
89+
xx[5].green = 0x00; \
90+
xx[5].blue = 0x82; \
91+
xx[6].red = 0x7f; \
92+
xx[6].green = 0x00; \
93+
xx[6].blue = 0xff;
94+
95+
#endif

logic/options.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
* along with OpenCorsairLink. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
#include "common.h"
19+
// #include "logic/support.h"
20+
// #include "logic/suboptions.h"
2021
#include "logic/options.h"
2122
#include "logic/print.h"
2223

0 commit comments

Comments
 (0)