Publish LumaOps source

This commit is contained in:
LumaOps release export
2026-09-03 01:18:36 +02:00
commit 7f1c0e5f71
2363 changed files with 501543 additions and 0 deletions
@@ -0,0 +1,271 @@
/*---------------------------------------------------------*\
| HyperXMicrophoneV2Controller.cpp |
| |
| Driver for HyperX QuadCast 2 S Microphone |
| |
| Morgan Guimard (morg) |
| Logan Phillips (Eclipse) 23 Oct 2025 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include <cstring>
#include <sstream>
#include <iomanip>
#include "HyperXMicrophoneV2Controller.h"
#include "StringUtils.h"
#include "LogManager.h"
HyperXMicrophoneV2Controller::HyperXMicrophoneV2Controller(hid_device* dev_handle, std::string path, std::string dev_name)
{
dev = dev_handle;
location = path;
name = dev_name;
errors = 0;
last_error_time = std::chrono::steady_clock::now();
pause_until = std::chrono::steady_clock::now();
}
HyperXMicrophoneV2Controller::~HyperXMicrophoneV2Controller()
{
if(dev)
{
hid_close(dev);
}
}
std::string HyperXMicrophoneV2Controller::GetDeviceLocation()
{
return(location);
}
std::string HyperXMicrophoneV2Controller::GetNameString()
{
return(name);
}
std::string HyperXMicrophoneV2Controller::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));
}
bool HyperXMicrophoneV2Controller::ShouldPauseUpdates()
{
return std::chrono::steady_clock::now() < pause_until;
}
void HyperXMicrophoneV2Controller::FlushInputBuffer()
{
uint8_t discard[HYPERX_QUADCAST_2S_PACKET_SIZE];
int flushed_count = 0;
/*---------------------------------------------------------*\
| Read and discard all pending responses in the buffer |
\*---------------------------------------------------------*/
while(hid_read_timeout(dev, discard, HYPERX_QUADCAST_2S_PACKET_SIZE, 10) > 0)
{
flushed_count++;
}
if(flushed_count > 0)
{
LOG_DEBUG("[%s] Flushed %d stale response(s) from input buffer", name.c_str(), flushed_count);
}
}
void HyperXMicrophoneV2Controller::TrackCommunicationError()
{
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
long long time_since_last_error = std::chrono::duration_cast<std::chrono::seconds>(now - last_error_time).count();
if(time_since_last_error < 10)
{
errors++;
if(errors >= 5)
{
LOG_WARNING("[%s] Multiple communication errors detected (%d). Flushing input buffer to clear stale responses.", name.c_str(), errors);
FlushInputBuffer();
}
if(errors >= 10)
{
LOG_ERROR("[%s] Multiple consecutive communication errors detected. Another program (such as HyperX NGENUITY) may be controlling this device. Pausing updates for 5 seconds.", name.c_str());
pause_until = std::chrono::steady_clock::now() + std::chrono::seconds(5);
errors = 0;
}
}
else
{
errors = 1;
}
last_error_time = now;
}
bool HyperXMicrophoneV2Controller::WaitForResponse(const uint8_t* sent_packet, int timeout_ms)
{
uint8_t response[HYPERX_QUADCAST_2S_PACKET_SIZE];
memset(response, 0, HYPERX_QUADCAST_2S_PACKET_SIZE);
int bytes_read = hid_read_timeout(dev, response, HYPERX_QUADCAST_2S_PACKET_SIZE, timeout_ms);
if(bytes_read <= 0)
{
LOG_WARNING("[%s] No response received from device (timeout: %d ms)", name.c_str(), timeout_ms);
TrackCommunicationError();
return false;
}
/*---------------------------------------------------------*\
| Verify the response echoes back the command bytes |
| Response bytes 14-15 should match sent bytes 0-1 |
\*---------------------------------------------------------*/
if(response[14] == sent_packet[0] && response[15] == sent_packet[1])
{
return true;
}
/*---------------------------------------------------------*\
| Log validation failure with full response payload |
\*---------------------------------------------------------*/
std::stringstream response_hex;
for(int i = 0; i < bytes_read; i++)
{
response_hex << std::hex << std::setw(2) << std::setfill('0') << (int)response[i];
}
LOG_WARNING("[%s] Invalid response from device. Expected echo of bytes [0x%02X 0x%02X] at positions 14-15, but got [0x%02X 0x%02X]. Full response: %s",
name.c_str(), sent_packet[0], sent_packet[1], response[14], response[15], response_hex.str().c_str());
TrackCommunicationError();
return false;
}
void HyperXMicrophoneV2Controller::SendColorPackets(std::vector<RGBColor> colors, uint8_t command_byte)
{
uint8_t buf[HYPERX_QUADCAST_2S_PACKET_SIZE];
unsigned int total_leds_sent = 0;
for(unsigned int packet = 0; packet < 6; packet++)
{
memset(buf, 0, HYPERX_QUADCAST_2S_PACKET_SIZE);
buf[0] = HYPERX_QUADCAST_2S_REPORT_ID;
buf[1] = command_byte;
buf[2] = packet;
unsigned int c = 0;
while(c < HYPERX_QUADCAST_2S_LEDS_PER_PACKET && total_leds_sent < HYPERX_QUADCAST_2S_TOTAL_LEDS)
{
buf[4 + (3 * c)] = RGBGetRValue(colors[total_leds_sent]);
buf[5 + (3 * c)] = RGBGetGValue(colors[total_leds_sent]);
buf[6 + (3 * c)] = RGBGetBValue(colors[total_leds_sent]);
c++;
total_leds_sent++;
}
hid_write(dev, buf, HYPERX_QUADCAST_2S_PACKET_SIZE);
WaitForResponse(buf);
}
}
void HyperXMicrophoneV2Controller::SendDirect(std::vector<RGBColor> colors)
{
lock.lock();
/*---------------------------------------------------------*\
| Skip sending if we're in pause mode |
\*---------------------------------------------------------*/
if(ShouldPauseUpdates())
{
lock.unlock();
return;
}
uint8_t buf[HYPERX_QUADCAST_2S_PACKET_SIZE];
/*---------------------------------------------------------*\
| Send header packet for direct mode |
\*---------------------------------------------------------*/
memset(buf, 0, HYPERX_QUADCAST_2S_PACKET_SIZE);
buf[0] = HYPERX_QUADCAST_2S_REPORT_ID;
buf[1] = 0x01;
buf[2] = 0x06;
hid_write(dev, buf, HYPERX_QUADCAST_2S_PACKET_SIZE);
WaitForResponse(buf);
/*---------------------------------------------------------*\
| Send color data packets |
\*---------------------------------------------------------*/
SendColorPackets(colors, 0x02);
lock.unlock();
}
void HyperXMicrophoneV2Controller::SaveColors(std::vector<RGBColor> colors)
{
lock.lock();
/*---------------------------------------------------------*\
| Skip sending if we're in pause mode |
\*---------------------------------------------------------*/
if(ShouldPauseUpdates())
{
lock.unlock();
return;
}
uint8_t buf[HYPERX_QUADCAST_2S_PACKET_SIZE];
/*---------------------------------------------------------*\
| Initiate save to device |
\*---------------------------------------------------------*/
memset(buf, 0, HYPERX_QUADCAST_2S_PACKET_SIZE);
buf[0] = HYPERX_QUADCAST_2S_REPORT_ID;
buf[1] = 0x03;
buf[2] = 0x01;
buf[3] = 0x06;
hid_write(dev, buf, HYPERX_QUADCAST_2S_PACKET_SIZE);
WaitForResponse(buf);
/*---------------------------------------------------------*\
| Send 6 color data packets |
\*---------------------------------------------------------*/
SendColorPackets(colors, 0x04);
/*---------------------------------------------------------*\
| Send "Framerate" packet |
| If someone ever wanted to try and replicate the effects, |
| apparently this is the packet to try and change. |
| I believe currently this is setting a "static" frame |
\*---------------------------------------------------------*/
memset(buf, 0, HYPERX_QUADCAST_2S_PACKET_SIZE);
buf[0] = 0x42;
buf[1] = 0x02;
buf[5] = 0xE8;
buf[6] = 0x03;
hid_write(dev, buf, HYPERX_QUADCAST_2S_PACKET_SIZE);
WaitForResponse(buf);
/*---------------------------------------------------------*\
| Send final packet |
\*---------------------------------------------------------*/
memset(buf, 0, HYPERX_QUADCAST_2S_PACKET_SIZE);
buf[0] = 0x40;
buf[1] = 0x01;
buf[4] = 0xFF;
hid_write(dev, buf, HYPERX_QUADCAST_2S_PACKET_SIZE);
WaitForResponse(buf);
lock.unlock();
}
@@ -0,0 +1,55 @@
/*---------------------------------------------------------*\
| HyperXMicrophoneV2Controller.h |
| |
| Driver for HyperX QuadCast 2 S Microphone |
| |
| Morgan Guimard (morg) |
| Logan Phillips (Eclipse) 23 Oct 2025 |
| |
| 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 HYPERX_QUADCAST_2S_PACKET_SIZE 64
#define HYPERX_QUADCAST_2S_REPORT_ID 0x44
#define HYPERX_QUADCAST_2S_LEDS_PER_PACKET 20
#define HYPERX_QUADCAST_2S_MATRIX_WIDTH 12
#define HYPERX_QUADCAST_2S_MATRIX_HEIGHT 9
#define HYPERX_QUADCAST_2S_TOTAL_LEDS 108
class HyperXMicrophoneV2Controller
{
public:
HyperXMicrophoneV2Controller(hid_device* dev, std::string path, std::string dev_name);
~HyperXMicrophoneV2Controller();
std::string GetDeviceLocation();
std::string GetNameString();
std::string GetSerialString();
void SendDirect(std::vector<RGBColor> color_data);
void SaveColors(std::vector<RGBColor> color_data);
bool ShouldPauseUpdates();
private:
hid_device* dev;
std::string location;
std::string name;
std::mutex lock;
bool WaitForResponse(const uint8_t* sent_packet, int timeout_ms = 2000);
void SendColorPackets(std::vector<RGBColor> colors, uint8_t command_byte);
void TrackCommunicationError();
void FlushInputBuffer();
unsigned int errors;
std::chrono::steady_clock::time_point last_error_time;
std::chrono::steady_clock::time_point pause_until;
};
@@ -0,0 +1,36 @@
/*---------------------------------------------------------*\
| HyperXMicrophoneV2ControllerDetect.cpp |
| |
| Detector for HyperX QuadCast 2 S Microphone |
| |
| Morgan Guimard (morg) |
| Logan Phillips (Eclipse) 23 Oct 2025 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include "Detector.h"
#include "HyperXMicrophoneV2Controller.h"
#include "RGBController_HyperXMicrophoneV2.h"
/*-----------------------------------------------------*\
| HyperX microphone vendor and product IDs |
\*-----------------------------------------------------*/
#define HYPERX_HP_VID 0x03F0
#define HYPERX_QUADCAST_2S_PID 0x02B5
void DetectHyperXMicrophoneV2Controllers(hid_device_info* info, const std::string& name)
{
hid_device* dev = hid_open_path(info->path);
if(dev)
{
HyperXMicrophoneV2Controller* controller = new HyperXMicrophoneV2Controller(dev, info->path, name);
RGBController_HyperXMicrophoneV2 *rgb_controller = new RGBController_HyperXMicrophoneV2(controller);
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
}
REGISTER_HID_DETECTOR_IPU("HyperX QuadCast 2 S", DetectHyperXMicrophoneV2Controllers, HYPERX_HP_VID, HYPERX_QUADCAST_2S_PID, 1, 0xFF13, 0xFF00);
@@ -0,0 +1,147 @@
/*---------------------------------------------------------*\
| RGBController_HyperXMicrophoneV2.cpp |
| |
| RGBController for HyperX QuadCast 2 S Microphone |
| |
| Morgan Guimard (morg) |
| Logan Phillips (Eclipse) 23 Oct 2025 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
/**------------------------------------------------------------------*\
@name HyperX Quadcast 2S
@type USB
@save :white_check_mark:
@direct :white_check_mark:
@effects :x:
@detectors DetectHyperXMicrophoneV2Controllers
@comment
\*-------------------------------------------------------------------*/
#include "RGBController_HyperXMicrophoneV2.h"
#include <LogManager.h>
using namespace std::chrono_literals;
RGBController_HyperXMicrophoneV2::RGBController_HyperXMicrophoneV2(HyperXMicrophoneV2Controller* controller_ptr)
{
controller = controller_ptr;
name = controller->GetNameString();
vendor = "HyperX";
type = DEVICE_TYPE_MICROPHONE;
description = "HyperX Microphone Device";
location = controller->GetDeviceLocation();
serial = controller->GetSerialString();
mode Direct;
Direct.name = "Direct";
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_MANUAL_SAVE;
Direct.color_mode = MODE_COLORS_PER_LED;
Direct.colors_min = HYPERX_QUADCAST_2S_TOTAL_LEDS;
Direct.colors_max = HYPERX_QUADCAST_2S_TOTAL_LEDS;
modes.push_back(Direct);
SetupZones();
keepalive_thread_run = 1;
keepalive_thread = new std::thread(&RGBController_HyperXMicrophoneV2::KeepaliveThread, this);
};
RGBController_HyperXMicrophoneV2::~RGBController_HyperXMicrophoneV2()
{
keepalive_thread_run = 0;
keepalive_thread->join();
delete keepalive_thread;
delete controller;
}
void RGBController_HyperXMicrophoneV2::SetupZones()
{
zone Mic;
Mic.name = "Microphone";
Mic.type = ZONE_TYPE_MATRIX;
Mic.leds_min = HYPERX_QUADCAST_2S_TOTAL_LEDS;
Mic.leds_max = HYPERX_QUADCAST_2S_TOTAL_LEDS;
Mic.leds_count = HYPERX_QUADCAST_2S_TOTAL_LEDS;
Mic.matrix_map = new matrix_map_type;
Mic.matrix_map->width = HYPERX_QUADCAST_2S_MATRIX_WIDTH;
Mic.matrix_map->height = HYPERX_QUADCAST_2S_MATRIX_HEIGHT;
Mic.matrix_map->map = new unsigned int[HYPERX_QUADCAST_2S_TOTAL_LEDS];
unsigned int led_mapping[HYPERX_QUADCAST_2S_TOTAL_LEDS] =
{
/* front */ /* rear */
26, 27, 44, 45, 62, 63, 80, 81, 98, 99, 8, 9,
25, 28, 43, 46, 61, 64, 79, 82, 97, 100, 7, 10,
24, 29, 42, 47, 60, 65, 78, 83, 96, 101, 6, 11,
23, 30, 41, 48, 59, 66, 77, 84, 95, 102, 5, 12,
22, 31, 40, 49, 58, 67, 76, 85, 94, 103, 4, 13,
21, 32, 39, 50, 57, 68, 75, 86, 93, 104, 3, 14,
20, 33, 38, 51, 56, 69, 74, 87, 92, 105, 2, 15,
19, 34, 37, 52, 55, 70, 73, 88, 91, 106, 1, 16,
18, 35, 36, 53, 54, 71, 72, 89, 90, 107, 0, 17
};
for(unsigned int i = 0; i < HYPERX_QUADCAST_2S_TOTAL_LEDS; i ++)
{
led l;
l.name = "LED " + std::to_string(i);
l.value = led_mapping[i];
leds.push_back(l);
Mic.matrix_map->map[i] = led_mapping[i];
}
zones.push_back(Mic);
SetupColors();
}
void RGBController_HyperXMicrophoneV2::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_HyperXMicrophoneV2::DeviceUpdateLEDs()
{
last_update_time = std::chrono::steady_clock::now();
controller->SendDirect(colors);
}
void RGBController_HyperXMicrophoneV2::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_HyperXMicrophoneV2::UpdateSingleLED(int /*led*/)
{
DeviceUpdateLEDs();
}
void RGBController_HyperXMicrophoneV2::DeviceUpdateMode()
{
DeviceUpdateLEDs();
}
void RGBController_HyperXMicrophoneV2::DeviceSaveMode()
{
LOG_DEBUG("[%s] Saving current direct colors to device", name.c_str());
controller->SaveColors(colors);
}
void RGBController_HyperXMicrophoneV2::KeepaliveThread()
{
while(keepalive_thread_run.load())
{
if(!controller->ShouldPauseUpdates() && (std::chrono::steady_clock::now() - last_update_time) > std::chrono::milliseconds(1000))
{
UpdateLEDs();
}
std::this_thread::sleep_for(250ms);
}
}
@@ -0,0 +1,43 @@
/*---------------------------------------------------------*\
| RGBController_HyperXMicrophoneV2.h |
| |
| RGBController for HyperX QuadCast 2 S Microphone |
| |
| Morgan Guimard (morg) |
| Logan Phillips (Eclipse) 23 Oct 2025 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include <chrono>
#include "RGBController.h"
#include "HyperXMicrophoneV2Controller.h"
class RGBController_HyperXMicrophoneV2 : public RGBController
{
public:
RGBController_HyperXMicrophoneV2(HyperXMicrophoneV2Controller* controller_ptr);
~RGBController_HyperXMicrophoneV2();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void DeviceUpdateMode();
void DeviceSaveMode();
void KeepaliveThread();
private:
HyperXMicrophoneV2Controller* controller;
std::thread* keepalive_thread;
std::atomic<bool> keepalive_thread_run;
std::chrono::time_point<std::chrono::steady_clock> last_update_time;
};