Skip to content

Commit

Permalink
Remove all libusb device handle from corsair device list.
Browse files Browse the repository at this point in the history
  • Loading branch information
audiohacked committed Mar 15, 2017
1 parent c8c8fd4 commit e6f680e
Show file tree
Hide file tree
Showing 22 changed files with 165 additions and 196 deletions.
16 changes: 0 additions & 16 deletions device.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ struct corsair_device_info corsairlink_devices[] = {
.name = "H80i",
.read_endpoint = 0x01|LIBUSB_ENDPOINT_IN,
.write_endpoint = LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE|LIBUSB_ENDPOINT_OUT,
.handle = NULL,
.context = NULL,
.driver = &corsairlink_driver_hid,
.led_control_count = 1,
.fan_control_count = 4,
Expand All @@ -48,8 +46,6 @@ struct corsair_device_info corsairlink_devices[] = {
.name = "H100i",
.read_endpoint = 0x01|LIBUSB_ENDPOINT_IN,
.write_endpoint = LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE|LIBUSB_ENDPOINT_OUT,
.handle = NULL,
.context = NULL,
.driver = &corsairlink_driver_hid,
.led_control_count = 1,
.fan_control_count = 4,
Expand All @@ -62,8 +58,6 @@ struct corsair_device_info corsairlink_devices[] = {
.name = "H110i",
.read_endpoint = 0x01|LIBUSB_ENDPOINT_IN,
.write_endpoint = LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE|LIBUSB_ENDPOINT_OUT,
.handle = NULL,
.context = NULL,
.driver = &corsairlink_driver_hid,
.led_control_count = 1,
.fan_control_count = 4,
Expand All @@ -76,8 +70,6 @@ struct corsair_device_info corsairlink_devices[] = {
.name = "H110i Extreme",
.read_endpoint = 0x01|LIBUSB_ENDPOINT_IN,
.write_endpoint = LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE|LIBUSB_ENDPOINT_OUT,
.handle = NULL,
.context = NULL,
.driver = &corsairlink_driver_hid,
.led_control_count = 1,
.fan_control_count = 4,
Expand All @@ -90,8 +82,6 @@ struct corsair_device_info corsairlink_devices[] = {
.name = "H100i V2", /** also called H100i GTX */
.read_endpoint = 0x02|LIBUSB_ENDPOINT_IN,
.write_endpoint = 0x02|LIBUSB_ENDPOINT_OUT,
.handle = NULL,
.context = NULL,
.driver = &corsairlink_driver_asetek,
.led_control_count = 1,
.fan_control_count = 1,
Expand All @@ -104,8 +94,6 @@ struct corsair_device_info corsairlink_devices[] = {
.name = "H115i", /** H115i */
.read_endpoint = 0x02|LIBUSB_ENDPOINT_IN,
.write_endpoint = 0x02|LIBUSB_ENDPOINT_OUT,
.handle = NULL,
.context = NULL,
.driver = &corsairlink_driver_asetek,
.led_control_count = 1,
.fan_control_count = 1,
Expand All @@ -118,8 +106,6 @@ struct corsair_device_info corsairlink_devices[] = {
.name = "RM650i",
.read_endpoint = 0x01|LIBUSB_ENDPOINT_IN,
.write_endpoint = 0x01|LIBUSB_ENDPOINT_OUT,
.handle = NULL,
.context = NULL,
.driver = &corsairlink_driver_rmi,
.led_control_count = 0,
.fan_control_count = 1,
Expand All @@ -132,8 +118,6 @@ struct corsair_device_info corsairlink_devices[] = {
.name = "RM750i",
.read_endpoint = 0x01|LIBUSB_ENDPOINT_IN,
.write_endpoint = 0x01|LIBUSB_ENDPOINT_OUT,
.handle = NULL,
.context = NULL,
.driver = &corsairlink_driver_rmi,
.led_control_count = 0,
.fan_control_count = 1,
Expand Down
6 changes: 3 additions & 3 deletions device.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ struct corsair_device_info {
uint8_t write_endpoint;

/** libusb device structures */
struct libusb_device_handle *handle;
libusb_context *context;
int interface;
// struct libusb_device_handle *handle;
// libusb_context *context;
// int interface;

/** device control info */
struct corsair_device_driver *driver;
Expand Down
38 changes: 19 additions & 19 deletions driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,37 @@ struct corsair_device_driver {
int (*write)(struct libusb_device_handle*, uint8_t, uint8_t*, int);

/** protocol functions */
int (*name)(struct corsair_device_info *dev, char *name);
int (*vendor)(struct corsair_device_info *dev, char *name);
int (*product)(struct corsair_device_info *dev, char *name);
int (*device_id)(struct corsair_device_info *dev, uint8_t *device_id);
int (*fw_version)(struct corsair_device_info *dev, char *name);
int (*name)(struct corsair_device_info *dev, struct libusb_device_handle *handle, char *name);
int (*vendor)(struct corsair_device_info *dev, struct libusb_device_handle *handle, char *name);
int (*product)(struct corsair_device_info *dev, struct libusb_device_handle *handle, char *name);
int (*device_id)(struct corsair_device_info *dev, struct libusb_device_handle *handle, uint8_t *device_id);
int (*fw_version)(struct corsair_device_info *dev, struct libusb_device_handle *handle, char *name);

int (*led)(struct corsair_device_info *dev, struct color *l, struct color *w, uint8_t t, uint8_t e);
int (*temperature)(struct corsair_device_info *dev, uint8_t select, uint16_t *temp);
int (*led)(struct corsair_device_info *dev, struct libusb_device_handle *handle, struct color *l, struct color *w, uint8_t t, uint8_t e);
int (*temperature)(struct corsair_device_info *dev, struct libusb_device_handle *handle, uint8_t select, uint16_t *temp);

struct fan_functions {
int (*profile)(struct corsair_device_info *dev, uint8_t profile);
int (*custom)(struct corsair_device_info *dev, struct fan_table *custom_profile);
int (*profile)(struct corsair_device_info *dev, struct libusb_device_handle *handle, uint8_t profile);
int (*custom)(struct corsair_device_info *dev, struct libusb_device_handle *handle, struct fan_table *custom_profile);
} fan;

struct pump_functions {
int (*profile)(struct corsair_device_info *dev, uint8_t profile);
int (*custom)(struct corsair_device_info *dev, struct fan_table *custom_profile);
int (*profile)(struct corsair_device_info *dev, struct libusb_device_handle *handle, uint8_t profile);
int (*custom)(struct corsair_device_info *dev, struct libusb_device_handle *handle, struct fan_table *custom_profile);
} pump;

struct power_functions {
int (*supply_voltage)(struct corsair_device_info *dev, uint16_t *volts);
int (*total_wattage)(struct corsair_device_info *dev, uint16_t *watts);
int (*select)(struct corsair_device_info *dev, uint8_t output_select);
int (*voltage)(struct corsair_device_info *dev, uint16_t *volts);
int (*amperage)(struct corsair_device_info *dev, uint16_t *amps);
int (*wattage)(struct corsair_device_info *dev, uint16_t *watts);
int (*supply_voltage)(struct corsair_device_info *dev, struct libusb_device_handle *handle, uint16_t *volts);
int (*total_wattage)(struct corsair_device_info *dev, struct libusb_device_handle *handle, uint16_t *watts);
int (*select)(struct corsair_device_info *dev, struct libusb_device_handle *handle, uint8_t output_select);
int (*voltage)(struct corsair_device_info *dev, struct libusb_device_handle *handle, uint16_t *volts);
int (*amperage)(struct corsair_device_info *dev, struct libusb_device_handle *handle, uint16_t *amps);
int (*wattage)(struct corsair_device_info *dev, struct libusb_device_handle *handle, uint16_t *watts);
} power;

struct time_functions {
int (*powered)(struct corsair_device_info *dev, uint32_t *v32);
int (*uptime)(struct corsair_device_info *dev, uint32_t *v32);
int (*powered)(struct corsair_device_info *dev, struct libusb_device_handle *handle, uint32_t *v32);
int (*uptime)(struct corsair_device_info *dev, struct libusb_device_handle *handle, uint32_t *v32);
} psu_time;

int (*fan_speed_read)();
Expand Down
36 changes: 18 additions & 18 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,33 +52,33 @@ int psu_settings(struct corsair_device_scan scanned_device, struct option_parse_
msg_debug("DEBUG: init done\n");

/* fetch device name, vendor name, product name */
r = dev->driver->vendor(dev, name);
r = dev->driver->vendor(dev, handle, name);
msg_info("Vendor: %s\n", name);
r = dev->driver->product(dev, name);
r = dev->driver->product(dev, handle, name);
msg_info("Product: %s\n", name);
r = dev->driver->fw_version(dev, name);
r = dev->driver->fw_version(dev, handle, name);
msg_info("Firmware: %s\n", name);
msg_debug("DEBUG: string done\n");

/* fetch temperatures */
for (i=0; i<2; i++) {
r = dev->driver->temperature(dev, i, &temperature);
r = dev->driver->temperature(dev, handle, i, &temperature);
msg_info("Temperature %d: %5.2f C\n", i, convert_bytes_double(temperature));
}

/* fetch device powered time and device uptime */
r = dev->driver->psu_time.powered(dev, &time);
r = dev->driver->psu_time.powered(dev, handle, &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);
r = dev->driver->psu_time.uptime(dev, handle, &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);
r = dev->driver->power.supply_voltage(dev, handle, &supply_volts);
msg_info("Supply Voltage: %5.2f\n", convert_bytes_double(supply_volts));
r = dev->driver->power.total_wattage(dev, &supply_watts);
r = dev->driver->power.total_wattage(dev, handle, &supply_watts);
msg_info("Total Watts: %5.2f\n", convert_bytes_double(supply_watts));
msg_debug("DEBUG: supply done\n");

Expand All @@ -91,17 +91,17 @@ int psu_settings(struct corsair_device_scan scanned_device, struct option_parse_
if (i==2)
msg_info("Output 3.3v:\n");

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

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

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

r = dev->driver->deinit(handle, dev->write_endpoint);

Expand All @@ -126,15 +126,15 @@ int hydro_settings(struct corsair_device_scan scanned_device, struct option_pars
msg_debug("DEBUG: init done\n");

/* fetch device name, vendor name, product name */
r = dev->driver->vendor(dev, name);
r = dev->driver->vendor(dev, handle, name);
msg_info("Vendor: %s\n", name);
r = dev->driver->product(dev, name);
r = dev->driver->product(dev, handle, name);
msg_info("Product: %s\n", name);
r = dev->driver->fw_version(dev, name);
r = dev->driver->fw_version(dev, handle, name);
msg_info("Firmware: %s\n", name);

for (i=0; i<3; i++) {
r = dev->driver->temperature(dev, i, &temperature);
r = dev->driver->temperature(dev, handle, i, &temperature);
if (dev->driver == &corsairlink_driver_asetek) {
uint8_t v1 = (temperature>>8);
uint8_t v2 = (temperature&0xFF);
Expand All @@ -147,7 +147,7 @@ int hydro_settings(struct corsair_device_scan scanned_device, struct option_pars
}
}

r = dev->driver->led(dev, &settings.led_color, &settings.warning_led, settings.warning_led_temp, (settings.warning_led_temp > -1));
r = dev->driver->led(dev, handle, &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");
Expand Down
10 changes: 5 additions & 5 deletions main_psu.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ int main(int argc, char *argv[])
msg_debug("DEBUG: init done\n");

/* fetch device name, vendor name, product name */
r = dev->driver->name(dev, name);
r = dev->driver->name(dev, handle, name);
msg_info("Name: %s\n", name);
r = dev->driver->vendor(dev, name);
r = dev->driver->vendor(dev, handle, name);
msg_info("Vendor: %s\n", name);
r = dev->driver->product(dev, name);
r = dev->driver->product(dev, handle, 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);
r = dev->driver->psu_time.powered(dev, handle, &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);
r = dev->driver->psu_time.uptime(dev, handle, &time);
msg_info("Uptime: %u (%dd. %dh)\n",
time, time/(24*60*60), time/(60*60)%24);
msg_debug("DEBUG: time done\n");
Expand Down
19 changes: 12 additions & 7 deletions protocol/asetek4/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
* @param[out] device id
* @return 0
*/
int corsairlink_asetek_device_id(struct corsair_device_info *dev, uint8_t *device_id)
int corsairlink_asetek_device_id(struct corsair_device_info *dev,
struct libusb_device_handle *handle, uint8_t *device_id)
{
//memcpy(device_id, 0x00, 1);
(*device_id) = 0xFF;
Expand All @@ -48,7 +49,8 @@ int corsairlink_asetek_device_id(struct corsair_device_info *dev, uint8_t *devic
* @param[out] Device Name
* @return 0
*/
int corsairlink_asetek_name(struct corsair_device_info *dev, char *name)
int corsairlink_asetek_name(struct corsair_device_info *dev,
struct libusb_device_handle *handle, char *name)
{
sprintf(name, "%s", dev->name);
return 0;
Expand All @@ -60,7 +62,8 @@ int corsairlink_asetek_name(struct corsair_device_info *dev, char *name)
* @param[out] Vendor Name
* @return 0
*/
int corsairlink_asetek_vendor(struct corsair_device_info *dev, char *name)
int corsairlink_asetek_vendor(struct corsair_device_info *dev,
struct libusb_device_handle *handle, char *name)
{
sprintf(name, "Corsair");
return 0;
Expand All @@ -72,7 +75,8 @@ int corsairlink_asetek_vendor(struct corsair_device_info *dev, char *name)
* @param[out] Product Name
* @return 0
*/
int corsairlink_asetek_product(struct corsair_device_info *dev, char *name)
int corsairlink_asetek_product(struct corsair_device_info *dev,
struct libusb_device_handle *handle, char *name)
{
sprintf(name, "%s", dev->name);
return 0;
Expand All @@ -84,7 +88,8 @@ int corsairlink_asetek_product(struct corsair_device_info *dev, char *name)
* @param[out] string for firmware number
* @return 0
*/
int corsairlink_asetek_firmware_id(struct corsair_device_info *dev, char *firmware)
int corsairlink_asetek_firmware_id(struct corsair_device_info *dev,
struct libusb_device_handle *handle, char *firmware)
{
int r;
uint8_t response[32];
Expand Down Expand Up @@ -112,8 +117,8 @@ int corsairlink_asetek_firmware_id(struct corsair_device_info *dev, char *firmwa
commands[17] = 0x00;
commands[19] = 0x01;

r = dev->driver->write(dev->handle, dev->write_endpoint, commands, 19);
r = dev->driver->read(dev->handle, dev->read_endpoint, response, 32);
r = dev->driver->write(handle, dev->write_endpoint, commands, 19);
r = dev->driver->read(handle, dev->read_endpoint, response, 32);

sprintf(firmware, "%d.%d.%d.%d", response[0x17], response[0x18], response[0x19], response[0x1A]);

Expand Down
20 changes: 10 additions & 10 deletions protocol/asetek4/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ enum Asetek_PumpModes {
.s1 = 0x32, .s2 = 0x32, .s3 = 0x4b, .s4 = 0x55, .s5 = 0x5d, .s6 = 0x64,\
}

int corsairlink_asetek_device_id(struct corsair_device_info *dev, uint8_t *device_id);
int corsairlink_asetek_name(struct corsair_device_info *dev, char *n);
int corsairlink_asetek_vendor(struct corsair_device_info *dev, char *n);
int corsairlink_asetek_product(struct corsair_device_info *dev, char *n);
int corsairlink_asetek_firmware_id(struct corsair_device_info *dev, char *f);
int corsairlink_asetek_device_id(struct corsair_device_info *dev, struct libusb_device_handle *handle, uint8_t *device_id);
int corsairlink_asetek_name(struct corsair_device_info *dev, struct libusb_device_handle *handle, char *n);
int corsairlink_asetek_vendor(struct corsair_device_info *dev, struct libusb_device_handle *handle, char *n);
int corsairlink_asetek_product(struct corsair_device_info *dev, struct libusb_device_handle *handle, char *n);
int corsairlink_asetek_firmware_id(struct corsair_device_info *dev, struct libusb_device_handle *handle, char *f);

int corsairlink_asetek_change_led(struct corsair_device_info *dev,
int corsairlink_asetek_change_led(struct corsair_device_info *dev, struct libusb_device_handle *handle,
struct color *color_led, struct color *warning_led,
uint8_t Warning_Temp, uint8_t Warning_Enable);
int corsairlink_asetek_pump_mode(struct corsair_device_info *dev,
int corsairlink_asetek_pump_mode(struct corsair_device_info *dev, struct libusb_device_handle *handle,
uint8_t pump_mode);
int corsairlink_asetek_fan_mode(struct corsair_device_info *dev,
int corsairlink_asetek_fan_mode(struct corsair_device_info *dev, struct libusb_device_handle *handle,
uint8_t fan_mode);
int corsairlink_asetek_fan_curve(struct corsair_device_info *dev,
int corsairlink_asetek_fan_curve(struct corsair_device_info *dev, struct libusb_device_handle *handle,
struct fan_table *fan);

int corsairlink_asetek_temperature(struct corsair_device_info *dev,
int corsairlink_asetek_temperature(struct corsair_device_info *dev, struct libusb_device_handle *handle,
uint8_t selector, uint16_t *temperature);

#endif
10 changes: 5 additions & 5 deletions protocol/asetek4/fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "../../driver.h"
#include "core.h"

int corsairlink_asetek_fan_mode(struct corsair_device_info *dev,
int corsairlink_asetek_fan_mode(struct corsair_device_info *dev, struct libusb_device_handle *handle,
uint8_t fan_mode)
{
int r;
Expand All @@ -38,12 +38,12 @@ int corsairlink_asetek_fan_mode(struct corsair_device_info *dev,
else if (fan_mode == QUIET) {
ASETEK_FAN_TABLE_QUIET(curve);
}
r = dev->driver->fan.custom(dev, &curve);
r = dev->driver->fan.custom(dev, handle, &curve);

return r;
}

int corsairlink_asetek_fan_curve(struct corsair_device_info *dev,
int corsairlink_asetek_fan_curve(struct corsair_device_info *dev, struct libusb_device_handle *handle,
struct fan_table *fan)
{
int r;
Expand All @@ -69,8 +69,8 @@ int corsairlink_asetek_fan_curve(struct corsair_device_info *dev,
commands[12] = fan->s5;
commands[13] = fan->s6;

r = dev->driver->write(dev->handle, dev->write_endpoint, commands, 14);
r = dev->driver->read(dev->handle, dev->read_endpoint, response, 32);
r = dev->driver->write(handle, dev->write_endpoint, commands, 14);
r = dev->driver->read(handle, dev->read_endpoint, response, 32);

return r;
}
Loading

0 comments on commit e6f680e

Please sign in to comment.