Store name in LenovoControllers to avoid setting it in detectors

This commit is contained in:
Adam Honse 2025-08-11 20:37:48 -05:00
parent 41eec46fa7
commit b331fbcd4d
13 changed files with 60 additions and 95 deletions

View file

@ -12,22 +12,12 @@
#include "LogManager.h"
#include "StringUtils.h"
Lenovo4ZoneUSBController::Lenovo4ZoneUSBController(hid_device* dev_handle, const char* path, uint16_t in_pid)
Lenovo4ZoneUSBController::Lenovo4ZoneUSBController(hid_device* dev_handle, const char* path, uint16_t in_pid, std::string dev_name)
{
dev = dev_handle;
location = path;
pid = in_pid;
/*---------------------------------------------------------*\
| Get device name from HID manufacturer and product strings |
\*---------------------------------------------------------*/
wchar_t name_string[HID_MAX_STR];
hid_get_manufacturer_string(dev, name_string, HID_MAX_STR);
name = StringUtils::wstring_to_string(name_string);
hid_get_product_string(dev, name_string, HID_MAX_STR);
name.append(" ").append(StringUtils::wstring_to_string(name_string));
name = dev_name;
}
Lenovo4ZoneUSBController::~Lenovo4ZoneUSBController()

View file

@ -30,7 +30,7 @@ class Lenovo4ZoneUSBController
/*--------------*\
|ctor(s) and dtor|
\*--------------*/
Lenovo4ZoneUSBController(hid_device* dev_handle, const char* path, uint16_t in_pid);
Lenovo4ZoneUSBController(hid_device* dev_handle, const char* path, uint16_t in_pid, std::string dev_name);
~Lenovo4ZoneUSBController();
void setMode(const KeyboardState &in_mode);

View file

