Publish LumaOps source
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| LogitechG933Controller.cpp |
|
||||
| |
|
||||
| Driver for Logitech G933 |
|
||||
| |
|
||||
| Edbgon 21 Jun 2021 |
|
||||
| Based on TheRogueZeta 31 Aug 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <cstring>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "LogitechG933Controller.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
LogitechG933Controller::LogitechG933Controller(hid_device* dev_handle, const char* path, std::string dev_name)
|
||||
{
|
||||
dev = dev_handle;
|
||||
location = path;
|
||||
name = dev_name;
|
||||
}
|
||||
|
||||
LogitechG933Controller::~LogitechG933Controller()
|
||||
{
|
||||
hid_close(dev);
|
||||
}
|
||||
|
||||
std::string LogitechG933Controller::GetDeviceLocation()
|
||||
{
|
||||
return("HID: " + location);
|
||||
}
|
||||
|
||||
std::string LogitechG933Controller::GetDeviceName()
|
||||
{
|
||||
return(name);
|
||||
}
|
||||
|
||||
void LogitechG933Controller::SetDirectMode(uint8_t zone)
|
||||
{
|
||||
unsigned char usb_buf[LOGI_G933_LED_PACKET_SIZE];
|
||||
|
||||
usb_buf[0x00] = 0x11;
|
||||
usb_buf[0x01] = 0xFF;
|
||||
usb_buf[0x02] = 0x04;
|
||||
usb_buf[0x03] = 0xCA;
|
||||
usb_buf[0x04] = zone;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
fail_retry_write(dev, usb_buf, LOGI_G933_LED_PACKET_SIZE);
|
||||
}
|
||||
|
||||
void LogitechG933Controller::SetOffMode(uint8_t zone)
|
||||
{
|
||||
unsigned char usb_buf[LOGI_G933_LED_PACKET_SIZE];
|
||||
|
||||
usb_buf[0x00] = 0x11;
|
||||
usb_buf[0x01] = 0xFF;
|
||||
usb_buf[0x02] = 0x04;
|
||||
usb_buf[0x03] = 0x3F;
|
||||
usb_buf[0x04] = zone;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
fail_retry_write(dev, usb_buf, LOGI_G933_LED_PACKET_SIZE);
|
||||
}
|
||||
|
||||
void LogitechG933Controller::SendHeadsetMode
|
||||
(
|
||||
unsigned char zone,
|
||||
unsigned char mode,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
)
|
||||
{
|
||||
unsigned char usb_buf[LOGI_G933_LED_PACKET_SIZE];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Lighting Control |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x11;
|
||||
usb_buf[0x01] = 0xFF;
|
||||
usb_buf[0x02] = 0x04;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| This packet sets speaker into direct mode. This mode |
|
||||
| is used by Lightsync Ambilight and Music Visualizer |
|
||||
| realtime effect. |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x03] = 0x3A;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up mode and speed |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x04] = zone;
|
||||
usb_buf[0x05] = mode;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| And set up the colors |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x06] = red;
|
||||
usb_buf[0x07] = green;
|
||||
usb_buf[0x08] = blue;
|
||||
|
||||
if(mode == LOGITECH_G933_MODE_DIRECT) //G933 only has Direct Mode.
|
||||
{
|
||||
usb_buf[0x09] = 0x02;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
fail_retry_write(dev, usb_buf, LOGI_G933_LED_PACKET_SIZE);
|
||||
}
|
||||
|
||||
void LogitechG933Controller::fail_retry_write(hid_device *device, const unsigned char *data, size_t length)
|
||||
{
|
||||
unsigned char usb_buf_out[LOGI_G933_LED_PACKET_SIZE];
|
||||
unsigned int write_max_retry = LOGI_G933_LED_COMMAND_SEND_RETRIES;
|
||||
do
|
||||
{
|
||||
std::this_thread::sleep_for(1ms);
|
||||
int ret = hid_write(device, data, length);
|
||||
|
||||
/*-------------------------------------------------------------------------------------*\
|
||||
| HID write fails if a change led color and set volume command are sent at |
|
||||
| the same time because RGB controller and volume control shares the same interface. |
|
||||
\*-------------------------------------------------------------------------------------*/
|
||||
if(ret == 20)
|
||||
{
|
||||
std::this_thread::sleep_for(1ms);
|
||||
hid_read_timeout(dev, usb_buf_out, LOGI_G933_LED_PACKET_SIZE, 20);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
write_max_retry--;
|
||||
std::this_thread::sleep_for(10ms);
|
||||
}
|
||||
|
||||
}while (write_max_retry > 0);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| LogitechG933Controller.h |
|
||||
| |
|
||||
| Driver for Logitech G933 |
|
||||
| |
|
||||
| Edbgon 21 Jun 2021 |
|
||||
| Based on TheRogueZeta 31 Aug 2020 |
|
||||
| |
|
||||
| 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"
|
||||
|
||||
#define LOGI_G933_LED_PACKET_SIZE 20
|
||||
#define LOGI_G933_LED_COMMAND_SEND_RETRIES 3
|
||||
|
||||
enum
|
||||
{
|
||||
LOGITECH_G933_MODE_OFF = 0x00,
|
||||
LOGITECH_G933_MODE_DIRECT = 0x01,
|
||||
LOGITECH_G933_MODE_CYCLE = 0x02,
|
||||
LOGITECH_G933_MODE_BREATHING = 0x03,
|
||||
};
|
||||
|
||||
class LogitechG933Controller
|
||||
{
|
||||
public:
|
||||
LogitechG933Controller(hid_device* dev_handle, const char* path, std::string dev_name);
|
||||
~LogitechG933Controller();
|
||||
|
||||
std::string GetDeviceLocation();
|
||||
std::string GetDeviceName();
|
||||
|
||||
void SetDirectMode(uint8_t zone);
|
||||
void SetOffMode(uint8_t zone);
|
||||
|
||||
void SendHeadsetMode
|
||||
(
|
||||
unsigned char zone,
|
||||
unsigned char mode,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
);
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
std::string location;
|
||||
std::string name;
|
||||
|
||||
void fail_retry_write(hid_device *device, const unsigned char *data, size_t length);
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_LogitechG933.cpp |
|
||||
| |
|
||||
| RGBController for Logitech G933 |
|
||||
| |
|
||||
| Edbgon 21 Jun 2021 |
|
||||
| Based on TheRogueZeta 31 Aug 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "RGBController_LogitechG933.h"
|
||||
|
||||
/**------------------------------------------------------------------*\
|
||||
@name Logitech G933
|
||||
@category Headset
|
||||
@type USB
|
||||
@save :x:
|
||||
@direct :white_check_mark:
|
||||
@effects :x:
|
||||
@detectors DetectLogitechG933
|
||||
@comment
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
RGBController_LogitechG933::RGBController_LogitechG933(LogitechG933Controller* controller_ptr)
|
||||
{
|
||||
controller = controller_ptr;
|
||||
|
||||
name = controller->GetDeviceName();
|
||||
vendor = "Logitech";
|
||||
type = DEVICE_TYPE_HEADSET;
|
||||
description = "Logitech G933 Lightsync Headset";
|
||||
location = controller->GetDeviceLocation();
|
||||
|
||||
mode Off;
|
||||
Off.name = "Off";
|
||||
Off.value = LOGITECH_G933_MODE_OFF;
|
||||
Off.flags = 0;
|
||||
Off.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Off);
|
||||
|
||||
mode Direct;
|
||||
Direct.name = "Direct";
|
||||
Direct.value = LOGITECH_G933_MODE_DIRECT;
|
||||
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
Direct.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Direct);
|
||||
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
void RGBController_LogitechG933::SetupZones()
|
||||
{
|
||||
zone G933_logo;
|
||||
G933_logo.name = "Logo";
|
||||
G933_logo.type = ZONE_TYPE_SINGLE;
|
||||
G933_logo.leds_min = 1;
|
||||
G933_logo.leds_max = 1;
|
||||
G933_logo.leds_count = 1;
|
||||
G933_logo.matrix_map = NULL;
|
||||
zones.push_back(G933_logo);
|
||||
|
||||
led G933_logo_led;
|
||||
G933_logo_led.name = "Logo";
|
||||
G933_logo_led.value = 0x00;
|
||||
leds.push_back(G933_logo_led);
|
||||
|
||||
zone G933_strip;
|
||||
G933_strip.name = "LED Strip";
|
||||
G933_strip.type = ZONE_TYPE_SINGLE;
|
||||
G933_strip.leds_min = 1;
|
||||
G933_strip.leds_max = 1;
|
||||
G933_strip.leds_count = 1;
|
||||
G933_strip.matrix_map = NULL;
|
||||
zones.push_back(G933_strip);
|
||||
|
||||
led G933_strip_led;
|
||||
G933_strip_led.name = "Led Strip";
|
||||
G933_strip_led.value = 0x01;
|
||||
leds.push_back(G933_strip_led);
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_LogitechG933::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_LogitechG933::DeviceUpdateLEDs()
|
||||
{
|
||||
for(std::size_t led_idx = 0; led_idx < leds.size(); led_idx++)
|
||||
{
|
||||
unsigned char red = RGBGetRValue(colors[led_idx]);
|
||||
unsigned char grn = RGBGetGValue(colors[led_idx]);
|
||||
unsigned char blu = RGBGetBValue(colors[led_idx]);
|
||||
|
||||
controller->SendHeadsetMode((unsigned char)leds[led_idx].value, modes[active_mode].value, red, grn, blu);
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_LogitechG933::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_LogitechG933::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_LogitechG933::DeviceUpdateMode()
|
||||
{
|
||||
for(std::size_t led_idx = 0; led_idx < leds.size(); led_idx++)
|
||||
{
|
||||
if(modes[active_mode].value == LOGITECH_G933_MODE_OFF)
|
||||
{
|
||||
controller->SetOffMode(leds[led_idx].value);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Required to "reset" RGB controller and start receiving |
|
||||
| color in direct mode |
|
||||
\*---------------------------------------------------------*/
|
||||
controller->SetDirectMode(leds[led_idx].value);
|
||||
}
|
||||
|
||||
}
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_LogitechG933.h |
|
||||
| |
|
||||
| RGBController for Logitech G933 |
|
||||
| |
|
||||
| Edbgon 21 Jun 2021 |
|
||||
| Based on TheRogueZeta 31 Aug 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "LogitechG933Controller.h"
|
||||
|
||||
class RGBController_LogitechG933 : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_LogitechG933(LogitechG933Controller* controller_ptr);
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void DeviceUpdateMode();
|
||||
|
||||
private:
|
||||
LogitechG933Controller* controller;
|
||||
};
|
||||
Reference in New Issue
Block a user