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

@ -20,51 +20,51 @@
| ordered_matrix: Physical LED layout |
\*---------------------------------------------------------*/
static unsigned int ordered_matrix[6][21] =
{
{
{0, NA, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, NA, NA, NA, NA},
{16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36},
{37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57},
{58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, NA, 70, NA, NA, NA, 71, 72, 73, NA},
{74, NA, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, NA, NA, 86, NA, 87, 88, 89, 90},
{91, 92, 93, NA, NA, NA, 94, NA, NA, NA, 95, 96, 97, 98, 99, 100, 101, 102, NA, 103, NA}
};
};
/*---------------------------------------------------------*\
| matrix_map: Logical LED mapping |
\*---------------------------------------------------------*/
static unsigned int matrix_map[6][21] =
{
{
{11, NA, 22, 30, 25, 27, 7, 51, 57, 62, 86, 87, 83, 85, 79, 72, 0, NA, NA, NA, NA},
{14, 15, 23, 31, 39, 38, 46, 47, 55, 63, 71, 70, 54, 81, 102, 118, 110, 92, 100, 108, 109},
{9, 8, 16, 24, 32, 33, 41, 40, 48, 56, 64, 65, 49, 82, 94, 119, 111, 88, 96, 104, 112},
{17, 10, 18, 26, 34, 35, 43, 42, 50, 58, 66, 67, NA, 84, NA, NA, NA, 89, 97, 105, NA},
{121, NA, 12, 20, 28, 36, 37, 45, 44, 52, 60, 69, 122, NA, NA, 115, NA, 90, 98, 106, 114},
{6, 124, 75, NA, NA, NA, 91, NA, NA, NA, 77, 125, 61, 4, 117, 93, 101, 99, NA, 107, NA}
};
};
/*---------------------------------------------------------*\
| zone_names: Zone names |
\*---------------------------------------------------------*/
const char *zone_names[] =
{
ZONE_EN_KEYBOARD,
};
{
ZONE_EN_KEYBOARD
};
zone_type zone_types[] =
{
{
ZONE_TYPE_MATRIX
};
};
const unsigned int zone_sizes[] =
{
LED_COUNT,
};
{
LED_COUNT
};
/*---------------------------------------------------------*\
| led_names: LED names |
\*---------------------------------------------------------*/
static const char *led_names[] =
{
{
KEY_EN_ESCAPE, // Esc
KEY_EN_F1, // F1
KEY_EN_F2, // F2
@ -115,7 +115,7 @@ static const char *led_names[] =
KEY_EN_P, // P
KEY_EN_LEFT_BRACKET, // [
KEY_EN_RIGHT_BRACKET, // ]
KEY_EN_ANSI_BACK_SLASH, //
KEY_EN_ANSI_BACK_SLASH, // Backslash
KEY_EN_DELETE, // Del
KEY_EN_END, // End
KEY_EN_PAGE_DOWN, // PgDn
@ -159,7 +159,7 @@ static const char *led_names[] =
KEY_EN_LEFT_CONTROL, // Ctrl
KEY_EN_LEFT_WINDOWS, // Win
KEY_EN_LEFT_ALT, // Alt
KEY_EN_SPACE, // Espacio
KEY_EN_SPACE, // Space
KEY_EN_RIGHT_ALT, // AltGr
KEY_EN_RIGHT_FUNCTION, // Fn
KEY_EN_MENU, // Menu
@ -169,13 +169,13 @@ static const char *led_names[] =
KEY_EN_RIGHT_ARROW, // →
KEY_EN_NUMPAD_0, // 0
KEY_EN_NUMPAD_PERIOD // .
};
};
/**------------------------------------------------------------------*\
@name XPG Summoner Keyboard
@category Keyboard
@type USB
@save :white_check_mark:
@save :x:
@direct :white_check_mark:
@effects :white_check_mark:
@detectors DetectXPGSummonerControllers
@ -198,24 +198,26 @@ RGBController_XPGSummoner::RGBController_XPGSummoner(XPGSummonerController *cont
mode Direct;
Direct.name = "Direct";
Direct.value = XPG_SUMMONER_MODE_DIRECT;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Direct.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Direct);
mode Static;
Static.name = "Static";
Static.value = XPG_SUMMONER_MODE_STATIC;
Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_MANUAL_SAVE;
Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS;
Static.color_mode = MODE_COLORS_MODE_SPECIFIC;
Static.colors_min = 1;
Static.colors_max = 1;
Static.color_mode = MODE_COLORS_MODE_SPECIFIC;
Static.brightness_min = 5;
Static.brightness_max = 64;
Static.colors.resize(1);
modes.push_back(Static);
mode Stars;
Stars.name = "Stars";
Stars.value = XPG_SUMMONER_MODE_STARS;
Stars.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_MANUAL_SAVE;
Stars.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
Stars.colors_min = 1;
Stars.colors_max = 1;
Stars.color_mode = MODE_COLORS_MODE_SPECIFIC;
@ -254,19 +256,19 @@ void RGBController_XPGSummoner::SetupZones()
{
leds.clear();
colors.clear();
unsigned int total_led_count = 0;
zones.clear();
for(unsigned int zone_idx = 0; zone_idx < 1; zone_idx++)
{
zone new_zone;
new_zone.name = zone_names[zone_idx];
new_zone.type = zone_types[zone_idx];
new_zone.leds_min = zone_sizes[zone_idx];
new_zone.leds_max = zone_sizes[zone_idx];
new_zone.leds_count= zone_sizes[zone_idx];
leds.reserve(LED_COUNT);
colors.reserve(LED_COUNT);
zones.reserve(1);
if(zone_types[zone_idx] == ZONE_TYPE_MATRIX)
zone new_zone;
new_zone.name = zone_names[0];
new_zone.type = zone_types[0];
new_zone.leds_min = zone_sizes[0];
new_zone.leds_max = zone_sizes[0];
new_zone.leds_count = zone_sizes[0];
if(new_zone.type == ZONE_TYPE_MATRIX)
{
new_zone.matrix_map = new matrix_map_type;
new_zone.matrix_map->height = 6;
@ -277,33 +279,24 @@ void RGBController_XPGSummoner::SetupZones()
{
new_zone.matrix_map = NULL;
}
zones.push_back(new_zone);
total_led_count += zone_sizes[zone_idx];
}
int rows = 6;
int cols = 21;
size_t linear_idx = 0;
for(int row = 0; row < rows; ++row)
for(int row = 0; row < 6; ++row)
{
for(int col = 0; col < cols; ++col)
for(int col = 0; col < 21; ++col)
{
unsigned int led_id = matrix_map[row][col];
if(led_id == NA)
{
continue;
}
led new_led;
new_led.name = led_names[linear_idx];
new_led.value = led_id;
leds.push_back(new_led);
colors.push_back(0x000000);
++linear_idx;
}
}
colors.assign(LED_COUNT, 0x000000);
SetupColors();
}
@ -321,7 +314,7 @@ void RGBController_XPGSummoner::ResizeZone(int /*zone*/, int /*new_size*/)
\*---------------------------------------------------------*/
void RGBController_XPGSummoner::DeviceUpdateLEDs()
{
const unsigned char brightness = 72;
const unsigned char brightness = 0x64;
const unsigned int frame_buf_length = 126 * 4;
unsigned char frame_buf[frame_buf_length] = {0};
@ -340,14 +333,13 @@ void RGBController_XPGSummoner::DeviceUpdateLEDs()
else if(modes[active_mode].color_mode == MODE_COLORS_MODE_SPECIFIC && modes[active_mode].value == XPG_SUMMONER_MODE_STATIC)
{
std::size_t real_idx = leds[led_idx].value;
frame_buf[(real_idx * 4) + 0] = brightness;
frame_buf[(real_idx * 4) + 0] = modes[active_mode].brightness;
frame_buf[(real_idx * 4) + 1] = RGBGetRValue(modes[active_mode].colors[0]);
frame_buf[(real_idx * 4) + 2] = RGBGetGValue(modes[active_mode].colors[0]);
frame_buf[(real_idx * 4) + 3] = RGBGetBValue(modes[active_mode].colors[0]);
}
else if(modes[active_mode].color_mode == MODE_COLORS_MODE_SPECIFIC && modes[active_mode].value == XPG_SUMMONER_MODE_STARS)
{
// Turn off all LEDs
for(std::size_t i = 0; i < leds.size(); ++i)
{
std::size_t real_idx = leds[i].value;
@ -358,7 +350,9 @@ void RGBController_XPGSummoner::DeviceUpdateLEDs()
}
controller->SendColors(frame_buf, sizeof(frame_buf));
// Select a random central LED in the physical matrix
/*---------------------------------------------------*\
| Select a random central LED in the physical matrix |
\*---------------------------------------------------*/
int rows = 6;
int cols = 21;
int center_row = rand() % rows;
@ -373,9 +367,12 @@ void RGBController_XPGSummoner::DeviceUpdateLEDs()
frame_buf[(center_led * 4) + 3] = RGBGetBValue(modes[active_mode].colors[0]);
}
// Neighbors (fade effect)
unsigned char fade_brightness = 36;
/*---------------------------------------------------*\
| Neighbors (fade effect) |
\*---------------------------------------------------*/
unsigned char fade_brightness = 0x32;
int neighbor_offsets[4][2] = { {0, -1}, {0, +1}, {-1, 0}, {+1, 0} };
for(int k = 0; k < 4; ++k)
{
int n_row = center_row + neighbor_offsets[k][0];
@ -430,3 +427,4 @@ void RGBController_XPGSummoner::DeviceUpdateMode()
{
DeviceUpdateLEDs();
}

View file

@ -21,9 +21,7 @@ public:
~RGBController_XPGSummoner();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
@ -31,5 +29,4 @@ public:
private:
XPGSummonerController* controller;
};

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,11 +73,7 @@ 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++)
{
@ -76,44 +83,6 @@ void XPGSummonerController::SendColors(unsigned char *color_data, unsigned int c
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);
| 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));
}

View file

@ -30,7 +30,7 @@ enum
XPG_SUMMONER_MODE_OFF = 0x00,
XPG_SUMMONER_MODE_DIRECT = 0x01,
XPG_SUMMONER_MODE_STATIC = 0x02,
XPG_SUMMONER_MODE_STARS = 0x03,
XPG_SUMMONER_MODE_STARS = 0x03
};
class XPGSummonerController
@ -44,17 +44,23 @@ public:
std::string GetSerialString();
unsigned short GetUSBPID();
void SendColors(
void SendColors
(
unsigned char *color_data,
unsigned int color_data_size);
void SendInitialize();
void SendInitializeColorPacket();
unsigned int SendColorDataPacket(
unsigned int color_data_size
);
unsigned int SendColorDataPacket
(
unsigned char packet_id,
unsigned char *color_data,
unsigned int color_size);
unsigned int color_size
);
void SendTerminateColorPacket();
void SendInitialize();
private:
hid_device *dev;
std::string location;