From b32ef761215ade6e235ee9d4fc7958eb398e9424 Mon Sep 17 00:00:00 2001 From: Cheerpipe Date: Mon, 5 Apr 2021 16:31:49 -0400 Subject: [PATCH] Creative Sound BlasterX G6 support Commits squashed and amended for code style by Adam Honse --- .../CreativeControllerDetect.cpp | 30 +++++++ .../CreativeSoundBlasterXG6Controller.cpp | 82 +++++++++++++++++++ .../CreativeSoundBlasterXG6Controller.h | 20 +++++ .../RGBController_CreativeSoundBlasterXG6.cpp | 81 ++++++++++++++++++ .../RGBController_CreativeSoundBlasterXG6.h | 24 ++++++ OpenRGB.pro | 6 ++ 6 files changed, 243 insertions(+) create mode 100644 Controllers/CreativeController/CreativeControllerDetect.cpp create mode 100644 Controllers/CreativeController/CreativeSoundBlasterXG6Controller.cpp create mode 100644 Controllers/CreativeController/CreativeSoundBlasterXG6Controller.h create mode 100644 Controllers/CreativeController/RGBController_CreativeSoundBlasterXG6.cpp create mode 100644 Controllers/CreativeController/RGBController_CreativeSoundBlasterXG6.h diff --git a/Controllers/CreativeController/CreativeControllerDetect.cpp b/Controllers/CreativeController/CreativeControllerDetect.cpp new file mode 100644 index 00000000..68945eca --- /dev/null +++ b/Controllers/CreativeController/CreativeControllerDetect.cpp @@ -0,0 +1,30 @@ +#include "CreativeSoundBlasterXG6Controller.h" +#include "RGBController_CreativeSoundBlasterXG6.h" +#include "Detector.h" +#include + +/*-----------------------------------------------------*\ +| Creative vendor ID | +\*-----------------------------------------------------*/ +#define CREATIVE_VID 0x041E +/*-----------------------------------------------------*\ +| SoundCards | +\*-----------------------------------------------------*/ +#define CREATIVE_SOUNDBLASTERX_G6_PID 0x3256 + +void DetectCreativeDevice(hid_device_info* info, const std::string& name) +{ + hid_device* dev = hid_open_path(info->path); + if(dev) + { + CreativeSoundBlasterXG6Controller* controller = new CreativeSoundBlasterXG6Controller(dev, info->path); + RGBController_CreativeSoundBlasterXG6* rgb_controller = new RGBController_CreativeSoundBlasterXG6(controller); + rgb_controller->name = name; + ResourceManager::get()->RegisterRGBController(rgb_controller); + } +} + +/*-------------------------------------------------------------------------------------------------------------------------------------------------*\ +| Sound Cards | +\*-------------------------------------------------------------------------------------------------------------------------------------------------*/ +REGISTER_HID_DETECTOR_I("Creative SoundBlasterX G6", DetectCreativeDevice, CREATIVE_VID, CREATIVE_SOUNDBLASTERX_G6_PID, 4); diff --git a/Controllers/CreativeController/CreativeSoundBlasterXG6Controller.cpp b/Controllers/CreativeController/CreativeSoundBlasterXG6Controller.cpp new file mode 100644 index 00000000..2680970f --- /dev/null +++ b/Controllers/CreativeController/CreativeSoundBlasterXG6Controller.cpp @@ -0,0 +1,82 @@ +#include "CreativeSoundBlasterXG6Controller.h" + +CreativeSoundBlasterXG6Controller::CreativeSoundBlasterXG6Controller(hid_device* dev_handle, const char* path) +{ + dev = dev_handle; + location = path; +} + +CreativeSoundBlasterXG6Controller::~CreativeSoundBlasterXG6Controller() +{ + hid_close(dev); +} + +std::string CreativeSoundBlasterXG6Controller::GetDeviceLocation() +{ + return("HID " + location); +} + +void CreativeSoundBlasterXG6Controller::SetLedColor (unsigned char red, unsigned char green, unsigned char blue) +{ + unsigned char usb_buf[64]; + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(usb_buf, 0x00, sizeof(usb_buf)); + + //5A 3A 02 06 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + usb_buf[0x01] = 0x5A; + usb_buf[0x02] = 0x3A; + usb_buf[0x03] = 0x02; + usb_buf[0x04] = 0x06; + usb_buf[0x05] = 0x01; + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_write(dev, (unsigned char *)usb_buf, 64); + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(usb_buf, 0x00, sizeof(usb_buf)); + + //5A 3A 06 04 00 03 01 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + usb_buf[0x01] = 0x5A; + usb_buf[0x02] = 0x3A; + usb_buf[0x03] = 0x06; + usb_buf[0x04] = 0x04; + usb_buf[0x06] = 0x03; + usb_buf[0x07] = 0x01; + usb_buf[0x09] = 0x01; + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_write(dev, (unsigned char *)usb_buf, 64); + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(usb_buf, 0x00, sizeof(usb_buf)); + + //5A 3A 09 0A 00 03 01 01 FF BB GG RR + usb_buf[0x01] = 0x5A; + usb_buf[0x02] = 0x3A; + usb_buf[0x03] = 0x09; + usb_buf[0x04] = 0x0A; + usb_buf[0x06] = 0x03; + usb_buf[0x07] = 0x01; + usb_buf[0x08] = 0x01; + usb_buf[0x09] = 0x0FF; + + usb_buf[0x0A] = blue; + usb_buf[0x0B] = green; + usb_buf[0x0C] = red; + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_write(dev, (unsigned char *)usb_buf, 64); +} diff --git a/Controllers/CreativeController/CreativeSoundBlasterXG6Controller.h b/Controllers/CreativeController/CreativeSoundBlasterXG6Controller.h new file mode 100644 index 00000000..e3b3affb --- /dev/null +++ b/Controllers/CreativeController/CreativeSoundBlasterXG6Controller.h @@ -0,0 +1,20 @@ +#include "RGBController.h" +#include +#include + +#pragma once + +class CreativeSoundBlasterXG6Controller +{ +public: + CreativeSoundBlasterXG6Controller(hid_device* dev_handle, const char* path); + ~CreativeSoundBlasterXG6Controller(); + void SetLedColor (unsigned char red, unsigned char green, unsigned char blue); + + std::string GetDeviceLocation(); + std::string GetSerialString(); + +private: + hid_device* dev; + std::string location; +}; diff --git a/Controllers/CreativeController/RGBController_CreativeSoundBlasterXG6.cpp b/Controllers/CreativeController/RGBController_CreativeSoundBlasterXG6.cpp new file mode 100644 index 00000000..4f03fb25 --- /dev/null +++ b/Controllers/CreativeController/RGBController_CreativeSoundBlasterXG6.cpp @@ -0,0 +1,81 @@ +#include "RGBController_CreativeSoundBlasterXG6.h" + +RGBController_CreativeSoundBlasterXG6::RGBController_CreativeSoundBlasterXG6(CreativeSoundBlasterXG6Controller* creative_device) +{ + creative = creative_device; + + name = "Creative SoundBlasterX G6 Device"; + vendor = "Creative"; + type = DEVICE_TYPE_HEADSET; + description = "Creative SoundBlasterX G6 Device"; + location = creative_device->GetDeviceLocation(); + serial = ""; + + mode Static; + Static.name = "Direct"; + Static.value = 0; + Static.flags = MODE_COLORS_PER_LED; + Static.color_mode = MODE_COLORS_PER_LED; + modes.push_back(Static); + + SetupZones(); +} + +RGBController_CreativeSoundBlasterXG6::~RGBController_CreativeSoundBlasterXG6() +{ + delete creative; +} + +void RGBController_CreativeSoundBlasterXG6::SetupZones() +{ + zone logo_zone; + logo_zone.name = "Logo"; + logo_zone.type = ZONE_TYPE_SINGLE; + logo_zone.leds_min = 1; + logo_zone.leds_max = 1; + logo_zone.leds_count = 1; + logo_zone.matrix_map = NULL; + zones.push_back(logo_zone); + + led logo_led; + logo_led.name = "Logo"; + leds.push_back(logo_led); + + SetupColors(); +} + +void RGBController_CreativeSoundBlasterXG6::ResizeZone(int /*zone*/, int /*new_size*/) +{ + /*---------------------------------------------------------*\ + | This device does not support resizing zones | + \*---------------------------------------------------------*/ +} + +void RGBController_CreativeSoundBlasterXG6::DeviceUpdateLEDs() +{ + unsigned char red = RGBGetRValue(colors[0]); + unsigned char grn = RGBGetGValue(colors[0]); + unsigned char blu = RGBGetBValue(colors[0]); + + creative->SetLedColor(red, grn, blu); +} + +void RGBController_CreativeSoundBlasterXG6::UpdateZoneLEDs(int /*zone*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_CreativeSoundBlasterXG6::UpdateSingleLED(int /*led*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_CreativeSoundBlasterXG6::SetCustomMode() +{ + active_mode = 0; +} + +void RGBController_CreativeSoundBlasterXG6::DeviceUpdateMode() +{ + DeviceUpdateLEDs(); +} diff --git a/Controllers/CreativeController/RGBController_CreativeSoundBlasterXG6.h b/Controllers/CreativeController/RGBController_CreativeSoundBlasterXG6.h new file mode 100644 index 00000000..1f53febd --- /dev/null +++ b/Controllers/CreativeController/RGBController_CreativeSoundBlasterXG6.h @@ -0,0 +1,24 @@ +#pragma once +#include "RGBController.h" +#include "CreativeSoundBlasterXG6Controller.h" + +class RGBController_CreativeSoundBlasterXG6: public RGBController +{ +public: + RGBController_CreativeSoundBlasterXG6(CreativeSoundBlasterXG6Controller* creative_device); + ~RGBController_CreativeSoundBlasterXG6(); + + void SetupZones(); + + void ResizeZone(int zone, int new_size); + + void DeviceUpdateLEDs(); + void UpdateZoneLEDs(int zone); + void UpdateSingleLED(int led); + + void SetCustomMode(); + void DeviceUpdateMode(); + +private: + CreativeSoundBlasterXG6Controller* creative; +}; diff --git a/OpenRGB.pro b/OpenRGB.pro index 01244a4d..760a8eb7 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -67,6 +67,7 @@ INCLUDEPATH += Controllers/CorsairLightingNodeController/ \ Controllers/CorsairVengeanceController/ \ Controllers/CorsairVengeanceProController/ \ + Controllers/CreativeController/ \ Controllers/CrucialController/ \ Controllers/DasKeyboardController/ \ Controllers/DebugController/ \ @@ -195,6 +196,8 @@ HEADERS += Controllers/CorsairVengeanceController/RGBController_CorsairVengeance.h \ Controllers/CorsairVengeanceProController/CorsairVengeanceProController.h \ Controllers/CorsairVengeanceProController/RGBController_CorsairVengeancePro.h \ + Controllers/CreativeController/CreativeSoundBlasterXG6Controller.h \ + Controllers/CreativeController/RGBController_CreativeSoundBlasterXG6.h \ Controllers/CrucialController/CrucialController.h \ Controllers/CrucialController/RGBController_Crucial.h \ Controllers/DasKeyboardController/DasKeyboardController.h \ @@ -441,6 +444,9 @@ SOURCES += Controllers/CorsairVengeanceProController/CorsairVengeanceProController.cpp \ Controllers/CorsairVengeanceProController/CorsairVengeanceProControllerDetect.cpp \ Controllers/CorsairVengeanceProController/RGBController_CorsairVengeancePro.cpp \ + Controllers/CreativeController/CreativeSoundBlasterXG6Controller.cpp \ + Controllers/CreativeController/CreativeControllerDetect.cpp \ + Controllers/CreativeController/RGBController_CreativeSoundBlasterXG6.cpp \ Controllers/CrucialController/CrucialController.cpp \ Controllers/CrucialController/CrucialControllerDetect.cpp \ Controllers/CrucialController/RGBController_Crucial.cpp \