Move and update Logitech G213 controller files to new standardized header comment
This commit is contained in:
parent
52423a325e
commit
6c30e92b21
5 changed files with 66 additions and 53 deletions
|
|
@ -1,153 +0,0 @@
|
|||
/*-----------------------------------------*\
|
||||
| LogitechG213Controller.cpp |
|
||||
| |
|
||||
| Generic RGB Interface for Logitech G213 |
|
||||
| |
|
||||
| Eric Samuelson (edbgon) 10/06/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "LogitechG213Controller.h"
|
||||
#include <cstring>
|
||||
|
||||
LogitechG213Controller::LogitechG213Controller(hid_device* dev_handle, const char* path)
|
||||
{
|
||||
dev = dev_handle;
|
||||
location = path;
|
||||
}
|
||||
|
||||
LogitechG213Controller::~LogitechG213Controller()
|
||||
{
|
||||
hid_close(dev);
|
||||
}
|
||||
|
||||
std::string LogitechG213Controller::GetDeviceLocation()
|
||||
{
|
||||
return("HID: " + location);
|
||||
}
|
||||
|
||||
std::string LogitechG213Controller::GetSerialString()
|
||||
{
|
||||
wchar_t serial_string[128];
|
||||
int ret = hid_get_serial_number_string(dev, serial_string, 128);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return("");
|
||||
}
|
||||
|
||||
std::wstring return_wstring = serial_string;
|
||||
std::string return_string(return_wstring.begin(), return_wstring.end());
|
||||
|
||||
return(return_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, (unsigned char *)usb_buf, 20);
|
||||
hid_read(dev, (unsigned char *)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
|
||||
)
|
||||
{
|
||||
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, (unsigned char *)usb_buf, 20);
|
||||
hid_read(dev, (unsigned char *)usb_buf, 20);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue