Skip to content

Commit

Permalink
Add driver.h to needed files
Browse files Browse the repository at this point in the history
Implement combined PSU and Hydro-series interfaces
  • Loading branch information
audiohacked committed Mar 1, 2017
1 parent 54470f3 commit 4f31ff8
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 70 deletions.
19 changes: 6 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ LDFLAGS ?= -lm
CFLAGS += $(shell pkg-config --cflags libusb-1.0)
LDFLAGS += $(shell pkg-config --libs libusb-1.0)

OBJ_MAIN = main.o
OBJ_PSU = main_psu.o
OBJ_SCAN = main_scanner.o
OBJS = device.o \
OBJS = main.o \
device.o \
driver.o \
options.o \
print.o \
scan.o
Expand All @@ -28,19 +27,13 @@ OBJS_PROTO = protocol/asetek4/core.o \

default: all

all: OpenCorsairLink.elf OpenCorsairLinkPSU.elf Scanner.elf
all: OpenCorsairLink.elf

OpenCorsairLink.elf: $(OBJ_MAIN) $(OBJS_PROTO) $(OBJS_LL) $(OBJS)
OpenCorsairLink.elf: $(OBJS) $(OBJS_PROTO) $(OBJS_LL) $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@

OpenCorsairLinkPSU.elf: $(OBJ_PSU) $(OBJS_PROTO) $(OBJS_LL) $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@

Scanner.elf: $(OBJ_SCAN) $(OBJS_PROTO) $(OBJS_LL) $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@

%.o: %.c
$(CC) $(CFLAGS) -g -c -o $@ $<

clean:
$(RM) OpenCorsairLink.elf OpenCorsairLinkPSU.elf Scanner.elf $(OBJ_MAIN) $(OBJ_PSU) $(OBJ_SCAN) $(OBJS) $(OBJS_LL) $(OBJS_PROTO)
$(RM) OpenCorsairLink.elf $(OBJS) $(OBJS_LL) $(OBJS_PROTO)
132 changes: 104 additions & 28 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <libusb.h>
#include "options.h"
#include "device.h"
#include "driver.h"
#include "print.h"
#include "scan.h"
#include "lowlevel/asetek4.h"
Expand All @@ -32,41 +33,82 @@
#include "protocol/hid/core.h"
#include "protocol/rmi/core.h"

