Organize most controller files into subfolders

This commit is contained in:
Adam Honse
2024-04-30 17:18:39 -05:00
parent ba57bad361
commit d52ad02c5c
415 changed files with 44 additions and 43 deletions

View File

@@ -0,0 +1,131 @@
/*-----------------------------------------*\
| HyperXAlloyFPSController.cpp |
| |
| Driver for HyperX Alloy FPS Keyboard |
| lighting controller |
| |
| Adam Honse (CalcProgrammer1) 1/30/2020 |
\*-----------------------------------------*/
#include "HyperXAlloyFPSController.h"
#include <cstring>
using namespace std::chrono_literals;
static unsigned int keys[] = {0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14,
0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x20, 0x21, 0x22,
0x23, 0x24, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30,
0x31, 0x32, 0x33, 0x34, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3E, 0x3F, 0x41,
0x44, 0x45, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x51, 0x54, 0x55,
0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5E, 0x5F, 0x61, 0x64, 0x65, 0x68, 0x69, 0x6A,
0x6B, 0x6C, 0x6E, 0x6F, 0x74, 0x75, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E,
0x7F, 0x81, 0x84, 0x85, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x91,
0x94, 0x95 };
HyperXAlloyFPSController::HyperXAlloyFPSController(hid_device* dev_handle, const char* path)
{
dev = dev_handle;
location = path;
}
HyperXAlloyFPSController::~HyperXAlloyFPSController()
{
hid_close(dev);
}
std::string HyperXAlloyFPSController::GetDeviceLocation()
{
return("HID: " + location);
}
std::string HyperXAlloyFPSController::GetSerialString()
{
wchar_t serial_string[128];
int ret = hid_get_serial_number_string(dev, serial_string, 128);
if(ret != 0)
{
return("");
}
std::wstring return_wstring = serial_string;
std::string return_string(return_wstring.begin(), return_wstring.end());
return(return_string);
}
void HyperXAlloyFPSController::SetLEDsDirect(std::vector<RGBColor> colors)
{
unsigned char red_color_data[106];
unsigned char grn_color_data[106];
unsigned char blu_color_data[106];
for(std::size_t i = 0; i < 106; i++)
{
red_color_data[i] = RGBGetRValue(colors[i]);
grn_color_data[i] = RGBGetGValue(colors[i]);
blu_color_data[i] = RGBGetBValue(colors[i]);
}
SendDirect
(
HYPERX_ALLOY_FPS_COLOR_CHANNEL_RED,
red_color_data
);
std::this_thread::sleep_for(10ms);
SendDirect
(
HYPERX_ALLOY_FPS_COLOR_CHANNEL_GREEN,
grn_color_data
);
std::this_thread::sleep_for(10ms);
SendDirect
(
HYPERX_ALLOY_FPS_COLOR_CHANNEL_BLUE,
blu_color_data
);
}
/*-------------------------------------------------------------------------------------------------*\
| Private packet sending functions. |
\*-------------------------------------------------------------------------------------------------*/
void HyperXAlloyFPSController::SendDirect
(
unsigned char color_channel,
unsigned char* color_data
)
{
unsigned char buf[264];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(buf, 0x00, sizeof(buf));
/*-----------------------------------------------------*\
| Set up Direct packet |
\*-----------------------------------------------------*/
buf[0x00] = 0x07;
buf[0x01] = HYPERX_ALLOY_FPS_PACKET_ID_DIRECT;
buf[0x02] = color_channel;
buf[0x03] = 0xA0;
/*-----------------------------------------------------*\
| Fill in color data |
\*-----------------------------------------------------*/
for(int i = 0; i < 106; i++)
{
buf[keys[i]] = color_data[i];
}
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_send_feature_report(dev, buf, 264);
}

View File

@@ -0,0 +1,49 @@
/*-----------------------------------------*\
| HyperXAlloyFPSController.h |
| |
| Definitions and types for HyperX Alloy |
| Elite Keyboard lighting controller |
| |
| Adam Honse (CalcProgrammer1) 1/30/2020 |
\*-----------------------------------------*/
#include "RGBController.h"
#include <string>
#include <hidapi/hidapi.h>
#pragma once
enum
{
HYPERX_ALLOY_FPS_PACKET_ID_DIRECT = 0x16, /* Direct control packet */
};
enum
{
HYPERX_ALLOY_FPS_COLOR_CHANNEL_RED = 0x01,
HYPERX_ALLOY_FPS_COLOR_CHANNEL_GREEN = 0x02,
HYPERX_ALLOY_FPS_COLOR_CHANNEL_BLUE = 0x03
};
class HyperXAlloyFPSController
{
public:
HyperXAlloyFPSController(hid_device* dev_handle, const char* path);
~HyperXAlloyFPSController();
std::string GetDeviceLocation();
std::string GetSerialString();
void SetLEDsDirect(std::vector<RGBColor> colors);
private:
hid_device* dev;
std::string location;
void SendDirect
(
unsigned char color_channel,
unsigned char* color_data
);
};

View File

