mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-03-24 08:51:07 -04:00
Attempt to implement !513 using shared mutex pointer for each detected mouse/mousemat combo
This commit is contained in:
@@ -406,10 +406,16 @@ void DetectLogitechMouseGLS(hid_device_info* info, const std::string& name)
|
||||
|
||||
if(dev)
|
||||
{
|
||||
/*---------------------------------------------*\
|
||||
| Create mutex to prevent the two controllers |
|
||||
| from interfering with each other |
|
||||
\*---------------------------------------------*/
|
||||
std::shared_ptr<std::mutex> logitech_mutex = std::make_shared<std::mutex>();
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Add mouse |
|
||||
\*---------------------------------------------*/
|
||||
LogitechGLightsyncController* controller = new LogitechGLightsyncController(dev, dev, info->path, 0x01, 0x07, 0x3C);
|
||||
LogitechGLightsyncController* controller = new LogitechGLightsyncController(dev, dev, info->path, 0x01, 0x07, 0x3C, logitech_mutex);
|
||||
RGBController_LogitechGLightsync* rgb_controller = new RGBController_LogitechGLightsync(controller);
|
||||
rgb_controller->name = name;
|
||||
ResourceManager::get()->RegisterRGBController(rgb_controller);
|
||||
@@ -417,7 +423,7 @@ void DetectLogitechMouseGLS(hid_device_info* info, const std::string& name)
|
||||
/*---------------------------------------------*\
|
||||
| Add Powerplay mousemat |
|
||||
\*---------------------------------------------*/
|
||||
LogitechGLightsyncController* mousemat_controller = new LogitechGLightsyncController(dev, dev, info->path, 0x07, 0x0B, 0x3C);
|
||||
LogitechGLightsyncController* mousemat_controller = new LogitechGLightsyncController(dev, dev, info->path, 0x07, 0x0B, 0x3C, logitech_mutex);
|
||||
RGBController_LogitechGPowerPlay* mousemat_rgb_controller = new RGBController_LogitechGPowerPlay(mousemat_controller);
|
||||
mousemat_rgb_controller->name = name;
|
||||
ResourceManager::get()->RegisterRGBController(mousemat_rgb_controller);
|
||||
|
||||
@@ -19,6 +19,18 @@ LogitechGLightsyncController::LogitechGLightsyncController(hid_device* dev_cmd_h
|
||||
dev_index = hid_dev_index;
|
||||
feature_index = hid_feature_index;
|
||||
fctn_ase_id = hid_fctn_ase_id;
|
||||
mutex = nullptr;
|
||||
}
|
||||
|
||||
LogitechGLightsyncController::LogitechGLightsyncController(hid_device* dev_cmd_handle, hid_device *dev_handle, const char *path, unsigned char hid_dev_index, unsigned char hid_feature_index, unsigned char hid_fctn_ase_id, std::shared_ptr<std::mutex> mutex_ptr)
|
||||
{
|
||||
dev = dev_handle;
|
||||
cmd_dev = dev_cmd_handle;
|
||||
location = path;
|
||||
dev_index = hid_dev_index;
|
||||
feature_index = hid_feature_index;
|
||||
fctn_ase_id = hid_fctn_ase_id;
|
||||
mutex = mutex_ptr;
|
||||
}
|
||||
|
||||
LogitechGLightsyncController::~LogitechGLightsyncController()
|
||||
@@ -94,15 +106,30 @@ void LogitechGLightsyncController::UpdateMouseLED(
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
| This code has to be protected to avoid crashes when |
|
||||
| this is called at the same time to change a powerplay |
|
||||
| mat and its paired wireless mouse leds. It will |
|
||||
| happen when using effects engines with high framerate |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, usb_buf, 20);
|
||||
hid_read(dev, usb_buf, 20);
|
||||
if(mutex)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
|
||||
hid_write(dev, usb_buf, 20);
|
||||
hid_read(dev, usb_buf, 20);
|
||||
}
|
||||
else
|
||||
{
|
||||
hid_write(dev, usb_buf, 20);
|
||||
hid_read(dev, usb_buf, 20);
|
||||
}
|
||||
}
|
||||
|
||||
void LogitechGLightsyncController::SetDirectMode(bool direct)
|
||||
{
|
||||
char cmd_buf[7];
|
||||
char usb_buf[20];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
@@ -117,6 +144,7 @@ void LogitechGLightsyncController::SetDirectMode(bool direct)
|
||||
cmd_buf[0x03] = 0x8A;
|
||||
cmd_buf[0x04] = 0x00;
|
||||
cmd_buf[0x05] = 0x00;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| If direct, disable save to flash |
|
||||
\*-----------------------------------------------------*/
|
||||
@@ -125,9 +153,24 @@ void LogitechGLightsyncController::SetDirectMode(bool direct)
|
||||
cmd_buf[0x04] = 0x01;
|
||||
cmd_buf[0x05] = 0x01;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
| This code has to be protected to avoid crashes when |
|
||||
| this is called at the same time to change a powerplay |
|
||||
| mat and its paired wireless mouse leds. It will |
|
||||
| happen when using effects engines with high framerate |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(cmd_dev, (unsigned char *)cmd_buf, 7);
|
||||
hid_read(dev, (unsigned char *)usb_buf, 20);
|
||||
}
|
||||
if(mutex)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
|
||||
hid_write(cmd_dev, (unsigned char *)cmd_buf, 7);
|
||||
hid_read(dev, (unsigned char *)usb_buf, 20);
|
||||
}
|
||||
else
|
||||
{
|
||||
hid_write(cmd_dev, (unsigned char *)cmd_buf, 7);
|
||||
hid_read(dev, (unsigned char *)usb_buf, 20);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,15 @@ public:
|
||||
unsigned char hid_dev_index,
|
||||
unsigned char hid_feature_index,
|
||||
unsigned char hid_fctn_ase_id);
|
||||
LogitechGLightsyncController(
|
||||
hid_device* dev_cmd_handle,
|
||||
hid_device* dev_handle,
|
||||
const char* path,
|
||||
unsigned char hid_dev_index,
|
||||
unsigned char hid_feature_index,
|
||||
unsigned char hid_fctn_ase_id,
|
||||
std::shared_ptr<std::mutex> mutex_ptr);
|
||||
|
||||
~LogitechGLightsyncController();
|
||||
|
||||
std::string GetDeviceLocation();
|
||||
@@ -61,11 +70,12 @@ public:
|
||||
void SetDirectMode(bool direct);
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
hid_device* cmd_dev;
|
||||
std::string location;
|
||||
unsigned char dev_index;
|
||||
unsigned char feature_index;
|
||||
unsigned char fctn_ase_id;
|
||||
bool direct_state;
|
||||
hid_device* dev;
|
||||
hid_device* cmd_dev;
|
||||
std::string location;
|
||||
unsigned char dev_index;
|
||||
unsigned char feature_index;
|
||||
unsigned char fctn_ase_id;
|
||||
bool direct_state;
|
||||
std::shared_ptr<std::mutex> mutex;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user