mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2025-12-26 16:57:51 -05:00
292 lines
7.5 KiB
C++
292 lines
7.5 KiB
C++
/*-----------------------------------------*\
|
|
| RGBController_HyperXAlloyFPS.cpp |
|
|
| |
|
|
| Generic RGB Interface for HyperX Alloy |
|
|
| FPS Keyboard |
|
|
| |
|
|
| Adam Honse (CalcProgrammer1) 2/2/2020 |
|
|
\*-----------------------------------------*/
|
|
|
|
#include "RGBController_HyperXAlloyFPS.h"
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
//0xFFFFFFFF indicates an unused entry in matrix
|
|
#define NA 0xFFFFFFFF
|
|
|
|
static unsigned int matrix_map[6][23] =
|
|
{ { 0, NA, 16, 30, 44, 54, NA, 65, 75, 84, 95, NA, 8, 23 , 38, 6 , 22, 36, 49, NA, NA, NA, NA },
|
|
{ 1, 17, 31, 45, 55, 66, 76, 85, 96, 9, 24, NA, 39, 7 , 37, NA , 60, 70, 80, 52, 63, 73, 82 },
|
|
{ 2, NA, 18, 32, 46, 56, NA, 67, 77, 86, 97, 10, 25, 40 , 90, 101, 50, 61, 71, 51, 62, 72, 93 },
|
|
{ 3, NA, 19, 33, 47, 57, NA, 68, 78, 87, 98, 11, 26, 41 , 28, 14 , NA, NA, NA, 92, 103, 53, NA },
|
|
{ 4, 20, 34, 48, 58, 69, NA, 79, NA, 88, 99, 12, 27, 42 , 81, NA , NA, 102, NA, 64, 74, 83, 104 },
|
|
{ 5, 21, 35, NA, NA, NA, NA, 59, NA, NA, NA, NA, 89, 100, 13, 91 , 15, 29, 43, 94, NA, 105, NA } };
|
|
|
|
static const char* zone_names[] =
|
|
{
|
|
"Keyboard"
|
|
};
|
|
|
|
static zone_type zone_types[] =
|
|
{
|
|
ZONE_TYPE_MATRIX
|
|
};
|
|
|
|
static const unsigned int zone_sizes[] =
|
|
{
|
|
106
|
|
};
|
|
|
|
static const char *led_names[] =
|
|
{
|
|
"Key: Escape",
|
|
"Key: `",
|
|
"Key: Tab",
|
|
"Key: Caps Lock",
|
|
"Key: Left Shift",
|
|
"Key: Left Control",
|
|
"Key: F12",
|
|
"Key: =",
|
|
"Key: F9",
|
|
"Key: 9",
|
|
"Key: O",
|
|
"Key: L",
|
|
"Key: ,",
|
|
"Key: Menu",
|
|
"Key: Enter (ISO)",
|
|
"Key: Left Arrow",
|
|
"Key: F1",
|
|
"Key: 1",
|
|
"Key: Q",
|
|
"Key: A",
|
|
"Key: \\ (ISO)",
|
|
"Key: Left Windows",
|
|
"Key: Print Screen",
|
|
"Key: F10",
|
|
"Key: 0",
|
|
"Key: P",
|
|
"Key: ;",
|
|
"Key: .",
|
|
"Key: Enter",
|
|
"Key: Down Arrow",
|
|
"Key: F2",
|
|
"Key: 2",
|
|
"Key: W",
|
|
"Key: S",
|
|
"Key: Z",
|
|
"Key: Left Alt",
|
|
"Key: Scroll Lock",
|
|
"Key: Backspace",
|
|
"Key: F11",
|
|
"Key: -",
|
|
"Key: [",
|
|
"Key: '",
|
|
"Key: /",
|
|
"Key: Right Arrow",
|
|
"Key: F3",
|
|
"Key: 3",
|
|
"Key: E",
|
|
"Key: D",
|
|
"Key: X",
|
|
"Key: Pause/Break",
|
|
"Key: Delete",
|
|
"Key: Number Pad 7",
|
|
"Key: Num Lock",
|
|
"Key: Number Pad 6",
|
|
"Key: F4",
|
|
"Key: 4",
|
|
"Key: R",
|
|
"Key: F",
|
|
"Key: C",
|
|
"Key: Space",
|
|
"Key: Insert",
|
|
"Key: End",
|
|
"Key: Number Pad 8",
|
|
"Key: Number Pad /",
|
|
"Key: Number Pad 1",
|
|
"Key: F5",
|
|
"Key: 5",
|
|
"Key: T",
|
|
"Key: G",
|
|
"Key: V",
|
|
"Key: Home",
|
|
"Key: Page Down",
|
|
"Key: Number Pad 9",
|
|
"Key: Number Pad *",
|
|
"Key: Number Pad 2",
|
|
"Key: F6",
|
|
"Key: 6",
|
|
"Key: Y",
|
|
"Key: H",
|
|
"Key: B",
|
|
"Key: Page Up",
|
|
"Key: Right Shift",
|
|
"Key: Number Pad -",
|
|
"Key: Number Pad 3",
|
|
"Key: F7",
|
|
"Key: 7",
|
|
"Key: U",
|
|
"Key: J",
|
|
"Key: N",
|
|
"Key: Right Alt",
|
|
"Key: ]",
|
|
"Key: Right Control",
|
|
"Key: Number Pad 4",
|
|
"Key: Number Pad +",
|
|
"Key: Number Pad 0",
|
|
"Key: F8",
|
|
"Key: 8",
|
|
"Key: I",
|
|
"Key: K",
|
|
"Key: M",
|
|
"Key: Right Windows",
|
|
"Key: \\ (ANSI)",
|
|
"Key: Up Arrow",
|
|
"Key: Number Pad 5",
|
|
"Key: Number Pad Enter",
|
|
"Key: Number Pad ."
|
|
};
|
|
|
|
RGBController_HyperXAlloyFPS::RGBController_HyperXAlloyFPS(HyperXAlloyFPSController* hyperx_ptr)
|
|
{
|
|
controller = hyperx_ptr;
|
|
|
|
name = "HyperX Alloy FPS";
|
|
vendor = "HyperX";
|
|
type = DEVICE_TYPE_KEYBOARD;
|
|
description = "HyperX Alloy FPS Device";
|
|
location = controller->GetDeviceLocation();
|
|
serial = controller->GetSerialString();
|
|
|
|
mode Direct;
|
|
Direct.name = "Direct";
|
|
Direct.value = 0;
|
|
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
|
|
Direct.color_mode = MODE_COLORS_PER_LED;
|
|
modes.push_back(Direct);
|
|
|
|
SetupZones();
|
|
|
|
/*-----------------------------------------------------*\
|
|
| The HyperX Alloy FPS requires a steady stream of |
|
|
| packets in order to not revert out of direct mode. |
|
|
| Start a thread to continuously refresh the device |
|
|
\*-----------------------------------------------------*/
|
|
keepalive_thread_run = true;
|
|
keepalive_thread = new std::thread(&RGBController_HyperXAlloyFPS::KeepaliveThreadFunction, this);
|
|
}
|
|
|
|
RGBController_HyperXAlloyFPS::~RGBController_HyperXAlloyFPS()
|
|
{
|
|
keepalive_thread_run = false;
|
|
keepalive_thread->join();
|
|
delete keepalive_thread;
|
|
|
|
/*---------------------------------------------------------*\
|
|
| Delete the matrix map |
|
|
\*---------------------------------------------------------*/
|
|
for(unsigned int zone_index = 0; zone_index < zones.size(); zone_index++)
|
|
{
|
|
if(zones[zone_index].matrix_map != NULL)
|
|
{
|
|
delete zones[zone_index].matrix_map;
|
|
}
|
|
}
|
|
|
|
delete controller;
|
|
}
|
|
|
|
void RGBController_HyperXAlloyFPS::SetupZones()
|
|
{
|
|
/*---------------------------------------------------------*\
|
|
| Set up zones |
|
|
\*---------------------------------------------------------*/
|
|
unsigned int total_led_count = 0;
|
|
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];
|
|
|
|
if(zone_types[zone_idx] == ZONE_TYPE_MATRIX)
|
|
{
|
|
new_zone.matrix_map = new matrix_map_type;
|
|
new_zone.matrix_map->height = 6;
|
|
new_zone.matrix_map->width = 23;
|
|
new_zone.matrix_map->map = (unsigned int *)&matrix_map;
|
|
}
|
|
else
|
|
{
|
|
new_zone.matrix_map = NULL;
|
|
}
|
|
|
|
zones.push_back(new_zone);
|
|
|
|
total_led_count += zone_sizes[zone_idx];
|
|
}
|
|
|
|
for(unsigned int led_idx = 0; led_idx < total_led_count; led_idx++)
|
|
{
|
|
led new_led;
|
|
new_led.name = led_names[led_idx];
|
|
leds.push_back(new_led);
|
|
}
|
|
|
|
SetupColors();
|
|
}
|
|
|
|
void RGBController_HyperXAlloyFPS::ResizeZone(int /*zone*/, int /*new_size*/)
|
|
{
|
|
/*---------------------------------------------------------*\
|
|
| This device does not support resizing zones |
|
|
\*---------------------------------------------------------*/
|
|
}
|
|
|
|
void RGBController_HyperXAlloyFPS::DeviceUpdateLEDs()
|
|
{
|
|
last_update_time = std::chrono::steady_clock::now();
|
|
|
|
if(active_mode == 0)
|
|
{
|
|
controller->SetLEDsDirect(colors);
|
|
}
|
|
}
|
|
|
|
void RGBController_HyperXAlloyFPS::UpdateZoneLEDs(int /*zone*/)
|
|
{
|
|
DeviceUpdateLEDs();
|
|
}
|
|
|
|
void RGBController_HyperXAlloyFPS::UpdateSingleLED(int /*led*/)
|
|
{
|
|
DeviceUpdateLEDs();
|
|
}
|
|
|
|
void RGBController_HyperXAlloyFPS::SetCustomMode()
|
|
{
|
|
active_mode = 0;
|
|
}
|
|
|
|
void RGBController_HyperXAlloyFPS::DeviceUpdateMode()
|
|
{
|
|
|
|
}
|
|
|
|
void RGBController_HyperXAlloyFPS::KeepaliveThreadFunction()
|
|
{
|
|
while(keepalive_thread_run)
|
|
{
|
|
if(active_mode == 0)
|
|
{
|
|
if((std::chrono::steady_clock::now() - last_update_time) > std::chrono::milliseconds(50))
|
|
{
|
|
UpdateLEDs();
|
|
}
|
|
}
|
|
std::this_thread::sleep_for(10ms);;
|
|
}
|
|
}
|