Publish LumaOps source

This commit is contained in:
LumaOps release export
2026-09-03 01:18:36 +02:00
commit 7f1c0e5f71
2363 changed files with 501543 additions and 0 deletions
@@ -0,0 +1,224 @@
/*---------------------------------------------------------*\
| LogitechG203LController.cpp |
| |
| Driver for Logitech G203L |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include <cstring>
#include "LogitechG203LController.h"
#include "StringUtils.h"
#define PACKET_SIZE 20
LogitechG203LController::LogitechG203LController(hid_device* dev_handle, const char* path, std::string dev_name)
{
dev = dev_handle;
location = path;
name = dev_name;
// enable software control
unsigned char usb_buf[PACKET_SIZE];
memset(usb_buf, 0x00, PACKET_SIZE);
usb_buf[0x00] = 0x11;
usb_buf[0x01] = 0xFF;
usb_buf[0x02] = 0x0E;
usb_buf[0x03] = 0x50;
usb_buf[0x04] = 0x01;
usb_buf[0x05] = 0x03;
usb_buf[0x06] = 0x07;
SendPacket(usb_buf);
}
LogitechG203LController::~LogitechG203LController()
{
if(dev != nullptr)
{
hid_close(dev);
}
}
std::string LogitechG203LController::GetDeviceLocation()
{
return("HID: " + location);
}
std::string LogitechG203LController::GetNameString()
{
return(name);
}
std::string LogitechG203LController::GetSerialString()
{
wchar_t serial_string[128];
int ret = hid_get_serial_number_string(dev, serial_string, 128);
if(ret != 0)
{
return("");
}
return(StringUtils::wstring_to_string(serial_string));
}
void LogitechG203LController::SendApply()
{
unsigned char usb_buf[PACKET_SIZE];
memset(usb_buf, 0x00, PACKET_SIZE);
usb_buf[0x00] = 0x11;
usb_buf[0x01] = 0xFF;
usb_buf[0x02] = 0x12;
usb_buf[0x03] = 0x70;
SendPacket(usb_buf);
}
void LogitechG203LController::SetSingleLED(int led, unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char usb_buf[PACKET_SIZE];
memset(usb_buf, 0x00, PACKET_SIZE);
usb_buf[0x00] = 0x11;
usb_buf[0x01] = 0xFF;
usb_buf[0x02] = 0x12;
usb_buf[0x03] = 0x10;
usb_buf[0x04] = (unsigned char)led;
usb_buf[0x05] = red;
usb_buf[0x06] = green;
usb_buf[0x07] = blue;
usb_buf[0x08] = 0xFF;
SendPacket(usb_buf);
SendApply();
}
void LogitechG203LController::SetMode(
int mode,
int speed,
unsigned char bright,
unsigned char dir,
unsigned char red,
unsigned char green,
unsigned char blue)
{
unsigned char usb_buf[PACKET_SIZE];
unsigned char brightness = bright * 5;
if(brightness == 0)
{
brightness = 1;
}
memset(usb_buf, 0x00, PACKET_SIZE);
//Header
usb_buf[0x00] = 0x11;
usb_buf[0x01] = 0xFF;
usb_buf[0x02] = 0x0E;
usb_buf[0x03] = 0x10;
//Common Data
usb_buf[0x04] = 0x00;
usb_buf[0x05] = (unsigned char)mode;
usb_buf[0x06] = red;
usb_buf[0x07] = green;
usb_buf[0x08] = blue;
//mode specific Data and position
if(mode == LOGITECH_G203L_MODE_STATIC) usb_buf[0x09] = 0x02;
if(mode == LOGITECH_G203L_MODE_CYCLE)
{
usb_buf[0x0B] = (unsigned char)((speed>>8) & 0x000000FF);
usb_buf[0x0C] = (unsigned char)(speed & 0x000000FF);
usb_buf[0x0D] = brightness;
}
if(mode == LOGITECH_G203L_MODE_BREATHING)
{
usb_buf[0x09] = (unsigned char)((speed>>8) & 0x000000FF);
usb_buf[0x0A] = (unsigned char)(speed & 0x000000FF);
usb_buf[0x0C] = brightness;
}
if(mode == LOGITECH_G203L_MODE_WAVE)
{
usb_buf[0x0C] = (unsigned char)(speed & 0x000000FF);
usb_buf[0x0D] = dir ? 0x01 : 0x06; //0x01: Left->Right 0x06: Right->Left
usb_buf[0x0E] = brightness;
usb_buf[0x0F] = (unsigned char)((speed>>8) & 0x000000FF);
}
if(mode == LOGITECH_G203L_MODE_COLORMIXING)
{
usb_buf[0x0C] = (unsigned char)(speed & 0x000000FF);
usb_buf[0x0D] = (unsigned char)((speed>>8) & 0x000000FF);
usb_buf[0x0E] = brightness;
}
//END BYTE
usb_buf[0x10] = 0x01;
SendPacket(usb_buf);
}
void LogitechG203LController::SetDevice(std::vector<RGBColor> colors)
{
unsigned char usb_buf[PACKET_SIZE];
memset(usb_buf, 0x00, PACKET_SIZE);
usb_buf[0x00] = 0x11;
usb_buf[0x01] = 0xFF;
usb_buf[0x02] = 0x12;
usb_buf[0x03] = 0x10;
usb_buf[0x04] = 0x01;
usb_buf[0x05] = RGBGetRValue(colors[0]);
usb_buf[0x06] = RGBGetGValue(colors[0]);
usb_buf[0x07] = RGBGetBValue(colors[0]);
usb_buf[0x08] = 0x02;
usb_buf[0x09] = RGBGetRValue(colors[1]);
usb_buf[0x0A] = RGBGetGValue(colors[1]);
usb_buf[0x0B] = RGBGetBValue(colors[1]);
usb_buf[0x0C] = 0x03;
usb_buf[0x0D] = RGBGetRValue(colors[2]);
usb_buf[0x0E] = RGBGetGValue(colors[2]);
usb_buf[0x0F] = RGBGetBValue(colors[2]);
usb_buf[0x10] = 0xFF;
SendPacket(usb_buf);
SendApply();
}
void LogitechG203LController::SendPacket(unsigned char* buffer)
{
if(dev != nullptr)
{
if(hid_write(dev, buffer, PACKET_SIZE) == -1)
{
hid_close(dev);
dev = hid_open_path(location.c_str());
return;
}
}
if(dev != nullptr)
{
if(hid_read_timeout(dev, buffer, PACKET_SIZE, 10) <= 0)
{
hid_close(dev);
dev = hid_open_path(location.c_str());
return;
}
}
}
@@ -0,0 +1,48 @@
/*---------------------------------------------------------*\
| LogitechG203LController.h |
| |
| Driver for Logitech G203L |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include <string>
#include <hidapi.h>
#include "RGBController.h"
enum
{
LOGITECH_G203L_MODE_DIRECT = 0x07,
LOGITECH_G203L_MODE_OFF = 0x00,
LOGITECH_G203L_MODE_STATIC = 0x01,
LOGITECH_G203L_MODE_CYCLE = 0x02,
LOGITECH_G203L_MODE_WAVE = 0x03,
LOGITECH_G203L_MODE_BREATHING = 0x04,
LOGITECH_G203L_MODE_COLORMIXING = 0x06,
};
class LogitechG203LController
{
public:
LogitechG203LController(hid_device* dev_handle, const char* path, std::string dev_name);
~LogitechG203LController();
std::string GetDeviceLocation();
std::string GetNameString();
std::string GetSerialString();
void SetSingleLED(int led, unsigned char red, unsigned char green, unsigned char blue);
void SetMode(int mode, int speed, unsigned char brightness, unsigned char dir, unsigned char red, unsigned char green, unsigned char blue);
void SetDevice(std::vector<RGBColor> colors);
private:
hid_device* dev;
std::string location;
std::string name;
void SendApply();
void SendPacket(unsigned char* buffer);
};
@@ -0,0 +1,202 @@
/*---------------------------------------------------------*\
| RGBController_LogitechG203L.cpp |
| |
| Driver for Logitech G203L |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include "RGBController_LogitechG203L.h"
/**------------------------------------------------------------------*\
@name Logitech G203L
@category Mouse
@type USB
@save :robot:
@direct :white_check_mark:
@effects :white_check_mark:
@detectors DetectLogitechMouseG203L
@comment
\*-------------------------------------------------------------------*/
RGBController_LogitechG203L::RGBController_LogitechG203L(LogitechG203LController* controller_ptr)
{
controller = controller_ptr;
name = controller->GetNameString();
vendor = "Logitech";
type = DEVICE_TYPE_MOUSE;
description = "Logitech Mouse Device";
location = controller->GetDeviceLocation();
serial = controller->GetSerialString();
mode Direct;
Direct.name = "Direct";
Direct.value = LOGITECH_G203L_MODE_DIRECT;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Direct.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Direct);
mode Off;
Off.name = "Off";
Off.value = LOGITECH_G203L_MODE_OFF;
Off.flags = 0;
Off.color_mode = MODE_COLORS_NONE;
modes.push_back(Off);
mode Static;
Static.name = "Static";
Static.value = LOGITECH_G203L_MODE_STATIC;
Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
Static.color_mode = MODE_COLORS_MODE_SPECIFIC;
Static.colors.resize(1);
modes.push_back(Static);
mode Cycle;
Cycle.name = "Cycle";
Cycle.value = LOGITECH_G203L_MODE_CYCLE;
Cycle.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS;
Cycle.color_mode = MODE_COLORS_NONE;
Cycle.speed_min = 0x4E20;
Cycle.speed_max = 0x03E8;
Cycle.brightness = 20;
Cycle.brightness_min = 0;
Cycle.brightness_max = 20;
modes.push_back(Cycle);
mode Breathing;
Breathing.name = "Breathing";
Breathing.value = LOGITECH_G203L_MODE_BREATHING;
Breathing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC;
Breathing.speed_min = 0x4E20;
Breathing.speed_max = 0x03E8;
Breathing.brightness = 20;
Breathing.brightness_min = 0;
Breathing.brightness_max = 20;
Breathing.colors.resize(1);
modes.push_back(Breathing);
mode Wave;
Wave.name = "Wave";
Wave.value = LOGITECH_G203L_MODE_WAVE;
Wave.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_DIRECTION_LR;
Wave.color_mode = MODE_COLORS_NONE;
Wave.speed_min = 0x4E20;
Wave.speed_max = 0x03E8;
Wave.brightness = 20;
Wave.brightness_min = 0;
Wave.brightness_max = 20;
modes.push_back(Wave);
mode Colormixing;
Colormixing.name = "Colormixing";
Colormixing.value = LOGITECH_G203L_MODE_COLORMIXING;
Colormixing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS;
Colormixing.color_mode = MODE_COLORS_NONE;
Colormixing.speed_min = 0x4E20;
Colormixing.speed_max = 0x03E8;
Colormixing.brightness = 20;
Colormixing.brightness_min = 0;
Colormixing.brightness_max = 20;
modes.push_back(Colormixing);
SetupZones();
}
RGBController_LogitechG203L::~RGBController_LogitechG203L()
{
delete controller;
}
void RGBController_LogitechG203L::SetupZones()
{
zone g203L_zone;
g203L_zone.name = "Mouse Zone";
g203L_zone.type = ZONE_TYPE_LINEAR;
g203L_zone.leds_min = 3;
g203L_zone.leds_max = 3;
g203L_zone.leds_count = 3;
g203L_zone.matrix_map = NULL;
zones.push_back(g203L_zone);
led g203L_led_l;
g203L_led_l.name = "Mouse Left";
g203L_led_l.value = 1;
leds.push_back(g203L_led_l);
led g203L_led_c;
g203L_led_c.name = "Mouse Center";
g203L_led_c.value = 2;
leds.push_back(g203L_led_c);
led g203L_led_r;
g203L_led_r.name = "Mouse Right";
g203L_led_r.value = 3;
leds.push_back(g203L_led_r);
SetupColors();
}
void RGBController_LogitechG203L::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_LogitechG203L::DeviceUpdateLEDs()
{
controller->SetDevice(colors);
controller->SetDevice(colors); //dirty workaround for color lag
}
void RGBController_LogitechG203L::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_LogitechG203L::UpdateSingleLED(int led)
{
unsigned char red = RGBGetRValue(colors[led]);
unsigned char grn = RGBGetGValue(colors[led]);
unsigned char blu = RGBGetBValue(colors[led]);
controller->SetSingleLED(leds[led].value, red, grn, blu);
controller->SetSingleLED(leds[led].value, red, grn, blu); //dirty workaround for color lag
}
void RGBController_LogitechG203L::DeviceUpdateMode()
{
unsigned char red = 0;
unsigned char grn = 0;
unsigned char blu = 0;
unsigned char dir = 0;
if(modes[active_mode].color_mode & MODE_COLORS_MODE_SPECIFIC)
{
red = RGBGetRValue(modes[active_mode].colors[0]);
grn = RGBGetGValue(modes[active_mode].colors[0]);
blu = RGBGetBValue(modes[active_mode].colors[0]);
}
if(modes[active_mode].flags & MODE_FLAG_HAS_DIRECTION_LR)
{
dir = (unsigned char)modes[active_mode].direction;
}
if(modes[active_mode].flags & MODE_FLAG_HAS_BRIGHTNESS)
{
//dunno where brightness is
}
if(modes[active_mode].value == LOGITECH_G203L_MODE_DIRECT)
{
controller->SetDevice(colors);
}
else
{
controller->SetMode(modes[active_mode].value, modes[active_mode].speed, modes[active_mode].brightness, dir, red, grn, blu);
}
}
@@ -0,0 +1,33 @@
/*---------------------------------------------------------*\
| RGBController_LogitechG203L.h |
| |
| Driver for Logitech G203L |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include "RGBController.h"
#include "LogitechG203LController.h"
class RGBController_LogitechG203L : public RGBController
{
public:
RGBController_LogitechG203L(LogitechG203LController* controller_ptr);
~RGBController_LogitechG203L();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void DeviceUpdateMode();
private:
LogitechG203LController* controller;
};