Create "Direct" Mode for ASRock Polychrome USB device.

This commit is contained in:
Shaun McThomas 2022-08-09 23:59:04 +00:00 committed by Adam Honse
parent 6292ee1664
commit 8b02484456
3 changed files with 53 additions and 2 deletions

View file

@ -165,6 +165,37 @@ void PolychromeUSBController::WriteZone
hid_read(dev, usb_buf, 64);
};
void PolychromeUSBController::WriteAllZones (
const std::vector<PolychromeZoneInfo> &zones_info,
const std::vector<zone> &zones
){
unsigned char usb_buf[65];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up message packet with leading 00 |
\*-----------------------------------------------------*/
usb_buf[0x01] = POLYCHROME_USB_SET_ZONE;
usb_buf[0x03] = 0x07;
usb_buf[0x04] = zones_info[0].mode;
usb_buf[0x04] = 0xE2;
for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
{
usb_buf[0x05 + (3 * zone_idx)] = RGBGetRValue(zones[zone_idx].colors[0]);
usb_buf[0x05 + (3 * zone_idx) + 1] = RGBGetGValue(zones[zone_idx].colors[0]);
usb_buf[0x05 + (3 * zone_idx) + 2] = RGBGetBValue(zones[zone_idx].colors[0]);
}
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev, usb_buf, 65);
hid_read(dev, usb_buf, 64);
}
void PolychromeUSBController::WriteRGSwap
(
bool ahdr1,
@ -262,7 +293,7 @@ PolychromeZoneInfo PolychromeUSBController::GetZoneConfig(unsigned char zone)
g = usb_buf[0x06];
b = usb_buf[0x07];
zoneinfo.mode = usb_buf[0x04];
zoneinfo.mode = usb_buf[0x04] != 0xE2 ? usb_buf[0x04] : 0x0F;
zoneinfo.color = ToRGBColor(r,g,b);
zoneinfo.speed = usb_buf[0x08];
zoneinfo.zone = usb_buf[0x03];

View file

@ -16,7 +16,7 @@
/*----------------------------------------------------------------------------------------------*\
| Definitions for Polychrome USB |
\*----------------------------------------------------------------------------------------------*/
#define POLYCHROME_USB_NUM_MODES 15 /* Number of Polychrome USB modes */
#define POLYCHROME_USB_NUM_MODES 16 /* Number of Polychrome USB modes */
enum
{
@ -35,6 +35,7 @@ enum
POLYCHROME_USB_MODE_NEON = 0x0C, /* Neon effect mode */
POLYCHROME_USB_MODE_WATER = 0x0D, /* Water effect mode */
POLYCHROME_USB_MODE_RAINBOW = 0x0E, /* Rainbow effect mode */
POLYCHROME_USB_MODE_DIRECT = 0x0F, /* CHROMA CONNECT effect mode */
};
enum
@ -127,6 +128,13 @@ public:
bool allzone
);
void WriteAllZones
(
const std::vector<PolychromeZoneInfo> &zones_info,
const std::vector<zone> &zones
);
void WriteHeader
(
unsigned char cfg,

View file

@ -173,6 +173,13 @@ RGBController_PolychromeUSB::RGBController_PolychromeUSB(PolychromeUSBController
Rainbow.color_mode = MODE_COLORS_NONE;
modes.push_back(Rainbow);
mode Direct;
Direct.name = "Direct";
Direct.value = POLYCHROME_USB_MODE_DIRECT;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Direct.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Direct);
SetupZones();
/*-------------------------------------------------*\
@ -276,6 +283,11 @@ void RGBController_PolychromeUSB::ResizeZone(int zone, int new_size)
void RGBController_PolychromeUSB::DeviceUpdateLEDs()
{
if(POLYCHROME_USB_MODE_DIRECT == zones_info[0].mode )
{
controller->WriteAllZones(zones_info,zones);
return;
}
for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
{
unsigned char set_mode = zones_info[zone_idx].mode;