add more feature creep (set colors)

This commit is contained in:
2026-05-25 15:28:26 +00:00
parent 920600b294
commit da8aec78a8
2 changed files with 54 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
#include "log.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
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);
}