Store name in SinowealthControllers to avoid setting it in detectors

This commit is contained in:
Adam Honse 2025-08-16 01:08:09 -05:00
parent f1a050a503
commit c2e0bd496f
23 changed files with 538 additions and 490 deletions

View file

@ -11,11 +11,12 @@
#include "GenesisXenon200Controller.h"
GenesisXenon200Controller::GenesisXenon200Controller(hid_device* dev_handle, hid_device* cmd_dev_handle, const char* path)
GenesisXenon200Controller::GenesisXenon200Controller(hid_device* dev_handle, hid_device* cmd_dev_handle, const char* path, std::string dev_name)
{
dev = dev_handle;
cmd_dev = cmd_dev_handle;
location = path;
name = dev_name;
}
GenesisXenon200Controller::~GenesisXenon200Controller()
@ -28,6 +29,11 @@ std::string GenesisXenon200Controller::GetLocationString()
return("HID: " + location);
}
std::string GenesisXenon200Controller::GetNameString()
{
return(name);
}
void GenesisXenon200Controller::SaveMode(unsigned char mode, unsigned char value, RGBColor color)
{
unsigned char usb_buf[154];

View file

@ -17,13 +17,17 @@
class GenesisXenon200Controller
{
public:
GenesisXenon200Controller(hid_device* dev_handle, hid_device* cmd_dev_handle, const char* path);
GenesisXenon200Controller(hid_device* dev_handle, hid_device* cmd_dev_handle, const char* path, std::string dev_name);
~GenesisXenon200Controller();
void SaveMode(unsigned char mode, unsigned char value, RGBColor color);
std::string GetLocationString();
std::string GetNameString();
void SaveMode(unsigned char mode, unsigned char value, RGBColor color);
private:
hid_device* dev;
hid_device* cmd_dev;
std::string location;
std::string name;
};

View file

@ -25,9 +25,9 @@ RGBController_GenesisXenon200::RGBController_GenesisXenon200(GenesisXenon200Cont
{
controller = controller_ptr;
name = "Genesis Xenon 200";
name = controller->GetNameString();
vendor = "Genesis";
description = "Genesis Xenon 200 Mouse";
description = "Genesis Xenon 200 Mouse Device";
type = DEVICE_TYPE_MOUSE;
location = controller->GetLocationString();

View file

@ -37,7 +37,7 @@ RGBController_Sinowealth1007::RGBController_Sinowealth1007(SinowealthController1
{
controller = controller_ptr;
name = "ZET Fury Pro Mouse Device";
name = controller->GetName();
vendor = "ZET";
type = DEVICE_TYPE_MOUSE;
description = "ZET Fury Pro Mouse Device";

View file

@ -14,16 +14,16 @@
#include "SinowealthController1007.h"
#include "StringUtils.h"
SinowealthController1007::SinowealthController1007(hid_device* dev, char *_path)
SinowealthController1007::SinowealthController1007(hid_device* dev, char *_path, std::string dev_name)
{
this->dev = dev;
this->location = _path;
this->name = dev_name;
this->led_count = 7;
this->current_mode = ZET_FURY_PRO_MODE_CUSTOM + ZET_FURY_PRO_SPEED_DEF;
this->current_direction = ZET_FURY_PRO_DIR_RIGHT;
this->location = _path;
memset(device_colors, 0x00, sizeof(device_colors));
}
@ -37,6 +37,11 @@ std::string SinowealthController1007::GetLocation()
return("HID: " + location);
}
std::string SinowealthController1007::GetName()
{
return(name);
}
unsigned int SinowealthController1007::GetLEDCount()
{
return(led_count);

View file

@ -57,11 +57,12 @@ enum
class SinowealthController1007
{
public:
SinowealthController1007(hid_device* dev, char *_path);
SinowealthController1007(hid_device* dev, char *_path, std::string dev_name);
~SinowealthController1007();
unsigned int GetLEDCount();
std::string GetLocation();
std::string GetName();
std::string GetSerialString();
void SetLEDColors(const std::vector<RGBColor>& colors);
@ -79,4 +80,5 @@ private:
unsigned char device_colors[ZET_FURY_PRO_COLOR_BUFFER_LENGTH];
std::string location;
std::string name;
};

View file

@ -26,7 +26,7 @@ RGBController_Sinowealth::RGBController_Sinowealth(SinowealthController* control
{
controller = controller_ptr;
name = "Sinowealth Device";
name = controller->GetName();
type = DEVICE_TYPE_MOUSE;
description = "Sinowealth Device";
location = controller->GetLocation();

View file

@ -29,7 +29,6 @@ public:
void DeviceUpdateMode();
private:
SinowealthController* controller;
};

View file

@ -14,11 +14,12 @@
#include "SinowealthController.h"
#include "StringUtils.h"
SinowealthController::SinowealthController(hid_device* dev_data_handle, hid_device* dev_cmd_handle, char *_path)
SinowealthController::SinowealthController(hid_device* dev_data_handle, hid_device* dev_cmd_handle, char *_path, std::string dev_name)
{
dev_data = dev_data_handle;
dev_cmd = dev_cmd_handle;
location = _path;
name = dev_name;
led_count = 1;
@ -30,6 +31,7 @@ SinowealthController::SinowealthController(hid_device* dev_data_handle, hid_devi
SinowealthController::~SinowealthController()
{
hid_close(dev_data);
/*---------------------------------------------------------------------*\
| If the dev_cmd handle was passed in as the same device as dev_data |
| then attempting to close it a second time will segfault |
@ -45,6 +47,11 @@ std::string SinowealthController::GetLocation()
return("HID: " + location);
}
std::string SinowealthController::GetName()
{
return(name);
}
unsigned int SinowealthController::GetLEDCount()
{
return(led_count);

View file

@ -57,11 +57,12 @@ enum
class SinowealthController
{
public:
SinowealthController(hid_device* dev_data_handle, hid_device* dev_cmd_handle, char *_path); //RGB, Command, path
SinowealthController(hid_device* dev_data_handle, hid_device* dev_cmd_handle, char *_path, std::string dev_name); //RGB, Command, path
~SinowealthController();
unsigned int GetLEDCount();
std::string GetLocation();
std::string GetName();
std::string GetSerialString();
std::string GetFirmwareVersion();
@ -71,13 +72,11 @@ public:
private:
hid_device* dev_cmd;
hid_device* dev_data;
unsigned int led_count;
unsigned char current_mode;
unsigned char current_speed;
unsigned char current_direction;
unsigned char device_configuration[SINOWEALTH_CONFIG_REPORT_SIZE];
std::string location;
std::string name;
};

View file

@ -240,7 +240,7 @@ static void DetectGenesisXenon200(hid_device_info* info, const std::string name)
hid_device* dev = reports.at(0).device;
hid_device* cmd_dev = reports.at(1).device;
GenesisXenon200Controller* controller = new GenesisXenon200Controller(dev, cmd_dev, info->path);
GenesisXenon200Controller* controller = new GenesisXenon200Controller(dev, cmd_dev, info->path, name);
RGBController* rgb_controller = new RGBController_GenesisXenon200(controller);
ResourceManager::get()->RegisterRGBController(rgb_controller);
@ -259,11 +259,11 @@ static void DetectZetFuryPro(hid_device_info* info, const std::string& name)
#else
hid_device* dev = hid_open_path(info->path);
#endif
if(dev)
{
SinowealthController1007* controller = new SinowealthController1007(dev, info->path);
RGBController *rgb_controller = new RGBController_Sinowealth1007(controller);
rgb_controller->name = name;
SinowealthController1007* controller = new SinowealthController1007(dev, info->path, name);
RGBController_Sinowealth1007* rgb_controller = new RGBController_Sinowealth1007(controller);
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
@ -279,18 +279,18 @@ static void DetectSinowealthMouse(hid_device_info* info, const std::string& name
{
return;
}
hid_device *dev = reports.at(0).device;
hid_device *dev_cmd = reports.at(0).cmd_device;
#else
hid_device* dev = hid_open_path(info->path);
hid_device* dev_cmd = dev;
#endif
if(dev && dev_cmd)
{
SinowealthController* controller = new SinowealthController(dev, dev_cmd, info->path);
RGBController* rgb_controller = new RGBController_Sinowealth(controller);
rgb_controller->name = name;
SinowealthController* controller = new SinowealthController(dev, dev_cmd, info->path, name);
RGBController_Sinowealth* rgb_controller = new RGBController_Sinowealth(controller);
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
@ -300,11 +300,11 @@ static void DetectGMOW_Cable(hid_device_info* info, const std::string& name)
{
LOG_DEBUG("[%s] Detected connection via USB cable", name.c_str());
hid_device *dev = hid_open_path(info->path);
if(dev)
{
SinowealthGMOWController* controller = new SinowealthGMOWController(dev, info->path, GMOW_CABLE_CONNECTED);
RGBController* rgb_controller = new RGBController_GMOW(controller);
rgb_controller->name = name;
SinowealthGMOWController* controller = new SinowealthGMOWController(dev, info->path, GMOW_CABLE_CONNECTED, name);
RGBController_GMOW* rgb_controller = new RGBController_GMOW(controller);
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
@ -334,11 +334,11 @@ static void DetectGMOW_Dongle(hid_device_info* info, const std::string& name)
hid_free_enumeration(start);
hid_device *dev = hid_open_path(info->path);
if(dev)
{
SinowealthGMOWController* controller = new SinowealthGMOWController(dev, info->path, GMOW_DONGLE_CONNECTED);
RGBController *rgb_controller = new RGBController_GMOW(controller);
rgb_controller->name = name;
SinowealthGMOWController* controller = new SinowealthGMOWController(dev, info->path, GMOW_DONGLE_CONNECTED, name);
RGBController_GMOW* rgb_controller = new RGBController_GMOW(controller);
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
@ -362,8 +362,7 @@ static void DetectGMOW_Dongle(hid_device_info* info, const std::string& name)
// if(dev && dev_cmd)
// {
// SinowealthKeyboard16Controller* controller = new SinowealthKeyboard16Controller(dev_cmd, dev, info->path, name);
// RGBController *rgb_controller = new RGBController_SinowealthKeyboard16(controller);
// rgb_controller->name = name;
// RGBController_SinowealthKeyboard16* rgb_controller = new RGBController_SinowealthKeyboard16(controller);
//
// ResourceManager::get()->RegisterRGBController(rgb_controller);
// }
@ -378,24 +377,25 @@ static void DetectGMOW_Dongle(hid_device_info* info, const std::string& name)
// {
// return;
// }
//
// hid_device *dev = reports.at(0).device;
// hid_device *dev_cmd = reports.at(0).cmd_device;
//
// if(dev && dev_cmd)
// {
// SinowealthKeyboardController* controller = new SinowealthKeyboardController(dev_cmd, dev, info->path);
// RGBController* rgb_controller = new RGBController_SinowealthKeyboard(controller);
// rgb_controller->name = name;
// SinowealthKeyboardController* controller = new SinowealthKeyboardController(dev_cmd, dev, info->path, name);
// RGBController_SinowealthKeyboard* rgb_controller = new RGBController_SinowealthKeyboard(controller);
//
// ResourceManager::get()->RegisterRGBController(rgb_controller);
// }
// #else
// // It is unknown why this code used the MOUSE controller here; could it be the reason why it was disabled?
// hid_device* dev = hid_open_path(info->path);
//
// if(dev)
// {
// SinowealthController* controller = new SinowealthController(dev, dev, info->path);
// RGBController* rgb_controller = new RGBController_Sinowealth(controller);
// rgb_controller->name = name;
// SinowealthController* controller = new SinowealthController(dev, dev, info->path, name);
// RGBController_Sinowealth* rgb_controller = new RGBController_Sinowealth(controller);
//
// ResourceManager::get()->RegisterRGBController(rgb_controller);
// }
@ -406,11 +406,11 @@ static void DetectSinowealthGenesisKeyboard(hid_device_info* info, const std::st
{
unsigned int pid = info->product_id;
hid_device* dev = hid_open_path(info->path);
if(dev)
{
SinowealthKeyboard90Controller* controller = new SinowealthKeyboard90Controller(dev, info->path, pid);
SinowealthKeyboard90Controller* controller = new SinowealthKeyboard90Controller(dev, info->path, pid, name);
RGBController_SinowealthKeyboard90* rgb_controller = new RGBController_SinowealthKeyboard90(controller);
rgb_controller->name = name;
ResourceManager::get()->RegisterRGBController(rgb_controller);
}

View file

@ -25,7 +25,7 @@ RGBController_GMOW::RGBController_GMOW(SinowealthGMOWController* controller_ptr)
{
controller = controller_ptr;
name = "Sinowealth Device";
name = controller->GetName();
type = DEVICE_TYPE_MOUSE;
description = "Sinowealth Device";
location = controller->GetLocation();

View file

@ -15,10 +15,12 @@
#include "SinowealthGMOWController.h"
#include "StringUtils.h"
SinowealthGMOWController::SinowealthGMOWController(hid_device* dev_handle, char *_path, int _type)
SinowealthGMOWController::SinowealthGMOWController(hid_device* dev_handle, char *_path, int _type, std::string dev_name)
{
dev = dev_handle;
location = _path;
name = dev_name;
type = _type;
memset(mode_packet,0x00, GMOW_PACKET_SIZE);
mode_packet[0x03] = 0x02;
@ -35,8 +37,6 @@ SinowealthGMOWController::SinowealthGMOWController(hid_device* dev_handle, char
memcpy(less_packet, wired_packet, GMOW_PACKET_SIZE);
less_packet[0x07] = 0x00;
type = _type;
}
SinowealthGMOWController::~SinowealthGMOWController()
@ -49,6 +49,11 @@ std::string SinowealthGMOWController::GetLocation()
return("HID: " + location);
}
std::string SinowealthGMOWController::GetName()
{
return(name);
}
std::string SinowealthGMOWController::GetSerialString()
{
wchar_t serial_string[128];

View file

@ -59,10 +59,11 @@ enum
class SinowealthGMOWController
{
public:
SinowealthGMOWController(hid_device* dev_handle, char *_path, int type);
SinowealthGMOWController(hid_device* dev_handle, char *_path, int type, std::string dev_name);
~SinowealthGMOWController();
std::string GetLocation();
std::string GetName();
std::string GetSerialString();
void SetMode(unsigned char mode,
@ -81,5 +82,6 @@ private:
unsigned char less_packet[GMOW_PACKET_SIZE];
std::string location;
std::string name;
int type;
};

View file

@ -184,9 +184,9 @@ RGBController_SinowealthKeyboard16::RGBController_SinowealthKeyboard16(Sinowealt
{
controller = controller_ptr;
name = "Sinowealth Keyboard";
name = controller->GetName();
type = DEVICE_TYPE_KEYBOARD;
description = "Generic Sinowealth Keyboard";
description = "Sinowealth Keyboard Device";
location = controller->GetLocation();
serial = controller->GetSerialString();

View file

@ -56,6 +56,11 @@ std::string SinowealthKeyboard16Controller::GetLocation()
return("HID: " + location);
}
std::string SinowealthKeyboard16Controller::GetName()
{
return(name);
}
unsigned char SinowealthKeyboard16Controller::GetCurrentMode()
{
return current_mode;

View file

@ -109,6 +109,7 @@ public:
unsigned int GetLEDCount();
std::string GetLocation();
std::string GetName();
std::string GetSerialString();
unsigned char GetCurrentMode();
std::vector<ModeCfg> GetDeviceModes();

View file

@ -28,7 +28,7 @@ RGBController_SinowealthKeyboard90::RGBController_SinowealthKeyboard90(Sinowealt
{
controller = controller_ptr;
name = "Genesis Thor 300";
name = controller->GetNameString();
vendor = "Sinowealth";
type = DEVICE_TYPE_KEYBOARD;
description = "Generic Sinowealth Keyboard";

View file

@ -15,10 +15,11 @@
using namespace thor300;
SinowealthKeyboard90Controller::SinowealthKeyboard90Controller(hid_device* dev_handle, const char* path, const unsigned short pid)
SinowealthKeyboard90Controller::SinowealthKeyboard90Controller(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;
}
@ -32,6 +33,11 @@ std::string SinowealthKeyboard90Controller::GetDeviceLocation()
return("HID: " + location);
}
std::string SinowealthKeyboard90Controller::GetNameString()
{
return(name);
}
std::string SinowealthKeyboard90Controller::GetSerialString()
{
wchar_t serial_string[128];

View file

@ -201,11 +201,13 @@ namespace thor300
class SinowealthKeyboard90Controller
{
public:
SinowealthKeyboard90Controller(hid_device* dev_handle, const char* path, const unsigned short pid);
SinowealthKeyboard90Controller(hid_device* dev_handle, const char* path, const unsigned short pid, std::string dev_name);
~SinowealthKeyboard90Controller();
std::string GetDeviceLocation();
std::string GetNameString();
std::string GetSerialString();
unsigned short GetUSBPID();
void SendMode

View file

@ -133,9 +133,9 @@ RGBController_SinowealthKeyboard::RGBController_SinowealthKeyboard(SinowealthKey
{
controller = controller_ptr;
name = "Sinowealth Keyboard";
name = controller->GetName();
type = DEVICE_TYPE_KEYBOARD;
description = "Sinowealth Keyboard";
description = "Sinowealth Keyboard Device";
location = controller->GetLocation();
serial = controller->GetSerialString();

View file

@ -71,10 +71,11 @@ static unsigned int keys_tkl_keys_indices_static_command[] = { 0x0022, 0x0024,
0x01E0, 0x01E2, 0x01E4, 0x01E6, 0x01E7, 0x01E8, 0x01E9, 0x01EA};
SinowealthKeyboardController::SinowealthKeyboardController(hid_device* dev_cmd_handle, hid_device* dev_data_handle, char* path)
SinowealthKeyboardController::SinowealthKeyboardController(hid_device* dev_cmd_handle, hid_device* dev_data_handle, char* path, std::string dev_name)
{
dev_cmd = dev_cmd_handle;
dev_data = dev_data_handle;
name = dev_name;
led_count = sizeof(tkl_keys_per_key_index) / sizeof(*tkl_keys_per_key_index);
@ -95,6 +96,11 @@ std::string SinowealthKeyboardController::GetLocation()
return("HID: " + location);
}
std::string SinowealthKeyboardController::GetName()
{
return(name);
}
unsigned char SinowealthKeyboardController::GetCurrentMode()
{
return current_mode;

View file

@ -61,11 +61,12 @@ enum
class SinowealthKeyboardController
{
public:
SinowealthKeyboardController(hid_device* dev_cmd_handle, hid_device* dev_data_handle, char *_path); //RGB, Command, path
SinowealthKeyboardController(hid_device* dev_cmd_handle, hid_device* dev_data_handle, char *_path, std::string dev_name); //RGB, Command, path
~SinowealthKeyboardController();
unsigned int GetLEDCount();
std::string GetLocation();
std::string GetName();
std::string GetSerialString();
unsigned char GetCurrentMode();
@ -79,11 +80,9 @@ private:
hid_device* dev_cmd;
hid_device* dev_data;
device_type type;
unsigned int led_count;
unsigned char current_mode;
unsigned char current_speed;
std::string location;
std::string name;
};