@@ -0,0 +1,298 @@
/*-----------------------------------------*\
| RGBController_HyperXAlloyFPS.cpp |
| |
| Generic RGB Interface for HyperX Alloy |
| FPS Keyboard |
| |
| Adam Honse (CalcProgrammer1) 2/2/2020 |
\*-----------------------------------------*/
#include "RGBControllerKeyNames.h"
#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[] =
{
ZONE_EN_KEYBOARD
};
static zone_type zone_types[] =
{
ZONE_TYPE_MATRIX
};
static const unsigned int zone_sizes[] =
{
106
};
static const char *led_names[] =
{
KEY_EN_ESCAPE,
KEY_EN_BACK_TICK,
KEY_EN_TAB,
KEY_EN_CAPS_LOCK,
KEY_EN_LEFT_SHIFT,
KEY_EN_LEFT_CONTROL,
KEY_EN_F12,
KEY_EN_EQUALS,
KEY_EN_F9,
KEY_EN_9,
KEY_EN_O,
KEY_EN_L,
KEY_EN_COMMA,
KEY_EN_MENU,
KEY_EN_ISO_ENTER,
KEY_EN_LEFT_ARROW,
KEY_EN_F1,
KEY_EN_1,
KEY_EN_Q,
KEY_EN_A,
KEY_EN_ISO_BACK_SLASH,
KEY_EN_LEFT_WINDOWS,
KEY_EN_PRINT_SCREEN,
KEY_EN_F10,
KEY_EN_0,
KEY_EN_P,
KEY_EN_SEMICOLON,
KEY_EN_PERIOD,
KEY_EN_ANSI_ENTER,
KEY_EN_DOWN_ARROW,
KEY_EN_F2,
KEY_EN_2,
KEY_EN_W,
KEY_EN_S,
KEY_EN_Z,
KEY_EN_LEFT_ALT,
KEY_EN_SCROLL_LOCK,
KEY_EN_BACKSPACE,
KEY_EN_F11,
KEY_EN_MINUS,
KEY_EN_LEFT_BRACKET,
KEY_EN_QUOTE,
KEY_EN_FORWARD_SLASH,
KEY_EN_RIGHT_ARROW,
KEY_EN_F3,
KEY_EN_3,
KEY_EN_E,
KEY_EN_D,
KEY_EN_X,
KEY_EN_PAUSE_BREAK,
KEY_EN_DELETE,
KEY_EN_NUMPAD_7,
KEY_EN_NUMPAD_LOCK,
KEY_EN_NUMPAD_6,
KEY_EN_F4,
KEY_EN_4,
KEY_EN_R,
KEY_EN_F,
KEY_EN_C,
KEY_EN_SPACE,
KEY_EN_INSERT,
KEY_EN_END,
KEY_EN_NUMPAD_8,
KEY_EN_NUMPAD_DIVIDE,
KEY_EN_NUMPAD_1,
KEY_EN_F5,
KEY_EN_5,
KEY_EN_T,
KEY_EN_G,
KEY_EN_V,
KEY_EN_HOME,
KEY_EN_PAGE_DOWN,
KEY_EN_NUMPAD_9,
KEY_EN_NUMPAD_TIMES,
KEY_EN_NUMPAD_2,
KEY_EN_F6,
KEY_EN_6,
KEY_EN_Y,
KEY_EN_H,
KEY_EN_B,
KEY_EN_PAGE_UP,
KEY_EN_RIGHT_SHIFT,
KEY_EN_NUMPAD_MINUS,
KEY_EN_NUMPAD_3,
KEY_EN_F7,
KEY_EN_7,
KEY_EN_U,
KEY_EN_J,
KEY_EN_N,
KEY_EN_RIGHT_ALT,
KEY_EN_RIGHT_BRACKET,
KEY_EN_RIGHT_CONTROL,
KEY_EN_NUMPAD_4,
KEY_EN_NUMPAD_PLUS,
KEY_EN_NUMPAD_0,
KEY_EN_F8,
KEY_EN_8,
KEY_EN_I,
KEY_EN_K,
KEY_EN_M,
KEY_EN_RIGHT_WINDOWS,
KEY_EN_ANSI_BACK_SLASH,
KEY_EN_UP_ARROW,
KEY_EN_NUMPAD_5,
KEY_EN_NUMPAD_ENTER,
KEY_EN_NUMPAD_PERIOD
};
/**------------------------------------------------------------------*\
@name HyperX Alloy FPS
@category Keyboard
@type USB
@save :x:
@direct :white_check_mark:
@effects :x:
@detectors DetectHyperXAlloyFPS
@comment
\*-------------------------------------------------------------------*/
RGBController_HyperXAlloyFPS::RGBController_HyperXAlloyFPS(HyperXAlloyFPSController* controller_ptr)
{
controller = controller_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::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);;
}
}

View File

@@ -0,0 +1,41 @@
/*-----------------------------------------*\
| RGBController_HyperXAlloyFPS.h |
| |
| Generic RGB Interface for HyperX Alloy |
| FPS Keyboard |
| |
| Adam Honse (CalcProgrammer1) 2/2/2020 |
\*-----------------------------------------*/
#pragma once
#include <atomic>
#include <chrono>
#include <thread>
#include "RGBController.h"
#include "HyperXAlloyFPSController.h"
class RGBController_HyperXAlloyFPS : public RGBController
{
public:
RGBController_HyperXAlloyFPS(HyperXAlloyFPSController* controller_ptr);
~RGBController_HyperXAlloyFPS();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void DeviceUpdateMode();
void KeepaliveThreadFunction();
private:
HyperXAlloyFPSController* controller;
std::atomic<bool> keepalive_thread_run;
std::thread* keepalive_thread;
std::chrono::time_point<std::chrono::steady_clock> last_update_time;
};