Add MadCatzCyborgController for MadCatz Cyborg Gaming Light
This commit is contained in:
parent
3e7ad705bb
commit
7177a534b9
5 changed files with 325 additions and 0 deletions
|
|
@ -0,0 +1,99 @@
|
|||
/*---------------------------------------------------------*\
|
||||
| MadCatzCyborgController.cpp |
|
||||
| |
|
||||
| Driver for MadCatz Cyborg Gaming Light |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "MadCatzCyborgController.h"
|
||||
#include "StringUtils.h"
|
||||
#include <cstring>
|
||||
|
||||
MadCatzCyborgController::MadCatzCyborgController(hid_device* dev_handle, const char* path)
|
||||
{
|
||||
dev = dev_handle;
|
||||
location = path;
|
||||
}
|
||||
|
||||
MadCatzCyborgController::~MadCatzCyborgController()
|
||||
{
|
||||
if(dev != nullptr)
|
||||
{
|
||||
hid_close(dev);
|
||||
dev = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::string MadCatzCyborgController::GetDeviceLocation()
|
||||
{
|
||||
return(location);
|
||||
}
|
||||
|
||||
std::string MadCatzCyborgController::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 MadCatzCyborgController::Initialize()
|
||||
{
|
||||
if(dev == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Enable the device
|
||||
unsigned char enable_buf[2] = { CMD_ENABLE, 0x00 };
|
||||
hid_send_feature_report(dev, enable_buf, 2);
|
||||
}
|
||||
|
||||
void MadCatzCyborgController::SetLEDColor(unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
if(dev == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Format: [CMD_COLOR][0x00][R][G][B][0x00][0x00][0x00][0x00]
|
||||
unsigned char usb_buf[9] =
|
||||
{
|
||||
CMD_COLOR,
|
||||
0x00,
|
||||
red,
|
||||
green,
|
||||
blue,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00
|
||||
};
|
||||
|
||||
hid_send_feature_report(dev, usb_buf, 9);
|
||||
}
|
||||
|
||||
void MadCatzCyborgController::SetIntensity(unsigned char intensity)
|
||||
{
|
||||
if(dev == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Clamp intensity to 0-100
|
||||
if(intensity > 100)
|
||||
{
|
||||
intensity = 100;
|
||||
}
|
||||
|
||||
// Format: [CMD_INTENSITY][0x00][intensity_value]
|
||||
unsigned char usb_buf[3] = { CMD_INTENSITY, 0x00, intensity };
|
||||
hid_send_feature_report(dev, usb_buf, 3);
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*---------------------------------------------------------*\
|
||||
| MadCatzCyborgController.h |
|
||||
| |
|
||||
| Driver for MadCatz Cyborg Gaming Light |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <hidapi.h>
|
||||
|
||||
class MadCatzCyborgController
|
||||
{
|
||||
public:
|
||||
MadCatzCyborgController(hid_device* dev_handle, const char* path);
|
||||
~MadCatzCyborgController();
|
||||
|
||||
std::string GetDeviceLocation();
|
||||
std::string GetSerialString();
|
||||
|
||||
void Initialize();
|
||||
void SetLEDColor(unsigned char red, unsigned char green, unsigned char blue);
|
||||
void SetIntensity(unsigned char intensity);
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
std::string location;
|
||||
|
||||
// Protocol constants
|
||||
enum Commands
|
||||
{
|
||||
CMD_ENABLE = 0xA1,
|
||||
CMD_COLOR = 0xA2,
|
||||
CMD_INTENSITY = 0xA6
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
/*---------------------------------------------------------*\
|
||||
| MadCatzCyborgControllerDetect.cpp |
|
||||
| |
|
||||
| Detector for MadCatz Cyborg Gaming Light |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "Detector.h"
|
||||
#include "MadCatzCyborgController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_MadCatzCyborg.h"
|
||||
#include <hidapi.h>
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| MadCatz Cyborg VID/PID |
|
||||
\*-----------------------------------------------------*/
|
||||
#define MADCATZ_VID 0x06A3
|
||||
#define MADCATZ_CYBORG_PID 0x0DC5
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectMadCatzCyborgControllers *
|
||||
* *
|
||||
* Tests the USB address to find MadCatz Cyborg Gaming Light devices *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectMadCatzCyborgControllers(hid_device_info* info, const std::string& name)
|
||||
{
|
||||
hid_device* dev = hid_open_path(info->path);
|
||||
|
||||
if(dev)
|
||||
{
|
||||
MadCatzCyborgController* controller = new MadCatzCyborgController(dev, info->path);
|
||||
controller->Initialize();
|
||||
|
||||
RGBController_MadCatzCyborg* rgb_controller = new RGBController_MadCatzCyborg(controller);
|
||||
|
||||
ResourceManager::get()->RegisterRGBController(rgb_controller);
|
||||
}
|
||||
}
|
||||
|
||||
REGISTER_HID_DETECTOR("MadCatz Cyborg Gaming Light", DetectMadCatzCyborgControllers, MADCATZ_VID, MADCATZ_CYBORG_PID);
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
/*---------------------------------------------------------*\
|
||||
| RGBController_MadCatzCyborg.cpp |
|
||||
| |
|
||||
| RGB Controller for MadCatz Cyborg Gaming Light |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "RGBController_MadCatzCyborg.h"
|
||||
|
||||
/**--------------------------------------------------------*\
|
||||
@name MadCatz Cyborg Gaming Light
|
||||
@category Accessory
|
||||
@type USB
|
||||
@save :x:
|
||||
@direct :white_check_mark:
|
||||
@effects :x:
|
||||
@detectors DetectMadCatzCyborgControllers
|
||||
@comment The MadCatz Cyborg Gaming Light is an ambient lighting device.
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
RGBController_MadCatzCyborg::RGBController_MadCatzCyborg(MadCatzCyborgController* controller_ptr)
|
||||
{
|
||||
controller = controller_ptr;
|
||||
|
||||
name = "MadCatz Cyborg Gaming Light";
|
||||
vendor = "MadCatz";
|
||||
type = DEVICE_TYPE_ACCESSORY;
|
||||
description = "MadCatz Cyborg Gaming Light";
|
||||
location = controller->GetDeviceLocation();
|
||||
serial = controller->GetSerialString();
|
||||
|
||||
mode Direct;
|
||||
Direct.name = "Direct";
|
||||
Direct.value = 0;
|
||||
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS;
|
||||
Direct.color_mode = MODE_COLORS_PER_LED;
|
||||
Direct.brightness_min = 0;
|
||||
Direct.brightness_max = 100;
|
||||
Direct.brightness = 100;
|
||||
modes.push_back(Direct);
|
||||
|
||||
SetupZones();
|
||||
|
||||
controller->SetIntensity(modes[active_mode].brightness);
|
||||
}
|
||||
|
||||
RGBController_MadCatzCyborg::~RGBController_MadCatzCyborg()
|
||||
{
|
||||
delete controller;
|
||||
}
|
||||
|
||||
void RGBController_MadCatzCyborg::SetupZones()
|
||||
{
|
||||
zone cyborg_zone;
|
||||
|
||||
cyborg_zone.name = "Cyborg";
|
||||
cyborg_zone.type = ZONE_TYPE_SINGLE;
|
||||
cyborg_zone.leds_min = 1;
|
||||
cyborg_zone.leds_max = 1;
|
||||
cyborg_zone.leds_count = 1;
|
||||
cyborg_zone.matrix_map = NULL;
|
||||
|
||||
zones.push_back(cyborg_zone);
|
||||
|
||||
led cyborg_led;
|
||||
cyborg_led.name = "LED";
|
||||
leds.push_back(cyborg_led);
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_MadCatzCyborg::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
// Single LED device - nothing to resize
|
||||
}
|
||||
|
||||
void RGBController_MadCatzCyborg::DeviceUpdateLEDs()
|
||||
{
|
||||
if(colors.size() > 0)
|
||||
{
|
||||
RGBColor color = colors[0];
|
||||
controller->SetLEDColor(RGBGetRValue(color), RGBGetGValue(color), RGBGetBValue(color));
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_MadCatzCyborg::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_MadCatzCyborg::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_MadCatzCyborg::DeviceUpdateMode()
|
||||
{
|
||||
if(modes[active_mode].flags & MODE_FLAG_HAS_BRIGHTNESS)
|
||||
{
|
||||
controller->SetIntensity(modes[active_mode].brightness);
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_MadCatzCyborg::SetCustomMode()
|
||||
{
|
||||
active_mode = 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
/*---------------------------------------------------------*\
|
||||
| RGBController_MadCatzCyborg.h |
|
||||
| |
|
||||
| RGB Controller for MadCatz Cyborg Gaming Light |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "MadCatzCyborgController.h"
|
||||
|
||||
class RGBController_MadCatzCyborg : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_MadCatzCyborg(MadCatzCyborgController* controller_ptr);
|
||||
~RGBController_MadCatzCyborg();
|
||||
|
||||
void SetupZones();
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void DeviceUpdateMode();
|
||||
void SetCustomMode();
|
||||
|
||||
private:
|
||||
MadCatzCyborgController* controller;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue