Skip to content

Commit d99be3e

Browse files
moooorgCalcProgrammer1
authored andcommitted
Add support for QuadCast 2S. Closes #5113
1 parent 5603ca8 commit d99be3e

5 files changed

Lines changed: 352 additions & 0 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*---------------------------------------------------------*\
2+
| HyperXMicrophoneV2Controller.cpp |
3+
| |
4+
| Driver for HyperX QuadCast 2S microphone |
5+
| |
6+
| Morgan Guimard (morg) |
7+
| |
8+
| This file is part of the OpenRGB project |
9+
| SPDX-License-Identifier: GPL-2.0-or-later |
10+
\*---------------------------------------------------------*/
11+
12+
#include <cstring>
13+
#include "HyperXMicrophoneV2Controller.h"
14+
#include "StringUtils.h"
15+
16+
using namespace std::chrono_literals;
17+
18+
HyperXMicrophoneV2Controller::HyperXMicrophoneV2Controller(hid_device* dev_handle, std::string path, std::string dev_name)
19+
{
20+
dev = dev_handle;
21+
location = path;
22+
name = dev_name;
23+
}
24+
25+
HyperXMicrophoneV2Controller::~HyperXMicrophoneV2Controller()
26+
{
27+
if(dev)
28+
{
29+
hid_close(dev);
30+
}
31+
}
32+
33+
std::string HyperXMicrophoneV2Controller::GetDeviceLocation()
34+
{
35+
return(location);
36+
}
37+
38+
std::string HyperXMicrophoneV2Controller::GetNameString()
39+
{
40+
return(name);
41+
}
42+
43+
std::string HyperXMicrophoneV2Controller::GetSerialString()
44+
{
45+
wchar_t serial_string[128];
46+
int ret = hid_get_serial_number_string(dev, serial_string, 128);
47+
48+
if(ret != 0)
49+
{
50+
return("");
51+
}
52+
53+
return(StringUtils::wstring_to_string(serial_string));
54+
}
55+
56+
void HyperXMicrophoneV2Controller::SendDirect(std::vector<RGBColor> colors)
57+
{
58+
lock.lock();
59+
60+
uint8_t buf[HYPERX_QUADCAST_2S_PACKET_SIZE];
61+
62+
unsigned int total_leds_sent = 0;
63+
64+
for(unsigned int i = 0; i < 7; i++)
65+
{
66+
memset(buf, 0, HYPERX_QUADCAST_2S_PACKET_SIZE);
67+
68+
buf[0] = HYPERX_QUADCAST_2S_REPORT_ID;
69+
buf[1] = i < 6 ? 0x02 : 0x01;
70+
buf[2] = i;
71+
72+
unsigned int c = 0;
73+
74+
while (c < HYPERX_QUADCAST_2S_LEDS_PER_PACKET && total_leds_sent < HYPERX_QUADCAST_2S_TOTAL_LEDS)
75+
{
76+
buf[4 + (3 * c)] = RGBGetRValue(colors[total_leds_sent]);
77+
buf[5 + (3 * c)] = RGBGetGValue(colors[total_leds_sent]);
78+
buf[6 + (3 * c)] = RGBGetBValue(colors[total_leds_sent]);
79+
80+
c++;
81+
total_leds_sent++;
82+
}
83+
84+
hid_write(dev, buf, HYPERX_QUADCAST_2S_PACKET_SIZE);
85+
}
86+
87+
lock.unlock();
88+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*---------------------------------------------------------*\
2+
| HyperXMicrophoneV2Controller.cpp |
3+
| |
4+
| Driver for HyperX QuadCast 2S microphone |
5+
| |
6+
| Morgan Guimard (morg) |
7+
| |
8+
| This file is part of the OpenRGB project |
9+
| SPDX-License-Identifier: GPL-2.0-or-later |
10+
\*---------------------------------------------------------*/
11+
12+
#pragma once
13+
14+
#include <string>
15+
#include <hidapi.h>
16+
#include "RGBController.h"
17+
18+
#define HYPERX_QUADCAST_2S_PACKET_SIZE 64
19+
#define HYPERX_QUADCAST_2S_REPORT_ID 0x44
20+
#define HYPERX_QUADCAST_2S_LEDS_PER_PACKET 20
21+
#define HYPERX_QUADCAST_2S_MATRIX_WIDTH 12
22+
#define HYPERX_QUADCAST_2S_MATRIX_HEIGHT 9
23+
#define HYPERX_QUADCAST_2S_TOTAL_LEDS 108
24+
25+
class HyperXMicrophoneV2Controller
26+
{
27+
public:
28+
HyperXMicrophoneV2Controller(hid_device* dev, std::string path, std::string dev_name);
29+
~HyperXMicrophoneV2Controller();
30+
31+
std::string GetDeviceLocation();
32+
std::string GetNameString();
33+
std::string GetSerialString();
34+
35+
void SendDirect(std::vector<RGBColor> color_data);
36+
37+
private:
38+
hid_device* dev;
39+
std::string location;
40+
std::string name;
41+
std::mutex lock;
42+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*---------------------------------------------------------*\
2+
| HyperXMicrophoneV2ControllerDetect.cpp |
3+
| |
4+
| Detector for HyperX QuadCast 2s microphone |
5+
| |
6+
| Morgan Guimard (morg) |
7+
| |
8+
| This file is part of the OpenRGB project |
9+
| SPDX-License-Identifier: GPL-2.0-or-later |
10+
\*---------------------------------------------------------*/
11+
12+
#include "Detector.h"
13+
#include "HyperXMicrophoneV2Controller.h"
14+
#include "RGBController_HyperXMicrophoneV2.h"
15+
16+
/*-----------------------------------------------------*\
17+
| HyperX microphone vendor and product IDs |
18+
\*-----------------------------------------------------*/
19+
#define HYPERX_HP_VID 0x03F0
20+
#define HYPERX_QUADCAST_2S_PID 0x02B5
21+
22+
void DetectHyperXMicrophoneV2Controllers(hid_device_info* info, const std::string& name)
23+
{
24+
hid_device* dev = hid_open_path(info->path);
25+
26+
if(dev)
27+
{
28+
HyperXMicrophoneV2Controller* controller = new HyperXMicrophoneV2Controller(dev, info->path, name);
29+
RGBController_HyperXMicrophoneV2 *rgb_controller = new RGBController_HyperXMicrophoneV2(controller);
30+
31+
ResourceManager::get()->RegisterRGBController(rgb_controller);
32+
}
33+
}
34+
35+
REGISTER_HID_DETECTOR_IPU("HyperX QuadCast 2S", DetectHyperXMicrophoneV2Controllers, HYPERX_HP_VID, HYPERX_QUADCAST_2S_PID, 1, 0xFF13, 0xFF00);
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*---------------------------------------------------------*\
2+
| RGBController_HyperXMicrophoneV2.cpp |
3+
| |
4+
| RGBController for HyperX QuadCast 2S microphone |
5+
| |
6+
| Morgan Guimard (morg) |
7+
| |
8+
| This file is part of the OpenRGB project |
9+
| SPDX-License-Identifier: GPL-2.0-or-later |
10+
\*---------------------------------------------------------*/
11+
12+
/**------------------------------------------------------------------*\
13+
@name HyperX Quadcast 2S
14+
@type USB
15+
@save :x:
16+
@direct :white_check_mark:
17+
@effects :x:
18+
@detectors DetectHyperXMicrophoneV2Controllers
19+
@comment
20+
\*-------------------------------------------------------------------*/
21+
22+
#include "RGBController_HyperXMicrophoneV2.h"
23+
#include <LogManager.h>
24+
25+
using namespace std::chrono_literals;
26+
27+
RGBController_HyperXMicrophoneV2::RGBController_HyperXMicrophoneV2(HyperXMicrophoneV2Controller* controller_ptr)
28+
{
29+
controller = controller_ptr;
30+
31+
name = controller->GetNameString();
32+
vendor = "HyperX";
33+
type = DEVICE_TYPE_MICROPHONE;
34+
description = "HyperX Microphone Device";
35+
location = controller->GetDeviceLocation();
36+
serial = controller->GetSerialString();
37+
38+
mode Direct;
39+
Direct.name = "Direct";
40+
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
41+
Direct.color_mode = MODE_COLORS_PER_LED;
42+
Direct.colors_min = HYPERX_QUADCAST_2S_TOTAL_LEDS;
43+
Direct.colors_max = HYPERX_QUADCAST_2S_TOTAL_LEDS;
44+
45+
modes.push_back(Direct);
46+
47+
SetupZones();
48+
49+
keepalive_thread_run = 1;
50+
keepalive_thread = new std::thread(&RGBController_HyperXMicrophoneV2::KeepaliveThread, this);
51+
};
52+
53+
RGBController_HyperXMicrophoneV2::~RGBController_HyperXMicrophoneV2()
54+
{
55+
keepalive_thread_run = 0;
56+
keepalive_thread->join();
57+
delete keepalive_thread;
58+
59+
delete controller;
60+
}
61+
62+
void RGBController_HyperXMicrophoneV2::SetupZones()
63+
{
64+
zone Mic;
65+
66+
Mic.name = "Microphone";
67+
Mic.type = ZONE_TYPE_MATRIX;
68+
Mic.leds_min = HYPERX_QUADCAST_2S_TOTAL_LEDS;
69+
Mic.leds_max = HYPERX_QUADCAST_2S_TOTAL_LEDS;
70+
Mic.leds_count = HYPERX_QUADCAST_2S_TOTAL_LEDS;
71+
Mic.matrix_map = new matrix_map_type;
72+
Mic.matrix_map->width = HYPERX_QUADCAST_2S_MATRIX_WIDTH;
73+
Mic.matrix_map->height = HYPERX_QUADCAST_2S_MATRIX_HEIGHT;
74+
Mic.matrix_map->map = new unsigned int[HYPERX_QUADCAST_2S_TOTAL_LEDS];
75+
76+
unsigned int led_mapping[HYPERX_QUADCAST_2S_TOTAL_LEDS] =
77+
{
78+
/* front */ /* rear */
79+
26, 27, 44, 45, 62, 63, 80, 81, 98, 99, 8, 9,
80+
25, 28, 43, 46, 61, 64, 79, 82, 97, 100, 7, 10,
81+
24, 29, 42, 47, 60, 65, 78, 83, 96, 101, 6, 11,
82+
23, 30, 41, 48, 59, 66, 77, 84, 95, 102, 5, 12,
83+
22, 31, 40, 49, 58, 67, 76, 85, 94, 103, 4, 13,
84+
21, 32, 39, 50, 57, 68, 75, 86, 93, 104, 3, 14,
85+
20, 33, 38, 51, 56, 69, 74, 87, 92, 105, 2, 15,
86+
19, 34, 37, 52, 55, 70, 73, 88, 91, 106, 1, 16,
87+
18, 35, 36, 53, 54, 71, 72, 89, 90, 107, 0, 17
88+
};
89+
90+
for(unsigned int i = 0; i < HYPERX_QUADCAST_2S_TOTAL_LEDS; i ++)
91+
{
92+
led l;
93+
l.name = "LED " + std::to_string(i);
94+
l.value = led_mapping[i];
95+
leds.push_back(l);
96+
97+
Mic.matrix_map->map[i] = led_mapping[i];
98+
}
99+
100+
zones.push_back(Mic);
101+
102+
SetupColors();
103+
}
104+
105+
void RGBController_HyperXMicrophoneV2::ResizeZone(int /*zone*/, int /*new_size*/)
106+
{
107+
/*---------------------------------------------------------*\
108+
| This device does not support resizing zones |
109+
\*---------------------------------------------------------*/
110+
}
111+
112+
void RGBController_HyperXMicrophoneV2::DeviceUpdateLEDs()
113+
{
114+
last_update_time = std::chrono::steady_clock::now();
115+
controller->SendDirect(colors);
116+
}
117+
void RGBController_HyperXMicrophoneV2::UpdateZoneLEDs(int /*zone*/)
118+
{
119+
DeviceUpdateLEDs();
120+
}
121+
void RGBController_HyperXMicrophoneV2::UpdateSingleLED(int /*led*/)
122+
{
123+
DeviceUpdateLEDs();
124+
}
125+
void RGBController_HyperXMicrophoneV2::DeviceUpdateMode()
126+
{
127+
DeviceUpdateLEDs();
128+
}
129+
130+
void RGBController_HyperXMicrophoneV2::DeviceSaveMode()
131+
{
132+
/* Unsuported */
133+
}
134+
135+
void RGBController_HyperXMicrophoneV2::KeepaliveThread()
136+
{
137+
while(keepalive_thread_run.load())
138+
{
139+
if((std::chrono::steady_clock::now() - last_update_time) > std::chrono::milliseconds(50))
140+
{
141+
UpdateLEDs();
142+
}
143+
std::this_thread::sleep_for(15ms);
144+
}
145+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*---------------------------------------------------------*\
2+
| RGBController_HyperXMicrophoneV2.h |
3+
| |
4+
| RGBController for HyperX QuadCast 2S microphone |
5+
| |
6+
| Morgan Guimard (morg) |
7+
| |
8+
| This file is part of the OpenRGB project |
9+
| SPDX-License-Identifier: GPL-2.0-or-later |
10+
\*---------------------------------------------------------*/
11+
12+
#pragma once
13+
14+
#include <chrono>
15+
#include "RGBController.h"
16+
#include "HyperXMicrophoneV2Controller.h"
17+
18+
class RGBController_HyperXMicrophoneV2 : public RGBController
19+
{
20+
public:
21+
RGBController_HyperXMicrophoneV2(HyperXMicrophoneV2Controller* controller_ptr);
22+
~RGBController_HyperXMicrophoneV2();
23+
24+
void SetupZones();
25+
26+
void ResizeZone(int zone, int new_size);
27+
28+
void DeviceUpdateLEDs();
29+
void UpdateZoneLEDs(int zone);
30+
void UpdateSingleLED(int led);
31+
32+
void DeviceUpdateMode();
33+
void DeviceSaveMode();
34+
35+
void KeepaliveThread();
36+
37+
private:
38+
HyperXMicrophoneV2Controller* controller;
39+
std::thread* keepalive_thread;
40+
std::atomic<bool> keepalive_thread_run;
41+
std::chrono::time_point<std::chrono::steady_clock> last_update_time;
42+
};

0 commit comments

Comments
 (0)