@ -33,9 +33,8 @@ void DetectLenovo4ZoneUSBControllers(hid_device_info* info, const std::string& n
if(dev)
{
Lenovo4ZoneUSBController* controller = new Lenovo4ZoneUSBController(dev, info->path, info->product_id);
Lenovo4ZoneUSBController* controller = new Lenovo4ZoneUSBController(dev, info->path, info->product_id, name);
RGBController_Lenovo4ZoneUSB* rgb_controller = new RGBController_Lenovo4ZoneUSB(controller);
rgb_controller->name = name;
ResourceManager::get()->RegisterRGBController(rgb_controller);
}

View file

@ -39,8 +39,6 @@ RGBController_Lenovo4ZoneUSB::RGBController_Lenovo4ZoneUSB(Lenovo4ZoneUSBControl
name = controller->getName();
type = DEVICE_TYPE_LAPTOP;
vendor = "Lenovo";
description = "Lenovo 4-Zone device";
mode Direct;
@ -54,8 +52,7 @@ RGBController_Lenovo4ZoneUSB::RGBController_Lenovo4ZoneUSB(Lenovo4ZoneUSBControl
mode Breath;
Breath.name = "Breathing";
Breath.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS |
MODE_FLAG_HAS_SPEED;
Breath.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_SPEED;
Breath.color_mode = MODE_COLORS_PER_LED;
Breath.brightness_min = 1;
Breath.brightness_max = 2;
@ -66,10 +63,7 @@ RGBController_Lenovo4ZoneUSB::RGBController_Lenovo4ZoneUSB(Lenovo4ZoneUSBControl
mode Wave;
Wave.name = "Rainbow Wave";
Wave.flags = MODE_FLAG_HAS_RANDOM_COLOR |
MODE_FLAG_HAS_BRIGHTNESS |
MODE_FLAG_HAS_SPEED |
MODE_FLAG_HAS_DIRECTION_LR;
Wave.flags = MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_DIRECTION_LR;
Wave.color_mode = MODE_COLORS_RANDOM;
Wave.brightness_min = 1;
Wave.brightness_max = 2;
@ -80,8 +74,7 @@ RGBController_Lenovo4ZoneUSB::RGBController_Lenovo4ZoneUSB(Lenovo4ZoneUSBControl
mode Smooth;
Smooth.name = "Spectrum Cycle";
Smooth.flags = MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_HAS_BRIGHTNESS |
MODE_FLAG_HAS_SPEED;
Smooth.flags = MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_SPEED;
Smooth.color_mode = MODE_COLORS_RANDOM;
Smooth.brightness_min = 1;
Smooth.brightness_max = 2;
@ -89,7 +82,6 @@ RGBController_Lenovo4ZoneUSB::RGBController_Lenovo4ZoneUSB(Lenovo4ZoneUSBControl
Smooth.speed_max = 4;
modes.push_back(Smooth);
SetupZones();
}

View file

@ -14,10 +14,11 @@
using namespace std;
LenovoM300Controller::LenovoM300Controller(hid_device* dev_handle, const hid_device_info& info)
LenovoM300Controller::LenovoM300Controller(hid_device* dev_handle, const hid_device_info& info, std::string dev_name)
{
device = dev_handle;
location = info.path;
name = dev_name;
}
LenovoM300Controller::~LenovoM300Controller()
@ -30,6 +31,11 @@ std::string LenovoM300Controller::GetDeviceLocation()
return("HID: " + location);
}
std::string LenovoM300Controller::GetDeviceName()
{
return(name);
}
void LenovoM300Controller::SetMode(std::vector<RGBColor> colors, unsigned char mode_value, unsigned int brigthness)
{
unsigned char usb_buf[M300_DATA_SIZE];

View file

@ -30,10 +30,11 @@ enum
class LenovoM300Controller
{
public:
LenovoM300Controller(hid_device* dev_handle, const hid_device_info& info);
LenovoM300Controller(hid_device* dev_handle, const hid_device_info& info, std::string dev_name);
~LenovoM300Controller();
std::string GetDeviceLocation();
std::string GetDeviceName();
void SetMode(std::vector<RGBColor> colors, unsigned char mode_value, unsigned int brightness);
@ -42,6 +43,7 @@ protected:
private:
std::string location;
std::string name;
unsigned char CalculateFinalByte(unsigned char* ptr, int count);
};

View file

@ -27,12 +27,10 @@ void DetectLenovoLegionM300Controllers(hid_device_info* info, const std::string&
if(dev)
{
LenovoM300Controller* controller = new LenovoM300Controller(dev, *info);
LenovoM300Controller* controller = new LenovoM300Controller(dev, *info, name);
RGBController_LenovoM300* rgb_controller = new RGBController_LenovoM300(controller);
rgb_controller->name = name;
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
}

View file

@ -26,10 +26,10 @@ RGBController_LenovoM300::RGBController_LenovoM300(LenovoM300Controller* control
{
controller = controller_ptr;
name = "Lenovo Legion M300";
name = controller->GetDeviceName();
vendor = "Lenovo";
type = DEVICE_TYPE_MOUSE;
description = name;
description = "Lenovo M300 Device";
location = controller->GetDeviceLocation();
mode Static;

View file

@ -15,22 +15,12 @@
using namespace std;
LenovoUSBController::LenovoUSBController(hid_device* dev_handle, const char* path, uint16_t in_pid)
LenovoUSBController::LenovoUSBController(hid_device* dev_handle, const char* path, uint16_t in_pid, std::string dev_name)
{
dev = dev_handle;
location = path;
pid = in_pid;
/*---------------------------------------------------------*\
| Get device name from HID manufacturer and product strings |
\*---------------------------------------------------------*/
wchar_t name_string[HID_MAX_STR];
hid_get_manufacturer_string(dev, name_string, HID_MAX_STR);
name = StringUtils::wstring_to_string(name_string);
hid_get_product_string(dev, name_string, HID_MAX_STR);
name.append(" ").append(StringUtils::wstring_to_string(name_string));
name = dev_name;
setDeviceSoftwareMode();
}

View file

@ -36,7 +36,7 @@ class LenovoUSBController
/*--------------*\
|ctor(s) and dtor|
\*--------------*/
LenovoUSBController(hid_device* dev_handle, const char* path, uint16_t in_pid);
LenovoUSBController(hid_device* dev_handle, const char* path, uint16_t in_pid, std::string dev_name);
~LenovoUSBController();
/*--------------*\

View file

@ -35,9 +35,8 @@ void DetectLenovoLegionUSBControllers(hid_device_info* info, const std::string&
if(dev)
{
LenovoUSBController* controller = new LenovoUSBController(dev, info->path, info->product_id);
LenovoUSBController* controller = new LenovoUSBController(dev, info->path, info->product_id, name);
RGBController_LenovoUSB* rgb_controller = new RGBController_LenovoUSB(controller);
rgb_controller->name = name;
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
@ -49,9 +48,8 @@ void DetectLenovoLegionUSBControllersGen7And8(hid_device_info* info, const std::
if(dev)
{
LenovoGen7And8USBController* controller = new LenovoGen7And8USBController(dev, info->path, info->product_id);
LenovoGen7And8USBController* controller = new LenovoGen7And8USBController(dev, info->path, info->product_id, name);
LenovoRGBController_Gen7_8* rgb_controller = new LenovoRGBController_Gen7_8(controller);
rgb_controller->name = name;
ResourceManager::get()->RegisterRGBController(rgb_controller);
}

View file

@ -14,22 +14,12 @@
using namespace std;
LenovoGen7And8USBController::LenovoGen7And8USBController(hid_device* dev_handle, const char* path, uint16_t in_pid)
LenovoGen7And8USBController::LenovoGen7And8USBController(hid_device* dev_handle, const char* path, uint16_t in_pid, std::string dev_name)
{
dev = dev_handle;
location = path;
pid = in_pid;
/*---------------------------------------------------------*\
| Get device name from HID manufacturer and product strings |
\*---------------------------------------------------------*/
wchar_t name_string[HID_MAX_STR];
hid_get_manufacturer_string(dev, name_string, HID_MAX_STR);
name = StringUtils::wstring_to_string(name_string);
hid_get_product_string(dev, name_string, HID_MAX_STR);
name.append(" ").append(StringUtils::wstring_to_string(name_string));
name = dev_name;
}
LenovoGen7And8USBController::~LenovoGen7And8USBController()

View file

@ -51,7 +51,7 @@ class LenovoGen7And8USBController
/*--------------*\
|ctor(s) and dtor|
\*--------------*/
LenovoGen7And8USBController(hid_device* dev_handle, const char* path, uint16_t in_pid);
LenovoGen7And8USBController(hid_device* dev_handle, const char* path, uint16_t in_pid, std::string dev_name);
~LenovoGen7And8USBController();
/*--------------*\