This commit is contained in:
2026-07-01 01:50:02 +02:00
parent 86da8434bd
commit 29c14dc56f
11 changed files with 48 additions and 52 deletions

View File

@@ -5,11 +5,11 @@
#include <string.h>
#include <unistd.h>
static const uint16_t usb_timeout = 250;
static const uint8_t buf_size = 32; // needs 32 bc of overflow issue on these aios?
static constexpr uint16_t usb_timeout = 250;
static constexpr uint8_t buf_size = 32; // needs 32 bc of overflow issue on these aios?
static const uint16_t max_fan_speed = 1200;
static const uint8_t max_curve_points = 7;
static constexpr uint16_t max_fan_speed = 1200;
static constexpr uint8_t max_curve_points = 7;
// posts cmd to the aio, puts n bytes of response inside resp buffer
#define POST_AND_GET_RESP(cmd, n) uint8_t req = cmd; uint8_t resp[buf_size]; aio_post(dev, &req, 1, resp, n)
@@ -23,7 +23,7 @@ static void aio_usb_claim(libusb_device_handle* dev) {
applog(LOG_ERR, "failed to claim AIO device: %s", libusb_error_name(ret));
return;
}
ret = libusb_control_transfer(dev,(LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE),0x02,0x02,0, NULL, 0, usb_timeout);
ret = libusb_control_transfer(dev,(LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE),0x02,0x02,0, nullptr, 0, usb_timeout);
if (ret < 0)
applog(LOG_ERR, "AIO clear-to-send failed: %s", libusb_error_name(ret));
}
@@ -33,8 +33,8 @@ static void aio_usb_release(libusb_device_handle* dev) {
}
static void aio_post(libusb_device_handle *dev, uint8_t *req, const int req_len, uint8_t *resp, const int resp_len) {
libusb_bulk_transfer(dev, 0x01, req, req_len, NULL, usb_timeout);
libusb_bulk_transfer(dev, 0x81, resp, resp_len, NULL, usb_timeout);
libusb_bulk_transfer(dev, 0x01, req, req_len, nullptr, usb_timeout);
libusb_bulk_transfer(dev, 0x81, resp, resp_len, nullptr, usb_timeout);
}
static float aio_get_water_temp(libusb_device_handle* dev) {
@@ -73,7 +73,7 @@ static void aio_set_color(libusb_device_handle* dev, const enum aio_color_mode_t
if (colors == NULL) // NOLINT no its not
return;
const uint8_t modes[] = {0x52, 0x55, 0x55, 0x58};
constexpr uint8_t modes[] = {0x52, 0x55, 0x55, 0x58};
uint8_t req[buf_size], resp[buf_size];
req[0] = 0x56;
@@ -89,8 +89,8 @@ static void aio_set_color(libusb_device_handle* dev, const enum aio_color_mode_t
// send speed, skip if fixed color
if (mode != AIO_COLOR_FIXED) {
const uint8_t speed_shift[] = {0x46, 0x28, 0x0F};
const uint8_t speed_pulse[] = {0x50, 0x37, 0x1E};
constexpr uint8_t speed_shift[] = {0x46, 0x28, 0x0F};
constexpr uint8_t speed_pulse[] = {0x50, 0x37, 0x1E};
req[0] = 0x53;
req[1] = mode == AIO_COLOR_SHIFT ? speed_shift[speed] : speed_pulse[speed];
aio_post(dev, req, 2, resp, buf_size);
@@ -130,8 +130,8 @@ static void aio_set_fan_curve(libusb_device_handle* dev, const struct curve_poin
}
void aio_detect(struct aio_t *aio, const float t_quiet, const float t_balanced) {
libusb_init(NULL);
aio->handle = libusb_open_device_with_vid_pid(NULL, AIO_USB_VID, AIO_USB_PID);
libusb_init(nullptr);
aio->handle = libusb_open_device_with_vid_pid(nullptr, AIO_USB_VID, AIO_USB_PID);
if (aio->handle == NULL) {
applog(LOG_ERR, "Can't open AIO USB device %x:%x", AIO_USB_VID, AIO_USB_PID);
return;
@@ -154,7 +154,7 @@ void aio_detect(struct aio_t *aio, const float t_quiet, const float t_balanced)
aio_usb_claim(aio->handle);
applog(LOG_INF, "found Corsair AIO device at %04x:%04x, fw ver: %s", AIO_USB_VID, AIO_USB_PID, aio_get_firmware_version(aio->handle, (char[16]){0}));
aio_set_pump_mode(aio->handle, QUIET); // needed for init ig?
aio_set_color(aio->handle, AIO_COLOR_FIXED, 0, NULL, 0); // so it doenst complain the func is unused
aio_set_color(aio->handle, AIO_COLOR_FIXED, 0, nullptr, 0); // so it doenst complain the func is unused
aio_set_fan_curve(aio->handle, fan_curve, sizeof(fan_curve) / sizeof(fan_curve[0]));
aio_usb_release(aio->handle);
}
@@ -182,6 +182,6 @@ void aio_update(struct aio_t *aio) {
void aio_close(const struct aio_t *aio) {
libusb_attach_kernel_driver(aio->handle, 0); // reattach so liquidctl still works
libusb_close(aio->handle);
libusb_exit(NULL);
libusb_exit(nullptr);
applog(LOG_INF, "AIO device closed");
}