Store name in OKSKeyboardController to avoid setting it in detector

This commit is contained in:
Adam Honse 2025-08-14 19:06:29 -05:00
parent e418aa7f95
commit 2c630a5218
4 changed files with 54 additions and 47 deletions

View file

@ -13,10 +13,11 @@
#include "OKSKeyboardController.h"
#include "StringUtils.h"
OKSKeyboardController::OKSKeyboardController(hid_device* dev_handle, const char* path, const unsigned short pid)
OKSKeyboardController::OKSKeyboardController(hid_device* dev_handle, const char* path, const unsigned short pid, std::string dev_name)
{
dev = dev_handle;
location = path;
name = dev_name;
usb_pid = pid;
SendInitialize();
@ -32,6 +33,11 @@ std::string OKSKeyboardController::GetDeviceLocation()
return("HID: " + location);
}
std::string OKSKeyboardController::GetNameString()
{
return(name);
}
std::string OKSKeyboardController::GetSerialString()
{
wchar_t serial_string[128];

View file

@ -67,26 +67,28 @@ union uint32_kb2
class OKSKeyboardController
{
public:
OKSKeyboardController(hid_device* dev_handle, const char* path, const unsigned short pid);
OKSKeyboardController(hid_device* dev_handle, const char* path, const unsigned short pid, std::string dev_name);
~OKSKeyboardController();
std::string GetDeviceLocation();
std::string GetNameString();
std::string GetSerialString();
unsigned short GetUSBPID();
void SendColors(unsigned char* color_data, unsigned int color_data_size);
void SendKeyboardModeEx(const mode &m, unsigned char red, unsigned char green, unsigned char blue);
void SendColors(unsigned char* color_data, unsigned int color_data_size);
void SendKeyboardModeEx(const mode &m, unsigned char red, unsigned char green, unsigned char blue);
private:
hid_device* dev;
std::string location;
unsigned short usb_pid;
hid_device* dev;
std::string location;
std::string name;
unsigned short usb_pid;
void Send(const uint8_t bin[64], const uint16_t len);
void SendInitialize();
uint8_t kb2_ComputeChecksum(const union kb2_port_t* const Pack);
int kb2_add_32b(union kb2_port_t* const Pack, const uint32_t value);
void kb2M_init(union kb2_port_t* const Pack, const enum kb2_cmd cmd);
void kb2M_wrgb(union kb2_port_t* const Pack, const uint8_t bright, const uint8_t mode, const uint8_t speed, const uint8_t dir);
void kb2M_wled(union kb2_port_t* const Pack, const uint32_t irgb[14]);
void Send(const uint8_t bin[64], const uint16_t len);
void SendInitialize();
uint8_t kb2_ComputeChecksum(const union kb2_port_t* const Pack);
int kb2_add_32b(union kb2_port_t* const Pack, const uint32_t value);
void kb2M_init(union kb2_port_t* const Pack, const enum kb2_cmd cmd);
void kb2M_wrgb(union kb2_port_t* const Pack, const uint8_t bright, const uint8_t mode, const uint8_t speed, const uint8_t dir);
void kb2M_wled(union kb2_port_t* const Pack, const uint32_t irgb[14]);
};

View file

@ -27,9 +27,9 @@ void DetectOKSKeyboardControllers(hid_device_info* info, const std::string& name
if(dev)
{
OKSKeyboardController* controller = new OKSKeyboardController(dev, info->path, info->product_id);
OKSKeyboardController* controller = new OKSKeyboardController(dev, info->path, info->product_id, name);
RGBController_OKSKeyboard* rgb_controller = new RGBController_OKSKeyboard(controller);
rgb_controller->name = name;
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
} /* DetectOKSKeyboardControllers() */

View file

@ -109,47 +109,46 @@ enum
RGBController_OKSKeyboard::RGBController_OKSKeyboard(OKSKeyboardController* controller_ptr)
{
controller = controller_ptr;
controller = controller_ptr;
name = "OKS Keyboard Device";
vendor = "OKS";
type = DEVICE_TYPE_KEYBOARD;
description = "OKS Keyboard Device";
location = controller->GetDeviceLocation();
serial = controller->GetSerialString();
name = controller->GetNameString();
vendor = "OKS";
type = DEVICE_TYPE_KEYBOARD;
description = "OKS Keyboard Device";
location = controller->GetDeviceLocation();
serial = controller->GetSerialString();
mode Direct;
Direct.name = "Direct";
Direct.value = UP_RGB_MODES_DIRECT;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS ;
Direct.brightness_min = 0;
Direct.brightness_max = 5;
Direct.brightness = 2;
Direct.color_mode = MODE_COLORS_PER_LED;
Direct.speed_min = OKS_SPEED_FASTEST;
Direct.speed_max = OKS_SPEED_SLOWEST;
Direct.speed = OKS_SPEED_NORMAL;
Direct.direction = MODE_DIRECTION_RIGHT;
Direct.name = "Direct";
Direct.value = UP_RGB_MODES_DIRECT;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS ;
Direct.brightness_min = 0;
Direct.brightness_max = 5;
Direct.brightness = 2;
Direct.color_mode = MODE_COLORS_PER_LED;
Direct.speed_min = OKS_SPEED_FASTEST;
Direct.speed_max = OKS_SPEED_SLOWEST;
Direct.speed = OKS_SPEED_NORMAL;
Direct.direction = MODE_DIRECTION_RIGHT;
modes.push_back(Direct);
mode udef = Direct;
udef.name = "User mode1";
udef.value = UP_RGB_MODES_UDEF1;
udef.direction = MODE_DIRECTION_LEFT;
udef.speed = 0;
udef.name = "User mode1";
udef.value = UP_RGB_MODES_UDEF1;
udef.direction = MODE_DIRECTION_LEFT;
udef.speed = 0;
modes.push_back(udef);
udef.name = "User mode2";
udef.value = UP_RGB_MODES_UDEF2;
udef.name = "User mode2";
udef.value = UP_RGB_MODES_UDEF2;
modes.push_back(udef);
udef.name = "User mode3";
udef.value = UP_RGB_MODES_UDEF3;
udef.name = "User mode3";
udef.value = UP_RGB_MODES_UDEF3;
modes.push_back(udef);
udef.name = "User mode4";
udef.value = UP_RGB_MODES_UDEF4;
udef.name = "User mode4";
udef.value = UP_RGB_MODES_UDEF4;
modes.push_back(udef);
udef.name = "User mode5";
udef.value = UP_RGB_MODES_UDEF5;
udef.name = "User mode5";
udef.value = UP_RGB_MODES_UDEF5;
modes.push_back(udef);
/*---------------------------------------------------------*\
| Delete the "Horse race lamp","Breathing"... mode |