int main(int argc, char *argv[])
{
int r; // result from libusb functions

uint8_t device_number;
int psu_settings(struct corsair_device_scan scanned_device, struct option_parse_return settings) {
int r;
int i;
char name[20];
name[sizeof(name) - 1] = 0;
uint32_t time = 0;
uint16_t supply_volts, supply_watts,
output_volts, output_amps, output_watts;
struct corsair_device_info *dev;
struct libusb_device_handle *handle;

struct option_flags flags;
struct color led_color;
struct color warning_led;
struct fan_table fan1;
struct fan_table pump;
int8_t warning_led_temp;
uint8_t pump_mode;
dev = scanned_device.device;
handle = scanned_device.handle;
msg_debug("DEBUG: shortcuts set\n");

options_parse(argc, argv, &flags, &device_number,
&led_color, &warning_led, &warning_led_temp,
&fan1, &pump, &pump_mode);

libusb_context *context = NULL;
r = dev->driver->init(handle, dev->write_endpoint);
msg_debug("DEBUG: init done\n");

r = libusb_init(&context);
if (r < 0) {
msg_info("Init Error %d\n", r);
return 1;
/* fetch device name, vendor name, product name */
r = dev->driver->name(dev, name);
msg_info("Name: %s\n", name);
r = dev->driver->vendor(dev, name);
msg_info("Vendor: %s\n", name);
r = dev->driver->product(dev, name);
msg_info("Product: %s\n", name);
msg_debug("DEBUG: string done\n");

/* fetch device powered time and device uptime */
r = dev->driver->psu_time.powered(dev, &time);
msg_info("Powered: %u (%dd. %dh)\n",
time, time/(24*60*60), time/(60*60)%24);
r = dev->driver->psu_time.uptime(dev, &time);
msg_info("Uptime: %u (%dd. %dh)\n",
time, time/(24*60*60), time/(60*60)%24);
msg_debug("DEBUG: time done\n");

/* fetch Supply Voltage and Total Watts Consumming */
r = dev->driver->power.supply_voltage(dev, &supply_volts);
msg_info("Supply Voltage %5.1f\n", convert_bytes_double(supply_volts));
r = dev->driver->power.total_wattage(dev, &supply_watts);
msg_info("Total Watts %5.1f\n", convert_bytes_double(supply_watts));
msg_debug("DEBUG: supply done\n");

/* fetch PSU output */
for (i=0; i<3; i++) {
if (i==0)
msg_info("Output 12v:\n");
if (i==1)
msg_info("Output 5v:\n");
if (i==2)
msg_info("Output 3.3v:\n");

r = dev->driver->power.select(dev, i);
r = dev->driver->power.voltage(dev, &output_volts);
msg_info("\tVoltage %5.2f\n", convert_bytes_double(output_volts));

r = dev->driver->power.amperage(dev, &output_amps);
msg_info("\tAmps %5.2f\n", convert_bytes_double(output_amps));

r = dev->driver->power.wattage(dev, &output_watts);
msg_info("\tWatts %5.2f\n", convert_bytes_double(output_watts));
}
libusb_set_debug(context, 3);
r = dev->driver->power.select(dev, 0);

corsairlink_device_scanner(context);
msg_debug("DEBUG: scan done, start routines\n");
msg_debug("DEBUG: device_number = %d\n", device_number);
r = dev->driver->deinit(handle, dev->write_endpoint);

return 0;
}

int hydro_settings(struct corsair_device_scan scanned_device, struct option_parse_return settings) {
int r;
struct corsair_device_info *dev;
struct libusb_device_handle *handle;

dev = scanlist[device_number].device;
handle = scanlist[device_number].handle;
dev = scanned_device.device;
handle = scanned_device.handle;
msg_debug("DEBUG: shortcuts set\n");

r = dev->driver->init(handle, dev->write_endpoint);
Expand All @@ -80,10 +122,44 @@ int main(int argc, char *argv[])
//r = dev->driver->product(dev, name);
//msg_info("Product: %s\n", name);

r = dev->driver->led(dev, &led_color, &warning_led, warning_led_temp, (warning_led_temp > -1));
r = dev->driver->led(dev, &settings.led_color, &settings.warning_led, settings.warning_led_temp, (settings.warning_led_temp > -1));

r = dev->driver->deinit(handle, dev->write_endpoint);
msg_debug("DEBUG: deinit done\n");

return 0;
}

int main(int argc, char *argv[])
{
int r; // result from libusb functions

int8_t device_number = -1;

struct option_flags flags;
struct option_parse_return settings;

options_parse(argc, argv, &flags, &device_number,
&settings);

libusb_context *context = NULL;

r = libusb_init(&context);
if (r < 0) {
msg_info("Init Error %d\n", r);
return 1;
}
libusb_set_debug(context, 3);

corsairlink_device_scanner(context);
msg_debug("DEBUG: scan done, start routines\n");
msg_debug("DEBUG: device_number = %d\n", device_number);

if (scanlist[device_number].device->psu == 1) {
psu_settings(scanlist[device_number], settings);
} else {
hydro_settings(scanlist[device_number], settings);
}

exit:
corsairlink_close(context);
Expand Down
45 changes: 22 additions & 23 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,18 @@ static struct option long_options[] = {
void options_print(void);

#define INIT_WARNING_LED(x) \
x->red = 0xFF; \
x->green = 0x00; \
x->blue = 0x00;
x.red = 0xFF; \
x.green = 0x00; \
x.blue = 0x00;

int options_parse(int argc, char **argv,
struct option_flags *flags, uint8_t *device_number,
struct color *led, struct color *warning, int8_t *warning_temp,
struct fan_table *fan, struct fan_table *pump, uint8_t *pump_mode)
struct option_flags *flags, int8_t *device_number,
struct option_parse_return *settings)
{
int c, returnCode = 0;

INIT_WARNING_LED(warning);
*warning_temp = 60;
INIT_WARNING_LED(settings->warning_led);
settings->warning_led_temp = 60;

while (1) {
int option_index = 0;
Expand All @@ -85,7 +84,7 @@ int options_parse(int argc, char **argv,
verbose++;
break;
case 3:
sscanf(optarg, "%hhu", device_number);
sscanf(optarg, "%hhd", device_number);
break;

case 4:
Expand All @@ -100,33 +99,33 @@ int options_parse(int argc, char **argv,
break;

case 7: /* led color */
sscanf(optarg, "%02hhX%02hhX%02hhX", &led->red, &led->green, &led->blue);
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", &warning->red, &warning->green, &warning->blue);
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", warning_temp);
sscanf(optarg, "%hhd", &settings->warning_led_temp);
break;

case 10:
sscanf(optarg, "%hhd,%hhd,%hhd,%hhd,%hhd",
&fan->t1,
&fan->t2,
&fan->t3,
&fan->t4,
&fan->t5);
&settings->fan1.t1,
&settings->fan1.t2,
&settings->fan1.t3,
&settings->fan1.t4,
&settings->fan1.t5);
break;
case 11:
sscanf(optarg, "%hhd,%hhd,%hhd,%hhd,%hhd",
&fan->s1,
&fan->s2,
&fan->s3,
&fan->s4,
&fan->s5);
&settings->fan1.s1,
&settings->fan1.s2,
&settings->fan1.s3,
&settings->fan1.s4,
&settings->fan1.s5);
break;
case 12:
sscanf(optarg, "%hhu", pump_mode);
sscanf(optarg, "%hhu", &settings->pump_mode);
break;

default:
Expand Down
10 changes: 4 additions & 6 deletions options.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,16 @@ struct option_flags {
};

struct option_parse_return {
struct color color_led;
struct color led_color;
struct color warning_led;
int8_t warning_temp;
int8_t warning_led_temp;
struct fan_table fan1;
struct fan_table pump;
uint8_t pump_mode;
uint8_t device_number;
};

int options_parse(int argc, char **argv,
struct option_flags *flags, uint8_t *device_number,
struct color *led, struct color *warning, int8_t *warning_temp,
struct fan_table *fan, struct fan_table *pump, uint8_t *pump_mode);
struct option_flags *flags, int8_t *device_number,
struct option_parse_return *settings);

#endif
1 change: 1 addition & 0 deletions protocol/asetek4/fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <libusb.h>
#include "../../lowlevel/asetek4.h"
#include "../../device.h"
#include "../../driver.h"
#include "core.h"

int corsairlink_asetek_fan_mode(struct corsair_device_info *dev,
Expand Down
2 changes: 2 additions & 0 deletions protocol/asetek4/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <libusb.h>
#include "../../lowlevel/asetek4.h"
#include "../../device.h"
#include "../../driver.h"


int corsairlink_asetek_change_led(struct corsair_device_info *dev,
struct color *color_led, struct color *warning_led,
Expand Down
1 change: 1 addition & 0 deletions protocol/asetek4/pump.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <libusb.h>
#include "../../lowlevel/asetek4.h"
#include "../../device.h"
#include "../../driver.h"
#include "core.h"

int corsairlink_asetek_pump_mode(struct corsair_device_info *dev, uint8_t pump_mode)
Expand Down
1 change: 1 addition & 0 deletions protocol/hid/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "../../lowlevel/hid.h"
#include "../../device.h"
#include "../../driver.h"
#include "core.h"

int corsairlink_hid_device_id(struct corsair_device_info *dev)
Expand Down
1 change: 1 addition & 0 deletions protocol/hid/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "../../lowlevel/hid.h"
#include "../../device.h"
#include "../../driver.h"
#include "core.h"

int corsairlink_hid_change_led(struct corsair_device_info *dev,
Expand Down
1 change: 1 addition & 0 deletions protocol/rmi/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "../../lowlevel/hid.h"
#include "../../device.h"
#include "../../driver.h"
#include "core.h"

double convert_bytes_double(uint16_t v16)
Expand Down
1 change: 1 addition & 0 deletions protocol/rmi/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "../../lowlevel/hid.h"
#include "../../device.h"
#include "../../driver.h"
#include "../../print.h"
#include "core.h"

Expand Down
1 change: 1 addition & 0 deletions protocol/rmi/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "../../lowlevel/rmi.h"
#include "../../device.h"
#include "../../driver.h"
#include "core.h"

int corsairlink_rmi_time_powered(struct corsair_device_info *dev,
Expand Down

0 comments on commit 4f31ff8

Please sign in to comment.