Fixes for the XPGSummoner keyboard controller

This commit is contained in:
Erick Granados
2025-08-26 17:23:25 +00:00
committed by Adam Honse
parent 9ad0fa26bf
commit d5f9411ecb
4 changed files with 241 additions and 278 deletions

View File

@@ -28,6 +28,17 @@ XPGSummonerController::~XPGSummonerController()
hid_close(dev);
}
void XPGSummonerController::SendInitialize()
{
unsigned char init_buf[265] =
{
0x07, 0xEA, 0x00, 0x00,
};
memset(init_buf + 4, 0x00, 261);
hid_write(dev, init_buf, 265);
std::this_thread::sleep_for(std::chrono::milliseconds(2));
}
std::string XPGSummonerController::GetLocationString()
{
return("HID: " + location);
@@ -62,58 +73,16 @@ void XPGSummonerController::SendColors(unsigned char *color_data, unsigned int c
const int bytes_per_led = 4;
const int total_bytes = leds_count * bytes_per_led;
const int block_size = 256;
SendInitialize();
SendInitializeColorPacket();
int zones = (total_bytes + block_size - 1) / block_size;
int zones = 2;
for(int zone = 0; zone < zones; zone++)
{
int offset = zone * block_size;
int remaining = total_bytes - offset;
int offset = zone * block_size;
int remaining = total_bytes - offset;
color_data_size = (remaining > block_size) ? block_size : remaining;
SendColorDataPacket(zone, &color_data[offset], color_data_size);
}
SendTerminateColorPacket();
}
void XPGSummonerController::SendInitialize()
{
unsigned char usb_buf[65];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up Initialize Direct Mode packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = 0x41;
usb_buf[0x02] = 0x01;
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev, usb_buf, 65);
std::this_thread::sleep_for(std::chrono::milliseconds(2));
}
void XPGSummonerController::SendInitializeColorPacket()
{
unsigned char packet[265] = {0};
packet[0] = 0x07;
packet[1] = 0xA3;
packet[2] = 0x08;
packet[3] = 0x00;
packet[4] = 0;
packet[5] = 0x00;
hid_write(dev, packet, 265);
std::this_thread::sleep_for(std::chrono::milliseconds(2));
}
unsigned int XPGSummonerController::SendColorDataPacket(
@@ -140,24 +109,17 @@ unsigned int XPGSummonerController::SendColorDataPacket(
void XPGSummonerController::SendTerminateColorPacket()
{
unsigned char usb_buf[65];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up Terminate Color packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = 0x51;
usb_buf[0x02] = 0x28;
usb_buf[0x05] = 0xFF;
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev, usb_buf, 65);
/*-------------------------------*\
| Set up Terminate Color packet |
| This packet is used to stop |
| any active color effects on the |
| keyboard. |
\*-------------------------------*/
unsigned char terminate_buf[265] =
{
0x07, 0xEA, 0x00, 0x00,
};
memset(terminate_buf + 4, 0x00, 261);
hid_write(dev, terminate_buf, 265);
std::this_thread::sleep_for(std::chrono::milliseconds(2));
}
}