From da8aec78a804faaac99b7c924a7b9954601554c6 Mon Sep 17 00:00:00 2001 From: Drath Date: Mon, 25 May 2026 15:28:26 +0000 Subject: [PATCH] add more feature creep (set colors) --- include/aio.h | 17 +++++++++++++++++ src/aio.c | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/include/aio.h b/include/aio.h index d3b39b8..603de61 100644 --- a/include/aio.h +++ b/include/aio.h @@ -6,12 +6,29 @@ #define AIO_USB_VID 0x1b1c #define AIO_USB_PID 0x0c13 +#define AIO_COLOR_CYAN { 0, 255, 255 } +#define AIO_COLOR_WHITE { 0, 255, 255 } +#define AIO_COLOR_OFF { 0, 0, 0 } + enum aio_pump_mode_t : uint8_t { QUIET, BALANCED, EXTREME }; +enum aio_color_mode_t : uint8_t { + AIO_COLOR_PULSE, + AIO_COLOR_SHIFT, + AIO_COLOR_FIXED, + AIO_COLOR_BLINKING +}; + +struct rgb_t { + uint8_t r; + uint8_t g; + uint8_t b; +}; + struct aio_t{ libusb_device_handle* handle; enum aio_pump_mode_t pump_mode; diff --git a/src/aio.c b/src/aio.c index eebb05c..dbacf39 100644 --- a/src/aio.c +++ b/src/aio.c @@ -2,6 +2,7 @@ #include "log.h" #include +#include #include static const uint16_t usb_timeout = 1000; @@ -65,6 +66,36 @@ static void aio_set_pump_mode(libusb_device_handle* dev, const enum aio_pump_mod POST_AND_GET_RESP2(0x32, mode, 6); } +static void aio_set_color(libusb_device_handle* dev, const enum aio_color_mode_t mode, const uint8_t speed, const struct rgb_t* colors, const uint8_t color_count) { + const uint8_t modes[] = {0x52, 0x55, 0x55, 0x58}; + uint8_t req[buf_size], resp[buf_size]; + + req[0] = 0x56; + req[1] = color_count; + + // sort out and send color table + memcpy(&req[2], colors, color_count * 3); + if (color_count < 2 || mode == AIO_COLOR_FIXED) { + memcpy(&req[5], colors, 3); // copy the same color to the 2nd pos in the table + req[1] = 2; + } + aio_post(dev, req, 2 + req[1] * 3, resp, buf_size); + + // 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}; + req[0] = 0x53; + req[1] = mode == AIO_COLOR_SHIFT ? speed_shift[speed] : speed_pulse[speed]; + aio_post(dev, req, 2, resp, buf_size); + } + + // actually set the aio to desired mode + req[0] = modes[mode]; + req[1] = 0x01; + aio_post(dev, req, 2, resp, buf_size); +} + 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); @@ -97,11 +128,15 @@ void aio_update(struct aio_t *aio) { aio->pump_mode = aio_get_pump_mode(aio->handle); aio_get_fan_speed(aio->handle, aio->fan_speed); - if (aio->water_temp > aio->t_b && aio->pump_mode != BALANCED) + if (aio->water_temp > aio->t_b && aio->pump_mode != BALANCED) { aio_set_pump_mode(aio->handle, BALANCED); + aio_set_color(aio->handle, AIO_COLOR_FIXED, 0, &(struct rgb_t)AIO_COLOR_WHITE, 1); + } - if (aio->water_temp < aio->t_q && aio->pump_mode != QUIET) + if (aio->water_temp < aio->t_q && aio->pump_mode != QUIET) { aio_set_pump_mode(aio->handle, QUIET); + aio_set_color(aio->handle, AIO_COLOR_FIXED, 0, &(struct rgb_t)AIO_COLOR_CYAN, 1); + } aio_usb_release(aio->handle); }