Move and update Logitech G560 controller files to new standardized header comment
This commit is contained in:
parent
6c30e92b21
commit
433ac0b8ce
5 changed files with 71 additions and 67 deletions
|
|
@ -0,0 +1,148 @@
|
|||
/*---------------------------------------------------------*\
|
||||
| LogitechG560Controller.cpp |
|
||||
| |
|
||||
| Driver for Logitech G560 |
|
||||
| |
|
||||
| Cheerpipe 28 Oct 2020 |
|
||||
| based on TheRogueZeta 31 Aug 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <cstring>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "LogitechG560Controller.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
LogitechG560Controller::LogitechG560Controller(hid_device* dev_handle, const char* path)
|
||||
{
|
||||
dev = dev_handle;
|
||||
location = path;
|
||||
}
|
||||
|
||||
LogitechG560Controller::~LogitechG560Controller()
|
||||
{
|
||||
hid_close(dev);
|
||||
}
|
||||
|
||||
std::string LogitechG560Controller::GetDeviceLocation()
|
||||
{
|
||||
return("HID: " + location);
|
||||
}
|
||||
|
||||
void LogitechG560Controller::SetDirectMode(uint8_t zone)
|
||||
{
|
||||
unsigned char usb_buf[LOGI_G560_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_G560_LED_PACKET_SIZE);
|
||||
}
|
||||
|
||||
void LogitechG560Controller::SetOffMode(uint8_t zone)
|
||||
{
|
||||
unsigned char usb_buf[LOGI_G560_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_G560_LED_PACKET_SIZE);
|
||||
}
|
||||
|
||||
void LogitechG560Controller::SendSpeakerMode
|
||||
(
|
||||
unsigned char zone,
|
||||
unsigned char mode,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
)
|
||||
{
|
||||
unsigned char usb_buf[LOGI_G560_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_G560_MODE_DIRECT) //G560 only has Direct Mode.
|
||||
{
|
||||
usb_buf[0x09] = 0x02;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
fail_retry_write(dev, usb_buf, LOGI_G560_LED_PACKET_SIZE);
|
||||
}
|
||||
|
||||
void LogitechG560Controller::fail_retry_write(hid_device *device, const unsigned char *data, size_t length)
|
||||
{
|
||||
unsigned char usb_buf_out[LOGI_G560_LED_PACKET_SIZE];
|
||||
unsigned int write_max_retry = LOGI_G560_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_G560_LED_PACKET_SIZE, 20);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
write_max_retry--;
|
||||
std::this_thread::sleep_for(10ms);
|
||||
}
|
||||
|
||||
}while (write_max_retry > 0);
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
/*---------------------------------------------------------*\
|
||||
| LogitechG560Controller.h |
|
||||
| |
|
||||
| Driver for Logitech G560 |
|
||||
| |
|
||||
| Cheerpipe 28 Oct 2020 |
|
||||
| based on TheRogueZeta 31 Aug 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <hidapi/hidapi.h>
|
||||
#include "RGBController.h"
|
||||
|
||||
#define LOGI_G560_LED_PACKET_SIZE 20
|
||||
#define LOGI_G560_LED_COMMAND_SEND_RETRIES 3
|
||||
|
||||
enum
|
||||
{
|
||||
LOGITECH_G560_MODE_OFF = 0x00,
|
||||
LOGITECH_G560_MODE_DIRECT = 0x01,
|
||||
LOGITECH_G560_MODE_CYCLE = 0x02,
|
||||
LOGITECH_G560_MODE_BREATHING = 0x03,
|
||||
};
|
||||
|
||||
class LogitechG560Controller
|
||||
{
|
||||
public:
|
||||
LogitechG560Controller(hid_device* dev_handle, const char* path);
|
||||
~LogitechG560Controller();
|
||||
|
||||
std::string GetDeviceLocation();
|
||||
|
||||
void SetDirectMode(uint8_t zone);
|
||||
void SetOffMode(uint8_t zone);
|
||||
|
||||
void SendSpeakerMode
|
||||
(
|
||||
unsigned char zone,
|
||||
unsigned char mode,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
);
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
std::string location;
|
||||
|
||||
void fail_retry_write(hid_device *device, const unsigned char *data, size_t length);
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,164 @@
|
|||
/*---------------------------------------------------------*\
|
||||
| RGBController_LogitechG560.cpp |
|
||||
| |
|
||||
| RGBController for Logitech G560 |
|
||||
| |
|
||||
| Cheerpipe 28 Oct 2020 |
|
||||
| based on TheRogueZeta 31 Aug 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "RGBController_LogitechG560.h"
|
||||
|
||||
/**------------------------------------------------------------------*\
|
||||
@name Logitech G560
|
||||
@category Speaker
|
||||
@type USB
|
||||
@save :x:
|
||||
@direct :white_check_mark:
|
||||
@effects :x:
|
||||
@detectors DetectLogitechG560
|
||||
@comment
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
RGBController_LogitechG560::RGBController_LogitechG560(LogitechG560Controller* controller_ptr)
|
||||
{
|
||||
controller = controller_ptr;
|
||||
|
||||
name = "Logitech G560 Lightsync Speaker";
|
||||
vendor = "Logitech";
|
||||
type = DEVICE_TYPE_SPEAKER;
|
||||
description = "Logitech G560 Lightsync Speaker";
|
||||
location = controller->GetDeviceLocation();
|
||||
|
||||
mode Off;
|
||||
Off.name = "Off";
|
||||
Off.value = LOGITECH_G560_MODE_OFF;
|
||||
Off.flags = 0;
|
||||
Off.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Off);
|
||||
|
||||
mode Direct;
|
||||
Direct.name = "Direct";
|
||||
Direct.value = LOGITECH_G560_MODE_DIRECT;
|
||||
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
Direct.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Direct);
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
void RGBController_LogitechG560::SetupZones()
|
||||
{
|
||||
zone G560_left_front;
|
||||
G560_left_front.name = "Left Front";
|
||||
G560_left_front.type = ZONE_TYPE_SINGLE;
|
||||
G560_left_front.leds_min = 1;
|
||||
G560_left_front.leds_max = 1;
|
||||
G560_left_front.leds_count = 1;
|
||||
G560_left_front.matrix_map = NULL;
|
||||
zones.push_back(G560_left_front);
|
||||
|
||||
led G560_left_front_led;
|
||||
G560_left_front_led.name = "Left Front";
|
||||
G560_left_front_led.value = 0x00;
|
||||
leds.push_back(G560_left_front_led);
|
||||
|
||||
|
||||
zone G560_right_front;
|
||||
G560_right_front.name = "Right Front";
|
||||
G560_right_front.type = ZONE_TYPE_SINGLE;
|
||||
G560_right_front.leds_min = 1;
|
||||
G560_right_front.leds_max = 1;
|
||||
G560_right_front.leds_count = 1;
|
||||
G560_right_front.matrix_map = NULL;
|
||||
zones.push_back(G560_right_front);
|
||||
|
||||
led G560_right_front_led;
|
||||
G560_right_front_led.name = "Right Front";
|
||||
G560_right_front_led.value = 0x01;
|
||||
leds.push_back(G560_right_front_led);
|
||||
|
||||
|
||||
zone G560_left_rear;
|
||||
G560_left_rear.name = "Left Rear";
|
||||
G560_left_rear.type = ZONE_TYPE_SINGLE;
|
||||
G560_left_rear.leds_min = 1;
|
||||
G560_left_rear.leds_max = 1;
|
||||
G560_left_rear.leds_count = 1;
|
||||
G560_left_rear.matrix_map = NULL;
|
||||
zones.push_back(G560_left_rear);
|
||||
|
||||
led G560_left_read_led;
|
||||
G560_left_read_led.name = "Left Rear";
|
||||
G560_left_read_led.value = 0x02;
|
||||
leds.push_back(G560_left_read_led);
|
||||
|
||||
|
||||
zone G560_right_rear;
|
||||
G560_right_rear.name = "Right Rear";
|
||||
G560_right_rear.type = ZONE_TYPE_SINGLE;
|
||||
G560_right_rear.leds_min = 1;
|
||||
G560_right_rear.leds_max = 1;
|
||||
G560_right_rear.leds_count = 1;
|
||||
G560_right_rear.matrix_map = NULL;
|
||||
zones.push_back(G560_right_rear);
|
||||
|
||||
led G560_right_rear_led;
|
||||
G560_right_rear_led.name = "Right Rear";
|
||||
G560_right_rear_led.value = 0x03;
|
||||
leds.push_back(G560_right_rear_led);
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_LogitechG560::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_LogitechG560::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->SendSpeakerMode((unsigned char)leds[led_idx].value, modes[active_mode].value, red, grn, blu);
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_LogitechG560::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_LogitechG560::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_LogitechG560::DeviceUpdateMode()
|
||||
{
|
||||
for(std::size_t led_idx = 0; led_idx < leds.size(); led_idx++)
|
||||
{
|
||||
if(modes[active_mode].value == LOGITECH_G560_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_LogitechG560.h |
|
||||
| |
|
||||
| RGBController for Logitech G560 |
|
||||
| |
|
||||
| Cheerpipe 28 Oct 2020 |
|
||||
| based on TheRogueZeta 31 Aug 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "LogitechG560Controller.h"
|
||||
|
||||
class RGBController_LogitechG560 : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_LogitechG560(LogitechG560Controller* controller_ptr);
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void DeviceUpdateMode();
|
||||
|
||||
private:
|
||||
LogitechG560Controller* controller;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue