Publish LumaOps source
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| LogitechG203LController.cpp |
|
||||
| |
|
||||
| Driver for Logitech G203L |
|
||||
| |
|
||||
| Eric Samuelson (edbgon) 06 Oct 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <cstring>
|
||||
#include "LogitechG213Controller.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
LogitechG213Controller::LogitechG213Controller(hid_device* dev_handle, const char* path, std::string dev_name)
|
||||
{
|
||||
dev = dev_handle;
|
||||
location = path;
|
||||
name = dev_name;
|
||||
}
|
||||
|
||||
LogitechG213Controller::~LogitechG213Controller()
|
||||
{
|
||||
hid_close(dev);
|
||||
}
|
||||
|
||||
std::string LogitechG213Controller::GetDeviceLocation()
|
||||
{
|
||||
return("HID: " + location);
|
||||
}
|
||||
|
||||
std::string LogitechG213Controller::GetNameString()
|
||||
{
|
||||
return(name);
|
||||
}
|
||||
|
||||
std::string LogitechG213Controller::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 LogitechG213Controller::SetDirect
|
||||
(
|
||||
unsigned char zone,
|
||||
unsigned char r,
|
||||
unsigned char g,
|
||||
unsigned char b
|
||||
)
|
||||
{
|
||||
unsigned char usb_buf[20];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Lighting Control packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x11;
|
||||
usb_buf[0x01] = 0xFF;
|
||||
usb_buf[0x02] = 0x0C;
|
||||
usb_buf[0x03] = 0x3A;
|
||||
usb_buf[0x04] = zone;
|
||||
usb_buf[0x05] = 0x01;
|
||||
usb_buf[0x06] = r;
|
||||
usb_buf[0x07] = g;
|
||||
usb_buf[0x08] = b;
|
||||
usb_buf[0x09] = 0x02;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, usb_buf, 20);
|
||||
hid_read(dev, usb_buf, 20);
|
||||
}
|
||||
|
||||
void LogitechG213Controller::SetMode
|
||||
(
|
||||
unsigned char mode,
|
||||
unsigned short speed,
|
||||
unsigned char direction,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
)
|
||||
{
|
||||
SendMode(LOGITECH_G213_ZONE_MODE_KEYBOARD, mode, speed, direction, red, green, blue);
|
||||
}
|
||||
|
||||
void LogitechG213Controller::SendMode
|
||||
(
|
||||
unsigned char zone,
|
||||
unsigned char mode,
|
||||
unsigned short speed,
|
||||
unsigned char direction,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
)
|
||||
{
|
||||
unsigned char usb_buf[20];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Lighting Control packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x11;
|
||||
usb_buf[0x01] = 0xFF;
|
||||
usb_buf[0x02] = 0x0C;
|
||||
usb_buf[0x03] = 0x3C;
|
||||
usb_buf[0x04] = zone;
|
||||
|
||||
usb_buf[0x05] = mode;
|
||||
|
||||
usb_buf[0x06] = red;
|
||||
usb_buf[0x07] = green;
|
||||
usb_buf[0x08] = blue;
|
||||
|
||||
speed = 100 * speed;
|
||||
|
||||
if(mode == LOGITECH_G213_MODE_BREATHING)
|
||||
{
|
||||
usb_buf[0x09] = speed >> 8;
|
||||
usb_buf[0x0A] = speed & 0xFF;
|
||||
usb_buf[0x0C] = 0x64;
|
||||
}
|
||||
else if(mode == LOGITECH_G213_MODE_CYCLE)
|
||||
{
|
||||
usb_buf[0x0B] = speed >> 8;
|
||||
usb_buf[0x0C] = speed & 0xFF;
|
||||
usb_buf[0x0D] = 0x64;
|
||||
}
|
||||
else if(mode == LOGITECH_G213_MODE_WAVE)
|
||||
{
|
||||
usb_buf[0x0B] = speed >> 8;
|
||||
usb_buf[0x0C] = speed & 0xFF;
|
||||
usb_buf[0x0D] = direction & 0xFF;
|
||||
usb_buf[0x0F] = speed >> 8;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, usb_buf, 20);
|
||||
hid_read(dev, usb_buf, 20);
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| LogitechG203LController.h |
|
||||
| |
|
||||
| Driver for Logitech G203L |
|
||||
| |
|
||||
| Eric Samuelson (edbgon) 06 Oct 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
|
||||
#include <string>
|
||||
#include <hidapi.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
enum
|
||||
{
|
||||
LOGITECH_G213_ZONE_MODE_KEYBOARD = 0x00
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
LOGITECH_G213_MODE_OFF = 0x00,
|
||||
LOGITECH_G213_MODE_STATIC = 0x01,
|
||||
LOGITECH_G213_MODE_BREATHING = 0x02,
|
||||
LOGITECH_G213_MODE_CYCLE = 0x03,
|
||||
LOGITECH_G213_MODE_WAVE = 0x04,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
LOGITECH_G213_WAVE_MODE_LEFT = 0x06,
|
||||
LOGITECH_G213_WAVE_MODE_RIGHT = 0x01,
|
||||
LOGITECH_G213_WAVE_MODE_CENTER_EDGE = 0x03,
|
||||
LOGITECH_G213_WAVE_MODE_EDGE_CENTER = 0x08,
|
||||
};
|
||||
|
||||
/*---------------------------------------------------------------------------------------------*\
|
||||
| Speed is 1000 for fast and 20000 for slow. |
|
||||
| Values are multiplied by 100 later to give lots of GUI steps. |
|
||||
\*---------------------------------------------------------------------------------------------*/
|
||||
enum
|
||||
{
|
||||
LOGITECH_G213_SPEED_SLOWEST = 0xC8, /* Slowest speed */
|
||||
LOGITECH_G213_SPEED_NORMAL = 0x32, /* Normal speed */
|
||||
LOGITECH_G213_SPEED_FASTEST = 0x0A, /* Fastest speed */
|
||||
};
|
||||
|
||||
class LogitechG213Controller
|
||||
{
|
||||
public:
|
||||
LogitechG213Controller(hid_device* dev_handle, const char* path, std::string dev_name);
|
||||
~LogitechG213Controller();
|
||||
|
||||
std::string GetDeviceLocation();
|
||||
std::string GetNameString();
|
||||
std::string GetSerialString();
|
||||
|
||||
void SetDirect
|
||||
(
|
||||
unsigned char zone,
|
||||
unsigned char r,
|
||||
unsigned char g,
|
||||
unsigned char b
|
||||
);
|
||||
|
||||
void SetMode
|
||||
(
|
||||
unsigned char mode,
|
||||
unsigned short speed,
|
||||
unsigned char direction,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
);
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
std::string location;
|
||||
std::string name;
|
||||
|
||||
void SendMode
|
||||
(
|
||||
unsigned char zone,
|
||||
unsigned char mode,
|
||||
unsigned short speed,
|
||||
unsigned char direction,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,209 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_LogitechG213.cpp |
|
||||
| |
|
||||
| RGBController for Logitech G203L |
|
||||
| |
|
||||
| Eric Samuelson (edbgon) 06 Oct 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "RGBController_LogitechG213.h"
|
||||
|
||||
static const char* led_names[] =
|
||||
{
|
||||
"Left Area",
|
||||
"Middle Area",
|
||||
"Right Area",
|
||||
"Arrow and Homekeys",
|
||||
"Numpad",
|
||||
};
|
||||
|
||||
static const unsigned char led_values[] =
|
||||
{
|
||||
0x01,
|
||||
0x02,
|
||||
0x03,
|
||||
0x04,
|
||||
0x05,
|
||||
};
|
||||
|
||||
#define LOGITECH_G213_ZONES (sizeof(led_values) / sizeof(led_values[ 0 ]))
|
||||
|
||||
/**------------------------------------------------------------------*\
|
||||
@name Logitech G213
|
||||
@category Keyboard
|
||||
@type USB
|
||||
@save :robot:
|
||||
@direct :white_check_mark:
|
||||
@effects :white_check_mark:
|
||||
@detectors DetectLogitechKeyboardG213
|
||||
@comment
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
RGBController_LogitechG213::RGBController_LogitechG213(LogitechG213Controller* controller_ptr)
|
||||
{
|
||||
controller = controller_ptr;
|
||||
|
||||
name = controller->GetNameString();
|
||||
vendor = "Logitech";
|
||||
type = DEVICE_TYPE_KEYBOARD;
|
||||
description = "Logitech G213 Keyboard Device";
|
||||
location = controller->GetDeviceLocation();
|
||||
serial = controller->GetSerialString();
|
||||
|
||||
mode Direct;
|
||||
Direct.name = "Direct";
|
||||
Direct.value = 0xFFFF;
|
||||
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_G213_MODE_OFF;
|
||||
Off.flags = 0;
|
||||
Off.color_mode = MODE_COLORS_NONE;
|
||||
modes.push_back(Off);
|
||||
|
||||
mode Cycle;
|
||||
Cycle.name = "Cycle";
|
||||
Cycle.value = LOGITECH_G213_MODE_CYCLE;
|
||||
Cycle.flags = MODE_FLAG_HAS_SPEED;
|
||||
Cycle.color_mode = MODE_COLORS_NONE;
|
||||
Cycle.speed_min = LOGITECH_G213_SPEED_SLOWEST;
|
||||
Cycle.speed_max = LOGITECH_G213_SPEED_FASTEST;
|
||||
Cycle.speed = LOGITECH_G213_SPEED_NORMAL;
|
||||
modes.push_back(Cycle);
|
||||
|
||||
mode Wave;
|
||||
Wave.name = "Wave";
|
||||
Wave.value = LOGITECH_G213_MODE_WAVE;
|
||||
Wave.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_DIRECTION_LR | MODE_FLAG_HAS_DIRECTION_UD;
|
||||
Wave.color_mode = MODE_COLORS_NONE;
|
||||
Wave.speed_min = LOGITECH_G213_SPEED_SLOWEST;
|
||||
Wave.speed_max = LOGITECH_G213_SPEED_FASTEST;
|
||||
Wave.speed = LOGITECH_G213_SPEED_NORMAL;
|
||||
Wave.direction = MODE_DIRECTION_LEFT;
|
||||
modes.push_back(Wave);
|
||||
|
||||
mode Breathing;
|
||||
Breathing.name = "Breathing";
|
||||
Breathing.value = LOGITECH_G213_MODE_BREATHING;
|
||||
Breathing.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED;
|
||||
Breathing.colors_min = 1;
|
||||
Breathing.colors_max = 1;
|
||||
Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
Breathing.colors.resize(1);
|
||||
Breathing.speed_min = LOGITECH_G213_SPEED_SLOWEST;
|
||||
Breathing.speed_max = LOGITECH_G213_SPEED_FASTEST;
|
||||
Breathing.speed = LOGITECH_G213_SPEED_NORMAL;
|
||||
modes.push_back(Breathing);
|
||||
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
RGBController_LogitechG213::~RGBController_LogitechG213()
|
||||
{
|
||||
delete controller;
|
||||
}
|
||||
|
||||
void RGBController_LogitechG213::SetupZones()
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Set up zones |
|
||||
\*---------------------------------------------------------*/
|
||||
zone new_zone;
|
||||
new_zone.name = "Keyboard";
|
||||
new_zone.type = ZONE_TYPE_LINEAR;
|
||||
new_zone.leds_min = 5;
|
||||
new_zone.leds_max = 5;
|
||||
new_zone.leds_count = 5;
|
||||
|
||||
new_zone.matrix_map = NULL;
|
||||
|
||||
zones.push_back(new_zone);
|
||||
|
||||
for(unsigned int led_idx = 0; led_idx < LOGITECH_G213_ZONES; led_idx++)
|
||||
{
|
||||
led new_led;
|
||||
new_led.name = led_names[led_idx];
|
||||
new_led.value = led_values[led_idx];
|
||||
leds.push_back(new_led);
|
||||
}
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_LogitechG213::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_LogitechG213::DeviceUpdateLEDs()
|
||||
{
|
||||
for(std::size_t led_idx = 0; led_idx < leds.size(); led_idx++)
|
||||
{
|
||||
controller->SetDirect((unsigned char)leds[led_idx].value, RGBGetRValue(colors[led_idx]), RGBGetGValue(colors[led_idx]), RGBGetBValue(colors[led_idx]));
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_LogitechG213::UpdateZoneLEDs(int zone)
|
||||
{
|
||||
controller->SetDirect((unsigned char) zone, RGBGetRValue(zones[zone].colors[0]), RGBGetGValue(zones[zone].colors[0]), RGBGetBValue(zones[zone].colors[0]));
|
||||
}
|
||||
|
||||
void RGBController_LogitechG213::UpdateSingleLED(int led)
|
||||
{
|
||||
controller->SetDirect(leds[led].value, RGBGetRValue(colors[led]), RGBGetGValue(colors[led]), RGBGetBValue(colors[led]));
|
||||
}
|
||||
|
||||
void RGBController_LogitechG213::DeviceUpdateMode()
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Direct mode does not send a mode packet |
|
||||
| Call UpdateLEDs to send direct packet |
|
||||
\*---------------------------------------------------------*/
|
||||
if(active_mode == 0xFFFF)
|
||||
{
|
||||
UpdateLEDs();
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned char red = 0;
|
||||
unsigned char grn = 0;
|
||||
unsigned char blu = 0;
|
||||
unsigned char direction = 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]);
|
||||
}
|
||||
|
||||
switch (modes[active_mode].direction)
|
||||
{
|
||||
case MODE_DIRECTION_LEFT:
|
||||
// Right to left
|
||||
direction = LOGITECH_G213_WAVE_MODE_LEFT;
|
||||
break;
|
||||
case MODE_DIRECTION_RIGHT:
|
||||
// Left to right
|
||||
direction = LOGITECH_G213_WAVE_MODE_RIGHT;
|
||||
break;
|
||||
case MODE_DIRECTION_UP:
|
||||
// Edge to center
|
||||
direction = LOGITECH_G213_WAVE_MODE_EDGE_CENTER;
|
||||
break;
|
||||
case MODE_DIRECTION_DOWN:
|
||||
// Center to edge
|
||||
direction = LOGITECH_G213_WAVE_MODE_CENTER_EDGE;
|
||||
break;
|
||||
}
|
||||
|
||||
controller->SetMode(modes[active_mode].value, modes[active_mode].speed, direction, red, grn, blu);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_LogitechG213.h |
|
||||
| |
|
||||
| RGBController for Logitech G203L |
|
||||
| |
|
||||
| Eric Samuelson (edbgon) 06 Oct 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "LogitechG213Controller.h"
|
||||
|
||||
class RGBController_LogitechG213 : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_LogitechG213(LogitechG213Controller* controller_ptr);
|
||||
~RGBController_LogitechG213();
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void DeviceUpdateMode();
|
||||
|
||||
private:
|
||||
LogitechG213Controller* controller;
|
||||
};
|
||||
Reference in New Issue
Block a user