Compare commits
256
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f8fe1d29fb | ||
|
|
42a9a9314d | ||
|
|
41d9a66c1c | ||
|
|
2437379506 | ||
|
|
f95e210260 | ||
|
|
a5d37819d2 | ||
|
|
80917314df | ||
|
|
3d25fa9451 | ||
|
|
5c4e2ee00a | ||
|
|
13b27fd966 | ||
|
|
a41a22d5d6 | ||
|
|
56572beba9 | ||
|
|
bbf98b2f72 | ||
|
|
0bba8539e4 | ||
|
|
4e00aac741 | ||
|
|
f3b20da6a3 | ||
|
|
7ae3ce651d | ||
|
|
2307566dac | ||
|
|
6101d9d43e | ||
|
|
c2541d9585 | ||
|
|
89cc9fc912 | ||
|
|
24a7940787 | ||
|
|
2aa33821dd | ||
|
|
82232b4aef | ||
|
|
de13ca2cff | ||
|
|
c45cf2466a | ||
|
|
f01aa31c3b | ||
|
|
c9f7fe8f3f | ||
|
|
e7483e22a9 | ||
|
|
438fc49127 | ||
|
|
f62851dbab | ||
|
|
5e3ad426e9 | ||
|
|
3622913291 | ||
|
|
dd0edb3f84 | ||
|
|
e1737fb971 | ||
|
|
56df7d65b3 | ||
|
|
4eb926f8ef | ||
|
|
8fc98a035b | ||
|
|
5567db88f8 | ||
|
|
b96d160ce2 | ||
|
|
f44c6365c0 | ||
|
|
94277e7d04 | ||
|
|
1d4393b5c4 | ||
|
|
fa015dd558 | ||
|
|
5c7359fa60 | ||
|
|
4dbe14febe | ||
|
|
c8346e1f7c | ||
|
|
095b9ce635 | ||
|
|
2dc443ff1e | ||
|
|
0ab0586dfa | ||
|
|
88fa6bf25a | ||
|
|
9346490e4a | ||
|
|
7d4e5d6122 | ||
|
|
d4a03b23c8 | ||
|
|
47b5c94310 | ||
|
|
079a984f8d | ||
|
|
b6e35c4155 | ||
|
|
c9d1ac5d8f | ||
|
|
427c635ed8 | ||
|
|
0703bcd0a8 | ||
|
|
984c6bb7f5 | ||
|
|
d27095dacd | ||
|
|
9228b5c4cd | ||
|
|
7fe87703e5 | ||
|
|
c65edbeebc | ||
|
|
b6bf34279c | ||
|
|
68e444aa3b | ||
|
|
3d12930067 | ||
|
|
3de7f32a3a | ||
|
|
216fe063e0 | ||
|
|
ef6195271e | ||
|
|
86eb273e46 | ||
|
|
22813c06dc | ||
|
|
9840f0a8b6 | ||
|
|
69539432b5 | ||
|
|
4433760cab | ||
|
|
ba2ce98a3e | ||
|
|
1e171fcfb0 | ||
|
|
dc88b1a752 | ||
|
|
3f2a118a39 | ||
|
|
b8c80e6ba5 | ||
|
|
405bbc5464 | ||
|
|
5371fe1cc2 | ||
|
|
cdce79bd07 | ||
|
|
87395d0b0d | ||
|
|
7050a0dac1 | ||
|
|
bc01b53de5 | ||
|
|
680c143ad7 | ||
|
|
38c3f2d94c | ||
|
|
5344806a85 | ||
|
|
21f29a1a56 | ||
|
|
c5149b2521 | ||
|
|
f9a25c9612 | ||
|
|
4b4d3bf790 | ||
|
|
3a11ed4e43 | ||
|
|
238dc0f0ae | ||
|
|
0568fc5ed2 | ||
|
|
37241ee6f2 | ||
|
|
1f91dd227f | ||
|
|
facfa05062 | ||
|
|
6fd6c7f176 | ||
|
|
d947cc2499 | ||
|
|
5db52e5dc2 | ||
|
|
1249814e93 | ||
|
|
dda8e9470f | ||
|
|
72482d4ff9 | ||
|
|
a50049e63b | ||
|
|
2970e56324 | ||
|
|
aa1ad8db85 | ||
|
|
7f865cfee9 | ||
|
|
c7b9fe90a6 | ||
|
|
0c7009b973 | ||
|
|
d791361f22 | ||
|
|
5719956441 | ||
|
|
eba9fc0213 | ||
|
|
556fb634bb | ||
|
|
e39617a665 | ||
|
|
9f6c3819bd | ||
|
|
91c8ec0cb0 | ||
|
|
314283a37c | ||
|
|
c3e5d91b6b | ||
|
|
c769c20af1 | ||
|
|
2a43cefbe6 | ||
|
|
68960b7b14 | ||
|
|
ad85efcb14 | ||
|
|
7c221416cc | ||
|
|
9ba1b2fc57 | ||
|
|
caf1e5c7f0 | ||
|
|
2b660a47c7 | ||
|
|
0c45e26c98 | ||
|
|
fdbaf9bf63 | ||
|
|
08a1197b7e | ||
|
|
87a9ea5b14 | ||
|
|
2b8d25559a | ||
|
|
3db9189cbb | ||
|
|
a0c379e8c7 | ||
|
|
0ae4964545 | ||
|
|
69651b3f91 | ||
|
|
ce9508aa88 | ||
|
|
aa182936ba | ||
|
|
745bbac93b | ||
|
|
5c3c15f930 | ||
|
|
4919b03bd1 | ||
|
|
18c18e3999 | ||
|
|
01020b50d9 | ||
|
|
00f422375b | ||
|
|
25807902c9 | ||
|
|
0bbef425a4 | ||
|
|
ec65d8a2a9 | ||
|
|
47df8f3414 | ||
|
|
c560ee4b7e | ||
|
|
74080150e0 | ||
|
|
ab7ddc1629 | ||
|
|
000bef969c | ||
|
|
c8e0aec596 | ||
|
|
ecf4427c76 | ||
|
|
d299e90954 | ||
|
|
98bb92acdb | ||
|
|
0e77149444 | ||
|
|
e6c21f0a72 | ||
|
|
da9f6d7c72 | ||
|
|
97975b6d36 | ||
|
|
ad98cc173b | ||
|
|
5a33c80d65 | ||
|
|
f661bf66f1 | ||
|
|
f1e1c41d68 | ||
|
|
a7ed250c4e | ||
|
|
62c06202e0 | ||
|
|
23ad5ca244 | ||
|
|
5712717ef8 | ||
|
|
da54e89839 | ||
|
|
57b8377f5a | ||
|
|
fbb718c532 | ||
|
|
5a469ea615 | ||
|
|
2099abb126 | ||
|
|
4b4e939d10 | ||
|
|
e0094915fe | ||
|
|
aa6e2e611b | ||
|
|
ce8331b467 | ||
|
|
54ff4d57b0 | ||
|
|
3abb0c05ba | ||
|
|
acc84f6a09 | ||
|
|
74b0d195d9 | ||
|
|
920e001bab | ||
|
|
4c2ceed5b6 | ||
|
|
515c17b8dd | ||
|
|
2ffb02abde | ||
|
|
3237c8842a | ||
|
|
fde468a162 | ||
|
|
f854441cf7 | ||
|
|
408020c244 | ||
|
|
f806f3ad66 | ||
|
|
7c1c9a7979 | ||
|
|
283cb5a8ac | ||
|
|
5f21674b8f | ||
|
|
fe6a84d6c9 | ||
|
|
f7cb8ca969 | ||
|
|
64dad049f9 | ||
|
|
1115213d5a | ||
|
|
bc01ec0e4b | ||
|
|
62518b5163 | ||
|
|
736e624366 | ||
|
|
d7298cafd0 | ||
|
|
70783fb28f | ||
|
|
45a5f629e5 | ||
|
|
ec73337929 | ||
|
|
148b84b7d1 | ||
|
|
3cf855bd10 | ||
|
|
9deb0f8fff | ||
|
|
8c86686d01 | ||
|
|
c451487401 | ||
|
|
5defbc1580 | ||
|
|
b5af840dcc | ||
|
|
1b170ff664 | ||
|
|
31a6da1b21 | ||
|
|
cb6dfd83d8 | ||
|
|
50ea274205 | ||
|
|
c7960c090a | ||
|
|
85b2545409 | ||
|
|
e10881db3e | ||
|
|
977feabe6e | ||
|
|
a6c9d1232a | ||
|
|
4024e6de85 | ||
|
|
f3df584d3a | ||
|
|
60a0ab5c93 | ||
|
|
c908847577 | ||
|
|
bd027e596e | ||
|
|
51c3568f7a | ||
|
|
4f8db7d63f | ||
|
|
f844c2fb07 | ||
|
|
f7041988e4 | ||
|
|
71c650cd45 | ||
|
|
3c6ac31eab | ||
|
|
20a99ef7ef | ||
|
|
c69a98096b | ||
|
|
92afebe2c7 | ||
|
|
5b82eb39a8 | ||
|
|
7b120515d8 | ||
|
|
b480bbd666 | ||
|
|
5e5ac81f53 | ||
|
|
adcd59848a | ||
|
|
937cbc656e | ||
|
|
aead384282 | ||
|
|
b717600c37 | ||
|
|
f38be5119e | ||
|
|
f8de686296 | ||
|
|
0703fb8c68 | ||
|
|
8d0915de6e | ||
|
|
ef33d7e2c4 | ||
|
|
bba88eb1f2 | ||
|
|
7b35cf72f7 | ||
|
|
9603489f4a | ||
|
|
d4cd2a6853 | ||
|
|
c4d2f72df1 | ||
|
|
1a07aee7a6 | ||
|
|
415d79a3ef |
+3
-3
@@ -1,3 +1,3 @@
|
||||
[submodule "dependencies/libe131"]
|
||||
path = dependencies/libe131
|
||||
url = https://github.com/CalcProgrammer1/libe131
|
||||
[submodule "razer-drivers-win32"]
|
||||
path = razer-drivers-win32
|
||||
url = https://github.com/rsandoz/razer-drivers-win32
|
||||
|
||||
@@ -0,0 +1,269 @@
|
||||
/*-----------------------------------------*\
|
||||
| AuraAddressableController.cpp |
|
||||
| |
|
||||
| Driver for ASUS Aura RGB Addressable |
|
||||
| lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 1/18/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "AuraAddressableController.h"
|
||||
#include <cstring>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
|
||||
static void Sleep(unsigned int milliseconds)
|
||||
{
|
||||
usleep(1000 * milliseconds);
|
||||
}
|
||||
#endif
|
||||
|
||||
AuraAddressableController::AuraAddressableController(hid_device* dev_handle)
|
||||
{
|
||||
dev = dev_handle;
|
||||
|
||||
GetFirmwareVersion();
|
||||
GetConfigTable();
|
||||
}
|
||||
|
||||
AuraAddressableController::~AuraAddressableController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
unsigned int AuraAddressableController::GetChannelCount()
|
||||
{
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
std::string AuraAddressableController::GetDeviceName()
|
||||
{
|
||||
return(device_name);
|
||||
}
|
||||
|
||||
void AuraAddressableController::SetChannelLEDs(unsigned char channel, RGBColor * colors, unsigned int num_colors)
|
||||
{
|
||||
unsigned char led_data[60];
|
||||
unsigned int leds_sent = 0;
|
||||
|
||||
while(leds_sent < num_colors)
|
||||
{
|
||||
unsigned int leds_to_send = 20;
|
||||
|
||||
if((num_colors - leds_sent) < leds_to_send)
|
||||
{
|
||||
leds_to_send = num_colors - leds_sent;
|
||||
}
|
||||
|
||||
for(int led_idx = 0; led_idx < leds_to_send; led_idx++)
|
||||
{
|
||||
led_data[(led_idx * 3) + 0] = RGBGetRValue(colors[led_idx + leds_sent]);
|
||||
led_data[(led_idx * 3) + 1] = RGBGetGValue(colors[led_idx + leds_sent]);
|
||||
led_data[(led_idx * 3) + 2] = RGBGetBValue(colors[led_idx + leds_sent]);
|
||||
}
|
||||
|
||||
SendDirect
|
||||
(
|
||||
channel,
|
||||
leds_sent,
|
||||
leds_to_send,
|
||||
led_data
|
||||
);
|
||||
|
||||
leds_sent += leds_to_send;
|
||||
}
|
||||
|
||||
SendDirectApply(channel);
|
||||
}
|
||||
|
||||
void AuraAddressableController::SetMode
|
||||
(
|
||||
unsigned char mode,
|
||||
unsigned char red,
|
||||
unsigned char grn,
|
||||
unsigned char blu
|
||||
)
|
||||
{
|
||||
for(int channel_idx = 0; channel_idx < GetChannelCount(); channel_idx++)
|
||||
{
|
||||
SendEffect
|
||||
(
|
||||
channel_idx,
|
||||
mode,
|
||||
red,
|
||||
grn,
|
||||
blu
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void AuraAddressableController::GetConfigTable()
|
||||
{
|
||||
unsigned char usb_buf[65];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up config table request packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0xEC;
|
||||
usb_buf[0x01] = AURA_REQUEST_CONFIG_TABLE;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, usb_buf, 65);
|
||||
hid_read(dev, usb_buf, 65);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy the firmware string if the reply ID is correct |
|
||||
\*-----------------------------------------------------*/
|
||||
if(usb_buf[1] == 0x30)
|
||||
{
|
||||
memcpy(config_table, &usb_buf[4], 60);
|
||||
|
||||
for(int i = 0; i < 60; i+=6)
|
||||
{
|
||||
printf("%02X %02X %02X %02X %02X %02X\r\n", config_table[i + 0],
|
||||
config_table[i + 1],
|
||||
config_table[i + 2],
|
||||
config_table[i + 3],
|
||||
config_table[i + 4],
|
||||
config_table[i + 5]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AuraAddressableController::GetFirmwareVersion()
|
||||
{
|
||||
unsigned char usb_buf[65];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up firmware version request packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0xEC;
|
||||
usb_buf[0x01] = AURA_REQUEST_FIRMWARE_VERSION;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, usb_buf, 65);
|
||||
hid_read(dev, usb_buf, 65);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy the firmware string if the reply ID is correct |
|
||||
\*-----------------------------------------------------*/
|
||||
if(usb_buf[1] == 0x02)
|
||||
{
|
||||
memcpy(device_name, &usb_buf[2], 16);
|
||||
}
|
||||
}
|
||||
|
||||
void AuraAddressableController::SendEffect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
unsigned char red,
|
||||
unsigned char grn,
|
||||
unsigned char blu
|
||||
)
|
||||
{
|
||||
unsigned char usb_buf[65];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up message packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0xEC;
|
||||
usb_buf[0x01] = AURA_CONTROL_MODE_EFFECT;
|
||||
usb_buf[0x02] = channel;
|
||||
usb_buf[0x03] = 0x00;
|
||||
usb_buf[0x04] = mode;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in color data bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x05] = red;
|
||||
usb_buf[0x06] = grn;
|
||||
usb_buf[0x07] = blu;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, usb_buf, 65);
|
||||
}
|
||||
|
||||
void AuraAddressableController::SendDirect
|
||||
(
|
||||
unsigned char device,
|
||||
unsigned char start_led,
|
||||
unsigned char led_count,
|
||||
unsigned char* led_data
|
||||
)
|
||||
{
|
||||
unsigned char usb_buf[65];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up message packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0xEC;
|
||||
usb_buf[0x01] = AURA_CONTROL_MODE_DIRECT;
|
||||
usb_buf[0x02] = device;
|
||||
usb_buf[0x03] = start_led;
|
||||
usb_buf[0x04] = led_count;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in color data bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(&usb_buf[0x05], led_data, led_count * 3);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, usb_buf, 65);
|
||||
}
|
||||
|
||||
void AuraAddressableController::SendDirectApply
|
||||
(
|
||||
unsigned char channel
|
||||
)
|
||||
{
|
||||
unsigned char usb_buf[65];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up message packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0xEC;
|
||||
usb_buf[0x01] = AURA_CONTROL_MODE_DIRECT;
|
||||
usb_buf[0x02] = 0x80 | channel;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, usb_buf, 65);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*-----------------------------------------*\
|
||||
| AuraAddressableController.h |
|
||||
| |
|
||||
| Definitions and types for ASUS Aura |
|
||||
| Addressable RGB lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 1/18/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
|
||||
#include <string>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
enum
|
||||
{
|
||||
AURA_MODE_OFF = 0, /* OFF mode */
|
||||
AURA_MODE_STATIC = 1, /* Static color mode */
|
||||
AURA_MODE_BREATHING = 2, /* Breathing effect mode */
|
||||
AURA_MODE_FLASHING = 3, /* Flashing effect mode */
|
||||
AURA_MODE_SPECTRUM_CYCLE = 4, /* Spectrum Cycle mode */
|
||||
AURA_MODE_RAINBOW = 5, /* Rainbow effect mode */
|
||||
AURA_MODE_SPECTRUM_CYCLE_BREATHING = 6, /* Rainbow Breathing effect mode */
|
||||
AURA_MODE_CHASE_FADE = 7, /* Chase with Fade effect mode */
|
||||
AURA_MODE_SPECTRUM_CYCLE_CHASE_FADE = 8, /* Chase with Fade, Rainbow effect mode */
|
||||
AURA_MODE_CHASE = 9, /* Chase effect mode */
|
||||
AURA_MODE_SPECTRUM_CYCLE_CHASE = 10, /* Chase with Rainbow effect mode */
|
||||
AURA_MODE_SPECTRUM_CYCLE_WAVE = 11, /* Wave effect mode */
|
||||
AURA_MODE_CHASE_RAINBOW_PULSE = 12, /* Chase with Rainbow Pulse effect mode*/
|
||||
AURA_MODE_RANDOM_FLICKER = 13, /* Random flicker effect mode */
|
||||
AURA_MODE_MUSIC = 14, /* Music effect mode */
|
||||
AURA_MODE_DIRECT = 0xFF, /* Direct control mode */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
AURA_CONTROL_MODE_EFFECT = 0x3B, /* Effect control mode */
|
||||
AURA_CONTROL_MODE_DIRECT = 0x40, /* Direct control mode */
|
||||
AURA_REQUEST_FIRMWARE_VERSION = 0x82, /* Request firmware string */
|
||||
AURA_REQUEST_CONFIG_TABLE = 0xB0, /* Request configuration table */
|
||||
};
|
||||
|
||||
class AuraAddressableController
|
||||
{
|
||||
public:
|
||||
AuraAddressableController(hid_device* dev_handle);
|
||||
~AuraAddressableController();
|
||||
|
||||
unsigned int GetChannelCount();
|
||||
|
||||
std::string GetDeviceName();
|
||||
|
||||
void SetChannelLEDs
|
||||
(
|
||||
unsigned char channel,
|
||||
RGBColor * colors,
|
||||
unsigned int num_colors
|
||||
);
|
||||
|
||||
void SetMode
|
||||
(
|
||||
unsigned char mode,
|
||||
unsigned char red,
|
||||
unsigned char grn,
|
||||
unsigned char blu
|
||||
);
|
||||
|
||||
private:
|
||||
char device_name[16];
|
||||
unsigned char config_table[60];
|
||||
hid_device* dev;
|
||||
unsigned int led_count;
|
||||
|
||||
void GetConfigTable();
|
||||
|
||||
void GetFirmwareVersion();
|
||||
|
||||
void SendEffect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
unsigned char red,
|
||||
unsigned char grn,
|
||||
unsigned char blu
|
||||
);
|
||||
|
||||
void SendDirect
|
||||
(
|
||||
unsigned char device,
|
||||
unsigned char start_led,
|
||||
unsigned char led_count,
|
||||
unsigned char* led_data
|
||||
);
|
||||
|
||||
void SendDirectApply
|
||||
(
|
||||
unsigned char channel
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
#include "AuraAddressableController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_AuraAddressable.h"
|
||||
#include <vector>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#define AURA_ADDRESSABLE_VID 0x0B05
|
||||
|
||||
#define NUM_PIDS 4
|
||||
static const unsigned short pid_table[] =
|
||||
{
|
||||
0x1867,
|
||||
0x1872,
|
||||
0x1889,
|
||||
0x18A3
|
||||
};
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectAuraAddressableControllers *
|
||||
* *
|
||||
* Tests the USB address to see if an Asus Aura addressable RGB header controller *
|
||||
* exists there. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectAuraAddressableControllers(std::vector<RGBController*>& rgb_controllers)
|
||||
{
|
||||
hid_device* dev;
|
||||
|
||||
//Look for Asus Aura addressable RGB header controller
|
||||
hid_init();
|
||||
|
||||
for(int pid_idx = 0; pid_idx < NUM_PIDS; pid_idx++)
|
||||
{
|
||||
dev = hid_open(AURA_ADDRESSABLE_VID, pid_table[pid_idx], 0);
|
||||
|
||||
if( dev )
|
||||
{
|
||||
AuraAddressableController* controller = new AuraAddressableController(dev);
|
||||
|
||||
RGBController_AuraAddressable* rgb_controller = new RGBController_AuraAddressable(controller);
|
||||
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/*-----------------------------------------*\
|
||||
| AuraCoreController.cpp |
|
||||
| |
|
||||
| Driver for ASUS ROG Aura Core RGB |
|
||||
| lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 4/13/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "AuraCoreController.h"
|
||||
#include <cstring>
|
||||
|
||||
AuraCoreController::AuraCoreController(hid_device* dev_handle)
|
||||
{
|
||||
dev = dev_handle;
|
||||
}
|
||||
|
||||
AuraCoreController::~AuraCoreController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AuraCoreController::SendBrightness
|
||||
(
|
||||
unsigned char brightness
|
||||
)
|
||||
{
|
||||
unsigned char usb_buf[17];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up message packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x5A;
|
||||
usb_buf[0x01] = AURA_CORE_COMMAND_BRIGHTNESS;
|
||||
usb_buf[0x02] = 0xC5;
|
||||
usb_buf[0x03] = 0xC4;
|
||||
usb_buf[0x04] = brightness;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_send_feature_report(dev, usb_buf, 17);
|
||||
}
|
||||
|
||||
void AuraCoreController::SendUpdate
|
||||
(
|
||||
unsigned char zone,
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
)
|
||||
{
|
||||
unsigned char usb_buf[17];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up message packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x5D;
|
||||
usb_buf[0x01] = AURA_CORE_COMMAND_UPDATE;
|
||||
usb_buf[0x02] = zone;
|
||||
usb_buf[0x03] = mode;
|
||||
usb_buf[0x04] = red;
|
||||
usb_buf[0x05] = green;
|
||||
usb_buf[0x06] = blue;
|
||||
usb_buf[0x07] = speed;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_send_feature_report(dev, usb_buf, 17);
|
||||
}
|
||||
|
||||
void AuraCoreController::SendSet()
|
||||
{
|
||||
unsigned char usb_buf[17];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up message packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x5D;
|
||||
usb_buf[0x01] = AURA_CORE_COMMAND_SET;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_send_feature_report(dev, usb_buf, 17);
|
||||
}
|
||||
|
||||
void AuraCoreController::SendApply()
|
||||
{
|
||||
unsigned char usb_buf[17];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up message packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x5D;
|
||||
usb_buf[0x01] = AURA_CORE_COMMAND_APPLY;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_send_feature_report(dev, usb_buf, 17);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*-----------------------------------------*\
|
||||
| AuraCoreController.h |
|
||||
| |
|
||||
| Definitions and types for ASUS ROG Aura |
|
||||
| Core RGB lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 4/13/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
|
||||
#include <string>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
enum
|
||||
{
|
||||
AURA_CORE_MODE_STATIC = 0, /* Static color mode */
|
||||
AURA_CORE_MODE_BREATHING = 1, /* Breathing effect mode */
|
||||
AURA_CORE_MODE_SPECTRUM_CYCLE = 2, /* Spectrum Cycle mode */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
AURA_CORE_COMMAND_UPDATE = 0xB3, /* Update mode and color */
|
||||
AURA_CORE_COMMAND_SET = 0xB5, /* Set command */
|
||||
AURA_CORE_COMMAND_APPLY = 0xB4, /* Apply command */
|
||||
AURA_CORE_COMMAND_BRIGHTNESS = 0xBA, /* Brightness command */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
AURA_CORE_ZONE_IDX_ALL = 0x00, /* Update all zones */
|
||||
AURA_CORE_ZONE_IDX_1 = 0x01, /* Update zone 1 */
|
||||
AURA_CORE_ZONE_IDX_2 = 0x02, /* Update zone 2 */
|
||||
AURA_CORE_ZONE_IDX_3 = 0x03, /* Update zone 3 */
|
||||
AURA_CORE_ZONE_IDX_4 = 0x04, /* Update zone 4 */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
AURA_CORE_SPEED_SLOW = 0xE1, /* Slowest speed */
|
||||
AURA_CORE_SPEED_NORMAL = 0xEB, /* Normal speed */
|
||||
AURA_CORE_SPEED_FAST = 0xF5, /* Fastest speed */
|
||||
};
|
||||
|
||||
class AuraCoreController
|
||||
{
|
||||
public:
|
||||
AuraCoreController(hid_device* dev_handle);
|
||||
~AuraCoreController();
|
||||
|
||||
void SendBrightness
|
||||
(
|
||||
unsigned char brightness
|
||||
);
|
||||
|
||||
void SendUpdate
|
||||
(
|
||||
unsigned char zone,
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
);
|
||||
|
||||
void SendSet();
|
||||
|
||||
void SendApply();
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "AuraCoreController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_AuraCore.h"
|
||||
#include <vector>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#define AURA_CORE_VID 0x0B05
|
||||
|
||||
#define NUM_PIDS 3
|
||||
static const unsigned short pid_table[] =
|
||||
{
|
||||
0x1854,
|
||||
0x1869,
|
||||
0x1866
|
||||
};
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectAuraCoreControllers *
|
||||
* *
|
||||
* Tests the USB address to see if an Asus ROG Aura Core controller exists there *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectAuraCoreControllers(std::vector<RGBController*>& rgb_controllers)
|
||||
{
|
||||
hid_device* dev;
|
||||
|
||||
//Look for Asus ROG Aura Core RGB controller
|
||||
hid_init();
|
||||
|
||||
for(int pid_idx = 0; pid_idx < NUM_PIDS; pid_idx++)
|
||||
{
|
||||
dev = hid_open(AURA_CORE_VID, pid_table[pid_idx], 0);
|
||||
|
||||
if( dev )
|
||||
{
|
||||
AuraCoreController* controller = new AuraCoreController(dev);
|
||||
|
||||
RGBController_AuraCore* rgb_controller = new RGBController_AuraCore(controller);
|
||||
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*-----------------------------------------*\
|
||||
| AuraGPUController.cpp |
|
||||
| |
|
||||
| Driver for ASUS Aura RGB on GPUs |
|
||||
| |
|
||||
| Jan Rettig (Klapstuhl) 14.02.2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "AuraGPUController.h"
|
||||
#include <cstring>
|
||||
|
||||
AuraGPUController::AuraGPUController(i2c_smbus_interface* bus, aura_gpu_dev_id dev)
|
||||
{
|
||||
this->bus = bus;
|
||||
this->dev = dev;
|
||||
|
||||
strcpy(device_name, "ASUS Aura GPU"); // Would be nice to get the actual GPU name. Using this as a placeholder.
|
||||
}
|
||||
|
||||
AuraGPUController::~AuraGPUController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string AuraGPUController::GetDeviceName()
|
||||
{
|
||||
return(device_name);
|
||||
}
|
||||
|
||||
std::string AuraGPUController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
return_string.append(addr);
|
||||
return(return_string);
|
||||
}
|
||||
|
||||
unsigned char AuraGPUController::GetLEDRed()
|
||||
{
|
||||
return(AuraGPURegisterRead(AURA_GPU_REG_RED));
|
||||
}
|
||||
|
||||
unsigned char AuraGPUController::GetLEDGreen()
|
||||
{
|
||||
return(AuraGPURegisterRead(AURA_GPU_REG_GREEN));
|
||||
}
|
||||
|
||||
unsigned char AuraGPUController::GetLEDBlue()
|
||||
{
|
||||
return(AuraGPURegisterRead(AURA_GPU_REG_BLUE));
|
||||
}
|
||||
|
||||
void AuraGPUController::SetLEDColorsDirect(unsigned char red, unsigned char green, unsigned char blue) // Direct Mode is just Static Mode without applying color changes
|
||||
{
|
||||
AuraGPURegisterWrite(AURA_GPU_REG_RED, red);
|
||||
AuraGPURegisterWrite(AURA_GPU_REG_GREEN, green);
|
||||
AuraGPURegisterWrite(AURA_GPU_REG_BLUE, blue);
|
||||
}
|
||||
|
||||
void AuraGPUController::SetLEDColorsEffect(unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
AuraGPURegisterWrite(AURA_GPU_REG_RED, red);
|
||||
AuraGPURegisterWrite(AURA_GPU_REG_GREEN, green);
|
||||
AuraGPURegisterWrite(AURA_GPU_REG_BLUE, blue);
|
||||
AuraGPURegisterWrite(AURA_GPU_REG_APPLY, AURA_GPU_APPLY_VAL);
|
||||
}
|
||||
|
||||
void AuraGPUController::SetMode(unsigned char mode)
|
||||
{
|
||||
AuraGPURegisterWrite(AURA_GPU_REG_MODE, mode);
|
||||
AuraGPURegisterWrite(AURA_GPU_REG_APPLY, AURA_GPU_APPLY_VAL);
|
||||
}
|
||||
|
||||
unsigned char AuraGPUController::AuraGPURegisterRead(unsigned char reg)
|
||||
{
|
||||
return(bus->i2c_smbus_read_byte_data(dev, reg));
|
||||
}
|
||||
|
||||
void AuraGPUController::AuraGPURegisterWrite(unsigned char reg, unsigned char val)
|
||||
{
|
||||
bus->i2c_smbus_write_byte_data(dev, reg, val);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*-----------------------------------------*\
|
||||
| AuraGPUController.h |
|
||||
| |
|
||||
| Definitions for ASUS Aura RGB on GPUs |
|
||||
| |
|
||||
| Jan Rettig (Klapstuhl) 14.02.2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include <string>
|
||||
#include "i2c_smbus.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef unsigned char aura_gpu_dev_id;
|
||||
|
||||
#define AURA_GPU_MAGIC_VAL 0x1589 /* This magic value is present in all Aura GPU controllers */
|
||||
#define AURA_GPU_APPLY_VAL 0x01 /* Value for Apply Changes Register */
|
||||
|
||||
enum
|
||||
{
|
||||
AURA_GPU_REG_RED = 0x04, /* AURA GPU RED Register */
|
||||
AURA_GPU_REG_GREEN = 0x05, /* AURA GPU GREEN Register */
|
||||
AURA_GPU_REG_BLUE = 0x06, /* AURA GPU BLUE Register */
|
||||
AURA_GPU_REG_MODE = 0x07, /* AURA GPU Mode Selection Register */
|
||||
AURA_GPU_REG_SYNC = 0x0C, /* AURA GPU "Sync" Register */
|
||||
AURA_GPU_REG_APPLY = 0x0E, /* AURA GPU Apply Chnages Register */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
AURA_GPU_MODE_OFF = 0, /* OFF mode (not a real Mode! Doesn't do anything!) */
|
||||
AURA_GPU_MODE_STATIC = 1, /* Static color mode */
|
||||
AURA_GPU_MODE_BREATHING = 2, /* Breathing effect mode */
|
||||
AURA_GPU_MODE_FLASHING = 3, /* Flashing effect mode */
|
||||
AURA_GPU_MODE_SPECTRUM_CYCLE = 4, /* Spectrum Cycle mode */
|
||||
AURA_GPU_MODE_DIRECT = 5, /* Direct mode (not a real Mode! Doesn't do anything!) */
|
||||
AURA_GPU_NUMBER_MODES
|
||||
};
|
||||
|
||||
class AuraGPUController
|
||||
{
|
||||
public:
|
||||
AuraGPUController(i2c_smbus_interface* bus, aura_gpu_dev_id);
|
||||
~AuraGPUController();
|
||||
|
||||
std::string GetDeviceName();
|
||||
std::string GetDeviceLocation();
|
||||
unsigned char GetLEDRed();
|
||||
unsigned char GetLEDGreen();
|
||||
unsigned char GetLEDBlue();
|
||||
void SetLEDColorsDirect(unsigned char red, unsigned char green, unsigned char blue);
|
||||
void SetLEDColorsEffect(unsigned char red, unsigned char green, unsigned char blue);
|
||||
void SetMode(unsigned char mode);
|
||||
|
||||
unsigned char AuraGPURegisterRead(unsigned char reg);
|
||||
void AuraGPURegisterWrite(unsigned char reg, unsigned char val);
|
||||
|
||||
bool direct = false; // Temporary solution to check if we are in "Direct" mode
|
||||
|
||||
private:
|
||||
char device_name[16];
|
||||
i2c_smbus_interface * bus;
|
||||
aura_gpu_dev_id dev;
|
||||
};
|
||||
@@ -0,0 +1,94 @@
|
||||
/*-----------------------------------------*\
|
||||
| AuraGPUControllerDetect.cpp |
|
||||
| |
|
||||
| Driver for ASUS Aura RGB on GPUs |
|
||||
| |
|
||||
| Jan Rettig (Klapstuhl) 14.02.2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "AuraGPUController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_AuraGPU.h"
|
||||
#include "i2c_smbus.h"
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
|
||||
static void Sleep(unsigned int milliseconds)
|
||||
{
|
||||
usleep(1000 * milliseconds);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------*\
|
||||
| This list contains the available I2C addresses for Aura GPUs |
|
||||
\*-------------------------------------------------------------*/
|
||||
#define AURA_GPU_ADDRESS_COUNT 3
|
||||
|
||||
static const unsigned char aura_gpu_addresses[] =
|
||||
{
|
||||
0x29,
|
||||
0x2A,
|
||||
0x60
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* TestForAuraGPUController *
|
||||
* *
|
||||
* Tests the given address to see if an Aura GPU controller exists there. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
bool TestForAuraGPUController(i2c_smbus_interface* bus, unsigned char address)
|
||||
{
|
||||
bool pass = false;
|
||||
|
||||
unsigned char aura_gpu_magic_high = bus->i2c_smbus_read_byte_data(address, 0x20); // High Byte of magic (0x15)
|
||||
unsigned char aura_gpu_magic_low = bus->i2c_smbus_read_byte_data(address, 0x21); // Low Byte of magic (0x89)
|
||||
|
||||
if((aura_gpu_magic_high << 8) + aura_gpu_magic_low == AURA_GPU_MAGIC_VAL)
|
||||
{
|
||||
pass = true;
|
||||
}
|
||||
|
||||
return(pass);
|
||||
|
||||
} /* TestForAuraGPUController() */
|
||||
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectAuraGPUControllers *
|
||||
* *
|
||||
* Detect Aura GPU controllers on the enumerated I2C busses. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectAuraGPUControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers)
|
||||
{
|
||||
AuraGPUController* new_aura_gpu;
|
||||
RGBController_AuraGPU* new_controller;
|
||||
|
||||
for (unsigned int bus = 0; bus < busses.size(); bus++)
|
||||
{
|
||||
// Add Aura-enabled GPU controllers
|
||||
for (unsigned int address_list_idx = 0; address_list_idx < AURA_GPU_ADDRESS_COUNT; address_list_idx++)
|
||||
{
|
||||
if (TestForAuraGPUController(busses[bus], aura_gpu_addresses[address_list_idx]))
|
||||
{
|
||||
new_aura_gpu = new AuraGPUController(busses[bus], aura_gpu_addresses[address_list_idx]);
|
||||
new_controller = new RGBController_AuraGPU(new_aura_gpu);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
|
||||
Sleep(1);
|
||||
}
|
||||
}
|
||||
} /* DetectAuraGPUControllers() */
|
||||
+22
-22
@@ -1,5 +1,5 @@
|
||||
/*-----------------------------------------*\
|
||||
| AuraController.cpp |
|
||||
| AuraSMBusController.cpp |
|
||||
| |
|
||||
| Driver for ASUS Aura RGB lighting |
|
||||
| controller |
|
||||
@@ -7,10 +7,10 @@
|
||||
| Adam Honse (CalcProgrammer1) 8/19/2018 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "AuraController.h"
|
||||
#include "AuraSMBusController.h"
|
||||
#include <cstring>
|
||||
|
||||
AuraController::AuraController(i2c_smbus_interface* bus, aura_dev_id dev)
|
||||
AuraSMBusController::AuraSMBusController(i2c_smbus_interface* bus, aura_dev_id dev)
|
||||
{
|
||||
this->bus = bus;
|
||||
this->dev = dev;
|
||||
@@ -77,17 +77,17 @@ AuraController::AuraController(i2c_smbus_interface* bus, aura_dev_id dev)
|
||||
}
|
||||
}
|
||||
|
||||
AuraController::~AuraController()
|
||||
AuraSMBusController::~AuraSMBusController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string AuraController::GetDeviceName()
|
||||
std::string AuraSMBusController::GetDeviceName()
|
||||
{
|
||||
return(device_name);
|
||||
}
|
||||
|
||||
std::string AuraController::GetDeviceLocation()
|
||||
std::string AuraSMBusController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
char addr[5];
|
||||
@@ -97,12 +97,12 @@ std::string AuraController::GetDeviceLocation()
|
||||
return(return_string);
|
||||
}
|
||||
|
||||
unsigned char AuraController::GetChannel(unsigned int led)
|
||||
unsigned char AuraSMBusController::GetChannel(unsigned int led)
|
||||
{
|
||||
return(config_table[channel_cfg + led]);
|
||||
}
|
||||
|
||||
const char * AuraController::GetChannelName(unsigned int led)
|
||||
const char * AuraSMBusController::GetChannelName(unsigned int led)
|
||||
{
|
||||
switch (config_table[channel_cfg + led])
|
||||
{
|
||||
@@ -152,27 +152,27 @@ const char * AuraController::GetChannelName(unsigned int led)
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int AuraController::GetLEDCount()
|
||||
unsigned int AuraSMBusController::GetLEDCount()
|
||||
{
|
||||
return(led_count);
|
||||
}
|
||||
|
||||
unsigned char AuraController::GetLEDRed(unsigned int led)
|
||||
unsigned char AuraSMBusController::GetLEDRed(unsigned int led)
|
||||
{
|
||||
return(AuraRegisterRead(direct_reg + ( 3 * led )));
|
||||
}
|
||||
|
||||
unsigned char AuraController::GetLEDGreen(unsigned int led)
|
||||
unsigned char AuraSMBusController::GetLEDGreen(unsigned int led)
|
||||
{
|
||||
return(AuraRegisterRead(direct_reg + ( 3 * led ) + 2));
|
||||
}
|
||||
|
||||
unsigned char AuraController::GetLEDBlue(unsigned int led)
|
||||
unsigned char AuraSMBusController::GetLEDBlue(unsigned int led)
|
||||
{
|
||||
return(AuraRegisterRead(direct_reg + ( 3 * led ) + 1));
|
||||
}
|
||||
|
||||
void AuraController::SetAllColorsDirect(unsigned char red, unsigned char green, unsigned char blue)
|
||||
void AuraSMBusController::SetAllColorsDirect(unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
unsigned char* colors = new unsigned char[led_count * 3];
|
||||
|
||||
@@ -188,7 +188,7 @@ void AuraController::SetAllColorsDirect(unsigned char red, unsigned char green,
|
||||
delete colors;
|
||||
}
|
||||
|
||||
void AuraController::SetAllColorsEffect(unsigned char red, unsigned char green, unsigned char blue)
|
||||
void AuraSMBusController::SetAllColorsEffect(unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
unsigned char* colors = new unsigned char[led_count * 3];
|
||||
|
||||
@@ -206,20 +206,20 @@ void AuraController::SetAllColorsEffect(unsigned char red, unsigned char green,
|
||||
delete[] colors;
|
||||
}
|
||||
|
||||
void AuraController::SetDirect(unsigned char direct)
|
||||
void AuraSMBusController::SetDirect(unsigned char direct)
|
||||
{
|
||||
AuraRegisterWrite(AURA_REG_DIRECT, direct);
|
||||
AuraRegisterWrite(AURA_REG_APPLY, AURA_APPLY_VAL);
|
||||
}
|
||||
|
||||
void AuraController::SetLEDColorDirect(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
|
||||
void AuraSMBusController::SetLEDColorDirect(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
unsigned char colors[3] = { red, blue, green };
|
||||
|
||||
AuraRegisterWriteBlock(direct_reg + ( 3 * led ), colors, 3);
|
||||
}
|
||||
|
||||
void AuraController::SetLEDColorEffect(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
|
||||
void AuraSMBusController::SetLEDColorEffect(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
unsigned char colors[3] = { red, blue, green };
|
||||
|
||||
@@ -228,13 +228,13 @@ void AuraController::SetLEDColorEffect(unsigned int led, unsigned char red, unsi
|
||||
AuraRegisterWrite(AURA_REG_APPLY, AURA_APPLY_VAL);
|
||||
}
|
||||
|
||||
void AuraController::SetMode(unsigned char mode)
|
||||
void AuraSMBusController::SetMode(unsigned char mode)
|
||||
{
|
||||
AuraRegisterWrite(AURA_REG_MODE, mode);
|
||||
AuraRegisterWrite(AURA_REG_APPLY, AURA_APPLY_VAL);
|
||||
}
|
||||
|
||||
void AuraController::AuraUpdateDeviceName()
|
||||
void AuraSMBusController::AuraUpdateDeviceName()
|
||||
{
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
@@ -242,7 +242,7 @@ void AuraController::AuraUpdateDeviceName()
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char AuraController::AuraRegisterRead(aura_register reg)
|
||||
unsigned char AuraSMBusController::AuraRegisterRead(aura_register reg)
|
||||
{
|
||||
//Write Aura register
|
||||
bus->i2c_smbus_write_word_data(dev, 0x00, ((reg << 8) & 0xFF00) | ((reg >> 8) & 0x00FF));
|
||||
@@ -252,7 +252,7 @@ unsigned char AuraController::AuraRegisterRead(aura_register reg)
|
||||
|
||||
}
|
||||
|
||||
void AuraController::AuraRegisterWrite(aura_register reg, unsigned char val)
|
||||
void AuraSMBusController::AuraRegisterWrite(aura_register reg, unsigned char val)
|
||||
{
|
||||
//Write Aura register
|
||||
bus->i2c_smbus_write_word_data(dev, 0x00, ((reg << 8) & 0xFF00) | ((reg >> 8) & 0x00FF));
|
||||
@@ -262,7 +262,7 @@ void AuraController::AuraRegisterWrite(aura_register reg, unsigned char val)
|
||||
|
||||
}
|
||||
|
||||
void AuraController::AuraRegisterWriteBlock(aura_register reg, unsigned char * data, unsigned char sz)
|
||||
void AuraSMBusController::AuraRegisterWriteBlock(aura_register reg, unsigned char * data, unsigned char sz)
|
||||
{
|
||||
//Write Aura register
|
||||
bus->i2c_smbus_write_word_data(dev, 0x00, ((reg << 8) & 0xFF00) | ((reg >> 8) & 0x00FF));
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*-----------------------------------------*\
|
||||
| AuraController.h |
|
||||
| AuraSMBusController.h |
|
||||
| |
|
||||
| Definitions and types for ASUS Aura RGB |
|
||||
| lighting controller |
|
||||
@@ -88,11 +88,11 @@ enum
|
||||
AURA_CONFIG_CHANNEL_V2 = 0x1B, /* LED Channel V2 configuration offset */
|
||||
};
|
||||
|
||||
class AuraController
|
||||
class AuraSMBusController
|
||||
{
|
||||
public:
|
||||
AuraController(i2c_smbus_interface* bus, aura_dev_id dev);
|
||||
~AuraController();
|
||||
AuraSMBusController(i2c_smbus_interface* bus, aura_dev_id dev);
|
||||
~AuraSMBusController();
|
||||
|
||||
std::string GetDeviceName();
|
||||
std::string GetDeviceLocation();
|
||||
+31
-27
@@ -1,6 +1,6 @@
|
||||
#include "AuraController.h"
|
||||
#include "AuraSMBusController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_Aura.h"
|
||||
#include "RGBController_AuraSMBus.h"
|
||||
#include "i2c_smbus.h"
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
@@ -20,12 +20,13 @@ static void Sleep(unsigned int milliseconds)
|
||||
/*----------------------------------------------------------------------*\
|
||||
| This list contains the available SMBus addresses for mapping Aura RAM |
|
||||
\*----------------------------------------------------------------------*/
|
||||
#define AURA_RAM_ADDRESS_COUNT 21
|
||||
#define AURA_RAM_ADDRESS_COUNT 22
|
||||
|
||||
static const unsigned char aura_ram_addresses[] =
|
||||
{
|
||||
0x70,
|
||||
0x71,
|
||||
0x72,
|
||||
0x73,
|
||||
0x74,
|
||||
0x75,
|
||||
@@ -50,23 +51,22 @@ static const unsigned char aura_ram_addresses[] =
|
||||
/*---------------------------------------------------------------------------------*\
|
||||
| This list contains the available SMBus addresses for mapping Aura motherboards |
|
||||
\*---------------------------------------------------------------------------------*/
|
||||
#define AURA_MOBO_ADDRESS_COUNT 4
|
||||
#define AURA_MOBO_ADDRESS_COUNT 3
|
||||
|
||||
static const unsigned char aura_mobo_addresses[] =
|
||||
{
|
||||
0x40,
|
||||
0x4E,
|
||||
0x4F,
|
||||
0x66
|
||||
0x4F
|
||||
};
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* AuraRegisterWrite *
|
||||
* *
|
||||
* A standalone version of the AuraController::AuraRegisterWrite function for access *
|
||||
* to Aura devices without instancing the AuraController class or reading the config *
|
||||
* table from the device. *
|
||||
* A standalone version of the AuraSMBusController::AuraRegisterWrite function for *
|
||||
* access to Aura devices without instancing the AuraSMBusController class or reading *
|
||||
* the config table from the device. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
@@ -81,7 +81,7 @@ void AuraRegisterWrite(i2c_smbus_interface* bus, aura_dev_id dev, aura_register
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* TestForAuraController *
|
||||
* TestForAuraSMBusController *
|
||||
* *
|
||||
* Tests the given address to see if an Aura controller exists there. First does a *
|
||||
* quick write to test for a response, and if so does a simple read at 0xA0 to test *
|
||||
@@ -89,7 +89,7 @@ void AuraRegisterWrite(i2c_smbus_interface* bus, aura_dev_id dev, aura_register
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
bool TestForAuraController(i2c_smbus_interface* bus, unsigned char address)
|
||||
bool TestForAuraSMBusController(i2c_smbus_interface* bus, unsigned char address)
|
||||
{
|
||||
bool pass = false;
|
||||
|
||||
@@ -112,11 +112,11 @@ bool TestForAuraController(i2c_smbus_interface* bus, unsigned char address)
|
||||
|
||||
return(pass);
|
||||
|
||||
} /* TestForAuraController() */
|
||||
} /* TestForAuraSMBusController() */
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectAuraControllers *
|
||||
* DetectAuraSMBusControllers *
|
||||
* *
|
||||
* Detect Aura controllers on the enumerated I2C busses. Searches for Aura-enabled *
|
||||
* RAM at 0x77 and tries to initialize their slot addresses, then searches for them *
|
||||
@@ -128,14 +128,14 @@ bool TestForAuraController(i2c_smbus_interface* bus, unsigned char address)
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectAuraControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers)
|
||||
void DetectAuraSMBusControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers)
|
||||
{
|
||||
AuraController* new_aura;
|
||||
RGBController_Aura* new_controller;
|
||||
AuraSMBusController* new_aura;
|
||||
RGBController_AuraSMBus* new_controller;
|
||||
|
||||
for (unsigned int bus = 0; bus < busses.size(); bus++)
|
||||
{
|
||||
int address_list_idx = 0;
|
||||
int address_list_idx = -1;
|
||||
|
||||
// Remap Aura-enabled RAM modules on 0x77
|
||||
for (unsigned int slot = 0; slot < 8; slot++)
|
||||
@@ -149,10 +149,11 @@ void DetectAuraControllers(std::vector<i2c_smbus_interface*> &busses, std::vecto
|
||||
|
||||
do
|
||||
{
|
||||
address_list_idx++;
|
||||
|
||||
if(address_list_idx < AURA_RAM_ADDRESS_COUNT)
|
||||
{
|
||||
res = busses[bus]->i2c_smbus_write_quick(aura_ram_addresses[address_list_idx], I2C_SMBUS_WRITE);
|
||||
address_list_idx++;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -160,17 +161,20 @@ void DetectAuraControllers(std::vector<i2c_smbus_interface*> &busses, std::vecto
|
||||
}
|
||||
} while (res >= 0);
|
||||
|
||||
AuraRegisterWrite(busses[bus], 0x77, AURA_REG_SLOT_INDEX, slot);
|
||||
AuraRegisterWrite(busses[bus], 0x77, AURA_REG_I2C_ADDRESS, (aura_ram_addresses[address_list_idx] << 1));
|
||||
if(address_list_idx < AURA_RAM_ADDRESS_COUNT)
|
||||
{
|
||||
AuraRegisterWrite(busses[bus], 0x77, AURA_REG_SLOT_INDEX, slot);
|
||||
AuraRegisterWrite(busses[bus], 0x77, AURA_REG_I2C_ADDRESS, (aura_ram_addresses[address_list_idx] << 1));
|
||||
}
|
||||
}
|
||||
|
||||
// Add Aura-enabled controllers at their remapped addresses
|
||||
for (unsigned int address_list_idx = 0; address_list_idx < AURA_RAM_ADDRESS_COUNT; address_list_idx++)
|
||||
{
|
||||
if (TestForAuraController(busses[bus], aura_ram_addresses[address_list_idx]))
|
||||
if (TestForAuraSMBusController(busses[bus], aura_ram_addresses[address_list_idx]))
|
||||
{
|
||||
new_aura = new AuraController(busses[bus], aura_ram_addresses[address_list_idx]);
|
||||
new_controller = new RGBController_Aura(new_aura);
|
||||
new_aura = new AuraSMBusController(busses[bus], aura_ram_addresses[address_list_idx]);
|
||||
new_controller = new RGBController_AuraSMBus(new_aura);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
|
||||
@@ -180,10 +184,10 @@ void DetectAuraControllers(std::vector<i2c_smbus_interface*> &busses, std::vecto
|
||||
// Add Aura-enabled motherboard controllers
|
||||
for (unsigned int address_list_idx = 0; address_list_idx < AURA_MOBO_ADDRESS_COUNT; address_list_idx++)
|
||||
{
|
||||
if (TestForAuraController(busses[bus], aura_mobo_addresses[address_list_idx]))
|
||||
if (TestForAuraSMBusController(busses[bus], aura_mobo_addresses[address_list_idx]))
|
||||
{
|
||||
new_aura = new AuraController(busses[bus], aura_mobo_addresses[address_list_idx]);
|
||||
new_controller = new RGBController_Aura(new_aura);
|
||||
new_aura = new AuraSMBusController(busses[bus], aura_mobo_addresses[address_list_idx]);
|
||||
new_controller = new RGBController_AuraSMBus(new_aura);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
|
||||
@@ -191,4 +195,4 @@ void DetectAuraControllers(std::vector<i2c_smbus_interface*> &busses, std::vecto
|
||||
}
|
||||
}
|
||||
|
||||
} /* DetectAuraControllers() */
|
||||
} /* DetectAuraSMBusControllers() */
|
||||
@@ -0,0 +1,100 @@
|
||||
/*-------------------------------------------------------------------*\
|
||||
| CMMP750Controller.cpp |
|
||||
| |
|
||||
| Driver for Coolermaster MP750 mousepad |
|
||||
| |
|
||||
| Chris M (Dr_No) 16th Apr 2020 |
|
||||
| |
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
#include "CMMP750Controller.h"
|
||||
#include <cstring>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
CMMP750Controller::CMMP750Controller(libusb_device_handle* dev_handle, unsigned int _inAddr, unsigned int _outAddr, int _interface)
|
||||
{
|
||||
dev = dev_handle;
|
||||
inAddr = _inAddr;
|
||||
outAddr = _outAddr;
|
||||
interface = _interface;
|
||||
|
||||
libusb_device* device = libusb_get_device(dev);
|
||||
int bus = libusb_get_bus_number(device);
|
||||
int bus_addr = libusb_get_device_address(device);
|
||||
int port = libusb_get_port_number(device);
|
||||
location = "Bus: " + std::to_string(bus) + " Addr: " + std::to_string(bus_addr) + " Port: " + std::to_string(port);
|
||||
|
||||
strcpy(device_name, "Cooler Master MP750");
|
||||
|
||||
current_mode = MP750_MODE_STATIC;
|
||||
current_speed = MP750_SPEED_NORMAL;
|
||||
}
|
||||
|
||||
CMMP750Controller::~CMMP750Controller()
|
||||
{
|
||||
libusb_release_interface(dev, interface);
|
||||
libusb_attach_kernel_driver(dev, interface);
|
||||
}
|
||||
|
||||
char* CMMP750Controller::GetDeviceName()
|
||||
{
|
||||
return device_name;
|
||||
}
|
||||
|
||||
char* CMMP750Controller::GetSerial()
|
||||
{
|
||||
return serial;
|
||||
}
|
||||
|
||||
std::string CMMP750Controller::GetLocation()
|
||||
{
|
||||
return location;
|
||||
}
|
||||
|
||||
void CMMP750Controller::SetMode(unsigned char mode, unsigned char speed)
|
||||
{
|
||||
current_mode = mode;
|
||||
current_speed = speed;
|
||||
|
||||
SendUpdate();
|
||||
}
|
||||
|
||||
void CMMP750Controller::SetColor(unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
current_red = red;
|
||||
current_green = green;
|
||||
current_blue = blue;
|
||||
|
||||
SendUpdate();
|
||||
}
|
||||
|
||||
void CMMP750Controller::SendUpdate()
|
||||
{
|
||||
int actual = 0;
|
||||
unsigned char buffer[0x40] = { 0x00 };
|
||||
int buffer_size = (sizeof(buffer) / sizeof(buffer[0]));
|
||||
|
||||
for(int i = 0; i < CM_COLOUR_MODE_DATA_SIZE; i++)
|
||||
{
|
||||
buffer[i] = colour_mode_data[current_mode][i];
|
||||
}
|
||||
|
||||
if(current_mode > MP750_MODE_BREATHING)
|
||||
{
|
||||
//If the mode is random colours set SPEED at BYTE2
|
||||
buffer[CM_RED_BYTE] = speed_mode_data[current_mode][current_speed];
|
||||
}
|
||||
else
|
||||
{
|
||||
//Otherwise SPEED is BYTE5
|
||||
buffer[CM_RED_BYTE] = current_red;
|
||||
buffer[CM_GREEN_BYTE] = current_green;
|
||||
buffer[CM_BLUE_BYTE] = current_blue;
|
||||
buffer[CM_SPEED_BYTE] = speed_mode_data[current_mode][current_speed];
|
||||
}
|
||||
|
||||
//Nothing will be done with the "actual" transfer length
|
||||
libusb_interrupt_transfer(dev, outAddr, buffer, buffer_size, nullptr, CM_INTERRUPT_TIMEOUT);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/*-------------------------------------------------------------------*\
|
||||
| CMMP750Controller.h |
|
||||
| |
|
||||
| Driver for Coolermaster MP750 mousepad |
|
||||
| |
|
||||
| Chris M (Dr_No) 16th Apr 2020 |
|
||||
| |
|
||||
| Simple RGB device with 5 modes |
|
||||
| BYTE0 = Mode (0x01 thru 0x05 |
|
||||
| BYTE1 = ?? Must be set to 0x04 for colour modes otherwise ignored |
|
||||
| BYTE2 = Colour Modes: RED else Cycle SPEED |
|
||||
| BYTE3 = Colour Modes: GREEN else ignored |
|
||||
| BYTE4 = Colour Modes: BLUE else ignored |
|
||||
| BYTE5 = Colour Modes: SPEED else ignored |
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
#define CM_COLOUR_MODE_DATA_SIZE (sizeof(colour_mode_data) / sizeof(colour_mode_data[0]))
|
||||
#define CM_INTERRUPT_TIMEOUT 250
|
||||
|
||||
enum
|
||||
{
|
||||
CM_MODE_BYTE = 0,
|
||||
CM_RED_BYTE = 2,
|
||||
CM_GREEN_BYTE = 3,
|
||||
CM_BLUE_BYTE = 4,
|
||||
CM_SPEED_BYTE = 5
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
MP750_MODE_STATIC = 0x00, //Static Mode
|
||||
MP750_MODE_BLINK = 0x01, //Blinking Mode
|
||||
MP750_MODE_BREATHING = 0x02, //Breathing Mode
|
||||
MP750_MODE_COLOR_CYCLE = 0x03, //Color Cycle Mode
|
||||
MP750_MODE_BREATH_CYCLE = 0x04 //Breathing Cycle Mode
|
||||
};
|
||||
|
||||
static unsigned char colour_mode_data[][6] =
|
||||
{
|
||||
{ 0x01, 0x04, 0xFF, 0x00, 0xFF, 0x00 }, /* Static */
|
||||
{ 0x02, 0x04, 0xFF, 0x00, 0xFF, 0x80 }, /* Blinking */
|
||||
{ 0x03, 0x04, 0xFF, 0x00, 0xFF, 0x80 }, /* Breathing */
|
||||
{ 0x04, 0x04, 0x80, 0x00, 0x00, 0x00 }, /* Colour Cycle */
|
||||
{ 0x05, 0x04, 0x80, 0x00, 0x00, 0x00 } /* Colour Breath */
|
||||
};
|
||||
|
||||
static unsigned char speed_mode_data[][9] =
|
||||
{
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },/* Static */
|
||||
{ 0x00, 0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0xE0, 0xFF },/* Blinking */
|
||||
{ 0x00, 0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0xE0, 0xFF },/* Breathing */
|
||||
{ 0x00, 0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0xE0, 0xFF },/* Colour Cycle */
|
||||
{ 0x00, 0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0xE0, 0xFF } /* Colour Breath */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
MP750_SPEED_SLOWEST = 0x00, /* Slowest speed */
|
||||
MP750_SPEED_SLOWER = 0x01, /* Slower speed */
|
||||
MP750_SPEED_SLOW = 0x02, /* Slow speed */
|
||||
MP750_SPEED_SLOWISH = 0x03, /* Slowish speed */
|
||||
MP750_SPEED_NORMAL = 0x04, /* Normal speed */
|
||||
MP750_SPEED_FASTISH = 0x05, /* Fastish speed */
|
||||
MP750_SPEED_FAST = 0x06, /* Fast speed */
|
||||
MP750_SPEED_FASTER = 0x07, /* Faster speed */
|
||||
MP750_SPEED_FASTEST = 0x08, /* Fastest speed */
|
||||
};
|
||||
|
||||
class CMMP750Controller
|
||||
{
|
||||
public:
|
||||
CMMP750Controller(libusb_device_handle *dev_handle, unsigned int _inAddr, unsigned int _outAddr, int _interface);
|
||||
~CMMP750Controller();
|
||||
|
||||
char* GetDeviceName();
|
||||
char* GetSerial();
|
||||
std::string GetLocation();
|
||||
|
||||
void SetMode(unsigned char mode, unsigned char speed);
|
||||
void SetColor(unsigned char red, unsigned char green, unsigned char blue);
|
||||
|
||||
private:
|
||||
char device_name[32];
|
||||
char serial[32];
|
||||
std::string location;
|
||||
libusb_device_handle* dev;
|
||||
unsigned char inAddr;
|
||||
unsigned char outAddr;
|
||||
int interface;
|
||||
|
||||
unsigned char current_mode;
|
||||
unsigned char current_speed;
|
||||
|
||||
unsigned char current_red;
|
||||
unsigned char current_green;
|
||||
unsigned char current_blue;
|
||||
|
||||
void SendUpdate();
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
#include "CMMP750Controller.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_CMMP750Controller.h"
|
||||
#include <vector>
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
#define COOLERMASTER_VID 0x2516
|
||||
|
||||
#define COOLERMASTER_NUM_DEVICES (sizeof(cm_pids) / sizeof(cm_pids[ 0 ]))
|
||||
|
||||
enum
|
||||
{
|
||||
CM_PID = 0,
|
||||
CM_INADDR = 1,
|
||||
CM_OUTADDR = 2,
|
||||
CM_INTERFACE = 3
|
||||
};
|
||||
|
||||
static const unsigned int cm_pids[][4] =
|
||||
{ //PID, inAddr, outAddr, interface
|
||||
{ 0x0109, 0x82, 0x03, 0x00 } //Coolermaster MP750
|
||||
};
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectCoolerMasterControllers *
|
||||
* *
|
||||
* Tests the USB address to see if any CoolerMaster controllers exists there. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectCoolerMasterControllers(std::vector<RGBController*>& rgb_controllers)
|
||||
{
|
||||
libusb_context * context;
|
||||
libusb_init(&context);
|
||||
|
||||
for(int cm_pid_idx = 0; cm_pid_idx < COOLERMASTER_NUM_DEVICES; cm_pid_idx++)
|
||||
{
|
||||
//Look for the passed in cm_pids
|
||||
libusb_device_handle * dev = libusb_open_device_with_vid_pid(context, COOLERMASTER_VID, cm_pids[cm_pid_idx][CM_PID]);
|
||||
|
||||
if(dev)
|
||||
{
|
||||
int status = libusb_detach_kernel_driver(dev, cm_pids[cm_pid_idx][CM_INTERFACE]);
|
||||
status = libusb_claim_interface(dev, cm_pids[cm_pid_idx][CM_INTERFACE]);
|
||||
|
||||
if(status == 0)
|
||||
{
|
||||
// Success: Device has been claimed
|
||||
CMMP750Controller* controller = new CMMP750Controller(dev, cm_pids[cm_pid_idx][CM_INADDR], cm_pids[cm_pid_idx][CM_OUTADDR], cm_pids[cm_pid_idx][CM_INTERFACE]);
|
||||
RGBController_CMMP750Controller* rgb_controller = new RGBController_CMMP750Controller(controller);
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,504 +0,0 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| Processing Code for Corsair Commander Pro |
|
||||
| |
|
||||
| Adam Honse ([email protected]), 1/16/2020 |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "CorsairCmdrProController.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
//Include thread libraries for Windows or Linux
|
||||
#ifdef WIN32
|
||||
#include <process.h>
|
||||
#else
|
||||
#include "pthread.h"
|
||||
#include "unistd.h"
|
||||
#endif
|
||||
|
||||
//Thread functions have different types in Windows and Linux
|
||||
#ifdef WIN32
|
||||
#define THREAD static void
|
||||
#define THREADRETURN
|
||||
#else
|
||||
#define THREAD static void*
|
||||
#define THREADRETURN return(NULL);
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
|
||||
static void Sleep(unsigned int milliseconds)
|
||||
{
|
||||
usleep(1000 * milliseconds);
|
||||
}
|
||||
#endif
|
||||
|
||||
THREAD keepalive_thread(void *param)
|
||||
{
|
||||
CorsairCmdrProController* corsair = static_cast<CorsairCmdrProController*>(param);
|
||||
corsair->KeepaliveThread();
|
||||
THREADRETURN
|
||||
}
|
||||
|
||||
CorsairCmdrProController::CorsairCmdrProController(libusb_device_handle* dev_handle)
|
||||
{
|
||||
dev = dev_handle;
|
||||
channel_leds[0] = 60;
|
||||
channel_leds[1] = 60;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| The Corsair Lighting Node Pro requires a packet within|
|
||||
| 20 seconds of sending the lighting change in order |
|
||||
| to not revert back into rainbow mode. Start a thread |
|
||||
| to continuously send a keepalive packet every 5s |
|
||||
\*-----------------------------------------------------*/
|
||||
#ifdef WIN32
|
||||
_beginthread(keepalive_thread, 0, this);
|
||||
#else
|
||||
pthread_t thread;
|
||||
pthread_create(&thread, NULL, &keepalive_thread, this);
|
||||
#endif
|
||||
}
|
||||
|
||||
CorsairCmdrProController::~CorsairCmdrProController()
|
||||
{
|
||||
}
|
||||
|
||||
void CorsairCmdrProController::KeepaliveThread()
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
SendCommit();
|
||||
Sleep(5000);
|
||||
}
|
||||
}
|
||||
|
||||
void CorsairCmdrProController::SetChannelEffect(unsigned char channel,
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
unsigned char direction,
|
||||
bool random,
|
||||
unsigned char red1,
|
||||
unsigned char grn1,
|
||||
unsigned char blu1,
|
||||
unsigned char red2,
|
||||
unsigned char grn2,
|
||||
unsigned char blu2
|
||||
)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Send Reset packet |
|
||||
\*-----------------------------------------------------*/
|
||||
SendReset(channel);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send Begin packet |
|
||||
\*-----------------------------------------------------*/
|
||||
SendBegin(channel);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set Port State packet |
|
||||
\*-----------------------------------------------------*/
|
||||
SendPortState(channel, CORSAIR_CMDR_PRO_PORT_STATE_HARDWARE);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set Effect Configuration packet |
|
||||
\*-----------------------------------------------------*/
|
||||
SendEffectConfig
|
||||
(
|
||||
channel,
|
||||
0,
|
||||
CORSAIR_CMDR_PRO_LED_TYPE_LED_STRIP,
|
||||
mode,
|
||||
speed,
|
||||
direction,
|
||||
random,
|
||||
red1,
|
||||
grn1,
|
||||
blu1,
|
||||
red2,
|
||||
grn2,
|
||||
blu2,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send Commit packet |
|
||||
\*-----------------------------------------------------*/
|
||||
SendCommit();
|
||||
}
|
||||
|
||||
void CorsairCmdrProController::SetChannelLEDs(unsigned char channel, std::vector<RGBColor> colors)
|
||||
{
|
||||
unsigned char color_data[50];
|
||||
unsigned char pkt_max;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send Port State packet |
|
||||
\*-----------------------------------------------------*/
|
||||
SendPortState(channel, CORSAIR_CMDR_PRO_PORT_STATE_SOFTWARE);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send red channel packet 1 |
|
||||
\*-----------------------------------------------------*/
|
||||
pkt_max = 50;
|
||||
|
||||
if(pkt_max > colors.size())
|
||||
{
|
||||
pkt_max = (unsigned char)colors.size();
|
||||
}
|
||||
|
||||
for(int idx = 0; idx < pkt_max; idx++)
|
||||
{
|
||||
color_data[idx] = RGBGetRValue(colors[idx]);
|
||||
}
|
||||
|
||||
SendDirect(channel, 0, pkt_max, CORSAIR_CMDR_PRO_DIRECT_CHANNEL_RED, color_data);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send red channel packet 2 if necessary |
|
||||
\*-----------------------------------------------------*/
|
||||
pkt_max = 0;
|
||||
|
||||
if (colors.size() > 50)
|
||||
{
|
||||
pkt_max = (unsigned char)(colors.size() - 50);
|
||||
}
|
||||
|
||||
if(pkt_max > 0)
|
||||
{
|
||||
for (std::size_t idx = 0; idx < pkt_max; idx++)
|
||||
{
|
||||
color_data[idx] = RGBGetRValue(colors[idx+50]);
|
||||
}
|
||||
|
||||
SendDirect(channel, 50, pkt_max, CORSAIR_CMDR_PRO_DIRECT_CHANNEL_RED, color_data);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send green channel packet 1 |
|
||||
\*-----------------------------------------------------*/
|
||||
pkt_max = 50;
|
||||
|
||||
if(pkt_max > colors.size())
|
||||
{
|
||||
pkt_max = (unsigned char)colors.size();
|
||||
}
|
||||
|
||||
for(int idx = 0; idx < pkt_max; idx++)
|
||||
{
|
||||
color_data[idx] = RGBGetGValue(colors[idx]);
|
||||
}
|
||||
|
||||
SendDirect(channel, 0, pkt_max, CORSAIR_CMDR_PRO_DIRECT_CHANNEL_GREEN, color_data);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send green channel packet 2 if necessary |
|
||||
\*-----------------------------------------------------*/
|
||||
pkt_max = 0;
|
||||
|
||||
if (colors.size() > 50)
|
||||
{
|
||||
pkt_max = (unsigned char)(colors.size() - 50);
|
||||
}
|
||||
|
||||
if(pkt_max > 0)
|
||||
{
|
||||
for (std::size_t idx = 0; idx < pkt_max; idx++)
|
||||
{
|
||||
color_data[idx] = RGBGetGValue(colors[idx+50]);
|
||||
}
|
||||
|
||||
SendDirect(channel, 50, pkt_max, CORSAIR_CMDR_PRO_DIRECT_CHANNEL_GREEN, color_data);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send blue channel packet 1 |
|
||||
\*-----------------------------------------------------*/
|
||||
pkt_max = 50;
|
||||
|
||||
if(pkt_max > colors.size())
|
||||
{
|
||||
pkt_max = (unsigned char)colors.size();
|
||||
}
|
||||
|
||||
for(int idx = 0; idx < pkt_max; idx++)
|
||||
{
|
||||
color_data[idx] = RGBGetBValue(colors[idx]);
|
||||
}
|
||||
|
||||
SendDirect(channel, 0, pkt_max, CORSAIR_CMDR_PRO_DIRECT_CHANNEL_BLUE, color_data);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send blue channel packet 2 if necessary |
|
||||
\*-----------------------------------------------------*/
|
||||
pkt_max = 0;
|
||||
|
||||
if (colors.size() > 50)
|
||||
{
|
||||
pkt_max = (unsigned char)(colors.size() - 50);
|
||||
}
|
||||
|
||||
if(pkt_max > 0)
|
||||
{
|
||||
for (std::size_t idx = 0; idx < pkt_max; idx++)
|
||||
{
|
||||
color_data[idx] = RGBGetBValue(colors[idx+50]);
|
||||
}
|
||||
|
||||
SendDirect(channel, 50, pkt_max, CORSAIR_CMDR_PRO_DIRECT_CHANNEL_BLUE, color_data);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send Commit packet |
|
||||
\*-----------------------------------------------------*/
|
||||
SendCommit();
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------------------------------*\
|
||||
| Private packet sending functions. |
|
||||
\*-------------------------------------------------------------------------------------------------*/
|
||||
|
||||
void CorsairCmdrProController::SendDirect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char start,
|
||||
unsigned char count,
|
||||
unsigned char color_channel,
|
||||
unsigned char* color_data
|
||||
)
|
||||
{
|
||||
int actual;
|
||||
unsigned char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Direct packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_CMDR_PRO_PACKET_ID_DIRECT;
|
||||
usb_buf[0x01] = channel;
|
||||
usb_buf[0x02] = start;
|
||||
usb_buf[0x03] = count;
|
||||
usb_buf[0x04] = color_channel;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in color data bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(&usb_buf[0x05], color_data, count);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
libusb_interrupt_transfer(dev, 0x02, usb_buf, 64, &actual, 0);
|
||||
}
|
||||
|
||||
void CorsairCmdrProController::SendCommit()
|
||||
{
|
||||
int actual;
|
||||
unsigned char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Commit packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_CMDR_PRO_PACKET_ID_COMMIT;
|
||||
usb_buf[0x01] = 0xFF;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
libusb_interrupt_transfer(dev, 0x02, usb_buf, 64, &actual, 0);
|
||||
}
|
||||
|
||||
void CorsairCmdrProController::SendBegin
|
||||
(
|
||||
unsigned char channel
|
||||
)
|
||||
{
|
||||
int actual;
|
||||
unsigned char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Begin packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_CMDR_PRO_PACKET_ID_BEGIN;
|
||||
usb_buf[0x01] = channel;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
libusb_interrupt_transfer(dev, 0x02, usb_buf, 64, &actual, 0);
|
||||
}
|
||||
|
||||
void CorsairCmdrProController::SendEffectConfig
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char count,
|
||||
unsigned char led_type,
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
unsigned char direction,
|
||||
unsigned char change_style,
|
||||
unsigned char color_0_red,
|
||||
unsigned char color_0_green,
|
||||
unsigned char color_0_blue,
|
||||
unsigned char color_1_red,
|
||||
unsigned char color_1_green,
|
||||
unsigned char color_1_blue,
|
||||
unsigned char color_2_red,
|
||||
unsigned char color_2_green,
|
||||
unsigned char color_2_blue,
|
||||
unsigned short temperature_0,
|
||||
unsigned short temperature_1,
|
||||
unsigned short temperature_2
|
||||
)
|
||||
{
|
||||
int actual;
|
||||
unsigned char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Effect Config packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_CMDR_PRO_PACKET_ID_EFFECT_CONFIG;
|
||||
usb_buf[0x01] = channel;
|
||||
usb_buf[0x02] = count * 10;
|
||||
usb_buf[0x03] = led_type;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up mode parameters |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x04] = mode;
|
||||
usb_buf[0x05] = speed;
|
||||
usb_buf[0x06] = direction;
|
||||
usb_buf[0x07] = change_style;
|
||||
usb_buf[0x08] = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up mode colors |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x09] = color_0_red;
|
||||
usb_buf[0x10] = color_0_green;
|
||||
usb_buf[0x11] = color_0_blue;
|
||||
usb_buf[0x12] = color_1_red;
|
||||
usb_buf[0x13] = color_1_green;
|
||||
usb_buf[0x14] = color_1_blue;
|
||||
usb_buf[0x15] = color_2_red;
|
||||
usb_buf[0x16] = color_2_green;
|
||||
usb_buf[0x17] = color_2_blue;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up temperatures |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x12] = (temperature_0 >> 8);
|
||||
usb_buf[0x13] = (temperature_0 & 0xFF);
|
||||
usb_buf[0x14] = (temperature_1 >> 8);
|
||||
usb_buf[0x15] = (temperature_1 & 0xFF);
|
||||
usb_buf[0x16] = (temperature_2 >> 8);
|
||||
usb_buf[0x17] = (temperature_2 & 0xFF);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
libusb_interrupt_transfer(dev, 0x02, usb_buf, 64, &actual, 0);
|
||||
}
|
||||
|
||||
void CorsairCmdrProController::SendTemperature()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CorsairCmdrProController::SendReset
|
||||
(
|
||||
unsigned char channel
|
||||
)
|
||||
{
|
||||
int actual;
|
||||
unsigned char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Reset packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_CMDR_PRO_PACKET_ID_RESET;
|
||||
usb_buf[0x01] = channel;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
libusb_interrupt_transfer(dev, 0x02, usb_buf, 64, &actual, 0);
|
||||
}
|
||||
|
||||
void CorsairCmdrProController::SendPortState
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char state
|
||||
)
|
||||
{
|
||||
int actual;
|
||||
unsigned char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Port State packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_CMDR_PRO_PACKET_ID_PORT_STATE;
|
||||
usb_buf[0x01] = channel;
|
||||
usb_buf[0x02] = state;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
libusb_interrupt_transfer(dev, 0x02, usb_buf, 64, &actual, 0);
|
||||
}
|
||||
|
||||
void CorsairCmdrProController::SendBrightness()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CorsairCmdrProController::SendLEDCount()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CorsairCmdrProController::SendProtocol()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,163 +0,0 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| Definitions for Corsair Commander Pro |
|
||||
| |
|
||||
| Adam Honse ([email protected]), 1/16/2020 |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
#include <vector>
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_CMDR_PRO_PACKET_ID_DIRECT = 0x32, /* Direct mode LED update packet */
|
||||
CORSAIR_CMDR_PRO_PACKET_ID_COMMIT = 0x33, /* Commit changes packet */
|
||||
CORSAIR_CMDR_PRO_PACKET_ID_BEGIN = 0x34, /* Begin effect packet */
|
||||
CORSAIR_CMDR_PRO_PACKET_ID_EFFECT_CONFIG = 0x35, /* Effect mode configuration packet */
|
||||
CORSAIR_CMDR_PRO_PACKET_ID_TEMPERATURE = 0x36, /* Update temperature value packet */
|
||||
CORSAIR_CMDR_PRO_PACKET_ID_RESET = 0x37, /* Reset channel packet */
|
||||
CORSAIR_CMDR_PRO_PACKET_ID_PORT_STATE = 0x38, /* Set port state packet */
|
||||
CORSAIR_CMDR_PRO_PACKET_ID_BRIGHTNESS = 0x39, /* Set brightness packet */
|
||||
CORSAIR_CMDR_PRO_PACKET_ID_LED_COUNT = 0x3A, /* Set LED count packet */
|
||||
CORSAIR_CMDR_PRO_PACKET_ID_PROTOCOL = 0x3B, /* Set protocol packet */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_CMDR_PRO_DIRECT_CHANNEL_RED = 0x00, /* Red channel for direct update */
|
||||
CORSAIR_CMDR_PRO_DIRECT_CHANNEL_GREEN = 0x01, /* Green channel for direct update */
|
||||
CORSAIR_CMDR_PRO_DIRECT_CHANNEL_BLUE = 0x02, /* Blue channel for direct update */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_CMDR_PRO_PORT_STATE_HARDWARE = 0x01, /* Effect hardware control of channel */
|
||||
CORSAIR_CMDR_PRO_PORT_STATE_SOFTWARE = 0x02, /* Direct software control of channel */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_CMDR_PRO_LED_TYPE_LED_STRIP = 0x0A, /* Corsair LED Strip Type */
|
||||
CORSAIR_CMDR_PRO_LED_TYPE_HD_FAN = 0x0C, /* Corsair HD-series Fan Type */
|
||||
CORSAIR_CMDR_PRO_LED_TYPE_SP_FAN = 0x01, /* Corsair SP-series Fan Type */
|
||||
CORSAIR_CMDR_PRO_LED_TYPE_ML_FAN = 0x02, /* Corsair ML-series Fan Type */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_CMDR_PRO_CHANNEL_1 = 0x00, /* Channel 1 */
|
||||
CORSAIR_CMDR_PRO_CHANNEL_2 = 0x01, /* Channel 2 */
|
||||
CORSAIR_CMDR_PRO_NUM_CHANNELS = 0x02, /* Number of channels */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_CMDR_PRO_SPEED_FAST = 0x00, /* Fast speed */
|
||||
CORSAIR_CMDR_PRO_SPEED_MEDIUM = 0x01, /* Medium speed */
|
||||
CORSAIR_CMDR_PRO_SPEED_SLOW = 0x02, /* Slow speed */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_CMDR_PRO_MODE_RAINBOW_WAVE = 0x00, /* Rainbow Wave mode */
|
||||
CORSAIR_CMDR_PRO_MODE_COLOR_SHIFT = 0x01, /* Color Shift mode */
|
||||
CORSAIR_CMDR_PRO_MODE_COLOR_PULSE = 0x02, /* Color Pulse mode */
|
||||
CORSAIR_CMDR_PRO_MODE_COLOR_WAVE = 0x03, /* Color Wave mode */
|
||||
CORSAIR_CMDR_PRO_MODE_STATIC = 0x04, /* Static mode */
|
||||
CORSAIR_CMDR_PRO_MODE_TEMPERATURE = 0x05, /* Temperature mode */
|
||||
CORSAIR_CMDR_PRO_MODE_VISOR = 0x06, /* Visor mode */
|
||||
CORSAIR_CMDR_PRO_MODE_MARQUEE = 0x07, /* Marquee mode */
|
||||
CORSAIR_CMDR_PRO_MODE_BLINK = 0x08, /* Blink mode */
|
||||
CORSAIR_CMDR_PRO_MODE_SEQUENTIAL = 0x09, /* Sequential mode */
|
||||
CORSAIR_CMDR_PRO_MODE_RAINBOW = 0x0A, /* Rainbow mode */
|
||||
};
|
||||
|
||||
class CorsairCmdrProController
|
||||
{
|
||||
public:
|
||||
CorsairCmdrProController(libusb_device_handle* dev_handle);
|
||||
~CorsairCmdrProController();
|
||||
|
||||
unsigned int GetStripsOnChannel(unsigned int channel);
|
||||
|
||||
void SetChannelEffect(unsigned char channel,
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
unsigned char direction,
|
||||
bool random,
|
||||
unsigned char red1,
|
||||
unsigned char grn1,
|
||||
unsigned char blu1,
|
||||
unsigned char red2,
|
||||
unsigned char grn2,
|
||||
unsigned char blu2
|
||||
);
|
||||
|
||||
void SetChannelLEDs(unsigned char channel, std::vector<RGBColor> colors);
|
||||
unsigned int channel_leds[CORSAIR_CMDR_PRO_NUM_CHANNELS];
|
||||
|
||||
void KeepaliveThread();
|
||||
|
||||
private:
|
||||
libusb_device_handle* dev;
|
||||
|
||||
void SendDirect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char start,
|
||||
unsigned char count,
|
||||
unsigned char color_channel,
|
||||
unsigned char* color_data
|
||||
);
|
||||
|
||||
void SendCommit();
|
||||
|
||||
void SendBegin
|
||||
(
|
||||
unsigned char channel
|
||||
);
|
||||
|
||||
void SendEffectConfig
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char count,
|
||||
unsigned char led_type,
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
unsigned char direction,
|
||||
unsigned char change_style,
|
||||
unsigned char color_0_red,
|
||||
unsigned char color_0_green,
|
||||
unsigned char color_0_blue,
|
||||
unsigned char color_1_red,
|
||||
unsigned char color_1_green,
|
||||
unsigned char color_1_blue,
|
||||
unsigned char color_2_red,
|
||||
unsigned char color_2_green,
|
||||
unsigned char color_2_blue,
|
||||
unsigned short temperature_0,
|
||||
unsigned short temperature_1,
|
||||
unsigned short temperature_2
|
||||
);
|
||||
|
||||
void SendTemperature();
|
||||
|
||||
void SendReset
|
||||
(
|
||||
unsigned char channel
|
||||
);
|
||||
|
||||
void SendPortState
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char state
|
||||
);
|
||||
|
||||
void SendBrightness();
|
||||
|
||||
void SendLEDCount();
|
||||
|
||||
void SendProtocol();
|
||||
};
|
||||
@@ -1,253 +0,0 @@
|
||||
/*-----------------------------------------*\
|
||||
| CorsairKeyboardController.cpp |
|
||||
| |
|
||||
| Driver for Corsair RGB keyboard lighting |
|
||||
| controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 1/9/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "CorsairKeyboardController.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
static unsigned int keys[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0x11, 0x12,
|
||||
0x14, 0x15, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x24, 0x25, 0x26,
|
||||
0x27, 0x28, 0x2A, 0x2B, 0x2C, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
|
||||
0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x42, 0x43, 0x44, 0x45, 0x48, 73, 74, 75, 76, 78,
|
||||
79, 80, 81, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 96, 97,
|
||||
98, 99, 100, 101, 102, 103, 104, 105, 108, 109, 110, 111, 112, 113, 115,
|
||||
116, 117, 120, 121, 122, 123, 124, 126, 127, 128, 129, 132, 133, 134, 135,
|
||||
136, 137, 139, 140, 141};
|
||||
|
||||
static void send_usb_msg(hid_device* dev, char * data_pkt)
|
||||
{
|
||||
char usb_pkt[65];
|
||||
usb_pkt[0] = 0x00;
|
||||
for(int i = 1; i < 65; i++)
|
||||
{
|
||||
usb_pkt[i] = data_pkt[i-1];
|
||||
}
|
||||
int bytes = hid_send_feature_report(dev, (unsigned char *)usb_pkt, 65);
|
||||
bytes++;
|
||||
}
|
||||
|
||||
static void get_usb_msg(hid_device* dev, char* data_pkt)
|
||||
{
|
||||
char usb_pkt[65];
|
||||
usb_pkt[0] = 0x00;
|
||||
for(int i = 1; i < 65; i++)
|
||||
{
|
||||
usb_pkt[i] = data_pkt[i-1];
|
||||
}
|
||||
int bytes = hid_get_feature_report(dev, (unsigned char*)data_pkt, 64);
|
||||
bytes++;
|
||||
}
|
||||
|
||||
CorsairKeyboardController::CorsairKeyboardController(hid_device* dev_handle)
|
||||
{
|
||||
dev = dev_handle;
|
||||
|
||||
char data_pkt[64] = { 0 };
|
||||
|
||||
LightingControl();
|
||||
}
|
||||
|
||||
CorsairKeyboardController::~CorsairKeyboardController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CorsairKeyboardController::SetLEDs(std::vector<RGBColor> colors)
|
||||
{
|
||||
unsigned char data_pkt[216];
|
||||
unsigned char red_val[144];
|
||||
unsigned char grn_val[144];
|
||||
unsigned char blu_val[144];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffers |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(data_pkt, 0x00, sizeof( data_pkt ));
|
||||
memset(red_val, 0x00, sizeof( red_val ));
|
||||
memset(grn_val, 0x00, sizeof( grn_val ));
|
||||
memset(blu_val, 0x00, sizeof( blu_val ));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Scale color values to 9-bit |
|
||||
\*-----------------------------------------------------*/
|
||||
for(int color_idx = 0; color_idx < colors.size(); color_idx++)
|
||||
{
|
||||
RGBColor color = colors[color_idx];
|
||||
unsigned char red = RGBGetRValue(color);
|
||||
unsigned char grn = RGBGetGValue(color);
|
||||
unsigned char blu = RGBGetBValue(color);
|
||||
|
||||
if( red > 7 ) red = 7;
|
||||
if( grn > 7 ) grn = 7;
|
||||
if( blu > 7 ) blu = 7;
|
||||
|
||||
red = 7 - red;
|
||||
grn = 7 - grn;
|
||||
blu = 7 - blu;
|
||||
|
||||
red_val[keys[color_idx]] = red;
|
||||
grn_val[keys[color_idx]] = grn;
|
||||
blu_val[keys[color_idx]] = blu;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Pack the color values, 2 values per byte |
|
||||
\*-----------------------------------------------------*/
|
||||
for(int red_idx = 0; red_idx < 72; red_idx++)
|
||||
{
|
||||
data_pkt[red_idx] = red_val[(red_idx * 2) + 1] << 4 | red_val[red_idx * 2];
|
||||
}
|
||||
|
||||
for(int grn_idx = 0; grn_idx < 72; grn_idx++)
|
||||
{
|
||||
data_pkt[grn_idx + 72] = grn_val[(grn_idx * 2) + 1] << 4 | grn_val[grn_idx * 2];
|
||||
}
|
||||
|
||||
for(int blu_idx = 0; blu_idx < 72; blu_idx++)
|
||||
{
|
||||
data_pkt[blu_idx + 144] = blu_val[(blu_idx * 2) + 1] << 4 | blu_val[blu_idx * 2];
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send the packets |
|
||||
\*-----------------------------------------------------*/
|
||||
StreamPacket(1, 60, &data_pkt[0]);
|
||||
StreamPacket(2, 60, &data_pkt[60]);
|
||||
StreamPacket(3, 60, &data_pkt[120]);
|
||||
StreamPacket(4, 36, &data_pkt[180]);
|
||||
|
||||
SubmitLimitedColors(216);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------------------------------*\
|
||||
| Private packet sending functions. |
|
||||
\*-------------------------------------------------------------------------------------------------*/
|
||||
|
||||
void CorsairKeyboardController::LightingControl()
|
||||
{
|
||||
char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Lighting Control packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_COMMAND_WRITE;
|
||||
usb_buf[0x01] = CORSAIR_PROPERTY_LIGHTING_CONTROL;
|
||||
usb_buf[0x02] = CORSAIR_LIGHTING_CONTROL_SOFTWARE;
|
||||
usb_buf[0x04] = 0x03;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
send_usb_msg(dev, usb_buf);
|
||||
}
|
||||
|
||||
void CorsairKeyboardController::ReadFirmwareInfo()
|
||||
{
|
||||
char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Read Firmware Info packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_COMMAND_READ;
|
||||
usb_buf[0x01] = CORSAIR_PROPERTY_FIRMWARE_INFO;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
send_usb_msg(dev, usb_buf);
|
||||
get_usb_msg(dev, usb_buf);
|
||||
}
|
||||
|
||||
void CorsairKeyboardController::StreamPacket
|
||||
(
|
||||
unsigned char packet_id,
|
||||
unsigned char data_sz,
|
||||
unsigned char* data_ptr
|
||||
)
|
||||
{
|
||||
char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Stream packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_COMMAND_STREAM;
|
||||
usb_buf[0x01] = packet_id;
|
||||
usb_buf[0x02] = data_sz;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in data bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(&usb_buf[0x04], data_ptr, data_sz);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
send_usb_msg(dev, usb_buf);
|
||||
}
|
||||
|
||||
void CorsairKeyboardController::SubmitColors()
|
||||
{
|
||||
char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Submit Keyboard 24-Bit Colors packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_COMMAND_WRITE;
|
||||
usb_buf[0x01] = CORSAIR_PROPERTY_SUBMIT_KEYBOARD_COLOR_24;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
send_usb_msg(dev, usb_buf);
|
||||
}
|
||||
|
||||
void CorsairKeyboardController::SubmitLimitedColors
|
||||
(
|
||||
unsigned char byte_count
|
||||
)
|
||||
{
|
||||
char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Submit Keyboard 9-Bit Colors packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_COMMAND_WRITE;
|
||||
usb_buf[0x01] = CORSAIR_PROPERTY_SUBMIT_KEYBOARD_COLOR_9;
|
||||
usb_buf[0x04] = byte_count;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
send_usb_msg(dev, usb_buf);
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
#include "CorsairKeyboardController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_CorsairKeyboard.h"
|
||||
#include <vector>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#define CORSAIR_RGB_KEYBOARD_VID 0x1B1C
|
||||
#define CORSAIR_RGB_KEYBOARD_K70_PID 0x1B13
|
||||
#define CORSAIR_RGB_KEYBOARD_K95_PID 0x1B11
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectCorsairKeyboardControllers *
|
||||
* *
|
||||
* Tests the USB address to see if a Corsair RGB Keyboard controller exists there. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectCorsairKeyboardControllers(std::vector<RGBController*>& rgb_controllers)
|
||||
{
|
||||
hid_device_info* info;
|
||||
hid_device* dev = NULL;
|
||||
|
||||
hid_init();
|
||||
|
||||
info = hid_enumerate(CORSAIR_RGB_KEYBOARD_VID, CORSAIR_RGB_KEYBOARD_K70_PID);
|
||||
|
||||
//Look for Corsair RGB Keyboard, interface 1
|
||||
while(info)
|
||||
{
|
||||
if((info->vendor_id == CORSAIR_RGB_KEYBOARD_VID)
|
||||
&&(info->product_id == CORSAIR_RGB_KEYBOARD_K70_PID)
|
||||
&&(info->interface_number == 1))
|
||||
{
|
||||
dev = hid_open_path(info->path);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
info = info->next;
|
||||
}
|
||||
}
|
||||
|
||||
if( dev )
|
||||
{
|
||||
CorsairKeyboardController* controller = new CorsairKeyboardController(dev);
|
||||
|
||||
RGBController_CorsairKeyboard* rgb_controller = new RGBController_CorsairKeyboard(controller);
|
||||
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
}
|
||||
+101
-142
@@ -4,7 +4,7 @@
|
||||
| Adam Honse (calcprogrammer1@gmail.com), 1/12/2020 |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "CorsairNodeProController.h"
|
||||
#include "CorsairLightingNodeController.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@@ -41,16 +41,17 @@ static void Sleep(unsigned int milliseconds)
|
||||
|
||||
THREAD keepalive_thread(void *param)
|
||||
{
|
||||
CorsairNodeProController* corsair = static_cast<CorsairNodeProController*>(param);
|
||||
CorsairLightingNodeController* corsair = static_cast<CorsairLightingNodeController*>(param);
|
||||
corsair->KeepaliveThread();
|
||||
THREADRETURN
|
||||
}
|
||||
|
||||
CorsairNodeProController::CorsairNodeProController(libusb_device_handle* dev_handle)
|
||||
CorsairLightingNodeController::CorsairLightingNodeController(libusb_device_handle* dev_handle, unsigned int dev_endpoint)
|
||||
{
|
||||
dev = dev_handle;
|
||||
channel_leds[0] = 60;
|
||||
channel_leds[1] = 60;
|
||||
endpoint = dev_endpoint;
|
||||
|
||||
SendFirmwareRequest();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| The Corsair Lighting Node Pro requires a packet within|
|
||||
@@ -66,11 +67,11 @@ CorsairNodeProController::CorsairNodeProController(libusb_device_handle* dev_han
|
||||
#endif
|
||||
}
|
||||
|
||||
CorsairNodeProController::~CorsairNodeProController()
|
||||
CorsairLightingNodeController::~CorsairLightingNodeController()
|
||||
{
|
||||
}
|
||||
|
||||
void CorsairNodeProController::KeepaliveThread()
|
||||
void CorsairLightingNodeController::KeepaliveThread()
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
@@ -79,7 +80,13 @@ void CorsairNodeProController::KeepaliveThread()
|
||||
}
|
||||
}
|
||||
|
||||
void CorsairNodeProController::SetChannelEffect(unsigned char channel,
|
||||
std::string CorsairLightingNodeController::GetFirmwareString()
|
||||
{
|
||||
return(firmware_version);
|
||||
}
|
||||
|
||||
void CorsairLightingNodeController::SetChannelEffect(unsigned char channel,
|
||||
unsigned char num_leds,
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
unsigned char direction,
|
||||
@@ -89,7 +96,10 @@ void CorsairNodeProController::SetChannelEffect(unsigned char channel,
|
||||
unsigned char blu1,
|
||||
unsigned char red2,
|
||||
unsigned char grn2,
|
||||
unsigned char blu2
|
||||
unsigned char blu2,
|
||||
unsigned char red3,
|
||||
unsigned char grn3,
|
||||
unsigned char blu3
|
||||
)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
@@ -105,7 +115,7 @@ void CorsairNodeProController::SetChannelEffect(unsigned char channel,
|
||||
/*-----------------------------------------------------*\
|
||||
| Set Port State packet |
|
||||
\*-----------------------------------------------------*/
|
||||
SendPortState(channel, CORSAIR_CMDR_PRO_PORT_STATE_HARDWARE);
|
||||
SendPortState(channel, CORSAIR_LIGHTING_NODE_PORT_STATE_HARDWARE);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set Effect Configuration packet |
|
||||
@@ -114,7 +124,7 @@ void CorsairNodeProController::SetChannelEffect(unsigned char channel,
|
||||
(
|
||||
channel,
|
||||
0,
|
||||
CORSAIR_CMDR_PRO_LED_TYPE_LED_STRIP,
|
||||
num_leds,
|
||||
mode,
|
||||
speed,
|
||||
direction,
|
||||
@@ -125,9 +135,9 @@ void CorsairNodeProController::SetChannelEffect(unsigned char channel,
|
||||
red2,
|
||||
grn2,
|
||||
blu2,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
red3,
|
||||
grn3,
|
||||
blu3,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
@@ -139,125 +149,47 @@ void CorsairNodeProController::SetChannelEffect(unsigned char channel,
|
||||
SendCommit();
|
||||
}
|
||||
|
||||
void CorsairNodeProController::SetChannelLEDs(unsigned char channel, std::vector<RGBColor> colors)
|
||||
void CorsairLightingNodeController::SetChannelLEDs(unsigned char channel, RGBColor * colors, unsigned int num_colors)
|
||||
{
|
||||
unsigned char color_data[50];
|
||||
unsigned char pkt_max;
|
||||
unsigned char red_color_data[50];
|
||||
unsigned char grn_color_data[50];
|
||||
unsigned char blu_color_data[50];
|
||||
unsigned char pkt_offset = 0;
|
||||
unsigned char pkt_size = 0;
|
||||
unsigned int colors_remaining = num_colors;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send Port State packet |
|
||||
\*-----------------------------------------------------*/
|
||||
SendPortState(channel, CORSAIR_CMDR_PRO_PORT_STATE_SOFTWARE);
|
||||
SendPortState(channel, CORSAIR_LIGHTING_NODE_PORT_STATE_SOFTWARE);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send red channel packet 1 |
|
||||
| Loop through colors and send 50 at a time |
|
||||
\*-----------------------------------------------------*/
|
||||
pkt_max = 50;
|
||||
|
||||
if(pkt_max > colors.size())
|
||||
while(colors_remaining > 0)
|
||||
{
|
||||
pkt_max = (unsigned char)colors.size();
|
||||
}
|
||||
|
||||
for(int idx = 0; idx < pkt_max; idx++)
|
||||
{
|
||||
color_data[idx] = RGBGetRValue(colors[idx]);
|
||||
}
|
||||
|
||||
SendDirect(channel, 0, pkt_max, CORSAIR_CMDR_PRO_DIRECT_CHANNEL_RED, color_data);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send red channel packet 2 if necessary |
|
||||
\*-----------------------------------------------------*/
|
||||
pkt_max = 0;
|
||||
|
||||
if (colors.size() > 50)
|
||||
{
|
||||
pkt_max = (unsigned char)(colors.size() - 50);
|
||||
}
|
||||
|
||||
if(pkt_max > 0)
|
||||
{
|
||||
for (std::size_t idx = 0; idx < pkt_max; idx++)
|
||||
if(colors_remaining < 50)
|
||||
{
|
||||
color_data[idx] = RGBGetRValue(colors[idx+50]);
|
||||
pkt_size = colors_remaining;
|
||||
}
|
||||
else
|
||||
{
|
||||
pkt_size = 50;
|
||||
}
|
||||
|
||||
for(int color_idx = 0; color_idx < pkt_size; color_idx++)
|
||||
{
|
||||
red_color_data[color_idx] = RGBGetRValue(colors[pkt_offset + color_idx]);
|
||||
grn_color_data[color_idx] = RGBGetGValue(colors[pkt_offset + color_idx]);
|
||||
blu_color_data[color_idx] = RGBGetBValue(colors[pkt_offset + color_idx]);
|
||||
}
|
||||
|
||||
SendDirect(channel, 50, pkt_max, CORSAIR_CMDR_PRO_DIRECT_CHANNEL_RED, color_data);
|
||||
}
|
||||
SendDirect(channel, pkt_offset, pkt_size, CORSAIR_LIGHTING_NODE_DIRECT_CHANNEL_RED, red_color_data);
|
||||
SendDirect(channel, pkt_offset, pkt_size, CORSAIR_LIGHTING_NODE_DIRECT_CHANNEL_GREEN, grn_color_data);
|
||||
SendDirect(channel, pkt_offset, pkt_size, CORSAIR_LIGHTING_NODE_DIRECT_CHANNEL_BLUE, blu_color_data);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send green channel packet 1 |
|
||||
\*-----------------------------------------------------*/
|
||||
pkt_max = 50;
|
||||
|
||||
if(pkt_max > colors.size())
|
||||
{
|
||||
pkt_max = (unsigned char)colors.size();
|
||||
}
|
||||
|
||||
for(int idx = 0; idx < pkt_max; idx++)
|
||||
{
|
||||
color_data[idx] = RGBGetGValue(colors[idx]);
|
||||
}
|
||||
|
||||
SendDirect(channel, 0, pkt_max, CORSAIR_CMDR_PRO_DIRECT_CHANNEL_GREEN, color_data);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send green channel packet 2 if necessary |
|
||||
\*-----------------------------------------------------*/
|
||||
pkt_max = 0;
|
||||
|
||||
if (colors.size() > 50)
|
||||
{
|
||||
pkt_max = (unsigned char)(colors.size() - 50);
|
||||
}
|
||||
|
||||
if(pkt_max > 0)
|
||||
{
|
||||
for (std::size_t idx = 0; idx < pkt_max; idx++)
|
||||
{
|
||||
color_data[idx] = RGBGetGValue(colors[idx+50]);
|
||||
}
|
||||
|
||||
SendDirect(channel, 50, pkt_max, CORSAIR_CMDR_PRO_DIRECT_CHANNEL_GREEN, color_data);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send blue channel packet 1 |
|
||||
\*-----------------------------------------------------*/
|
||||
pkt_max = 50;
|
||||
|
||||
if(pkt_max > colors.size())
|
||||
{
|
||||
pkt_max = (unsigned char)colors.size();
|
||||
}
|
||||
|
||||
for(int idx = 0; idx < pkt_max; idx++)
|
||||
{
|
||||
color_data[idx] = RGBGetBValue(colors[idx]);
|
||||
}
|
||||
|
||||
SendDirect(channel, 0, pkt_max, CORSAIR_CMDR_PRO_DIRECT_CHANNEL_BLUE, color_data);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send blue channel packet 2 if necessary |
|
||||
\*-----------------------------------------------------*/
|
||||
pkt_max = 0;
|
||||
|
||||
if (colors.size() > 50)
|
||||
{
|
||||
pkt_max = (unsigned char)(colors.size() - 50);
|
||||
}
|
||||
|
||||
if(pkt_max > 0)
|
||||
{
|
||||
for (std::size_t idx = 0; idx < pkt_max; idx++)
|
||||
{
|
||||
color_data[idx] = RGBGetBValue(colors[idx+50]);
|
||||
}
|
||||
|
||||
SendDirect(channel, 50, pkt_max, CORSAIR_CMDR_PRO_DIRECT_CHANNEL_BLUE, color_data);
|
||||
colors_remaining -= pkt_size;
|
||||
pkt_offset += pkt_size;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
@@ -270,7 +202,34 @@ void CorsairNodeProController::SetChannelLEDs(unsigned char channel, std::vector
|
||||
| Private packet sending functions. |
|
||||
\*-------------------------------------------------------------------------------------------------*/
|
||||
|
||||
void CorsairNodeProController::SendDirect
|
||||
void CorsairLightingNodeController::SendFirmwareRequest()
|
||||
{
|
||||
int actual;
|
||||
unsigned char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Firmware Version Request packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_LIGHTING_NODE_PACKET_ID_FIRMWARE;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
libusb_interrupt_transfer(dev, endpoint, usb_buf, 64, &actual, 0);
|
||||
libusb_interrupt_transfer(dev, 0x80 + endpoint, usb_buf, 64, &actual, 0);
|
||||
|
||||
if(actual > 0)
|
||||
{
|
||||
firmware_version = std::to_string(usb_buf[0x01]) + "." + std::to_string(usb_buf[0x02]) + "." + std::to_string(usb_buf[0x03]);
|
||||
}
|
||||
}
|
||||
|
||||
void CorsairLightingNodeController::SendDirect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char start,
|
||||
@@ -290,7 +249,7 @@ void CorsairNodeProController::SendDirect
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Direct packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_CMDR_PRO_PACKET_ID_DIRECT;
|
||||
usb_buf[0x00] = CORSAIR_LIGHTING_NODE_PACKET_ID_DIRECT;
|
||||
usb_buf[0x01] = channel;
|
||||
usb_buf[0x02] = start;
|
||||
usb_buf[0x03] = count;
|
||||
@@ -304,10 +263,10 @@ void CorsairNodeProController::SendDirect
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
libusb_interrupt_transfer(dev, 0x01, usb_buf, 64, &actual, 0);
|
||||
libusb_interrupt_transfer(dev, endpoint, usb_buf, 64, &actual, 0);
|
||||
}
|
||||
|
||||
void CorsairNodeProController::SendCommit()
|
||||
void CorsairLightingNodeController::SendCommit()
|
||||
{
|
||||
int actual;
|
||||
unsigned char usb_buf[64];
|
||||
@@ -320,16 +279,16 @@ void CorsairNodeProController::SendCommit()
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Commit packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_CMDR_PRO_PACKET_ID_COMMIT;
|
||||
usb_buf[0x00] = CORSAIR_LIGHTING_NODE_PACKET_ID_COMMIT;
|
||||
usb_buf[0x01] = 0xFF;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
libusb_interrupt_transfer(dev, 0x01, usb_buf, 64, &actual, 0);
|
||||
libusb_interrupt_transfer(dev, endpoint, usb_buf, 64, &actual, 0);
|
||||
}
|
||||
|
||||
void CorsairNodeProController::SendBegin
|
||||
void CorsairLightingNodeController::SendBegin
|
||||
(
|
||||
unsigned char channel
|
||||
)
|
||||
@@ -345,16 +304,16 @@ void CorsairNodeProController::SendBegin
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Begin packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_CMDR_PRO_PACKET_ID_BEGIN;
|
||||
usb_buf[0x00] = CORSAIR_LIGHTING_NODE_PACKET_ID_BEGIN;
|
||||
usb_buf[0x01] = channel;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
libusb_interrupt_transfer(dev, 0x01, usb_buf, 64, &actual, 0);
|
||||
libusb_interrupt_transfer(dev, endpoint, usb_buf, 64, &actual, 0);
|
||||
}
|
||||
|
||||
void CorsairNodeProController::SendEffectConfig
|
||||
void CorsairLightingNodeController::SendEffectConfig
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char count,
|
||||
@@ -388,7 +347,7 @@ void CorsairNodeProController::SendEffectConfig
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Effect Config packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_CMDR_PRO_PACKET_ID_EFFECT_CONFIG;
|
||||
usb_buf[0x00] = CORSAIR_LIGHTING_NODE_PACKET_ID_EFFECT_CONFIG;
|
||||
usb_buf[0x01] = channel;
|
||||
usb_buf[0x02] = count * 10;
|
||||
usb_buf[0x03] = led_type;
|
||||
@@ -428,15 +387,15 @@ void CorsairNodeProController::SendEffectConfig
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
libusb_interrupt_transfer(dev, 0x01, usb_buf, 64, &actual, 0);
|
||||
libusb_interrupt_transfer(dev, endpoint, usb_buf, 64, &actual, 0);
|
||||
}
|
||||
|
||||
void CorsairNodeProController::SendTemperature()
|
||||
void CorsairLightingNodeController::SendTemperature()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CorsairNodeProController::SendReset
|
||||
void CorsairLightingNodeController::SendReset
|
||||
(
|
||||
unsigned char channel
|
||||
)
|
||||
@@ -452,16 +411,16 @@ void CorsairNodeProController::SendReset
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Reset packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_CMDR_PRO_PACKET_ID_RESET;
|
||||
usb_buf[0x00] = CORSAIR_LIGHTING_NODE_PACKET_ID_RESET;
|
||||
usb_buf[0x01] = channel;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
libusb_interrupt_transfer(dev, 0x01, usb_buf, 64, &actual, 0);
|
||||
libusb_interrupt_transfer(dev, endpoint, usb_buf, 64, &actual, 0);
|
||||
}
|
||||
|
||||
void CorsairNodeProController::SendPortState
|
||||
void CorsairLightingNodeController::SendPortState
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char state
|
||||
@@ -478,27 +437,27 @@ void CorsairNodeProController::SendPortState
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Port State packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_CMDR_PRO_PACKET_ID_PORT_STATE;
|
||||
usb_buf[0x00] = CORSAIR_LIGHTING_NODE_PACKET_ID_PORT_STATE;
|
||||
usb_buf[0x01] = channel;
|
||||
usb_buf[0x02] = state;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
libusb_interrupt_transfer(dev, 0x01, usb_buf, 64, &actual, 0);
|
||||
libusb_interrupt_transfer(dev, endpoint, usb_buf, 64, &actual, 0);
|
||||
}
|
||||
|
||||
void CorsairNodeProController::SendBrightness()
|
||||
void CorsairLightingNodeController::SendBrightness()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CorsairNodeProController::SendLEDCount()
|
||||
void CorsairLightingNodeController::SendLEDCount()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CorsairNodeProController::SendProtocol()
|
||||
void CorsairLightingNodeController::SendProtocol()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| Definitions for Corsair Lighting Node Pro |
|
||||
| |
|
||||
| Adam Honse ([email protected]), 1/12/2020 |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
#include <vector>
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_LIGHTING_NODE_PACKET_ID_FIRMWARE = 0x02, /* Get firmware version */
|
||||
CORSAIR_LIGHTING_NODE_PACKET_ID_DIRECT = 0x32, /* Direct mode LED update packet */
|
||||
CORSAIR_LIGHTING_NODE_PACKET_ID_COMMIT = 0x33, /* Commit changes packet */
|
||||
CORSAIR_LIGHTING_NODE_PACKET_ID_BEGIN = 0x34, /* Begin effect packet */
|
||||
CORSAIR_LIGHTING_NODE_PACKET_ID_EFFECT_CONFIG = 0x35, /* Effect mode configuration packet */
|
||||
CORSAIR_LIGHTING_NODE_PACKET_ID_TEMPERATURE = 0x36, /* Update temperature value packet */
|
||||
CORSAIR_LIGHTING_NODE_PACKET_ID_RESET = 0x37, /* Reset channel packet */
|
||||
CORSAIR_LIGHTING_NODE_PACKET_ID_PORT_STATE = 0x38, /* Set port state packet */
|
||||
CORSAIR_LIGHTING_NODE_PACKET_ID_BRIGHTNESS = 0x39, /* Set brightness packet */
|
||||
CORSAIR_LIGHTING_NODE_PACKET_ID_LED_COUNT = 0x3A, /* Set LED count packet */
|
||||
CORSAIR_LIGHTING_NODE_PACKET_ID_PROTOCOL = 0x3B, /* Set protocol packet */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_LIGHTING_NODE_DIRECT_CHANNEL_RED = 0x00, /* Red channel for direct update */
|
||||
CORSAIR_LIGHTING_NODE_DIRECT_CHANNEL_GREEN = 0x01, /* Green channel for direct update */
|
||||
CORSAIR_LIGHTING_NODE_DIRECT_CHANNEL_BLUE = 0x02, /* Blue channel for direct update */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_LIGHTING_NODE_PORT_STATE_HARDWARE = 0x01, /* Effect hardware control of channel */
|
||||
CORSAIR_LIGHTING_NODE_PORT_STATE_SOFTWARE = 0x02, /* Direct software control of channel */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_LIGHTING_NODE_LED_TYPE_LED_STRIP = 0x0A, /* Corsair LED Strip Type */
|
||||
CORSAIR_LIGHTING_NODE_LED_TYPE_HD_FAN = 0x0C, /* Corsair HD-series Fan Type */
|
||||
CORSAIR_LIGHTING_NODE_LED_TYPE_SP_FAN = 0x01, /* Corsair SP-series Fan Type */
|
||||
CORSAIR_LIGHTING_NODE_LED_TYPE_ML_FAN = 0x02, /* Corsair ML-series Fan Type */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_LIGHTING_NODE_CHANNEL_1 = 0x00, /* Channel 1 */
|
||||
CORSAIR_LIGHTING_NODE_CHANNEL_2 = 0x01, /* Channel 2 */
|
||||
CORSAIR_LIGHTING_NODE_NUM_CHANNELS = 0x02, /* Number of channels */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_LIGHTING_NODE_SPEED_FAST = 0x00, /* Fast speed */
|
||||
CORSAIR_LIGHTING_NODE_SPEED_MEDIUM = 0x01, /* Medium speed */
|
||||
CORSAIR_LIGHTING_NODE_SPEED_SLOW = 0x02, /* Slow speed */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_LIGHTING_NODE_MODE_RAINBOW_WAVE = 0x00, /* Rainbow Wave mode */
|
||||
CORSAIR_LIGHTING_NODE_MODE_COLOR_SHIFT = 0x01, /* Color Shift mode */
|
||||
CORSAIR_LIGHTING_NODE_MODE_COLOR_PULSE = 0x02, /* Color Pulse mode */
|
||||
CORSAIR_LIGHTING_NODE_MODE_COLOR_WAVE = 0x03, /* Color Wave mode */
|
||||
CORSAIR_LIGHTING_NODE_MODE_STATIC = 0x04, /* Static mode */
|
||||
CORSAIR_LIGHTING_NODE_MODE_TEMPERATURE = 0x05, /* Temperature mode */
|
||||
CORSAIR_LIGHTING_NODE_MODE_VISOR = 0x06, /* Visor mode */
|
||||
CORSAIR_LIGHTING_NODE_MODE_MARQUEE = 0x07, /* Marquee mode */
|
||||
CORSAIR_LIGHTING_NODE_MODE_BLINK = 0x08, /* Blink mode */
|
||||
CORSAIR_LIGHTING_NODE_MODE_SEQUENTIAL = 0x09, /* Sequential mode */
|
||||
CORSAIR_LIGHTING_NODE_MODE_RAINBOW = 0x0A, /* Rainbow mode */
|
||||
};
|
||||
|
||||
class CorsairLightingNodeController
|
||||
{
|
||||
public:
|
||||
CorsairLightingNodeController(libusb_device_handle* dev_handle, unsigned int dev_endpoint);
|
||||
~CorsairLightingNodeController();
|
||||
|
||||
std::string GetFirmwareString();
|
||||
|
||||
unsigned int GetStripsOnChannel(unsigned int channel);
|
||||
|
||||
void SetChannelEffect(unsigned char channel,
|
||||
unsigned char num_leds,
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
unsigned char direction,
|
||||
bool random,
|
||||
unsigned char red1,
|
||||
unsigned char grn1,
|
||||
unsigned char blu1,
|
||||
unsigned char red2,
|
||||
unsigned char grn2,
|
||||
unsigned char blu2,
|
||||
unsigned char red3,
|
||||
unsigned char grn3,
|
||||
unsigned char blu3
|
||||
);
|
||||
|
||||
void SetChannelLEDs(unsigned char channel, RGBColor * colors, unsigned int num_colors);
|
||||
|
||||
void KeepaliveThread();
|
||||
|
||||
private:
|
||||
libusb_device_handle* dev;
|
||||
unsigned int endpoint;
|
||||
std::string firmware_version;
|
||||
|
||||
void SendFirmwareRequest();
|
||||
|
||||
void SendDirect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char start,
|
||||
unsigned char count,
|
||||
unsigned char color_channel,
|
||||
unsigned char* color_data
|
||||
);
|
||||
|
||||
void SendCommit();
|
||||
|
||||
void SendBegin
|
||||
(
|
||||
unsigned char channel
|
||||
);
|
||||
|
||||
void SendEffectConfig
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char count,
|
||||
unsigned char led_type,
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
unsigned char direction,
|
||||
unsigned char change_style,
|
||||
unsigned char color_0_red,
|
||||
unsigned char color_0_green,
|
||||
unsigned char color_0_blue,
|
||||
unsigned char color_1_red,
|
||||
unsigned char color_1_green,
|
||||
unsigned char color_1_blue,
|
||||
unsigned char color_2_red,
|
||||
unsigned char color_2_green,
|
||||
unsigned char color_2_blue,
|
||||
unsigned short temperature_0,
|
||||
unsigned short temperature_1,
|
||||
unsigned short temperature_2
|
||||
);
|
||||
|
||||
void SendTemperature();
|
||||
|
||||
void SendReset
|
||||
(
|
||||
unsigned char channel
|
||||
);
|
||||
|
||||
void SendPortState
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char state
|
||||
);
|
||||
|
||||
void SendBrightness();
|
||||
|
||||
void SendLEDCount();
|
||||
|
||||
void SendProtocol();
|
||||
};
|
||||
@@ -0,0 +1,67 @@
|
||||
#include "CorsairLightingNodeController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_CorsairLightingNode.h"
|
||||
#include <vector>
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
#define CORSAIR_VID 0x1B1C
|
||||
#define CORSAIR_LIGHTING_NODE_CORE_PID 0x0C1A
|
||||
#define CORSAIR_LIGHTING_NODE_PRO_PID 0x0C0B
|
||||
#define CORSAIR_COMMANDER_PRO_PID 0x0C10
|
||||
#define CORSAIR_LS100_PID 0x0C1E
|
||||
#define CORSAIR_1000D_OBSIDIAN_PID 0x1D00
|
||||
#define CORSAIR_SPEC_OMEGA_RGB_PID 0x1D04
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned short usb_vid;
|
||||
unsigned short usb_pid;
|
||||
unsigned char usb_endpoint;
|
||||
unsigned char channel_count;
|
||||
const char * name;
|
||||
} corsair_node_device;
|
||||
|
||||
static const corsair_node_device device_list[6] =
|
||||
{
|
||||
{ CORSAIR_VID, CORSAIR_LIGHTING_NODE_CORE_PID, 1, 1, "Corsair Lighting Node Core" },
|
||||
{ CORSAIR_VID, CORSAIR_LIGHTING_NODE_PRO_PID, 1, 2, "Corsair Lighting Node Pro" },
|
||||
{ CORSAIR_VID, CORSAIR_COMMANDER_PRO_PID, 2, 2, "Corsair Commander Pro" },
|
||||
{ CORSAIR_VID, CORSAIR_LS100_PID, 1, 1, "Corsair LS100 Lighting Kit" },
|
||||
{ CORSAIR_VID, CORSAIR_1000D_OBSIDIAN_PID, 2, 2, "Corsair 1000D Obsidian" },
|
||||
{ CORSAIR_VID, CORSAIR_SPEC_OMEGA_RGB_PID, 1, 2, "Corsair SPEC OMEGA RGB" }
|
||||
|
||||
};
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectCorsairLightingNodeControllers *
|
||||
* *
|
||||
* Detect devices supported by the Corsair Lighting Node Pro driver *
|
||||
* * *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectCorsairLightingNodeControllers(std::vector<RGBController*> &rgb_controllers)
|
||||
{
|
||||
libusb_context * ctx;
|
||||
libusb_init(&ctx);
|
||||
|
||||
for(int device_idx = 0; device_idx < 6; device_idx++)
|
||||
{
|
||||
//Look for Corsair Lighting Node Device
|
||||
libusb_device_handle * dev = libusb_open_device_with_vid_pid(ctx, device_list[device_idx].usb_vid, device_list[device_idx].usb_pid);
|
||||
|
||||
if( dev )
|
||||
{
|
||||
libusb_detach_kernel_driver(dev, 0);
|
||||
libusb_claim_interface(dev, 0);
|
||||
|
||||
CorsairLightingNodeController* controller = new CorsairLightingNodeController(dev, device_list[device_idx].usb_endpoint);
|
||||
|
||||
RGBController_CorsairLightingNode* rgb_controller = new RGBController_CorsairLightingNode(controller);
|
||||
|
||||
rgb_controller->name = device_list[device_idx].name;
|
||||
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
}
|
||||
} /* DetectCorsairLightingNodeControllers() */
|
||||
@@ -1,170 +0,0 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| Definitions for Corsair Lighting Node Pro |
|
||||
| |
|
||||
| Adam Honse ([email protected]), 1/12/2020 |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
#include <vector>
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_CMDR_PRO_PACKET_ID_DIRECT = 0x32, /* Direct mode LED update packet */
|
||||
CORSAIR_CMDR_PRO_PACKET_ID_COMMIT = 0x33, /* Commit changes packet */
|
||||
CORSAIR_CMDR_PRO_PACKET_ID_BEGIN = 0x34, /* Begin effect packet */
|
||||
CORSAIR_CMDR_PRO_PACKET_ID_EFFECT_CONFIG = 0x35, /* Effect mode configuration packet */
|
||||
CORSAIR_CMDR_PRO_PACKET_ID_TEMPERATURE = 0x36, /* Update temperature value packet */
|
||||
CORSAIR_CMDR_PRO_PACKET_ID_RESET = 0x37, /* Reset channel packet */
|
||||
CORSAIR_CMDR_PRO_PACKET_ID_PORT_STATE = 0x38, /* Set port state packet */
|
||||
CORSAIR_CMDR_PRO_PACKET_ID_BRIGHTNESS = 0x39, /* Set brightness packet */
|
||||
CORSAIR_CMDR_PRO_PACKET_ID_LED_COUNT = 0x3A, /* Set LED count packet */
|
||||
CORSAIR_CMDR_PRO_PACKET_ID_PROTOCOL = 0x3B, /* Set protocol packet */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_CMDR_PRO_DIRECT_CHANNEL_RED = 0x00, /* Red channel for direct update */
|
||||
CORSAIR_CMDR_PRO_DIRECT_CHANNEL_GREEN = 0x01, /* Green channel for direct update */
|
||||
CORSAIR_CMDR_PRO_DIRECT_CHANNEL_BLUE = 0x02, /* Blue channel for direct update */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_CMDR_PRO_PORT_STATE_HARDWARE = 0x01, /* Effect hardware control of channel */
|
||||
CORSAIR_CMDR_PRO_PORT_STATE_SOFTWARE = 0x02, /* Direct software control of channel */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_CMDR_PRO_LED_TYPE_LED_STRIP = 0x0A, /* Corsair LED Strip Type */
|
||||
CORSAIR_CMDR_PRO_LED_TYPE_HD_FAN = 0x0C, /* Corsair HD-series Fan Type */
|
||||
CORSAIR_CMDR_PRO_LED_TYPE_SP_FAN = 0x01, /* Corsair SP-series Fan Type */
|
||||
CORSAIR_CMDR_PRO_LED_TYPE_ML_FAN = 0x02, /* Corsair ML-series Fan Type */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_CMDR_PRO_CHANNEL_1 = 0x00, /* Channel 1 */
|
||||
CORSAIR_CMDR_PRO_CHANNEL_2 = 0x01, /* Channel 2 */
|
||||
CORSAIR_CMDR_PRO_NUM_CHANNELS = 0x02, /* Number of channels */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_CMDR_PRO_SPEED_FAST = 0x00, /* Fast speed */
|
||||
CORSAIR_CMDR_PRO_SPEED_MEDIUM = 0x01, /* Medium speed */
|
||||
CORSAIR_CMDR_PRO_SPEED_SLOW = 0x02, /* Slow speed */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_CMDR_PRO_MODE_RAINBOW_WAVE = 0x00, /* Rainbow Wave mode */
|
||||
CORSAIR_CMDR_PRO_MODE_COLOR_SHIFT = 0x01, /* Color Shift mode */
|
||||
CORSAIR_CMDR_PRO_MODE_COLOR_PULSE = 0x02, /* Color Pulse mode */
|
||||
CORSAIR_CMDR_PRO_MODE_COLOR_WAVE = 0x03, /* Color Wave mode */
|
||||
CORSAIR_CMDR_PRO_MODE_STATIC = 0x04, /* Static mode */
|
||||
CORSAIR_CMDR_PRO_MODE_TEMPERATURE = 0x05, /* Temperature mode */
|
||||
CORSAIR_CMDR_PRO_MODE_VISOR = 0x06, /* Visor mode */
|
||||
CORSAIR_CMDR_PRO_MODE_MARQUEE = 0x07, /* Marquee mode */
|
||||
CORSAIR_CMDR_PRO_MODE_BLINK = 0x08, /* Blink mode */
|
||||
CORSAIR_CMDR_PRO_MODE_SEQUENTIAL = 0x09, /* Sequential mode */
|
||||
CORSAIR_CMDR_PRO_MODE_RAINBOW = 0x0A, /* Rainbow mode */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_NODE_PRO_CHANNEL_1 = 0x00, /* Channel 1 */
|
||||
CORSAIR_NODE_PRO_CHANNEL_2 = 0x01, /* Channel 2 */
|
||||
CORSAIR_NODE_PRO_NUM_CHANNELS = 0x02 /* Number of channels */
|
||||
};
|
||||
|
||||
class CorsairNodeProController
|
||||
{
|
||||
public:
|
||||
CorsairNodeProController(libusb_device_handle* dev_handle);
|
||||
~CorsairNodeProController();
|
||||
|
||||
unsigned int GetStripsOnChannel(unsigned int channel);
|
||||
|
||||
void SetChannelEffect(unsigned char channel,
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
unsigned char direction,
|
||||
bool random,
|
||||
unsigned char red1,
|
||||
unsigned char grn1,
|
||||
unsigned char blu1,
|
||||
unsigned char red2,
|
||||
unsigned char grn2,
|
||||
unsigned char blu2
|
||||
);
|
||||
|
||||
void SetChannelLEDs(unsigned char channel, std::vector<RGBColor> colors);
|
||||
unsigned int channel_leds[CORSAIR_NODE_PRO_NUM_CHANNELS];
|
||||
|
||||
void KeepaliveThread();
|
||||
|
||||
private:
|
||||
libusb_device_handle* dev;
|
||||
|
||||
void SendDirect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char start,
|
||||
unsigned char count,
|
||||
unsigned char color_channel,
|
||||
unsigned char* color_data
|
||||
);
|
||||
|
||||
void SendCommit();
|
||||
|
||||
void SendBegin
|
||||
(
|
||||
unsigned char channel
|
||||
);
|
||||
|
||||
void SendEffectConfig
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char count,
|
||||
unsigned char led_type,
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
unsigned char direction,
|
||||
unsigned char change_style,
|
||||
unsigned char color_0_red,
|
||||
unsigned char color_0_green,
|
||||
unsigned char color_0_blue,
|
||||
unsigned char color_1_red,
|
||||
unsigned char color_1_green,
|
||||
unsigned char color_1_blue,
|
||||
unsigned char color_2_red,
|
||||
unsigned char color_2_green,
|
||||
unsigned char color_2_blue,
|
||||
unsigned short temperature_0,
|
||||
unsigned short temperature_1,
|
||||
unsigned short temperature_2
|
||||
);
|
||||
|
||||
void SendTemperature();
|
||||
|
||||
void SendReset
|
||||
(
|
||||
unsigned char channel
|
||||
);
|
||||
|
||||
void SendPortState
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char state
|
||||
);
|
||||
|
||||
void SendBrightness();
|
||||
|
||||
void SendLEDCount();
|
||||
|
||||
void SendProtocol();
|
||||
};
|
||||
@@ -1,37 +0,0 @@
|
||||
#include "CorsairNodeProController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_CorsairNodePro.h"
|
||||
#include <vector>
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
#define CORSAIR_LIGHTING_NODE_PRO_VID 0x1B1C
|
||||
#define CORSAIR_LIGHTING_NODE_PRO_PID 0x0C0B
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectCorsairNodeProControllers *
|
||||
* *
|
||||
* Detect devices supported by the Corsair Lighting Node Pro driver *
|
||||
* * *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectCorsairNodeProControllers(std::vector<RGBController*> &rgb_controllers)
|
||||
{
|
||||
libusb_context * ctx;
|
||||
libusb_init(&ctx);
|
||||
|
||||
//Look for Corsair Lighting Node Pro
|
||||
libusb_device_handle * dev = libusb_open_device_with_vid_pid(ctx, CORSAIR_LIGHTING_NODE_PRO_VID, CORSAIR_LIGHTING_NODE_PRO_PID);
|
||||
|
||||
if( dev )
|
||||
{
|
||||
libusb_detach_kernel_driver(dev, 0);
|
||||
libusb_claim_interface(dev, 0);
|
||||
|
||||
CorsairNodeProController* controller = new CorsairNodeProController(dev);
|
||||
|
||||
RGBController_CorsairNodePro* rgb_controller = new RGBController_CorsairNodePro(controller);
|
||||
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
} /* DetectCorsairNodeProControllers() */
|
||||
@@ -0,0 +1,487 @@
|
||||
/*-----------------------------------------*\
|
||||
| CorsairPeripheralController.cpp |
|
||||
| |
|
||||
| Driver for Corsair RGB keyboard, mouse, |
|
||||
| and mousemat lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 1/9/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "CorsairPeripheralController.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
static unsigned int keys[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0x11, 0x12,
|
||||
0x14, 0x15, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x24, 0x25, 0x26,
|
||||
0x27, 0x28, 0x2A, 0x2B, 0x2C, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
|
||||
0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x42, 0x43, 0x44, 0x45, 0x48, 73, 74, 75, 76, 78,
|
||||
79, 80, 81, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 96, 97,
|
||||
98, 99, 100, 101, 102, 103, 104, 105, 108, 109, 110, 111, 112, 113, 115,
|
||||
116, 117, 120, 121, 122, 123, 124, 126, 127, 128, 129, 132, 133, 134, 135,
|
||||
136, 137, 139, 140, 141};
|
||||
|
||||
static void send_usb_msg(hid_device* dev, char * data_pkt)
|
||||
{
|
||||
char usb_pkt[65];
|
||||
usb_pkt[0] = 0x00;
|
||||
for(int i = 1; i < 65; i++)
|
||||
{
|
||||
usb_pkt[i] = data_pkt[i-1];
|
||||
}
|
||||
int bytes = hid_send_feature_report(dev, (unsigned char *)usb_pkt, 65);
|
||||
bytes++;
|
||||
}
|
||||
|
||||
CorsairPeripheralController::CorsairPeripheralController(hid_device* dev_handle)
|
||||
{
|
||||
dev = dev_handle;
|
||||
|
||||
ReadFirmwareInfo();
|
||||
|
||||
SpecialFunctionControl();
|
||||
LightingControl();
|
||||
}
|
||||
|
||||
CorsairPeripheralController::~CorsairPeripheralController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
device_type CorsairPeripheralController::GetDeviceType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
std::string CorsairPeripheralController::GetFirmwareString()
|
||||
{
|
||||
return firmware_version;
|
||||
}
|
||||
|
||||
void CorsairPeripheralController::SetLEDs(std::vector<RGBColor>colors)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case DEVICE_TYPE_KEYBOARD:
|
||||
SetLEDsKeyboardFull(colors);
|
||||
break;
|
||||
|
||||
case DEVICE_TYPE_MOUSE:
|
||||
SetLEDsMouse(colors);
|
||||
break;
|
||||
|
||||
case DEVICE_TYPE_MOUSEMAT:
|
||||
SetLEDsMousemat(colors);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CorsairPeripheralController::SetLEDsKeyboardFull(std::vector<RGBColor> colors)
|
||||
{
|
||||
unsigned char red_val[144];
|
||||
unsigned char grn_val[144];
|
||||
unsigned char blu_val[144];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffers |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(red_val, 0x00, sizeof( red_val ));
|
||||
memset(grn_val, 0x00, sizeof( grn_val ));
|
||||
memset(blu_val, 0x00, sizeof( blu_val ));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy red, green, and blue components into buffers |
|
||||
\*-----------------------------------------------------*/
|
||||
for(std::size_t color_idx = 0; color_idx < colors.size(); color_idx++)
|
||||
{
|
||||
RGBColor color = colors[color_idx];
|
||||
red_val[keys[color_idx]] = RGBGetRValue(color);
|
||||
grn_val[keys[color_idx]] = RGBGetGValue(color);
|
||||
blu_val[keys[color_idx]] = RGBGetBValue(color);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send red bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
StreamPacket(1, 60, &red_val[0]);
|
||||
StreamPacket(2, 60, &red_val[60]);
|
||||
StreamPacket(3, 24, &red_val[120]);
|
||||
SubmitKeyboardFullColors(1, 3, 1);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send green bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
StreamPacket(1, 60, &grn_val[0]);
|
||||
StreamPacket(2, 60, &grn_val[60]);
|
||||
StreamPacket(3, 24, &grn_val[120]);
|
||||
SubmitKeyboardFullColors(2, 3, 1);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send blue bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
StreamPacket(1, 60, &blu_val[0]);
|
||||
StreamPacket(2, 60, &blu_val[60]);
|
||||
StreamPacket(3, 24, &blu_val[120]);
|
||||
SubmitKeyboardFullColors(3, 3, 2);
|
||||
}
|
||||
|
||||
void CorsairPeripheralController::SetLEDsMouse(std::vector<RGBColor> colors)
|
||||
{
|
||||
SubmitMouseColors(colors.size(), &colors[0]);
|
||||
}
|
||||
|
||||
void CorsairPeripheralController::SetLEDsMousemat(std::vector<RGBColor> colors)
|
||||
{
|
||||
SubmitMousematColors(colors.size(), &colors[0]);
|
||||
}
|
||||
|
||||
void CorsairPeripheralController::SetLEDsKeyboardLimited(std::vector<RGBColor> colors)
|
||||
{
|
||||
unsigned char data_pkt[216];
|
||||
unsigned char red_val[144];
|
||||
unsigned char grn_val[144];
|
||||
unsigned char blu_val[144];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffers |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(data_pkt, 0x00, sizeof( data_pkt ));
|
||||
memset(red_val, 0x00, sizeof( red_val ));
|
||||
memset(grn_val, 0x00, sizeof( grn_val ));
|
||||
memset(blu_val, 0x00, sizeof( blu_val ));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Scale color values to 9-bit |
|
||||
\*-----------------------------------------------------*/
|
||||
for(std::size_t color_idx = 0; color_idx < colors.size(); color_idx++)
|
||||
{
|
||||
RGBColor color = colors[color_idx];
|
||||
unsigned char red = RGBGetRValue(color);
|
||||
unsigned char grn = RGBGetGValue(color);
|
||||
unsigned char blu = RGBGetBValue(color);
|
||||
|
||||
if( red > 7 ) red = 7;
|
||||
if( grn > 7 ) grn = 7;
|
||||
if( blu > 7 ) blu = 7;
|
||||
|
||||
red = 7 - red;
|
||||
grn = 7 - grn;
|
||||
blu = 7 - blu;
|
||||
|
||||
red_val[keys[color_idx]] = red;
|
||||
grn_val[keys[color_idx]] = grn;
|
||||
blu_val[keys[color_idx]] = blu;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Pack the color values, 2 values per byte |
|
||||
\*-----------------------------------------------------*/
|
||||
for(int red_idx = 0; red_idx < 72; red_idx++)
|
||||
{
|
||||
data_pkt[red_idx] = red_val[(red_idx * 2) + 1] << 4 | red_val[red_idx * 2];
|
||||
}
|
||||
|
||||
for(int grn_idx = 0; grn_idx < 72; grn_idx++)
|
||||
{
|
||||
data_pkt[grn_idx + 72] = grn_val[(grn_idx * 2) + 1] << 4 | grn_val[grn_idx * 2];
|
||||
}
|
||||
|
||||
for(int blu_idx = 0; blu_idx < 72; blu_idx++)
|
||||
{
|
||||
data_pkt[blu_idx + 144] = blu_val[(blu_idx * 2) + 1] << 4 | blu_val[blu_idx * 2];
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send the packets |
|
||||
\*-----------------------------------------------------*/
|
||||
StreamPacket(1, 60, &data_pkt[0]);
|
||||
StreamPacket(2, 60, &data_pkt[60]);
|
||||
StreamPacket(3, 60, &data_pkt[120]);
|
||||
StreamPacket(4, 36, &data_pkt[180]);
|
||||
|
||||
SubmitKeyboardLimitedColors(216);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------------------------------*\
|
||||
| Private packet sending functions. |
|
||||
\*-------------------------------------------------------------------------------------------------*/
|
||||
|
||||
void CorsairPeripheralController::LightingControl()
|
||||
{
|
||||
char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Lighting Control packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_COMMAND_WRITE;
|
||||
usb_buf[0x01] = CORSAIR_PROPERTY_LIGHTING_CONTROL;
|
||||
usb_buf[0x02] = CORSAIR_LIGHTING_CONTROL_SOFTWARE;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Lighting control byte needs to be 3 for keyboards, 1 |
|
||||
| for mice and mousepads |
|
||||
\*-----------------------------------------------------*/
|
||||
switch(type)
|
||||
{
|
||||
default:
|
||||
case DEVICE_TYPE_KEYBOARD:
|
||||
usb_buf[0x04] = 0x03;
|
||||
break;
|
||||
|
||||
case DEVICE_TYPE_MOUSE:
|
||||
usb_buf[0x04] = 0x01;
|
||||
break;
|
||||
|
||||
case DEVICE_TYPE_MOUSEMAT:
|
||||
usb_buf[0x04] = 0x04;
|
||||
break;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
send_usb_msg(dev, usb_buf);
|
||||
}
|
||||
|
||||
void CorsairPeripheralController::SpecialFunctionControl()
|
||||
{
|
||||
char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Lighting Control packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_COMMAND_WRITE;
|
||||
usb_buf[0x01] = CORSAIR_PROPERTY_SPECIAL_FUNCTION;
|
||||
usb_buf[0x02] = CORSAIR_LIGHTING_CONTROL_SOFTWARE;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
send_usb_msg(dev, usb_buf);
|
||||
}
|
||||
|
||||
void CorsairPeripheralController::ReadFirmwareInfo()
|
||||
{
|
||||
char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Read Firmware Info packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_COMMAND_READ;
|
||||
usb_buf[0x01] = CORSAIR_PROPERTY_FIRMWARE_INFO;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
send_usb_msg(dev, usb_buf);
|
||||
hid_get_feature_report(dev, (unsigned char*)usb_buf, 64);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Get device type |
|
||||
| 0xC0 Device is a keyboard |
|
||||
| 0xC1 Device is a mouse |
|
||||
| 0xC2 Device is a mousepad |
|
||||
\*-----------------------------------------------------*/
|
||||
switch((unsigned char)usb_buf[0x14])
|
||||
{
|
||||
case 0xC0:
|
||||
type = DEVICE_TYPE_KEYBOARD;
|
||||
break;
|
||||
|
||||
case 0xC1:
|
||||
type = DEVICE_TYPE_MOUSE;
|
||||
break;
|
||||
|
||||
case 0xC2:
|
||||
type = DEVICE_TYPE_MOUSEMAT;
|
||||
break;
|
||||
|
||||
default:
|
||||
type = DEVICE_TYPE_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Format firmware version string if device type is valid|
|
||||
\*-----------------------------------------------------*/
|
||||
if(type != DEVICE_TYPE_UNKNOWN)
|
||||
{
|
||||
firmware_version = std::to_string(usb_buf[0x09]) + "." + std::to_string(usb_buf[0x08]);
|
||||
}
|
||||
}
|
||||
|
||||
void CorsairPeripheralController::StreamPacket
|
||||
(
|
||||
unsigned char packet_id,
|
||||
unsigned char data_sz,
|
||||
unsigned char* data_ptr
|
||||
)
|
||||
{
|
||||
char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Stream packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_COMMAND_STREAM;
|
||||
usb_buf[0x01] = packet_id;
|
||||
usb_buf[0x02] = data_sz;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in data bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(&usb_buf[0x04], data_ptr, data_sz);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
send_usb_msg(dev, usb_buf);
|
||||
}
|
||||
|
||||
void CorsairPeripheralController::SubmitKeyboardFullColors
|
||||
(
|
||||
unsigned char color_channel,
|
||||
unsigned char packet_count,
|
||||
unsigned char finish_val
|
||||
)
|
||||
{
|
||||
char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Submit Keyboard 24-Bit Colors packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_COMMAND_WRITE;
|
||||
usb_buf[0x01] = CORSAIR_PROPERTY_SUBMIT_KEYBOARD_COLOR_24;
|
||||
usb_buf[0x02] = color_channel;
|
||||
usb_buf[0x03] = packet_count;
|
||||
usb_buf[0x04] = finish_val;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
send_usb_msg(dev, usb_buf);
|
||||
}
|
||||
|
||||
void CorsairPeripheralController::SubmitKeyboardLimitedColors
|
||||
(
|
||||
unsigned char byte_count
|
||||
)
|
||||
{
|
||||
char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Submit Keyboard 9-Bit Colors packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_COMMAND_WRITE;
|
||||
usb_buf[0x01] = CORSAIR_PROPERTY_SUBMIT_KEYBOARD_COLOR_9;
|
||||
usb_buf[0x04] = byte_count;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
send_usb_msg(dev, usb_buf);
|
||||
}
|
||||
|
||||
void CorsairPeripheralController::SubmitMouseColors
|
||||
(
|
||||
unsigned char num_zones,
|
||||
RGBColor * color_data
|
||||
)
|
||||
{
|
||||
char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Submit Mouse Colors packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_COMMAND_WRITE;
|
||||
usb_buf[0x01] = CORSAIR_PROPERTY_SUBMIT_MOUSE_COLOR;
|
||||
usb_buf[0x02] = num_zones;
|
||||
usb_buf[0x03] = 0x00;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in colors in <ZONE> <RED> <GREEN> <BLUE> order |
|
||||
\*-----------------------------------------------------*/
|
||||
for(unsigned int zone_idx = 0; zone_idx < num_zones; zone_idx++)
|
||||
{
|
||||
usb_buf[(zone_idx * 4) + 4] = zone_idx;
|
||||
usb_buf[(zone_idx * 4) + 5] = RGBGetRValue(color_data[zone_idx]);
|
||||
usb_buf[(zone_idx * 4) + 6] = RGBGetGValue(color_data[zone_idx]);
|
||||
usb_buf[(zone_idx * 4) + 7] = RGBGetBValue(color_data[zone_idx]);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
send_usb_msg(dev, usb_buf);
|
||||
}
|
||||
|
||||
void CorsairPeripheralController::SubmitMousematColors
|
||||
(
|
||||
unsigned char num_zones,
|
||||
RGBColor * color_data
|
||||
)
|
||||
{
|
||||
char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Submit Mouse Colors packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = CORSAIR_COMMAND_WRITE;
|
||||
usb_buf[0x01] = CORSAIR_PROPERTY_SUBMIT_MOUSE_COLOR;
|
||||
usb_buf[0x02] = num_zones;
|
||||
usb_buf[0x03] = 0x00;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in colors in <ZONE> <RED> <GREEN> <BLUE> order |
|
||||
\*-----------------------------------------------------*/
|
||||
for(unsigned int zone_idx = 0; zone_idx < num_zones; zone_idx++)
|
||||
{
|
||||
//usb_buf[(zone_idx * 4) + 4] = zone_idx;
|
||||
usb_buf[(zone_idx * 3) + 4] = RGBGetRValue(color_data[zone_idx]);
|
||||
usb_buf[(zone_idx * 3) + 5] = RGBGetGValue(color_data[zone_idx]);
|
||||
usb_buf[(zone_idx * 3) + 6] = RGBGetBValue(color_data[zone_idx]);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
send_usb_msg(dev, usb_buf);
|
||||
}
|
||||
+37
-9
@@ -1,8 +1,9 @@
|
||||
/*-----------------------------------------*\
|
||||
| CorsairKeyboardController.h |
|
||||
| CorsairPeripheralController.h |
|
||||
| |
|
||||
| Definitions and types for Corsair RGB |
|
||||
| keyboard lighting controller |
|
||||
| keyboard, mouse, and mousemat lighting |
|
||||
| controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 1/9/2020 |
|
||||
\*-----------------------------------------*/
|
||||
@@ -46,19 +47,29 @@ enum
|
||||
CORSAIR_COLOR_CHANNEL_BLUE = 0x03
|
||||
};
|
||||
|
||||
class CorsairKeyboardController
|
||||
class CorsairPeripheralController
|
||||
{
|
||||
public:
|
||||
CorsairKeyboardController(hid_device* dev_handle);
|
||||
~CorsairKeyboardController();
|
||||
CorsairPeripheralController(hid_device* dev_handle);
|
||||
~CorsairPeripheralController();
|
||||
|
||||
void SetLEDsDirect(std::vector<RGBColor> colors);
|
||||
void SetLEDs(std::vector<RGBColor> colors);
|
||||
device_type GetDeviceType();
|
||||
std::string GetFirmwareString();
|
||||
|
||||
void SetLEDs(std::vector<RGBColor> colors);
|
||||
void SetLEDsKeyboardFull(std::vector<RGBColor> colors);
|
||||
void SetLEDsKeyboardLimited(std::vector<RGBColor> colors);
|
||||
void SetLEDsMouse(std::vector<RGBColor> colors);
|
||||
void SetLEDsMousemat(std::vector<RGBColor> colors);
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
|
||||
std::string firmware_version;
|
||||
device_type type;
|
||||
|
||||
void LightingControl();
|
||||
void SpecialFunctionControl();
|
||||
|
||||
void ReadFirmwareInfo();
|
||||
|
||||
@@ -69,10 +80,27 @@ private:
|
||||
unsigned char* data_ptr
|
||||
);
|
||||
|
||||
void SubmitColors();
|
||||
void SubmitKeyboardFullColors
|
||||
(
|
||||
unsigned char color_channel,
|
||||
unsigned char packet_count,
|
||||
unsigned char finish_val
|
||||
);
|
||||
|
||||
void SubmitLimitedColors
|
||||
void SubmitKeyboardLimitedColors
|
||||
(
|
||||
unsigned char byte_count
|
||||
);
|
||||
|
||||
void SubmitMouseColors
|
||||
(
|
||||
unsigned char num_zones,
|
||||
RGBColor * color_data
|
||||
);
|
||||
|
||||
void SubmitMousematColors
|
||||
(
|
||||
unsigned char num_zones,
|
||||
RGBColor * color_data
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,137 @@
|
||||
#include "CorsairPeripheralController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_CorsairPeripheral.h"
|
||||
#include <vector>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Corsair vendor ID |
|
||||
\*-----------------------------------------------------*/
|
||||
#define CORSAIR_VID 0x1B1C
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Keyboard product IDs |
|
||||
| List taken from ckb-next |
|
||||
| Non-RGB keyboards were omitted from this list |
|
||||
\*-----------------------------------------------------*/
|
||||
#define CORSAIR_K55_RGB_PID 0x1B3D
|
||||
|
||||
#define CORSAIR_K65_RGB_PID 0x1B17
|
||||
#define CORSAIR_K65_LUX_RGB_PID 0x1B37
|
||||
#define CORSAIR_K65_RGB_RAPIDFIRE_PID 0x1B39
|
||||
|
||||
#define CORSAIR_K68_RGB 0x1B4F
|
||||
|
||||
#define CORSAIR_K70_RGB_PID 0x1B13
|
||||
#define CORSAIR_K70_LUX_RGB_PID 0x1B33
|
||||
#define CORSAIR_K70_RGB_RAPIDFIRE_PID 0x1B38
|
||||
#define CORSAIR_K70_RGB_MK2_PID 0x1B38
|
||||
#define CORSAIR_K70_RGB_MK2_SE_PID 0x1B6B
|
||||
#define CORSAIR_K70_RGB_MK2_LP_PID 0x1B55
|
||||
|
||||
#define CORSAIR_K95_RGB_PID 0x1B11
|
||||
#define CORSAIR_K95_PLATINUM_PID 0x1B2D
|
||||
|
||||
#define CORSAIR_STRAFE_PID 0x1B20
|
||||
#define CORSAIR_STRAFE_MK2_PID 0x1B48
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Mouse product IDs |
|
||||
| List taken from ckb-next |
|
||||
\*-----------------------------------------------------*/
|
||||
#define CORSAIR_M65_PRO_PID 0x1B2E
|
||||
#define CORSAIR_M65_RGB_ELITE_PID 0x1B5A
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Mousepad product IDs |
|
||||
| List taken from ckb-next |
|
||||
\*-----------------------------------------------------*/
|
||||
#define CORSAIR_MM800_RGB_POLARIS_PID 0x1B3B
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned short usb_vid;
|
||||
unsigned short usb_pid;
|
||||
unsigned char usb_interface;
|
||||
const char * name;
|
||||
} corsair_node_device;
|
||||
|
||||
#define CORSAIR_NUM_DEVICES (sizeof(device_list) / sizeof(device_list[ 0 ]))
|
||||
|
||||
static const corsair_node_device device_list[] =
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------------------------*\
|
||||
| Keyboards |
|
||||
\*-----------------------------------------------------------------------------------------------------*/
|
||||
{ CORSAIR_VID, CORSAIR_K68_RGB, 1, "Corsair K68 RGB" },
|
||||
{ CORSAIR_VID, CORSAIR_K70_RGB_PID, 1, "Corsair K70 RGB" },
|
||||
{ CORSAIR_VID, CORSAIR_K70_LUX_RGB_PID, 1, "Corsair K70 LUX RGB" },
|
||||
{ CORSAIR_VID, CORSAIR_K70_RGB_RAPIDFIRE_PID, 1, "Corsair K70 RGB RAPIDFIRE" },
|
||||
{ CORSAIR_VID, CORSAIR_K70_RGB_MK2_PID, 1, "Corsair K70 RGB MK.2" },
|
||||
{ CORSAIR_VID, CORSAIR_K70_RGB_MK2_SE_PID, 1, "Corsair K70 RGB MK.2 SE" },
|
||||
{ CORSAIR_VID, CORSAIR_K70_RGB_MK2_LP_PID, 1, "Corsair K70 RGB MK.2 Low Profile" },
|
||||
{ CORSAIR_VID, CORSAIR_K95_RGB_PID, 1, "Corsair K95 RGB" },
|
||||
{ CORSAIR_VID, CORSAIR_K95_PLATINUM_PID, 1, "Corsair K95 RGB PLATINUM" },
|
||||
/*-----------------------------------------------------------------------------------------------------*\
|
||||
| Mice |
|
||||
\*-----------------------------------------------------------------------------------------------------*/
|
||||
{ CORSAIR_VID, CORSAIR_M65_PRO_PID, 1, "Corsair M65 PRO" },
|
||||
{ CORSAIR_VID, CORSAIR_M65_RGB_ELITE_PID, 1, "Corsair M65 RGB Elite" },
|
||||
/*-----------------------------------------------------------------------------------------------------*\
|
||||
| Mousemats |
|
||||
\*-----------------------------------------------------------------------------------------------------*/
|
||||
{ CORSAIR_VID, CORSAIR_MM800_RGB_POLARIS_PID, 0, "Corsair MM800 RGB Polaris" }
|
||||
};
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectCorsairPeripheralControllers *
|
||||
* *
|
||||
* Tests the USB address to see if a Corsair RGB Keyboard controller exists there. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectCorsairPeripheralControllers(std::vector<RGBController*>& rgb_controllers)
|
||||
{
|
||||
hid_device_info* info;
|
||||
hid_device* dev;
|
||||
|
||||
hid_init();
|
||||
|
||||
for(std::size_t device_idx = 0; device_idx < CORSAIR_NUM_DEVICES; device_idx++)
|
||||
{
|
||||
dev = NULL;
|
||||
|
||||
info = hid_enumerate(device_list[device_idx].usb_vid, device_list[device_idx].usb_pid);
|
||||
|
||||
//Look for Corsair RGB Peripheral
|
||||
while(info)
|
||||
{
|
||||
if((info->vendor_id == device_list[device_idx].usb_vid)
|
||||
&&(info->product_id == device_list[device_idx].usb_pid)
|
||||
&&(info->interface_number == device_list[device_idx].usb_interface))
|
||||
{
|
||||
dev = hid_open_path(info->path);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
info = info->next;
|
||||
}
|
||||
}
|
||||
|
||||
if( dev )
|
||||
{
|
||||
CorsairPeripheralController* controller = new CorsairPeripheralController(dev);
|
||||
|
||||
if(controller->GetDeviceType() != DEVICE_TYPE_UNKNOWN)
|
||||
{
|
||||
RGBController_CorsairPeripheral* rgb_controller = new RGBController_CorsairPeripheral(controller);
|
||||
|
||||
rgb_controller->name = device_list[device_idx].name;
|
||||
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-9
@@ -1,5 +1,5 @@
|
||||
/*-----------------------------------------*\
|
||||
| CorsairController.h |
|
||||
| CorsairVengeanceController.h |
|
||||
| |
|
||||
| Driver for Corsair Vengeance RGB RAM |
|
||||
| lighting controller |
|
||||
@@ -7,10 +7,10 @@
|
||||
| Adam Honse (CalcProgrammer1) 3/8/2019 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "CorsairController.h"
|
||||
#include "CorsairVengeanceController.h"
|
||||
#include <cstring>
|
||||
|
||||
CorsairController::CorsairController(i2c_smbus_interface* bus, corsair_dev_id dev)
|
||||
CorsairVengeanceController::CorsairVengeanceController(i2c_smbus_interface* bus, corsair_dev_id dev)
|
||||
{
|
||||
this->bus = bus;
|
||||
this->dev = dev;
|
||||
@@ -19,17 +19,17 @@ CorsairController::CorsairController(i2c_smbus_interface* bus, corsair_dev_id de
|
||||
led_count = 1;
|
||||
}
|
||||
|
||||
CorsairController::~CorsairController()
|
||||
CorsairVengeanceController::~CorsairVengeanceController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string CorsairController::GetDeviceName()
|
||||
std::string CorsairVengeanceController::GetDeviceName()
|
||||
{
|
||||
return(device_name);
|
||||
}
|
||||
|
||||
std::string CorsairController::GetDeviceLocation()
|
||||
std::string CorsairVengeanceController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
char addr[5];
|
||||
@@ -39,12 +39,12 @@ std::string CorsairController::GetDeviceLocation()
|
||||
return(return_string);
|
||||
}
|
||||
|
||||
unsigned int CorsairController::GetLEDCount()
|
||||
unsigned int CorsairVengeanceController::GetLEDCount()
|
||||
{
|
||||
return(led_count);
|
||||
}
|
||||
|
||||
void CorsairController::SetLEDColor(unsigned char red, unsigned char green, unsigned char blue)
|
||||
void CorsairVengeanceController::SetLEDColor(unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_FADE_TIME, 0x00);
|
||||
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_RED_VAL, red);
|
||||
@@ -53,7 +53,7 @@ void CorsairController::SetLEDColor(unsigned char red, unsigned char green, unsi
|
||||
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_MODE, CORSAIR_VENGEANCE_RGB_MODE_SINGLE);
|
||||
}
|
||||
|
||||
void CorsairController::SetMode(unsigned char /*mode*/)
|
||||
void CorsairVengeanceController::SetMode(unsigned char /*mode*/)
|
||||
{
|
||||
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_MODE, CORSAIR_VENGEANCE_RGB_MODE_SINGLE);
|
||||
}
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*-----------------------------------------*\
|
||||
| CorsairController.h |
|
||||
| CorsairVengeanceController.h |
|
||||
| |
|
||||
| Definitions and types for Corsair |
|
||||
| Vengeance RGB RAM lighting controller |
|
||||
@@ -33,11 +33,11 @@ enum
|
||||
CORSAIR_NUMBER_MODES /* Number of Corsair modes */
|
||||
};
|
||||
|
||||
class CorsairController
|
||||
class CorsairVengeanceController
|
||||
{
|
||||
public:
|
||||
CorsairController(i2c_smbus_interface* bus, corsair_dev_id dev);
|
||||
~CorsairController();
|
||||
CorsairVengeanceController(i2c_smbus_interface* bus, corsair_dev_id dev);
|
||||
~CorsairVengeanceController();
|
||||
|
||||
std::string GetDeviceName();
|
||||
std::string GetDeviceLocation();
|
||||
+34
-34
@@ -1,6 +1,6 @@
|
||||
#include "CorsairController.h"
|
||||
#include "CorsairVengeanceController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_Corsair.h"
|
||||
#include "RGBController_CorsairVengeance.h"
|
||||
#include "i2c_smbus.h"
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
@@ -8,13 +8,13 @@
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* TestForCorsairController *
|
||||
* TestForCorsairVengeanceController *
|
||||
* *
|
||||
* Tests the given address to see if a Corsair controller exists there. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
bool TestForCorsairController(i2c_smbus_interface* bus, unsigned char address)
|
||||
bool TestForCorsairVengeanceController(i2c_smbus_interface* bus, unsigned char address)
|
||||
{
|
||||
bool pass = false;
|
||||
|
||||
@@ -37,11 +37,11 @@ bool TestForCorsairController(i2c_smbus_interface* bus, unsigned char address)
|
||||
|
||||
return(pass);
|
||||
|
||||
} /* TestForCorsairController() */
|
||||
} /* TestForCorsairVengeanceController() */
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectCorsairControllers *
|
||||
* DetectCorsairVengeanceControllers *
|
||||
* *
|
||||
* Detect Corsair controllers on the enumerated I2C busses. *
|
||||
* *
|
||||
@@ -50,76 +50,76 @@ bool TestForCorsairController(i2c_smbus_interface* bus, unsigned char address)
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectCorsairControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers)
|
||||
void DetectCorsairVengeanceControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers)
|
||||
{
|
||||
CorsairController* new_corsair;
|
||||
RGBController_Corsair* new_controller;
|
||||
CorsairVengeanceController* new_corsair;
|
||||
RGBController_CorsairVengeance* new_controller;
|
||||
|
||||
for (unsigned int bus = 0; bus < busses.size(); bus++)
|
||||
{
|
||||
// Check for Corsair controller at 0x58
|
||||
if (TestForCorsairController(busses[bus], 0x58))
|
||||
if (TestForCorsairVengeanceController(busses[bus], 0x58))
|
||||
{
|
||||
new_corsair = new CorsairController(busses[bus], 0x58);
|
||||
new_controller = new RGBController_Corsair(new_corsair);
|
||||
new_corsair = new CorsairVengeanceController(busses[bus], 0x58);
|
||||
new_controller = new RGBController_CorsairVengeance(new_corsair);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
|
||||
// Check for Corsair controller at 0x59
|
||||
if (TestForCorsairController(busses[bus], 0x59))
|
||||
if (TestForCorsairVengeanceController(busses[bus], 0x59))
|
||||
{
|
||||
new_corsair = new CorsairController(busses[bus], 0x59);
|
||||
new_controller = new RGBController_Corsair(new_corsair);
|
||||
new_corsair = new CorsairVengeanceController(busses[bus], 0x59);
|
||||
new_controller = new RGBController_CorsairVengeance(new_corsair);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
|
||||
// Check for Corsair controller at 0x5A
|
||||
if (TestForCorsairController(busses[bus], 0x5A))
|
||||
if (TestForCorsairVengeanceController(busses[bus], 0x5A))
|
||||
{
|
||||
new_corsair = new CorsairController(busses[bus], 0x5A);
|
||||
new_controller = new RGBController_Corsair(new_corsair);
|
||||
new_corsair = new CorsairVengeanceController(busses[bus], 0x5A);
|
||||
new_controller = new RGBController_CorsairVengeance(new_corsair);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
|
||||
// Check for Corsair controller at 0x5B
|
||||
if (TestForCorsairController(busses[bus], 0x5B))
|
||||
if (TestForCorsairVengeanceController(busses[bus], 0x5B))
|
||||
{
|
||||
new_corsair = new CorsairController(busses[bus], 0x5B);
|
||||
new_controller = new RGBController_Corsair(new_corsair);
|
||||
new_corsair = new CorsairVengeanceController(busses[bus], 0x5B);
|
||||
new_controller = new RGBController_CorsairVengeance(new_corsair);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
|
||||
// Check for Corsair controller at 0x5C
|
||||
if (TestForCorsairController(busses[bus], 0x5C))
|
||||
if (TestForCorsairVengeanceController(busses[bus], 0x5C))
|
||||
{
|
||||
new_corsair = new CorsairController(busses[bus], 0x5C);
|
||||
new_controller = new RGBController_Corsair(new_corsair);
|
||||
new_corsair = new CorsairVengeanceController(busses[bus], 0x5C);
|
||||
new_controller = new RGBController_CorsairVengeance(new_corsair);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
|
||||
// Check for Corsair controller at 0x5D
|
||||
if (TestForCorsairController(busses[bus], 0x5D))
|
||||
if (TestForCorsairVengeanceController(busses[bus], 0x5D))
|
||||
{
|
||||
new_corsair = new CorsairController(busses[bus], 0x5D);
|
||||
new_controller = new RGBController_Corsair(new_corsair);
|
||||
new_corsair = new CorsairVengeanceController(busses[bus], 0x5D);
|
||||
new_controller = new RGBController_CorsairVengeance(new_corsair);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
|
||||
// Check for Corsair controller at 0x5E
|
||||
if (TestForCorsairController(busses[bus], 0x5E))
|
||||
if (TestForCorsairVengeanceController(busses[bus], 0x5E))
|
||||
{
|
||||
new_corsair = new CorsairController(busses[bus], 0x5E);
|
||||
new_controller = new RGBController_Corsair(new_corsair);
|
||||
new_corsair = new CorsairVengeanceController(busses[bus], 0x5E);
|
||||
new_controller = new RGBController_CorsairVengeance(new_corsair);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
|
||||
// Check for Corsair controller at 0x5F
|
||||
if (TestForCorsairController(busses[bus], 0x5F))
|
||||
if (TestForCorsairVengeanceController(busses[bus], 0x5F))
|
||||
{
|
||||
new_corsair = new CorsairController(busses[bus], 0x5F);
|
||||
new_controller = new RGBController_Corsair(new_corsair);
|
||||
new_corsair = new CorsairVengeanceController(busses[bus], 0x5F);
|
||||
new_controller = new RGBController_CorsairVengeance(new_corsair);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
}
|
||||
|
||||
} /* DetectCorsairControllers() */
|
||||
} /* DetectCorsairVengeanceControllers() */
|
||||
+13
-13
@@ -1,5 +1,5 @@
|
||||
/*-----------------------------------------*\
|
||||
| CorsairProController.cpp |
|
||||
| CorsairVengeanceProController.cpp |
|
||||
| |
|
||||
| Definitions and types for Corsair |
|
||||
| Vengeance Pro RGB RAM lighting controller|
|
||||
@@ -7,7 +7,7 @@
|
||||
| Adam Honse (CalcProgrammer1) 6/30/2019 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "CorsairProController.h"
|
||||
#include "CorsairVengeanceProController.h"
|
||||
#include <cstring>
|
||||
|
||||
#ifdef WIN32
|
||||
@@ -21,7 +21,7 @@ static void Sleep(unsigned int milliseconds)
|
||||
}
|
||||
#endif
|
||||
|
||||
CorsairProController::CorsairProController(i2c_smbus_interface* bus, corsair_dev_id dev)
|
||||
CorsairVengeanceProController::CorsairVengeanceProController(i2c_smbus_interface* bus, corsair_dev_id dev)
|
||||
{
|
||||
this->bus = bus;
|
||||
this->dev = dev;
|
||||
@@ -39,17 +39,17 @@ CorsairProController::CorsairProController(i2c_smbus_interface* bus, corsair_dev
|
||||
}
|
||||
}
|
||||
|
||||
CorsairProController::~CorsairProController()
|
||||
CorsairVengeanceProController::~CorsairVengeanceProController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string CorsairProController::GetDeviceName()
|
||||
std::string CorsairVengeanceProController::GetDeviceName()
|
||||
{
|
||||
return(device_name);
|
||||
}
|
||||
|
||||
std::string CorsairProController::GetDeviceLocation()
|
||||
std::string CorsairVengeanceProController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
char addr[5];
|
||||
@@ -59,17 +59,17 @@ std::string CorsairProController::GetDeviceLocation()
|
||||
return(return_string);
|
||||
}
|
||||
|
||||
unsigned int CorsairProController::GetLEDCount()
|
||||
unsigned int CorsairVengeanceProController::GetLEDCount()
|
||||
{
|
||||
return(led_count);
|
||||
}
|
||||
|
||||
unsigned char CorsairProController::GetEffect()
|
||||
unsigned char CorsairVengeanceProController::GetEffect()
|
||||
{
|
||||
return(effect_mode);
|
||||
}
|
||||
|
||||
void CorsairProController::SetAllColors(unsigned char red, unsigned char green, unsigned char blue)
|
||||
void CorsairVengeanceProController::SetAllColors(unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
for (unsigned int i = 0; i < led_count; i++)
|
||||
{
|
||||
@@ -79,14 +79,14 @@ void CorsairProController::SetAllColors(unsigned char red, unsigned char green,
|
||||
}
|
||||
}
|
||||
|
||||
void CorsairProController::SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
|
||||
void CorsairVengeanceProController::SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
led_red[led] = red;
|
||||
led_green[led] = green;
|
||||
led_blue[led] = blue;
|
||||
}
|
||||
|
||||
void CorsairProController::ApplyColors()
|
||||
void CorsairVengeanceProController::ApplyColors()
|
||||
{
|
||||
bus->i2c_smbus_write_byte_data(dev, 0x26, 0x02);
|
||||
Sleep(1);
|
||||
@@ -104,7 +104,7 @@ void CorsairProController::ApplyColors()
|
||||
bus->i2c_smbus_write_byte_data(dev, 0x82, 0x02);
|
||||
}
|
||||
|
||||
void CorsairProController::SetEffect(unsigned char mode,
|
||||
void CorsairVengeanceProController::SetEffect(unsigned char mode,
|
||||
unsigned char speed,
|
||||
unsigned char direction,
|
||||
bool random,
|
||||
@@ -159,7 +159,7 @@ void CorsairProController::SetEffect(unsigned char mode,
|
||||
WaitReady();
|
||||
}
|
||||
|
||||
bool CorsairProController::WaitReady()
|
||||
bool CorsairVengeanceProController::WaitReady()
|
||||
{
|
||||
int i = 0;
|
||||
while (bus->i2c_smbus_read_byte_data(dev, 0x41) != 0x00)
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*-----------------------------------------*\
|
||||
| CorsairProController.h |
|
||||
| CorsairVengeanceProController.h |
|
||||
| |
|
||||
| Definitions and types for Corsair |
|
||||
| Vengeance Pro RGB RAM lighting controller|
|
||||
@@ -60,11 +60,11 @@ enum
|
||||
CORSAIR_PRO_DIRECTION_HORIZONTAL = 0x03, /* Horizontal direction */
|
||||
};
|
||||
|
||||
class CorsairProController
|
||||
class CorsairVengeanceProController
|
||||
{
|
||||
public:
|
||||
CorsairProController(i2c_smbus_interface* bus, corsair_dev_id dev);
|
||||
~CorsairProController();
|
||||
CorsairVengeanceProController(i2c_smbus_interface* bus, corsair_dev_id dev);
|
||||
~CorsairVengeanceProController();
|
||||
|
||||
std::string GetDeviceName();
|
||||
std::string GetDeviceLocation();
|
||||
+36
-36
@@ -1,6 +1,6 @@
|
||||
#include "CorsairProController.h"
|
||||
#include "CorsairVengeanceProController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_CorsairPro.h"
|
||||
#include "RGBController_CorsairVengeancePro.h"
|
||||
#include "i2c_smbus.h"
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
@@ -19,13 +19,13 @@ static void Sleep(unsigned int milliseconds)
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* TestForCorsairProController *
|
||||
* TestForCorsairVengeanceProController *
|
||||
* *
|
||||
* Tests the given address to see if a Corsair Pro controller exists there. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
bool TestForCorsairProController(i2c_smbus_interface* bus, unsigned char address)
|
||||
bool TestForCorsairVengeanceProController(i2c_smbus_interface* bus, unsigned char address)
|
||||
{
|
||||
bool pass = false;
|
||||
|
||||
@@ -44,7 +44,7 @@ bool TestForCorsairProController(i2c_smbus_interface* bus, unsigned char address
|
||||
|
||||
res = bus->i2c_smbus_read_byte_data(address, 0x44);
|
||||
|
||||
if (res != 0x03)
|
||||
if (!((res == 0x03) || (res == 0x04)))
|
||||
{
|
||||
pass = false;
|
||||
}
|
||||
@@ -54,89 +54,89 @@ bool TestForCorsairProController(i2c_smbus_interface* bus, unsigned char address
|
||||
|
||||
return(pass);
|
||||
|
||||
} /* TestForCorsairProController() */
|
||||
} /* TestForCorsairVengeanceProController() */
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectCorsairProControllers *
|
||||
* DetectCorsairVengeanceProControllers *
|
||||
* *
|
||||
* Detect Corsair Pro controllers on the enumerated I2C busses. *
|
||||
* Detect Corsair Vengeance Pro controllers on the enumerated I2C busses. *
|
||||
* *
|
||||
* bus - pointer to i2c_smbus_interface where Aura device is connected *
|
||||
* dev - I2C address of Aura device *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectCorsairProControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers)
|
||||
void DetectCorsairVengeanceProControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers)
|
||||
{
|
||||
CorsairProController* new_corsair_pro;
|
||||
RGBController_CorsairPro* new_controller;
|
||||
CorsairVengeanceProController* new_corsair_pro;
|
||||
RGBController_CorsairVengeancePro* new_controller;
|
||||
|
||||
for (unsigned int bus = 0; bus < busses.size(); bus++)
|
||||
{
|
||||
// Check for Corsair controller at 0x58
|
||||
if (TestForCorsairProController(busses[bus], 0x58))
|
||||
if (TestForCorsairVengeanceProController(busses[bus], 0x58))
|
||||
{
|
||||
new_corsair_pro = new CorsairProController(busses[bus], 0x58);
|
||||
new_controller = new RGBController_CorsairPro(new_corsair_pro);
|
||||
new_corsair_pro = new CorsairVengeanceProController(busses[bus], 0x58);
|
||||
new_controller = new RGBController_CorsairVengeancePro(new_corsair_pro);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
|
||||
// Check for Corsair controller at 0x59
|
||||
if (TestForCorsairProController(busses[bus], 0x59))
|
||||
if (TestForCorsairVengeanceProController(busses[bus], 0x59))
|
||||
{
|
||||
new_corsair_pro = new CorsairProController(busses[bus], 0x59);
|
||||
new_controller = new RGBController_CorsairPro(new_corsair_pro);
|
||||
new_corsair_pro = new CorsairVengeanceProController(busses[bus], 0x59);
|
||||
new_controller = new RGBController_CorsairVengeancePro(new_corsair_pro);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
|
||||
// Check for Corsair controller at 0x5A
|
||||
if (TestForCorsairProController(busses[bus], 0x5A))
|
||||
if (TestForCorsairVengeanceProController(busses[bus], 0x5A))
|
||||
{
|
||||
new_corsair_pro = new CorsairProController(busses[bus], 0x5A);
|
||||
new_controller = new RGBController_CorsairPro(new_corsair_pro);
|
||||
new_corsair_pro = new CorsairVengeanceProController(busses[bus], 0x5A);
|
||||
new_controller = new RGBController_CorsairVengeancePro(new_corsair_pro);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
|
||||
// Check for Corsair controller at 0x5B
|
||||
if (TestForCorsairProController(busses[bus], 0x5B))
|
||||
if (TestForCorsairVengeanceProController(busses[bus], 0x5B))
|
||||
{
|
||||
new_corsair_pro = new CorsairProController(busses[bus], 0x5B);
|
||||
new_controller = new RGBController_CorsairPro(new_corsair_pro);
|
||||
new_corsair_pro = new CorsairVengeanceProController(busses[bus], 0x5B);
|
||||
new_controller = new RGBController_CorsairVengeancePro(new_corsair_pro);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
|
||||
// Check for Corsair controller at 0x5C
|
||||
if (TestForCorsairProController(busses[bus], 0x5C))
|
||||
if (TestForCorsairVengeanceProController(busses[bus], 0x5C))
|
||||
{
|
||||
new_corsair_pro = new CorsairProController(busses[bus], 0x5C);
|
||||
new_controller = new RGBController_CorsairPro(new_corsair_pro);
|
||||
new_corsair_pro = new CorsairVengeanceProController(busses[bus], 0x5C);
|
||||
new_controller = new RGBController_CorsairVengeancePro(new_corsair_pro);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
|
||||
// Check for Corsair controller at 0x5D
|
||||
if (TestForCorsairProController(busses[bus], 0x5D))
|
||||
if (TestForCorsairVengeanceProController(busses[bus], 0x5D))
|
||||
{
|
||||
new_corsair_pro = new CorsairProController(busses[bus], 0x5D);
|
||||
new_controller = new RGBController_CorsairPro(new_corsair_pro);
|
||||
new_corsair_pro = new CorsairVengeanceProController(busses[bus], 0x5D);
|
||||
new_controller = new RGBController_CorsairVengeancePro(new_corsair_pro);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
|
||||
// Check for Corsair controller at 0x5E
|
||||
if (TestForCorsairProController(busses[bus], 0x5E))
|
||||
if (TestForCorsairVengeanceProController(busses[bus], 0x5E))
|
||||
{
|
||||
new_corsair_pro = new CorsairProController(busses[bus], 0x5E);
|
||||
new_controller = new RGBController_CorsairPro(new_corsair_pro);
|
||||
new_corsair_pro = new CorsairVengeanceProController(busses[bus], 0x5E);
|
||||
new_controller = new RGBController_CorsairVengeancePro(new_corsair_pro);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
|
||||
// Check for Corsair controller at 0x5F
|
||||
if (TestForCorsairProController(busses[bus], 0x5F))
|
||||
if (TestForCorsairVengeanceProController(busses[bus], 0x5F))
|
||||
{
|
||||
new_corsair_pro = new CorsairProController(busses[bus], 0x5F);
|
||||
new_controller = new RGBController_CorsairPro(new_corsair_pro);
|
||||
new_corsair_pro = new CorsairVengeanceProController(busses[bus], 0x5F);
|
||||
new_controller = new RGBController_CorsairVengeancePro(new_corsair_pro);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
}
|
||||
|
||||
} /* DetectCorsairProControllers() */
|
||||
} /* DetectCorsairVengeanceProControllers() */
|
||||
@@ -52,16 +52,15 @@ void CrucialController::SetAllColorsDirect(RGBColor* colors)
|
||||
SendDirectColors(colors);
|
||||
}
|
||||
|
||||
void CrucialController::SendEffectColors(unsigned char red, unsigned char green, unsigned char blue)
|
||||
void CrucialController::SetAllColorsEffect(RGBColor* colors)
|
||||
{
|
||||
CrucialRegisterWrite(0x82E9, 0xFF);
|
||||
CrucialRegisterWrite(0x82EA, 0x00);
|
||||
CrucialRegisterWrite(0x82EB, 0x00);
|
||||
CrucialRegisterWrite(0x82EC, 0x00);
|
||||
CrucialRegisterWrite(0x82ED, red);
|
||||
CrucialRegisterWrite(0x82EE, green);
|
||||
CrucialRegisterWrite(0x82EF, blue);
|
||||
CrucialRegisterWrite(0x82F0, 0x01);
|
||||
for(int led_idx = 0; led_idx < 8; led_idx++)
|
||||
{
|
||||
unsigned char red = RGBGetRValue(colors[led_idx]);
|
||||
unsigned char grn = RGBGetGValue(colors[led_idx]);
|
||||
unsigned char blu = RGBGetBValue(colors[led_idx]);
|
||||
SendEffectColor(led_idx, red, grn, blu);
|
||||
}
|
||||
}
|
||||
|
||||
void CrucialController::SendBrightness(unsigned char brightness)
|
||||
@@ -131,3 +130,21 @@ void CrucialController::CrucialRegisterWrite(crucial_register reg, unsigned char
|
||||
bus->i2c_smbus_write_byte_data(dev, 0x01, val);
|
||||
|
||||
}
|
||||
|
||||
void CrucialController::SendEffectColor
|
||||
(
|
||||
unsigned int led_idx,
|
||||
unsigned int red,
|
||||
unsigned int green,
|
||||
unsigned int blue
|
||||
)
|
||||
{
|
||||
CrucialRegisterWrite(0x82E9, (1 << led_idx));
|
||||
CrucialRegisterWrite(0x82EA, 0x00);
|
||||
CrucialRegisterWrite(0x82EB, 0x00);
|
||||
CrucialRegisterWrite(0x82EC, 0x00);
|
||||
CrucialRegisterWrite(0x82ED, red);
|
||||
CrucialRegisterWrite(0x82EE, green);
|
||||
CrucialRegisterWrite(0x82EF, blue);
|
||||
CrucialRegisterWrite(0x82F0, 0x01);
|
||||
}
|
||||
@@ -42,6 +42,7 @@ public:
|
||||
std::string GetDeviceLocation();
|
||||
unsigned int GetLEDCount();
|
||||
void SetAllColorsDirect(RGBColor* colors);
|
||||
void SetAllColorsEffect(RGBColor* colors);
|
||||
void SetMode(unsigned char mode);
|
||||
|
||||
unsigned char CrucialRegisterRead(crucial_register reg);
|
||||
@@ -55,8 +56,15 @@ private:
|
||||
i2c_smbus_interface * bus;
|
||||
crucial_dev_id dev;
|
||||
|
||||
void SendEffectColor
|
||||
(
|
||||
unsigned int led_idx,
|
||||
unsigned int red,
|
||||
unsigned int green,
|
||||
unsigned int blue
|
||||
);
|
||||
|
||||
void SendDirectColors(RGBColor* color_buf);
|
||||
void SendEffectColors(unsigned char red, unsigned char green, unsigned char blue);
|
||||
void SendBrightness(unsigned char brightness);
|
||||
void SendEffectMode(unsigned char mode, unsigned char speed);
|
||||
};
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
Hue2Controller::Hue2Controller(libusb_device_handle* dev_handle)
|
||||
{
|
||||
@@ -19,9 +20,7 @@ Hue2Controller::Hue2Controller(libusb_device_handle* dev_handle)
|
||||
|
||||
Hue2Controller::~Hue2Controller()
|
||||
{
|
||||
current_mode = HUE_2_MODE_FIXED;
|
||||
current_speed = HUE_2_SPEED_NORMAL;
|
||||
current_direction = false;
|
||||
|
||||
}
|
||||
|
||||
unsigned int Hue2Controller::GetStripsOnChannel(unsigned int /*channel*/)
|
||||
@@ -89,73 +88,199 @@ unsigned int Hue2Controller::GetStripsOnChannel(unsigned int /*channel*/)
|
||||
return(ret_val);
|
||||
}
|
||||
|
||||
void Hue2Controller::SetMode(unsigned char mode, unsigned char speed, bool direction)
|
||||
void Hue2Controller::SetChannelEffect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
bool direction,
|
||||
RGBColor * colors,
|
||||
unsigned int num_colors
|
||||
)
|
||||
{
|
||||
current_mode = mode;
|
||||
current_speed = speed;
|
||||
current_direction = direction;
|
||||
}
|
||||
|
||||
void Hue2Controller::SetChannelLEDs(unsigned char channel, std::vector<RGBColor> colors)
|
||||
{
|
||||
unsigned char usb_buf[] =
|
||||
{
|
||||
0x28, 0x03, 0x00, 0x28,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
int actual = 0;
|
||||
unsigned char color_data[24];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set channel in USB packet |
|
||||
| Fill in color data (up to 8 colors) |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x02] = 1 << channel;
|
||||
for (std::size_t idx = 0; idx < num_colors; idx++)
|
||||
{
|
||||
int pixel_idx = idx * 3;
|
||||
RGBColor color = colors[idx];
|
||||
color_data[pixel_idx + 0x00] = RGBGetGValue(color);
|
||||
color_data[pixel_idx + 0x01] = RGBGetRValue(color);
|
||||
color_data[pixel_idx + 0x02] = RGBGetBValue(color);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send effect packet |
|
||||
\*-----------------------------------------------------*/
|
||||
SendEffect(channel, mode, speed, direction, num_colors, &color_data[0]);
|
||||
}
|
||||
|
||||
void Hue2Controller::SetChannelLEDs
|
||||
(
|
||||
unsigned char channel,
|
||||
RGBColor * colors,
|
||||
unsigned int num_colors
|
||||
)
|
||||
{
|
||||
unsigned char color_data[120];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Fill in color data (up to 40 colors) |
|
||||
\*-----------------------------------------------------*/
|
||||
for (std::size_t idx = 0; idx < num_colors; idx++)
|
||||
{
|
||||
int pixel_idx = idx * 3;
|
||||
RGBColor color = colors[idx];
|
||||
color_data[pixel_idx + 0x00] = RGBGetGValue(color);
|
||||
color_data[pixel_idx + 0x01] = RGBGetRValue(color);
|
||||
color_data[pixel_idx + 0x02] = RGBGetBValue(color);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send first group of color data |
|
||||
\*-----------------------------------------------------*/
|
||||
SendDirect(channel, 0, 20, &color_data[0]);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send second group of color data if necessary |
|
||||
\*-----------------------------------------------------*/
|
||||
if(num_colors > 20)
|
||||
{
|
||||
SendDirect(channel, 1, 20, &color_data[60]);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send apply packet |
|
||||
\*-----------------------------------------------------*/
|
||||
SendApply(channel);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------------------------------*\
|
||||
| Private packet sending functions. |
|
||||
\*-------------------------------------------------------------------------------------------------*/
|
||||
|
||||
void Hue2Controller::SendApply
|
||||
(
|
||||
unsigned char channel
|
||||
)
|
||||
{
|
||||
int actual;
|
||||
unsigned char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Apply packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x22;
|
||||
usb_buf[0x01] = 0xA0;
|
||||
usb_buf[0x02] = (unsigned char)(1 << channel);
|
||||
usb_buf[0x04] = 0x01;
|
||||
usb_buf[0x07] = 0x28;
|
||||
usb_buf[0x0A] = 0x80;
|
||||
usb_buf[0x0C] = 0x32;
|
||||
usb_buf[0x0F] = 0x01;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
libusb_interrupt_transfer(dev, 0x01, usb_buf, 64, &actual, 0);
|
||||
libusb_interrupt_transfer(dev, 0x81, usb_buf, 64, &actual, 0);
|
||||
}
|
||||
|
||||
void Hue2Controller::SendDirect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char group,
|
||||
unsigned char color_count,
|
||||
unsigned char* color_data
|
||||
)
|
||||
{
|
||||
int actual;
|
||||
unsigned char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Direct packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x22;
|
||||
usb_buf[0x01] = 0x10 | group;
|
||||
usb_buf[0x02] = (unsigned char)(1 << channel);
|
||||
usb_buf[0x03] = 0x00;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in color data bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(&usb_buf[0x04], color_data, color_count * 3);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
libusb_interrupt_transfer(dev, 0x01, usb_buf, 64, &actual, 0);
|
||||
libusb_interrupt_transfer(dev, 0x81, usb_buf, 64, &actual, 0);
|
||||
}
|
||||
|
||||
void Hue2Controller::SendEffect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
bool direction,
|
||||
unsigned char color_count,
|
||||
unsigned char* color_data
|
||||
)
|
||||
{
|
||||
int actual;
|
||||
unsigned char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Effect packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x28;
|
||||
usb_buf[0x01] = 0x03;
|
||||
usb_buf[0x02] = (unsigned char)(1 << channel);
|
||||
usb_buf[0x03] = 0x28;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set mode in USB packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x04] = current_mode;
|
||||
usb_buf[0x04] = mode;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set speed in USB packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x05] = current_speed;
|
||||
usb_buf[0x05] = speed;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set direction in USB packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x06] = current_direction ? 0x01 : 0x00;
|
||||
|
||||
usb_buf[0x06] = direction ? 0x01 : 0x00;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set color count in USB packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x08] = colors.size();
|
||||
usb_buf[0x08] = color_count;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Fill in color data |
|
||||
| Copy in color data bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
for (std::size_t idx = 0; idx < colors.size(); idx++)
|
||||
{
|
||||
int pixel_idx = idx * 3;
|
||||
RGBColor color = colors[idx];
|
||||
usb_buf[pixel_idx + 0x0A] = RGBGetGValue(color);
|
||||
usb_buf[pixel_idx + 0x0B] = RGBGetRValue(color);
|
||||
usb_buf[pixel_idx + 0x0C] = RGBGetBValue(color);
|
||||
}
|
||||
memcpy(&usb_buf[0x0A], color_data, color_count * 3);
|
||||
|
||||
libusb_interrupt_transfer(dev, 0x01, usb_buf, 64, &actual, 0);
|
||||
libusb_interrupt_transfer(dev, 0x81, usb_buf, 64, &actual, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,16 +56,53 @@ public:
|
||||
Hue2Controller(libusb_device_handle* dev_handle);
|
||||
~Hue2Controller();
|
||||
|
||||
unsigned int GetStripsOnChannel(unsigned int channel);
|
||||
void SetChannelLEDs(unsigned char channel, std::vector<RGBColor> colors);
|
||||
void SetMode(unsigned char mode, unsigned char speed, bool direction);
|
||||
unsigned int GetStripsOnChannel
|
||||
(
|
||||
unsigned int channel
|
||||
);
|
||||
|
||||
void SetChannelEffect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
bool direction,
|
||||
RGBColor * colors,
|
||||
unsigned int num_colors
|
||||
);
|
||||
|
||||
void SetChannelLEDs
|
||||
(
|
||||
unsigned char channel,
|
||||
RGBColor * colors,
|
||||
unsigned int num_colors
|
||||
);
|
||||
|
||||
unsigned int channel_leds[HUE_2_NUM_CHANNELS];
|
||||
|
||||
private:
|
||||
libusb_device_handle* dev;
|
||||
|
||||
unsigned char current_mode;
|
||||
unsigned char current_speed;
|
||||
bool current_direction;
|
||||
void SendApply
|
||||
(
|
||||
unsigned char channel
|
||||
);
|
||||
|
||||
void SendDirect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char group,
|
||||
unsigned char color_count,
|
||||
unsigned char* color_data
|
||||
);
|
||||
|
||||
void SendEffect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
bool direction,
|
||||
unsigned char color_count,
|
||||
unsigned char* color_data
|
||||
);
|
||||
};
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
@@ -24,9 +24,7 @@ static void Sleep(unsigned int milliseconds)
|
||||
|
||||
HuePlusController::HuePlusController()
|
||||
{
|
||||
current_mode = HUE_PLUS_MODE_FIXED;
|
||||
current_speed = HUE_PLUS_SPEED_NORMAL;
|
||||
current_direction = false;
|
||||
|
||||
}
|
||||
|
||||
HuePlusController::~HuePlusController()
|
||||
@@ -85,86 +83,166 @@ unsigned int HuePlusController::GetLEDsOnChannel(unsigned int channel)
|
||||
return(ret_val);
|
||||
}
|
||||
|
||||
void HuePlusController::SetMode(unsigned char mode, unsigned char speed, bool direction)
|
||||
void HuePlusController::SetChannelEffect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
bool direction,
|
||||
RGBColor * colors,
|
||||
unsigned int num_colors
|
||||
)
|
||||
{
|
||||
current_mode = mode;
|
||||
current_speed = speed;
|
||||
current_direction = direction;
|
||||
unsigned char color_data[120];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| If mode requires no colors, send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
if(num_colors == 0)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Send mode without color data |
|
||||
\*-----------------------------------------------------*/
|
||||
SendPacket(channel, mode, direction, 0, speed, 0, NULL);
|
||||
}
|
||||
/*-----------------------------------------------------*\
|
||||
| If mode requires indexed colors, send color index |
|
||||
| packets for each mode color |
|
||||
\*-----------------------------------------------------*/
|
||||
else if(num_colors <= 8)
|
||||
{
|
||||
for(std::size_t color_idx = 0; color_idx < num_colors; color_idx++)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Fill in color data (40 entries per color) |
|
||||
\*-----------------------------------------------------*/
|
||||
for (std::size_t idx = 0; idx < 40; idx++)
|
||||
{
|
||||
int pixel_idx = idx * 3;
|
||||
RGBColor color = colors[color_idx];
|
||||
color_data[pixel_idx + 0x00] = RGBGetGValue(color);
|
||||
color_data[pixel_idx + 0x01] = RGBGetRValue(color);
|
||||
color_data[pixel_idx + 0x02] = RGBGetBValue(color);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send mode and color data |
|
||||
\*-----------------------------------------------------*/
|
||||
SendPacket(channel, mode, direction, color_idx, speed, 40, &color_data[0]);
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------*\
|
||||
| If mode requires per-LED colors, fill colors array |
|
||||
\*-----------------------------------------------------*/
|
||||
else
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Fill in color data (up to 40 colors) |
|
||||
\*-----------------------------------------------------*/
|
||||
for (std::size_t idx = 0; idx < num_colors; idx++)
|
||||
{
|
||||
int pixel_idx = idx * 3;
|
||||
RGBColor color = colors[idx];
|
||||
color_data[pixel_idx + 0x00] = RGBGetGValue(color);
|
||||
color_data[pixel_idx + 0x01] = RGBGetRValue(color);
|
||||
color_data[pixel_idx + 0x02] = RGBGetBValue(color);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send mode and color data |
|
||||
\*-----------------------------------------------------*/
|
||||
SendPacket(channel, mode, direction, 0, speed, num_colors, &color_data[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void HuePlusController::SetChannelLEDs(unsigned char channel, std::vector<RGBColor> colors)
|
||||
void HuePlusController::SetChannelLEDs
|
||||
(
|
||||
unsigned char channel,
|
||||
RGBColor * colors,
|
||||
unsigned int num_colors
|
||||
)
|
||||
{
|
||||
unsigned char serial_buf[] =
|
||||
unsigned char color_data[120];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Fill in color data (up to 40 colors) |
|
||||
\*-----------------------------------------------------*/
|
||||
for (std::size_t idx = 0; idx < num_colors; idx++)
|
||||
{
|
||||
0x4B, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00
|
||||
};
|
||||
int pixel_idx = idx * 3;
|
||||
RGBColor color = colors[idx];
|
||||
color_data[pixel_idx + 0x00] = RGBGetGValue(color);
|
||||
color_data[pixel_idx + 0x01] = RGBGetRValue(color);
|
||||
color_data[pixel_idx + 0x02] = RGBGetBValue(color);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send color data |
|
||||
\*-----------------------------------------------------*/
|
||||
SendPacket(channel, HUE_PLUS_MODE_FIXED, false, 0, 0, num_colors, &color_data[0]);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------------------------------*\
|
||||
| Private packet sending functions. |
|
||||
\*-------------------------------------------------------------------------------------------------*/
|
||||
|
||||
void HuePlusController::SendPacket
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
bool direction,
|
||||
unsigned char color_idx,
|
||||
unsigned char speed,
|
||||
unsigned char color_count,
|
||||
unsigned char* color_data
|
||||
)
|
||||
{
|
||||
unsigned char serial_buf[125];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(serial_buf, 0x00, sizeof(serial_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Direct packet |
|
||||
\*-----------------------------------------------------*/
|
||||
serial_buf[0x00] = 0x4B;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set channel in serial packet |
|
||||
\*-----------------------------------------------------*/
|
||||
serial_buf[0x01] = channel;
|
||||
serial_buf[0x01] = channel + 1;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set mode in serial packet |
|
||||
\*-----------------------------------------------------*/
|
||||
serial_buf[0x02] = current_mode;
|
||||
serial_buf[0x02] = mode;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set options bitfield in serial packet |
|
||||
\*-----------------------------------------------------*/
|
||||
serial_buf[0x03] = 0;
|
||||
serial_buf[0x03] |= current_direction ? ( 1 << 4 ) : 0;
|
||||
serial_buf[0x03] |= direction ? ( 1 << 4 ) : 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set speed in serial packet |
|
||||
| Set color index and speed in serial packet |
|
||||
\*-----------------------------------------------------*/
|
||||
serial_buf[0x04] = current_speed;
|
||||
serial_buf[0x04] = ( color_idx << 5 ) | speed;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Fill in color data |
|
||||
| Copy in color data bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
for (std::size_t idx = 0; idx < colors.size(); idx++)
|
||||
{
|
||||
int pixel_idx = idx * 3;
|
||||
RGBColor color = colors[idx];
|
||||
serial_buf[pixel_idx + 0x05] = RGBGetGValue(color);
|
||||
serial_buf[pixel_idx + 0x06] = RGBGetRValue(color);
|
||||
serial_buf[pixel_idx + 0x07] = RGBGetBValue(color);
|
||||
}
|
||||
memcpy(&serial_buf[0x05], color_data, color_count * 3);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
serialport->serial_write((char *)serial_buf, HUE_PLUS_PACKET_SIZE);
|
||||
serialport->serial_flush_tx();
|
||||
|
||||
Sleep(10);
|
||||
}
|
||||
/*-----------------------------------------------------*\
|
||||
| Delay to allow Hue+ device to ready for next packet |
|
||||
\*-----------------------------------------------------*/
|
||||
Sleep(20);
|
||||
}
|
||||
|
||||
@@ -73,8 +73,23 @@ public:
|
||||
void Initialize(char* port);
|
||||
char* GetLocation();
|
||||
unsigned int GetLEDsOnChannel(unsigned int channel);
|
||||
void SetChannelLEDs(unsigned char channel, std::vector<RGBColor> colors);
|
||||
void SetMode(unsigned char mode, unsigned char speed, bool direction);
|
||||
|
||||
void SetChannelEffect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
bool direction,
|
||||
RGBColor * colors,
|
||||
unsigned int num_colors
|
||||
);
|
||||
|
||||
void SetChannelLEDs
|
||||
(
|
||||
unsigned char channel,
|
||||
RGBColor * colors,
|
||||
unsigned int num_colors
|
||||
);
|
||||
|
||||
unsigned int channel_leds[HUE_PLUS_NUM_CHANNELS];
|
||||
|
||||
@@ -82,9 +97,16 @@ private:
|
||||
char port_name[128];
|
||||
serial_port *serialport;
|
||||
|
||||
unsigned char current_mode;
|
||||
unsigned char current_speed;
|
||||
bool current_direction;
|
||||
void SendPacket
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
bool direction,
|
||||
unsigned char color_idx,
|
||||
unsigned char speed,
|
||||
unsigned char color_count,
|
||||
unsigned char* color_data
|
||||
);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+15
-15
@@ -1,16 +1,16 @@
|
||||
/*-----------------------------------------*\
|
||||
| HyperXController.cpp |
|
||||
| HyperXDRAMController.cpp |
|
||||
| |
|
||||
| Definitions and types for HyperX Predator|
|
||||
| RGB RAM lighting controller |
|
||||
| and Fury RGB RAM lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 6/29/2019 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "HyperXController.h"
|
||||
#include "HyperXDRAMController.h"
|
||||
#include <cstring>
|
||||
|
||||
HyperXController::HyperXController(i2c_smbus_interface* bus, hyperx_dev_id dev, unsigned char slots)
|
||||
HyperXDRAMController::HyperXDRAMController(i2c_smbus_interface* bus, hyperx_dev_id dev, unsigned char slots)
|
||||
{
|
||||
this->bus = bus;
|
||||
this->dev = dev;
|
||||
@@ -31,17 +31,17 @@ HyperXController::HyperXController(i2c_smbus_interface* bus, hyperx_dev_id dev,
|
||||
mode = HYPERX_MODE_DIRECT;
|
||||
}
|
||||
|
||||
HyperXController::~HyperXController()
|
||||
HyperXDRAMController::~HyperXDRAMController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string HyperXController::GetDeviceName()
|
||||
std::string HyperXDRAMController::GetDeviceName()
|
||||
{
|
||||
return(device_name);
|
||||
}
|
||||
|
||||
std::string HyperXController::GetDeviceLocation()
|
||||
std::string HyperXDRAMController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
char addr[5];
|
||||
@@ -51,12 +51,12 @@ std::string HyperXController::GetDeviceLocation()
|
||||
return(return_string);
|
||||
}
|
||||
|
||||
unsigned int HyperXController::GetLEDCount()
|
||||
unsigned int HyperXDRAMController::GetLEDCount()
|
||||
{
|
||||
return(led_count);
|
||||
}
|
||||
|
||||
unsigned int HyperXController::GetSlotCount()
|
||||
unsigned int HyperXDRAMController::GetSlotCount()
|
||||
{
|
||||
unsigned int slot_count = 0;
|
||||
|
||||
@@ -71,12 +71,12 @@ unsigned int HyperXController::GetSlotCount()
|
||||
return(slot_count);
|
||||
}
|
||||
|
||||
unsigned int HyperXController::GetMode()
|
||||
unsigned int HyperXDRAMController::GetMode()
|
||||
{
|
||||
return(mode);
|
||||
}
|
||||
|
||||
void HyperXController::SetEffectColor(unsigned char red, unsigned char green, unsigned char blue)
|
||||
void HyperXDRAMController::SetEffectColor(unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01);
|
||||
|
||||
@@ -89,7 +89,7 @@ void HyperXController::SetEffectColor(unsigned char red, unsigned char green, un
|
||||
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x03);
|
||||
}
|
||||
|
||||
void HyperXController::SetAllColors(unsigned char red, unsigned char green, unsigned char blue)
|
||||
void HyperXDRAMController::SetAllColors(unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01);
|
||||
|
||||
@@ -126,7 +126,7 @@ void HyperXController::SetAllColors(unsigned char red, unsigned char green, unsi
|
||||
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x03);
|
||||
}
|
||||
|
||||
void HyperXController::SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
|
||||
void HyperXDRAMController::SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| led_slot - the unmapped slot ID for the given LED |
|
||||
@@ -175,7 +175,7 @@ void HyperXController::SetLEDColor(unsigned int led, unsigned char red, unsigned
|
||||
}
|
||||
|
||||
|
||||
void HyperXController::SetLEDColor(unsigned int slot, unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
|
||||
void HyperXDRAMController::SetLEDColor(unsigned int slot, unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
unsigned char base = slot_base[slot];
|
||||
unsigned char red_base = base + 0x00;
|
||||
@@ -194,7 +194,7 @@ void HyperXController::SetLEDColor(unsigned int slot, unsigned int led, unsigned
|
||||
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x03);
|
||||
}
|
||||
|
||||
void HyperXController::SetMode(unsigned char new_mode, bool random, unsigned short new_speed)
|
||||
void HyperXDRAMController::SetMode(unsigned char new_mode, bool random, unsigned short new_speed)
|
||||
{
|
||||
mode = new_mode;
|
||||
speed = new_speed;
|
||||
+5
-5
@@ -1,8 +1,8 @@
|
||||
/*-----------------------------------------*\
|
||||
| HyperXController.h |
|
||||
| HyperXDRAMController.h |
|
||||
| |
|
||||
| Definitions and types for HyperX Predator|
|
||||
| RGB RAM lighting controller |
|
||||
| and Fury RGB RAM lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 6/29/2019 |
|
||||
\*-----------------------------------------*/
|
||||
@@ -193,11 +193,11 @@ static const unsigned char slot_base[4] =
|
||||
HYPERX_REG_SLOT3_LED0_RED /* SPD 0x53 maps to slot 3 */
|
||||
};
|
||||
|
||||
class HyperXController
|
||||
class HyperXDRAMController
|
||||
{
|
||||
public:
|
||||
HyperXController(i2c_smbus_interface* bus, hyperx_dev_id dev, unsigned char slots);
|
||||
~HyperXController();
|
||||
HyperXDRAMController(i2c_smbus_interface* bus, hyperx_dev_id dev, unsigned char slots);
|
||||
~HyperXDRAMController();
|
||||
|
||||
std::string GetDeviceName();
|
||||
std::string GetDeviceLocation();
|
||||
+15
-15
@@ -1,6 +1,6 @@
|
||||
#include "HyperXController.h"
|
||||
#include "HyperXDRAMController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_HyperX.h"
|
||||
#include "RGBController_HyperXDRAM.h"
|
||||
#include "i2c_smbus.h"
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
@@ -19,13 +19,13 @@ static void Sleep(unsigned int milliseconds)
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* TestForHyperXController *
|
||||
* TestForHyperXDRAMController *
|
||||
* *
|
||||
* Tests the given address to see if a HyperX controller exists there. *
|
||||
* Tests the given address to see if a HyperX controller exists there. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
bool TestForHyperXController(i2c_smbus_interface* bus, unsigned char address)
|
||||
bool TestForHyperXDRAMController(i2c_smbus_interface* bus, unsigned char address)
|
||||
{
|
||||
bool pass = false;
|
||||
|
||||
@@ -48,31 +48,31 @@ bool TestForHyperXController(i2c_smbus_interface* bus, unsigned char address)
|
||||
|
||||
return(pass);
|
||||
|
||||
} /* TestForHyperXController() */
|
||||
} /* TestForHyperXDRAMController() */
|
||||
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectHyperXControllers *
|
||||
* DetectHyperXDRAMControllers *
|
||||
* *
|
||||
* Detect HyperX controllers on the enumerated I2C busses. *
|
||||
* Detect HyperX DRAM controllers on the enumerated I2C busses. *
|
||||
* *
|
||||
* bus - pointer to i2c_smbus_interface where Aura device is connected *
|
||||
* dev - I2C address of Aura device *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectHyperXControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers)
|
||||
void DetectHyperXDRAMControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers)
|
||||
{
|
||||
HyperXController* new_hyperx;
|
||||
RGBController_HyperX* new_controller;
|
||||
HyperXDRAMController* new_hyperx;
|
||||
RGBController_HyperXDRAM* new_controller;
|
||||
|
||||
for (unsigned int bus = 0; bus < busses.size(); bus++)
|
||||
{
|
||||
unsigned char slots_valid = 0x00;
|
||||
|
||||
// Check for HyperX controller at 0x27
|
||||
if (TestForHyperXController(busses[bus], 0x27))
|
||||
if (TestForHyperXDRAMController(busses[bus], 0x27))
|
||||
{
|
||||
busses[bus]->i2c_smbus_write_byte_data(0x37, 0x00, 0xFF);
|
||||
|
||||
@@ -94,11 +94,11 @@ void DetectHyperXControllers(std::vector<i2c_smbus_interface*> &busses, std::vec
|
||||
|
||||
if(slots_valid != 0)
|
||||
{
|
||||
new_hyperx = new HyperXController(busses[bus], 0x27, slots_valid);
|
||||
new_controller = new RGBController_HyperX(new_hyperx);
|
||||
new_hyperx = new HyperXDRAMController(busses[bus], 0x27, slots_valid);
|
||||
new_controller = new RGBController_HyperXDRAM(new_hyperx);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} /* DetectHyperXControllers() */
|
||||
} /* DetectHyperXDRAMControllers() */
|
||||
@@ -46,12 +46,48 @@ HyperXKeyboardController::~HyperXKeyboardController()
|
||||
|
||||
}
|
||||
|
||||
void HyperXKeyboardController::SetMode(unsigned char mode, unsigned char direction, unsigned char speed)
|
||||
void HyperXKeyboardController::SetMode
|
||||
(
|
||||
unsigned char mode,
|
||||
unsigned char direction,
|
||||
unsigned char speed,
|
||||
std::vector<RGBColor> colors
|
||||
)
|
||||
{
|
||||
unsigned char color_mode;
|
||||
unsigned char mode_colors[9];
|
||||
|
||||
active_mode = mode;
|
||||
active_direction = direction;
|
||||
active_speed = speed;
|
||||
|
||||
memset(mode_colors, 0x00, sizeof(mode_colors));
|
||||
|
||||
switch(colors.size())
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
color_mode = HYPERX_COLOR_MODE_SPECTRUM;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
color_mode = HYPERX_COLOR_MODE_SINGLE;
|
||||
mode_colors[0] = RGBGetRValue(colors[0]);
|
||||
mode_colors[1] = RGBGetGValue(colors[0]);
|
||||
mode_colors[2] = RGBGetBValue(colors[0]);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
color_mode = HYPERX_COLOR_MODE_DUAL;
|
||||
mode_colors[3] = RGBGetRValue(colors[0]);
|
||||
mode_colors[4] = RGBGetGValue(colors[0]);
|
||||
mode_colors[5] = RGBGetBValue(colors[0]);
|
||||
mode_colors[6] = RGBGetRValue(colors[1]);
|
||||
mode_colors[7] = RGBGetGValue(colors[1]);
|
||||
mode_colors[8] = RGBGetBValue(colors[1]);
|
||||
break;
|
||||
}
|
||||
|
||||
SendEffect
|
||||
(
|
||||
0x01,
|
||||
@@ -59,8 +95,19 @@ void HyperXKeyboardController::SetMode(unsigned char mode, unsigned char directi
|
||||
active_direction,
|
||||
HYPERX_REACTIVE_MODE_NONE,
|
||||
active_speed,
|
||||
HYPERX_COLOR_MODE_SPECTRUM
|
||||
color_mode,
|
||||
mode_colors[0],
|
||||
mode_colors[1],
|
||||
mode_colors[2],
|
||||
mode_colors[3],
|
||||
mode_colors[4],
|
||||
mode_colors[5],
|
||||
mode_colors[6],
|
||||
mode_colors[7],
|
||||
mode_colors[8]
|
||||
);
|
||||
|
||||
Sleep(100);
|
||||
}
|
||||
|
||||
void HyperXKeyboardController::SetLEDsDirect(std::vector<RGBColor> colors)
|
||||
@@ -90,7 +137,7 @@ void HyperXKeyboardController::SetLEDsDirect(std::vector<RGBColor> colors)
|
||||
red_color_data
|
||||
);
|
||||
|
||||
Sleep(2);
|
||||
Sleep(5);
|
||||
|
||||
SendDirect
|
||||
(
|
||||
@@ -98,7 +145,7 @@ void HyperXKeyboardController::SetLEDsDirect(std::vector<RGBColor> colors)
|
||||
grn_color_data
|
||||
);
|
||||
|
||||
Sleep(2);
|
||||
Sleep(5);
|
||||
|
||||
SendDirect
|
||||
(
|
||||
@@ -106,7 +153,7 @@ void HyperXKeyboardController::SetLEDsDirect(std::vector<RGBColor> colors)
|
||||
blu_color_data
|
||||
);
|
||||
|
||||
Sleep(2);
|
||||
Sleep(5);
|
||||
|
||||
SendDirectExtended
|
||||
(
|
||||
@@ -142,6 +189,8 @@ void HyperXKeyboardController::SetLEDs(std::vector<RGBColor> colors)
|
||||
red_color_data
|
||||
);
|
||||
|
||||
Sleep(5);
|
||||
|
||||
SendColor
|
||||
(
|
||||
0x01,
|
||||
@@ -149,6 +198,8 @@ void HyperXKeyboardController::SetLEDs(std::vector<RGBColor> colors)
|
||||
grn_color_data
|
||||
);
|
||||
|
||||
Sleep(5);
|
||||
|
||||
SendColor
|
||||
(
|
||||
0x01,
|
||||
@@ -156,6 +207,8 @@ void HyperXKeyboardController::SetLEDs(std::vector<RGBColor> colors)
|
||||
blu_color_data
|
||||
);
|
||||
|
||||
Sleep(5);
|
||||
|
||||
SendExtendedColor
|
||||
(
|
||||
0x01,
|
||||
@@ -202,7 +255,16 @@ void HyperXKeyboardController::SendEffect
|
||||
unsigned char direction,
|
||||
unsigned char reactive_mode,
|
||||
unsigned char speed,
|
||||
unsigned char color_mode
|
||||
unsigned char color_mode,
|
||||
unsigned char red_single,
|
||||
unsigned char grn_single,
|
||||
unsigned char blu_single,
|
||||
unsigned char red_dual_1,
|
||||
unsigned char grn_dual_1,
|
||||
unsigned char blu_dual_1,
|
||||
unsigned char red_dual_2,
|
||||
unsigned char grn_dual_2,
|
||||
unsigned char blu_dual_2
|
||||
)
|
||||
{
|
||||
unsigned char buf[264];
|
||||
@@ -243,6 +305,19 @@ void HyperXKeyboardController::SendEffect
|
||||
buf[0x21] = reactive_mode;
|
||||
buf[0x22] = reactive_mode;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set mode-specific colors |
|
||||
\*-----------------------------------------------------*/
|
||||
buf[0x29] = red_single;
|
||||
buf[0x41] = grn_single;
|
||||
buf[0x59] = blu_single;
|
||||
buf[0x2A] = red_dual_1;
|
||||
buf[0x42] = grn_dual_1;
|
||||
buf[0x5A] = blu_dual_1;
|
||||
buf[0x2B] = red_dual_2;
|
||||
buf[0x43] = grn_dual_2;
|
||||
buf[0x5B] = blu_dual_2;
|
||||
|
||||
buf[0x6B] = 0x09;
|
||||
buf[0x6C] = 0x09;
|
||||
buf[0x6D] = 0x05;
|
||||
|
||||
@@ -68,7 +68,14 @@ public:
|
||||
HyperXKeyboardController(hid_device* dev_handle);
|
||||
~HyperXKeyboardController();
|
||||
|
||||
void SetMode(unsigned char mode, unsigned char direction, unsigned char speed);
|
||||
void SetMode
|
||||
(
|
||||
unsigned char mode,
|
||||
unsigned char direction,
|
||||
unsigned char speed,
|
||||
std::vector<RGBColor> colors
|
||||
);
|
||||
|
||||
void SetLEDsDirect(std::vector<RGBColor> colors);
|
||||
void SetLEDs(std::vector<RGBColor> colors);
|
||||
|
||||
@@ -90,7 +97,16 @@ private:
|
||||
unsigned char direction,
|
||||
unsigned char reactive_mode,
|
||||
unsigned char speed,
|
||||
unsigned char color_mode
|
||||
unsigned char color_mode,
|
||||
unsigned char red_single,
|
||||
unsigned char grn_single,
|
||||
unsigned char blu_single,
|
||||
unsigned char red_dual_1,
|
||||
unsigned char grn_dual_1,
|
||||
unsigned char blu_dual_1,
|
||||
unsigned char red_dual_2,
|
||||
unsigned char grn_dual_2,
|
||||
unsigned char blu_dual_2
|
||||
);
|
||||
|
||||
void SendColor
|
||||
|
||||
@@ -0,0 +1,394 @@
|
||||
/*-----------------------------------------*\
|
||||
| MSIMysticLightController.cpp |
|
||||
| |
|
||||
| Driver for MSI Mystic Light USB |
|
||||
| lighting controller |
|
||||
| |
|
||||
| T-bond 3/4/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "MSIMysticLightController.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <bitset>
|
||||
|
||||
MSIMysticLightController::MSIMysticLightController(hid_device* handle, const char *path)
|
||||
{
|
||||
dev = handle;
|
||||
|
||||
if(dev)
|
||||
{
|
||||
loc = path;
|
||||
|
||||
ReadName();
|
||||
ReadSerial();
|
||||
ReadFwVersion();
|
||||
ReadSettings();
|
||||
}
|
||||
}
|
||||
|
||||
MSIMysticLightController::~MSIMysticLightController()
|
||||
{
|
||||
if(dev)
|
||||
{
|
||||
hid_close(dev);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int MSIMysticLightController::GetZoneMinLedCount(ZONE /*zone*/)
|
||||
{
|
||||
return 1u;
|
||||
}
|
||||
|
||||
unsigned int MSIMysticLightController::GetZoneMaxLedCount(ZONE zone)
|
||||
{
|
||||
switch (zone)
|
||||
{
|
||||
case J_RAINBOW_1:
|
||||
case J_RAINBOW_2:
|
||||
case J_CORSAIR:
|
||||
return 4u; // TODO: It can be different by zone and by mobo
|
||||
default:
|
||||
return 1u;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int MSIMysticLightController::GetZoneLedCount(ZONE zone)
|
||||
{
|
||||
RainbowZoneData *requestedZone = GetRainbowZoneData(zone);
|
||||
|
||||
if (!requestedZone)
|
||||
{
|
||||
return GetZoneMaxLedCount(zone);
|
||||
}
|
||||
|
||||
return requestedZone->cycle_or_led_num;
|
||||
}
|
||||
|
||||
void MSIMysticLightController::SetZoneLedCount(ZONE zone, unsigned int led_count)
|
||||
{
|
||||
RainbowZoneData *requestedZone = GetRainbowZoneData(zone);
|
||||
|
||||
if (!requestedZone)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
led_count = std::min(GetZoneMaxLedCount(zone), std::max(GetZoneMinLedCount(zone), led_count));
|
||||
requestedZone->cycle_or_led_num = led_count;
|
||||
}
|
||||
|
||||
void MSIMysticLightController::SetMode(ZONE zone, EFFECT mode, SPEED speed, BRIGHTNESS brightness, bool rainbow_color)
|
||||
{
|
||||
ZoneData* zoneData = GetZoneData(zone);
|
||||
if(!zoneData)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
zoneData->effect = mode;
|
||||
zoneData->speedAndBrightnessFlags = (zoneData->speedAndBrightnessFlags & 128u) | brightness << 2u | speed;
|
||||
zoneData->colorFlags = BitSet(zoneData->colorFlags, !rainbow_color, 7u);
|
||||
}
|
||||
|
||||
std::string MSIMysticLightController::GetDeviceName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
std::string MSIMysticLightController::GetFWVersion()
|
||||
{
|
||||
return std::string("AP/LD ").append(version_APROM).append(" / ").append(version_LDROM);
|
||||
}
|
||||
|
||||
std::string MSIMysticLightController::GetDeviceLocation()
|
||||
{
|
||||
return loc;
|
||||
}
|
||||
|
||||
std::string MSIMysticLightController::GetSerial()
|
||||
{
|
||||
return chip_id;
|
||||
}
|
||||
|
||||
bool MSIMysticLightController::ReadSettings()
|
||||
{
|
||||
return hid_get_feature_report(dev, reinterpret_cast<unsigned char *>(&data), sizeof data) == sizeof data;
|
||||
}
|
||||
|
||||
bool MSIMysticLightController::Update()
|
||||
{
|
||||
return hid_send_feature_report(dev, reinterpret_cast<unsigned char *>(&data), sizeof data) == sizeof data;
|
||||
}
|
||||
|
||||
void MSIMysticLightController::SaveOnUpdate(bool save)
|
||||
{
|
||||
data.save_data = save;
|
||||
}
|
||||
|
||||
void MSIMysticLightController::SetZoneColor(ZONE zone, unsigned char r1, unsigned char g1, unsigned char b1, unsigned char r2, unsigned char g2, unsigned char b2)
|
||||
{
|
||||
ZoneData* zoneData = GetZoneData(zone);
|
||||
if(!zoneData)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
zoneData->color.R = r1;
|
||||
zoneData->color.G = g1;
|
||||
zoneData->color.B = b1;
|
||||
|
||||
zoneData->color2.R = r2;
|
||||
zoneData->color2.G = g2;
|
||||
zoneData->color2.B = b2;
|
||||
}
|
||||
|
||||
std::pair<Color, Color> MSIMysticLightController::GetZoneColor(ZONE zone)
|
||||
{
|
||||
ZoneData *zoneData = GetZoneData(zone);
|
||||
if (!zoneData)
|
||||
{
|
||||
return std::make_pair(Color{}, Color{});
|
||||
}
|
||||
|
||||
return std::make_pair(Color{
|
||||
zoneData->color.R,
|
||||
zoneData->color.G,
|
||||
zoneData->color.B},
|
||||
Color{zoneData->color2.R, zoneData->color2.G, zoneData->color2.B});
|
||||
}
|
||||
|
||||
ZoneData *MSIMysticLightController::GetZoneData(ZONE zone)
|
||||
{
|
||||
switch (zone)
|
||||
{
|
||||
case J_RGB_1:
|
||||
return &data.j_rgb_1;
|
||||
case J_RGB_2:
|
||||
return &data.j_rgb_2;
|
||||
case J_RAINBOW_1:
|
||||
return &data.j_rainbow_1;
|
||||
case J_RAINBOW_2:
|
||||
return &data.j_rainbow_2;
|
||||
case J_PIPE_1:
|
||||
return &data.j_pipe_1;
|
||||
case J_PIPE_2:
|
||||
return &data.j_pipe_2;
|
||||
case ON_BOARD_LED:
|
||||
return &data.on_board_led;
|
||||
case ON_BOARD_LED_1:
|
||||
return &data.on_board_led_1;
|
||||
case ON_BOARD_LED_2:
|
||||
return &data.on_board_led_2;
|
||||
case ON_BOARD_LED_3:
|
||||
return &data.on_board_led_3;
|
||||
case ON_BOARD_LED_4:
|
||||
return &data.on_board_led_4;
|
||||
case ON_BOARD_LED_5:
|
||||
return &data.on_board_led_5;
|
||||
case ON_BOARD_LED_6:
|
||||
return &data.on_board_led_6;
|
||||
case ON_BOARD_LED_7:
|
||||
return &data.on_board_led_7;
|
||||
case ON_BOARD_LED_8:
|
||||
return &data.on_board_led_8;
|
||||
case ON_BOARD_LED_9:
|
||||
return &data.on_board_led_9;
|
||||
case J_CORSAIR_OUTERLL120:
|
||||
return &data.j_corsair_outerll120;
|
||||
default:
|
||||
case J_CORSAIR:
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RainbowZoneData *MSIMysticLightController::GetRainbowZoneData(ZONE zone)
|
||||
{
|
||||
switch (zone)
|
||||
{
|
||||
case J_RAINBOW_1:
|
||||
return &data.j_rainbow_1;
|
||||
case J_RAINBOW_2:
|
||||
return &data.j_rainbow_2;
|
||||
case J_CORSAIR:
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool MSIMysticLightController::ReadFwVersion()
|
||||
{
|
||||
// First read the APROM
|
||||
// Checksum also available at report ID 180, with highCheksum stored at index 8, and low at 9
|
||||
int num = 1;
|
||||
unsigned char request[64] = {1, 176};
|
||||
unsigned char response[64];
|
||||
|
||||
std::fill_n(request + 2, sizeof request - 2, 204);
|
||||
num &= hid_write(dev, request, 64);
|
||||
num &= hid_read(dev, response, 64);
|
||||
|
||||
unsigned char highValue = response[2] >> 4;
|
||||
unsigned char lowValue = response[2] & 15;
|
||||
|
||||
version_APROM = std::to_string(static_cast<int>(highValue)).append(".").append(std::to_string(static_cast<int>(lowValue)));
|
||||
|
||||
// Now read the LDROM
|
||||
// Checksum also available at report ID 184, with highCheksum stored at index 8, and low at 9
|
||||
request[1] = 182u;
|
||||
num &= hid_write(dev, request, 64);
|
||||
num &= hid_read(dev, response, 64);
|
||||
|
||||
highValue = response[2] >> 4u;
|
||||
lowValue = response[2] & 15u;
|
||||
|
||||
version_LDROM = std::to_string(static_cast<int>(highValue)).append(".").append(std::to_string(static_cast<int>(lowValue)));
|
||||
|
||||
return num == 1;
|
||||
}
|
||||
|
||||
void MSIMysticLightController::ReadSerial()
|
||||
{
|
||||
wchar_t serial[256];
|
||||
hid_get_serial_number_string(dev, serial, 256);
|
||||
std::wstring wserial = std::wstring(serial);
|
||||
chip_id = std::string(wserial.begin(), wserial.end());
|
||||
}
|
||||
|
||||
void MSIMysticLightController::ReadName()
|
||||
{
|
||||
wchar_t tname[256];
|
||||
hid_get_manufacturer_string(dev, tname, 256);
|
||||
std::wstring wname = std::wstring(tname);
|
||||
name = std::string(wname.begin(), wname.end());
|
||||
|
||||
hid_get_product_string(dev, tname, 256);
|
||||
wname = std::wstring(tname);
|
||||
name.append(" ").append(std::string(wname.begin(), wname.end()));
|
||||
}
|
||||
|
||||
void MSIMysticLightController::SetDeviceSettings(bool is_fan, FAN_TYPE fan_type,
|
||||
unsigned char corsair_device_quantity,
|
||||
bool is_LL120Outer_individual)
|
||||
{
|
||||
// If is_fan false, it is a stripe
|
||||
CorsairZoneData &settingsZone = data.j_corsair;
|
||||
settingsZone.fan_flags = (settingsZone.fan_flags & 128u) | fan_type << 1u | is_fan;
|
||||
settingsZone.corsair_quantity = corsair_device_quantity << 2u;
|
||||
settingsZone.is_individual = BitSet(settingsZone.is_individual, is_LL120Outer_individual, 0u);
|
||||
}
|
||||
|
||||
bool MSIMysticLightController::SetVolume(unsigned char main, unsigned char left, unsigned char right)
|
||||
{
|
||||
unsigned char packet[64];
|
||||
std::fill_n(packet, sizeof packet, 204u);
|
||||
|
||||
if(main > 100u)
|
||||
{
|
||||
main = 100u;
|
||||
}
|
||||
|
||||
if(left > 100u)
|
||||
{
|
||||
left = 100u;
|
||||
}
|
||||
|
||||
if(right > 100u)
|
||||
{
|
||||
right = 100u;
|
||||
}
|
||||
|
||||
packet[0] = 1u;
|
||||
packet[1] = 192u;
|
||||
packet[3] = main;
|
||||
packet[4] = left;
|
||||
packet[5] = right;
|
||||
|
||||
return hid_write(dev, packet, sizeof packet);
|
||||
}
|
||||
|
||||
void MSIMysticLightController::SetBoardSyncSettings(bool onboard_sync, bool combine_JRGB, bool combine_JPIPE1,
|
||||
bool combine_JPIPE2, bool combine_JRAINBOW1, bool combine_JRAINBOW2,
|
||||
bool combine_crossair)
|
||||
{
|
||||
ZoneData &syncZone = data.on_board_led;
|
||||
syncZone.colorFlags = BitSet(syncZone.colorFlags, onboard_sync, 0u);
|
||||
syncZone.colorFlags = BitSet(syncZone.colorFlags, combine_JRAINBOW1, 1u);
|
||||
syncZone.colorFlags = BitSet(syncZone.colorFlags, combine_JRAINBOW2, 2u);
|
||||
syncZone.colorFlags = BitSet(syncZone.colorFlags, combine_crossair, 3u);
|
||||
syncZone.colorFlags = BitSet(syncZone.colorFlags, combine_JPIPE1, 4u);
|
||||
syncZone.colorFlags = BitSet(syncZone.colorFlags, combine_JPIPE2, 5u);
|
||||
|
||||
syncZone.speedAndBrightnessFlags = BitSet(syncZone.speedAndBrightnessFlags, combine_JRGB, 7u);
|
||||
}
|
||||
|
||||
void MSIMysticLightController::GetMode(ZONE zone, EFFECT &mode, SPEED &speed, BRIGHTNESS &brightness, bool &rainbow_color)
|
||||
{
|
||||
ZoneData *zoneData = GetZoneData(zone);
|
||||
if (!zoneData)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
mode = static_cast<EFFECT>(zoneData->effect);
|
||||
speed = static_cast<SPEED>(zoneData->speedAndBrightnessFlags & 3u);
|
||||
brightness = static_cast<BRIGHTNESS>((zoneData->speedAndBrightnessFlags >> 2u) & 31u);
|
||||
rainbow_color = (zoneData->colorFlags & 128u) >> 7u;
|
||||
}
|
||||
|
||||
unsigned char MSIMysticLightController::BitSet(unsigned char value, bool bit, unsigned int position)
|
||||
{
|
||||
return static_cast<unsigned char>(std::bitset<8>(value).set(position, bit).to_ulong());
|
||||
}
|
||||
|
||||
void MSIMysticLightController::SetCycleCount(ZONE zone, unsigned char cycle_num)
|
||||
{
|
||||
RainbowZoneData *requestedZone = GetRainbowZoneData(zone);
|
||||
|
||||
if (!requestedZone)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
requestedZone->cycle_or_led_num = cycle_num;
|
||||
}
|
||||
|
||||
unsigned char MSIMysticLightController::GetCycleCount(ZONE zone)
|
||||
{
|
||||
RainbowZoneData *requestedZone = GetRainbowZoneData(zone);
|
||||
|
||||
if (!requestedZone)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return requestedZone->cycle_or_led_num;
|
||||
}
|
||||
|
||||
void MSIMysticLightController::GetBoardSyncSettings(bool &onboard_sync, bool &combine_JRGB, bool &combine_JPIPE1,
|
||||
bool &combine_JPIPE2, bool &combine_JRAINBOW1,
|
||||
bool &combine_JRAINBOW2, bool &combine_crossair)
|
||||
{
|
||||
ZoneData &syncZone = data.on_board_led;
|
||||
onboard_sync = syncZone.colorFlags & 1u;
|
||||
combine_JRAINBOW1 = syncZone.colorFlags >> 1u & 1u;
|
||||
combine_JRAINBOW2 = syncZone.colorFlags >> 1u & 1u;
|
||||
combine_crossair = syncZone.colorFlags >> 3u & 1u;
|
||||
combine_JPIPE1 = syncZone.colorFlags >> 4u & 1u;
|
||||
combine_JPIPE2 = syncZone.colorFlags >> 5u & 1u;
|
||||
|
||||
combine_JRGB = (syncZone.speedAndBrightnessFlags & 128u) >> 7u;
|
||||
}
|
||||
|
||||
void MSIMysticLightController::GetDeviceSettings(bool &stripe_or_fan, FAN_TYPE &fan_type,
|
||||
unsigned char &corsair_device_quantity,
|
||||
bool &is_LL120Outer_individual)
|
||||
{
|
||||
CorsairZoneData &settingsZone = data.j_corsair;
|
||||
stripe_or_fan = settingsZone.fan_flags & 1u;
|
||||
fan_type = static_cast<FAN_TYPE >((settingsZone.fan_flags & 14u) >> 1u);
|
||||
corsair_device_quantity = (settingsZone.corsair_quantity & 252u) >> 2u;
|
||||
is_LL120Outer_individual = settingsZone.is_individual & 1u;
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
/*-----------------------------------------*\
|
||||
| MSIMysticLightController.h |
|
||||
| |
|
||||
| Definitions and types for MSI Mystic |
|
||||
| Light USB lighting controllers |
|
||||
| |
|
||||
| T-bond 3/4/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
#include <cstring>
|
||||
#include <hidapi/hidapi.h>
|
||||
#include <limits>
|
||||
|
||||
#pragma once
|
||||
|
||||
enum ZONE
|
||||
{
|
||||
J_RGB_1 = 1,
|
||||
J_RGB_2 = 174,
|
||||
J_PIPE_1 = 11,
|
||||
J_PIPE_2 = 21,
|
||||
J_RAINBOW_1 = 31,
|
||||
J_RAINBOW_2 = 42,
|
||||
J_CORSAIR = 53,
|
||||
J_CORSAIR_OUTERLL120 = 64,
|
||||
ON_BOARD_LED = 74,
|
||||
ON_BOARD_LED_1 = 84,
|
||||
ON_BOARD_LED_2 = 94,
|
||||
ON_BOARD_LED_3 = 104,
|
||||
ON_BOARD_LED_4 = 114,
|
||||
ON_BOARD_LED_5 = 124,
|
||||
ON_BOARD_LED_6 = 134,
|
||||
ON_BOARD_LED_7 = 144,
|
||||
ON_BOARD_LED_8 = 154,
|
||||
ON_BOARD_LED_9 = 164
|
||||
};
|
||||
|
||||
struct ZoneDescription
|
||||
{
|
||||
std::string name;
|
||||
ZONE value;
|
||||
};
|
||||
|
||||
enum EFFECT
|
||||
{
|
||||
DISABLE,
|
||||
STATIC,
|
||||
BREATHING,
|
||||
FLASHING,
|
||||
DOUBLE_FLASHING,
|
||||
LIGHTNING,
|
||||
MSI_MARQUEE,
|
||||
METEOR,
|
||||
WATER_DROP,
|
||||
MSI_RAINBOW,
|
||||
POP,
|
||||
RAP,
|
||||
JAZZ,
|
||||
PLAY,
|
||||
MOVIE,
|
||||
COLOR_RING,
|
||||
PLANETARY,
|
||||
DOUBLE_METEOR,
|
||||
ENERGY,
|
||||
BLINK,
|
||||
CLOCK,
|
||||
COLOR_PULSE,
|
||||
COLOR_SHIFT,
|
||||
COLOR_WAVE,
|
||||
MARQUEE,
|
||||
RAINBOW,
|
||||
RAINBOW_WAVE,
|
||||
VISOR,
|
||||
JRAINBOW,
|
||||
RAINBOW_FLASHING,
|
||||
RAINBOW_DOUBLE_FLASHING,
|
||||
RANDOM,
|
||||
FAN_CONTROL,
|
||||
DISABLE_2,
|
||||
COLOR_RING_FLASHING,
|
||||
COLOR_RING_DOUBLE_FLASHING,
|
||||
STACK,
|
||||
CORSAIR_QUE,
|
||||
FIRE,
|
||||
LAVA
|
||||
};
|
||||
|
||||
enum SPEED
|
||||
{
|
||||
LOW,
|
||||
MEDIUM,
|
||||
HIGH
|
||||
};
|
||||
|
||||
enum FAN_TYPE
|
||||
{
|
||||
SP,
|
||||
HD,
|
||||
LL
|
||||
};
|
||||
|
||||
enum BRIGHTNESS
|
||||
{
|
||||
OFF,
|
||||
LEVEL_10,
|
||||
LEVEL_20,
|
||||
LEVEL_30,
|
||||
LEVEL_40,
|
||||
LEVEL_50,
|
||||
LEVEL_60,
|
||||
LEVEL_70,
|
||||
LEVEL_80,
|
||||
LEVEL_90,
|
||||
LEVEL_100
|
||||
};
|
||||
|
||||
struct Color
|
||||
{
|
||||
unsigned char R;
|
||||
unsigned char G;
|
||||
unsigned char B;
|
||||
};
|
||||
|
||||
struct CorsairZoneData
|
||||
{
|
||||
unsigned char effect = EFFECT::STATIC;
|
||||
Color color { std::numeric_limits<unsigned char>::max(), 0, 0 };
|
||||
unsigned char fan_flags = 40;
|
||||
unsigned char corsair_quantity;
|
||||
unsigned char padding[3];
|
||||
|
||||
unsigned char is_individual = 0;
|
||||
};
|
||||
|
||||
struct ZoneData
|
||||
{
|
||||
unsigned char effect = EFFECT::STATIC;
|
||||
Color color { std::numeric_limits<unsigned char>::max(), 0u, 0u };
|
||||
unsigned char speedAndBrightnessFlags = 40u;
|
||||
Color color2 { 0, std::numeric_limits<unsigned char>::max(), 0u };
|
||||
unsigned char colorFlags = 128u;
|
||||
|
||||
const unsigned char padding = 0u;
|
||||
};
|
||||
|
||||
struct RainbowZoneData : ZoneData
|
||||
{
|
||||
unsigned char cycle_or_led_num = 20u;
|
||||
};
|
||||
|
||||
struct FeaturePacket
|
||||
{
|
||||
const unsigned char report_id = 82u; // Report ID
|
||||
ZoneData j_rgb_1; // 1
|
||||
ZoneData j_pipe_1; // 11
|
||||
ZoneData j_pipe_2; // 21
|
||||
RainbowZoneData j_rainbow_1; // 31
|
||||
RainbowZoneData j_rainbow_2; // 42
|
||||
CorsairZoneData j_corsair; // 53
|
||||
ZoneData j_corsair_outerll120; // 64
|
||||
ZoneData on_board_led; // 74
|
||||
ZoneData on_board_led_1; // 84
|
||||
ZoneData on_board_led_2; // 94
|
||||
ZoneData on_board_led_3; // 104
|
||||
ZoneData on_board_led_4; // 114
|
||||
ZoneData on_board_led_5; // 124
|
||||
ZoneData on_board_led_6; // 134
|
||||
ZoneData on_board_led_7; // 144
|
||||
ZoneData on_board_led_8; // 154
|
||||
ZoneData on_board_led_9; // 164
|
||||
ZoneData j_rgb_2; // 174
|
||||
|
||||
unsigned char save_data = 0u; // 184
|
||||
};
|
||||
|
||||
|
||||
class MSIMysticLightController
|
||||
{
|
||||
public:
|
||||
MSIMysticLightController(hid_device* handle, const char *path);
|
||||
~MSIMysticLightController();
|
||||
|
||||
unsigned int GetZoneMinLedCount(ZONE zone);
|
||||
unsigned int GetZoneMaxLedCount(ZONE zone);
|
||||
unsigned int GetZoneLedCount(ZONE zone);
|
||||
void SetZoneLedCount(ZONE zone, unsigned int led_count);
|
||||
|
||||
void SetMode(ZONE zone, EFFECT mode, SPEED speed, BRIGHTNESS brightness, bool rainbow_color);
|
||||
void GetMode(ZONE zone, EFFECT &mode, SPEED &speed, BRIGHTNESS &brightness, bool &rainbow_color);
|
||||
void SetZoneColor(ZONE zone, unsigned char r1, unsigned char g1, unsigned char b1, unsigned char r2, unsigned char g2, unsigned char b2);
|
||||
void SetCycleCount(ZONE zone, unsigned char cycle_num);
|
||||
unsigned char GetCycleCount(ZONE zone);
|
||||
std::pair<Color, Color>
|
||||
GetZoneColor(ZONE zone);
|
||||
bool Update();
|
||||
|
||||
void SetDeviceSettings(bool stripe_or_fan, FAN_TYPE fan_type, unsigned char corsair_device_quantity, bool is_LL120Outer_individual);
|
||||
void GetDeviceSettings(bool &stripe_or_fan, FAN_TYPE &fan_type, unsigned char &corsair_device_quantity, bool &is_LL120Outer_individual);
|
||||
bool SetVolume(unsigned char main, unsigned char left, unsigned char right);
|
||||
void SetBoardSyncSettings(bool onboard_sync, bool combine_JRGB, bool combine_JPIPE1, bool combine_JPIPE2, bool combine_JRAINBOW1, bool combine_JRAINBOW2, bool combine_crossair);
|
||||
void GetBoardSyncSettings(bool &onboard_sync, bool &combine_JRGB, bool &combine_JPIPE1, bool &combine_JPIPE2, bool &combine_JRAINBOW1, bool &combine_JRAINBOW2, bool &combine_crossair);
|
||||
|
||||
std::string GetDeviceName();
|
||||
std::string GetDeviceLocation();
|
||||
std::string GetFWVersion();
|
||||
std::string GetSerial();
|
||||
|
||||
private:
|
||||
bool ReadSettings();
|
||||
void SaveOnUpdate(bool send);
|
||||
bool ReadFwVersion();
|
||||
void ReadSerial();
|
||||
void ReadName();
|
||||
ZoneData* GetZoneData(ZONE zone);
|
||||
RainbowZoneData*
|
||||
GetRainbowZoneData(ZONE zone);
|
||||
static unsigned char BitSet(unsigned char value, bool bit, unsigned int position);
|
||||
|
||||
hid_device* dev;
|
||||
std::string name;
|
||||
std::string loc;
|
||||
std::string version_APROM;
|
||||
std::string version_LDROM;
|
||||
std::string chip_id;
|
||||
|
||||
FeaturePacket data;
|
||||
};
|
||||
@@ -0,0 +1,90 @@
|
||||
#include "MSIMysticLightController.h"
|
||||
#include "RGBController_MSIMysticLight.h"
|
||||
#include <algorithm>
|
||||
|
||||
#define MSI_VID 0x1462
|
||||
|
||||
constexpr unsigned short SupportedPIDs[41] =
|
||||
{
|
||||
31847, // MS_7C67
|
||||
31504, // MS_7B10
|
||||
31879, // MS_7C87
|
||||
31635, // MS_7B93
|
||||
31796, // MS_7C34
|
||||
31797, // MS_7C35
|
||||
31798, // MS_7C36
|
||||
31799, // MS_7C37
|
||||
31810, // MS_7C42
|
||||
31876, // MS_7C84
|
||||
31636, // MS_7B94
|
||||
31638, // MS_7B96
|
||||
31833, // MS_7C59
|
||||
31840, // MS_7C60
|
||||
31856, // MS_7C70
|
||||
31857, // MS_7C71
|
||||
31859, // MS_7C73
|
||||
31861, // MS_7C75
|
||||
31862, // MS_7C76
|
||||
31863, // MS_7C77
|
||||
31865, // MS_7C79
|
||||
31872, // MS_7C80
|
||||
31896, // MS_7C98
|
||||
31897, // MS_7C99
|
||||
31873, // MS_7C81
|
||||
31874, // MS_7C82
|
||||
31875, // MS_7C83
|
||||
31877, // MS_7C85
|
||||
31878, // MS_7C86
|
||||
31880, // MS_7C88
|
||||
31881, // MS_7C89
|
||||
17497, // MS_4459
|
||||
16036, // MS_3EA4
|
||||
36957, // MS_905D
|
||||
31888, // MS_7C90
|
||||
31889, // MS_7C91
|
||||
31890, // MS_7C92
|
||||
31892, // MS_7C94
|
||||
31893, // MS_7C95
|
||||
31894, // MS_7C96
|
||||
31830 // MS_7C56
|
||||
};
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectMSIMysticLightControllers *
|
||||
* *
|
||||
* Detect MSI Mystic Light devices that use NCT6775 RGB controllers *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectMSIMysticLightControllers(std::vector<RGBController*> &rgb_controllers)
|
||||
{
|
||||
if(hid_init() < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
hid_device_info * device_list = hid_enumerate(MSI_VID, 0);
|
||||
if(!device_list)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
hid_device_info * device = device_list;
|
||||
while(device)
|
||||
{
|
||||
if(std::find(std::begin(SupportedPIDs), std::end(SupportedPIDs), device->product_id) != std::end(SupportedPIDs))
|
||||
{
|
||||
hid_device * dev = hid_open_path(device->path);
|
||||
if(dev)
|
||||
{
|
||||
MSIMysticLightController * controller = new MSIMysticLightController(dev, device_list->path);
|
||||
RGBController_MSIMysticLight * rgb_controller = new RGBController_MSIMysticLight(controller);
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
}
|
||||
device = device->next;
|
||||
}
|
||||
|
||||
hid_free_enumeration(device_list);
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*-----------------------------------------*\
|
||||
| MSIRGBController.cpp |
|
||||
| |
|
||||
| Driver for MSI-RGB lighting controller |
|
||||
| |
|
||||
| Logic adapted from: |
|
||||
| https://github.com/nagisa/msi-rgb |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 2/11/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "MSIRGBController.h"
|
||||
#include "super_io.h"
|
||||
|
||||
MSIRGBController::MSIRGBController(int sioaddr)
|
||||
{
|
||||
msi_sioaddr = sioaddr;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| This setup step isn't well documented |
|
||||
| Without this, pulsing does not work |
|
||||
\*-----------------------------------------------------*/
|
||||
superio_outb(msi_sioaddr, SIO_REG_LOGDEV, 0x09);
|
||||
|
||||
int val_at_2c = superio_inb(msi_sioaddr, 0x2C);
|
||||
|
||||
val_at_2c &= 0b11110111;
|
||||
val_at_2c |= 0b00010000;
|
||||
|
||||
superio_outb(msi_sioaddr, 0x2C, val_at_2c);
|
||||
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set logical device register to RGB controller |
|
||||
\*-----------------------------------------------------*/
|
||||
superio_outb(msi_sioaddr, SIO_REG_LOGDEV, MSI_SIO_LOGDEV_RGB);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Test if RGB is enabled. If it is not, enable it. |
|
||||
\*-----------------------------------------------------*/
|
||||
int enable = superio_inb(msi_sioaddr, MSI_SIO_RGB_REG_ENABLE);
|
||||
|
||||
if((enable & MSI_SIO_RGB_ENABLE_MASK) != MSI_SIO_RGB_ENABLE_MASK)
|
||||
{
|
||||
superio_outb(msi_sioaddr, MSI_SIO_RGB_REG_ENABLE, MSI_SIO_RGB_ENABLE_MASK & (enable & !MSI_SIO_RGB_ENABLE_MASK));
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Lighting enabled, no pulsing or blinking |
|
||||
\*-----------------------------------------------------*/
|
||||
superio_outb(msi_sioaddr, MSI_SIO_RGB_REG_CFG_1, 0x00);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Lighting enabled, RGB non-inverted, header on |
|
||||
\*-----------------------------------------------------*/
|
||||
superio_outb(msi_sioaddr, MSI_SIO_RGB_REG_CFG_3, 0xE2);
|
||||
}
|
||||
|
||||
MSIRGBController::~MSIRGBController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MSIRGBController::SetColor(unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| The MSI RGB controller uses 4 bits per color rather |
|
||||
| than 8. Shift the values by 4 so that the 4 most |
|
||||
| significant bits of each color are the new color value|
|
||||
\*-----------------------------------------------------*/
|
||||
red = red >> 4;
|
||||
green = green >> 4;
|
||||
blue = blue >> 4;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set logical device register to RGB controller |
|
||||
\*-----------------------------------------------------*/
|
||||
superio_outb(msi_sioaddr, SIO_REG_LOGDEV, MSI_SIO_LOGDEV_RGB);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Write the colors to the color sequence registers |
|
||||
| Only static mode is supported right now - all colors |
|
||||
| are the same. |
|
||||
\*-----------------------------------------------------*/
|
||||
superio_outb(msi_sioaddr, MSI_SIO_RGB_REG_RED_1_0, (red | (red << 4)));
|
||||
superio_outb(msi_sioaddr, MSI_SIO_RGB_REG_RED_3_2, (red | (red << 4)));
|
||||
superio_outb(msi_sioaddr, MSI_SIO_RGB_REG_RED_5_4, (red | (red << 4)));
|
||||
superio_outb(msi_sioaddr, MSI_SIO_RGB_REG_RED_7_6, (red | (red << 4)));
|
||||
|
||||
superio_outb(msi_sioaddr, MSI_SIO_RGB_REG_GREEN_1_0, (green | (green << 4)));
|
||||
superio_outb(msi_sioaddr, MSI_SIO_RGB_REG_GREEN_3_2, (green | (green << 4)));
|
||||
superio_outb(msi_sioaddr, MSI_SIO_RGB_REG_GREEN_5_4, (green | (green << 4)));
|
||||
superio_outb(msi_sioaddr, MSI_SIO_RGB_REG_GREEN_7_6, (green | (green << 4)));
|
||||
|
||||
superio_outb(msi_sioaddr, MSI_SIO_RGB_REG_BLUE_1_0, (blue | (blue << 4)));
|
||||
superio_outb(msi_sioaddr, MSI_SIO_RGB_REG_BLUE_3_2, (blue | (blue << 4)));
|
||||
superio_outb(msi_sioaddr, MSI_SIO_RGB_REG_BLUE_5_4, (blue | (blue << 4)));
|
||||
superio_outb(msi_sioaddr, MSI_SIO_RGB_REG_BLUE_7_6, (blue | (blue << 4)));
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*-----------------------------------------*\
|
||||
| MSIRGBController.h |
|
||||
| |
|
||||
| Definitions and types for MSI-RGB |
|
||||
| lighting controller |
|
||||
| |
|
||||
| Logic adapted from: |
|
||||
| https://github.com/nagisa/msi-rgb |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 2/11/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#pragma once
|
||||
|
||||
#define MSI_SIO_LOGDEV_RGB 0x12
|
||||
|
||||
enum
|
||||
{
|
||||
MSI_SIO_RGB_REG_ENABLE = 0xE0,
|
||||
MSI_SIO_RGB_REG_CFG_1 = 0xE4,
|
||||
MSI_SIO_RGB_REG_RED_1_0 = 0xF0,
|
||||
MSI_SIO_RGB_REG_RED_3_2 = 0xF1,
|
||||
MSI_SIO_RGB_REG_RED_5_4 = 0xF2,
|
||||
MSI_SIO_RGB_REG_RED_7_6 = 0xF3,
|
||||
MSI_SIO_RGB_REG_GREEN_1_0 = 0xF4,
|
||||
MSI_SIO_RGB_REG_GREEN_3_2 = 0xF5,
|
||||
MSI_SIO_RGB_REG_GREEN_5_4 = 0xF6,
|
||||
MSI_SIO_RGB_REG_GREEN_7_6 = 0xF7,
|
||||
MSI_SIO_RGB_REG_BLUE_1_0 = 0xF8,
|
||||
MSI_SIO_RGB_REG_BLUE_3_2 = 0xF9,
|
||||
MSI_SIO_RGB_REG_BLUE_5_4 = 0xFA,
|
||||
MSI_SIO_RGB_REG_BLUE_7_6 = 0xFB,
|
||||
MSI_SIO_RGB_REG_CFG_2 = 0xFE,
|
||||
MSI_SIO_RGB_REG_CFG_3 = 0xFF,
|
||||
};
|
||||
|
||||
#define MSI_SIO_RGB_ENABLE_MASK 0xE0
|
||||
|
||||
class MSIRGBController
|
||||
{
|
||||
public:
|
||||
MSIRGBController(int sioaddr);
|
||||
~MSIRGBController();
|
||||
|
||||
std::string GetDeviceName();
|
||||
std::string GetDeviceLocation();
|
||||
|
||||
unsigned int GetMode();
|
||||
void SetMode(unsigned char new_mode, unsigned char new_speed);
|
||||
|
||||
void SetColor(unsigned char red, unsigned char green, unsigned char blue);
|
||||
private:
|
||||
int msi_sioaddr;
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
#include "MSIRGBController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_MSIRGB.h"
|
||||
#include "super_io.h"
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectMSIRGBControllers *
|
||||
* *
|
||||
* Detect MSI-RGB compatible Super-IO chips. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectMSIRGBControllers(std::vector<RGBController*> &rgb_controllers)
|
||||
{
|
||||
int sio_addrs[2] = {0x2E, 0x4E};
|
||||
|
||||
for(int sioaddr_idx = 0; sioaddr_idx < 2; sioaddr_idx++)
|
||||
{
|
||||
int sioaddr = sio_addrs[sioaddr_idx];
|
||||
|
||||
superio_enter(sioaddr);
|
||||
|
||||
int val = (superio_inb(sioaddr, SIO_REG_DEVID) << 8) | superio_inb(sioaddr, SIO_REG_DEVID + 1);
|
||||
|
||||
switch (val & SIO_ID_MASK)
|
||||
{
|
||||
case SIO_NCT6795_ID:
|
||||
case SIO_NCT6797_ID:
|
||||
MSIRGBController* new_msi = new MSIRGBController(sioaddr);
|
||||
RGBController_MSIRGB* new_rgb = new RGBController_MSIRGB(new_msi);
|
||||
|
||||
rgb_controllers.push_back(new_rgb);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} /* DetectMSIRGBControllers() */
|
||||
@@ -0,0 +1,166 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| Driver for NZXT Kraken |
|
||||
| |
|
||||
| Martin Hartl (inlart), 04/04/2020 |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "NZXTKrakenController.h"
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
|
||||
const int NZXT_KRAKEN_READ_ENDPOINT = 0x81;
|
||||
const int NZXT_KRAKEN_WRITE_ENDPOINT = 0x01;
|
||||
|
||||
static void SetColor(const std::vector<RGBColor>& colors, unsigned char* color_data)
|
||||
{
|
||||
for (std::size_t idx = 0; idx < colors.size(); idx++)
|
||||
{
|
||||
int pixel_idx = idx * 3;
|
||||
RGBColor color = colors[idx];
|
||||
color_data[pixel_idx + 0x00] = RGBGetRValue(color);
|
||||
color_data[pixel_idx + 0x01] = RGBGetGValue(color);
|
||||
color_data[pixel_idx + 0x02] = RGBGetBValue(color);
|
||||
}
|
||||
}
|
||||
|
||||
static RGBColor ToLogoColor(RGBColor rgb)
|
||||
{
|
||||
return ToRGBColor(RGBGetGValue(rgb), RGBGetRValue(rgb), RGBGetBValue(rgb));
|
||||
}
|
||||
|
||||
NZXTKrakenController::NZXTKrakenController(libusb_device_handle* dev_handle)
|
||||
{
|
||||
dev = dev_handle;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Get the firmware version |
|
||||
\*-----------------------------------------------------*/
|
||||
UpdateStatus();
|
||||
}
|
||||
|
||||
NZXTKrakenController::~NZXTKrakenController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string NZXTKrakenController::GetFirmwareVersion()
|
||||
{
|
||||
return firmware_version;
|
||||
}
|
||||
|
||||
void NZXTKrakenController::UpdateStatus()
|
||||
{
|
||||
int actual;
|
||||
unsigned char usb_buf[64];
|
||||
memset(usb_buf, 0, sizeof(usb_buf));
|
||||
|
||||
libusb_interrupt_transfer(dev, NZXT_KRAKEN_READ_ENDPOINT, usb_buf, sizeof(usb_buf), &actual, 0);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Extract cooler information |
|
||||
\*-----------------------------------------------------*/
|
||||
liquid_temperature = usb_buf[0x1] + (usb_buf[0x2] * 0.1);
|
||||
fan_speed = usb_buf[0x3] << 8 | usb_buf[0x4];
|
||||
pump_speed = usb_buf[0x5] << 8 | usb_buf[0x6];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Extract firmware version |
|
||||
\*-----------------------------------------------------*/
|
||||
int major = usb_buf[0xb];
|
||||
int minor = usb_buf[0xc] << 8 | usb_buf[0xd];
|
||||
int patch = usb_buf[0xe];
|
||||
std::stringstream ss;
|
||||
ss << major << '.' << minor << '.' << patch;
|
||||
firmware_version = ss.str();
|
||||
}
|
||||
|
||||
void NZXTKrakenController::UpdateEffect
|
||||
(
|
||||
NZXTKrakenChannel_t channel,
|
||||
unsigned char mode,
|
||||
bool direction,
|
||||
unsigned char speed,
|
||||
int seq,
|
||||
std::vector<RGBColor> colors
|
||||
)
|
||||
{
|
||||
unsigned char color_data[9 * 3];
|
||||
memset(color_data, 0, sizeof(color_data));
|
||||
|
||||
if(!colors.empty() && channel != NZXT_KRAKEN_CHANNEL_RING)
|
||||
{
|
||||
colors[0] = ToLogoColor(colors[0]);
|
||||
}
|
||||
|
||||
SetColor(colors, color_data);
|
||||
SendEffect(channel, mode, direction, color_data, speed, false, seq);
|
||||
}
|
||||
|
||||
void NZXTKrakenController::SendEffect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
bool direction,
|
||||
unsigned char* color_data,
|
||||
unsigned char speed /* = 0x02 */,
|
||||
bool movement /* = false */,
|
||||
int cis /* = 0 */,
|
||||
int size /* = 0 */
|
||||
)
|
||||
{
|
||||
int actual;
|
||||
unsigned char usb_buf[65];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set effect mode |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x02;
|
||||
usb_buf[0x01] = 0x4c;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set effect channel, movement and direction |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x02] = channel;
|
||||
usb_buf[0x02] |= movement ? ( 1 << 3 ) : 0;
|
||||
usb_buf[0x02] |= direction ? ( 1 << 4 ) : 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set mode |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x03] = mode;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set effect speed, size and color in set |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x04] = speed;
|
||||
usb_buf[0x04] |= size << 3;
|
||||
usb_buf[0x04] |= cis << 5;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy color data bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
if(color_data)
|
||||
{
|
||||
memcpy(usb_buf + 0x05, color_data, 9 * 3);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send effect |
|
||||
\*-----------------------------------------------------*/
|
||||
libusb_interrupt_transfer
|
||||
(
|
||||
dev,
|
||||
NZXT_KRAKEN_WRITE_ENDPOINT,
|
||||
usb_buf,
|
||||
sizeof(usb_buf),
|
||||
&actual,
|
||||
0
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| Definitions for NZXT Kraken |
|
||||
| |
|
||||
| Martin Hartl (inlart), 04/04/2020 |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RGBController.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
enum NZXTKrakenChannel_t
|
||||
{
|
||||
NZXT_KRAKEN_CHANNEL_SYNC = 0x00, /* Sync Channel */
|
||||
NZXT_KRAKEN_CHANNEL_LOGO = 0x01, /* Logo Channel */
|
||||
NZXT_KRAKEN_CHANNEL_RING = 0x02, /* Ring Channel */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
NZXT_KRAKEN_MODE_FIXED = 0x00, /* Fixed colors mode */
|
||||
NZXT_KRAKEN_MODE_FADING = 0x01, /* Fading mode */
|
||||
NZXT_KRAKEN_MODE_SPECTRUM = 0x02, /* Spectrum cycle mode */
|
||||
NZXT_KRAKEN_MODE_MARQUEE = 0x03, /* Marquee mode */
|
||||
NZXT_KRAKEN_MODE_COVER_MARQUEE = 0x04, /* Cover marquee mode */
|
||||
NZXT_KRAKEN_MODE_ALTERNATING = 0x05, /* Alternating mode */
|
||||
NZXT_KRAKEN_MODE_BREATHING = 0x06, /* Breathing mode */
|
||||
NZXT_KRAKEN_MODE_PULSE = 0x07, /* Pulse mode */
|
||||
NZXT_KRAKEN_MODE_TAI_CHI = 0x08, /* Tai Chi mode */
|
||||
NZXT_KRAKEN_MODE_WATER_COOLER = 0x09, /* Water color mode */
|
||||
NZXT_KRAKEN_MODE_LOADING = 0x0a, /* Loading mode */
|
||||
NZXT_KRAKEN_MODE_WINGS = 0x0c, /* Wings mode */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
NZXT_KRAKEN_SPEED_SLOWEST = 0x00, /* Slowest speed */
|
||||
NZXT_KRAKEN_SPEED_SLOW = 0x01, /* Slow speed */
|
||||
NZXT_KRAKEN_SPEED_NORMAL = 0x02, /* Normal speed */
|
||||
NZXT_KRAKEN_SPEED_FAST = 0x03, /* Fast speed */
|
||||
NZXT_KRAKEN_SPEED_FASTEST = 0x04, /* Fastest speed */
|
||||
};
|
||||
|
||||
class NZXTKrakenController
|
||||
{
|
||||
public:
|
||||
NZXTKrakenController(libusb_device_handle* dev_handle);
|
||||
~NZXTKrakenController();
|
||||
|
||||
std::string GetFirmwareVersion();
|
||||
|
||||
void UpdateEffect
|
||||
(
|
||||
NZXTKrakenChannel_t channel,
|
||||
unsigned char mode,
|
||||
bool direction,
|
||||
unsigned char speed,
|
||||
int seq,
|
||||
std::vector<RGBColor> colors
|
||||
);
|
||||
|
||||
private:
|
||||
void UpdateStatus();
|
||||
|
||||
void SendEffect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
bool direction,
|
||||
unsigned char* color_data,
|
||||
unsigned char speed = 0x02,
|
||||
bool movement = false,
|
||||
int cis = 0 ,
|
||||
int size = 0
|
||||
);
|
||||
|
||||
libusb_device_handle* dev;
|
||||
|
||||
// -- status
|
||||
std::string firmware_version;
|
||||
double liquid_temperature;
|
||||
unsigned int fan_speed;
|
||||
unsigned int pump_speed;
|
||||
};
|
||||
+12
-12
@@ -1,37 +1,37 @@
|
||||
#include "CorsairCmdrProController.h"
|
||||
#include "NZXTKrakenController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_CorsairCmdrPro.h"
|
||||
#include "RGBController_NZXTKraken.h"
|
||||
#include <vector>
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
#define CORSAIR_COMMANDER_PRO_VID 0x1B1C
|
||||
#define CORSAIR_COMMANDER_PRO_PID 0x0C10
|
||||
#define NZXT_KRAKEN_VID 0x1E71
|
||||
#define NZXT_KRAKEN_PID 0x170E
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectCorsairCmdrProControllers *
|
||||
* DetectNZXTKrakenControllers *
|
||||
* *
|
||||
* Detect devices supported by the Corsair Commander Pro driver *
|
||||
* Detect devices supported by the NZXTKraken driver *
|
||||
* * *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectCorsairCmdrProControllers(std::vector<RGBController*> &rgb_controllers)
|
||||
void DetectNZXTKrakenControllers(std::vector<RGBController*> &rgb_controllers)
|
||||
{
|
||||
libusb_context * ctx;
|
||||
libusb_init(&ctx);
|
||||
|
||||
//Look for Corsair Commander Pro
|
||||
libusb_device_handle * dev = libusb_open_device_with_vid_pid(ctx, CORSAIR_COMMANDER_PRO_VID, CORSAIR_COMMANDER_PRO_PID);
|
||||
libusb_device_handle * dev = libusb_open_device_with_vid_pid(ctx, NZXT_KRAKEN_VID, NZXT_KRAKEN_PID);
|
||||
|
||||
if( dev )
|
||||
{
|
||||
libusb_detach_kernel_driver(dev, 0);
|
||||
libusb_claim_interface(dev, 0);
|
||||
|
||||
CorsairCmdrProController* controller = new CorsairCmdrProController(dev);
|
||||
NZXTKrakenController* controller = new NZXTKrakenController(dev);
|
||||
|
||||
RGBController_CorsairCmdrPro* rgb_controller = new RGBController_CorsairCmdrPro(controller);
|
||||
RGBController_NZXTKraken* rgb_controller = new RGBController_NZXTKraken(controller);
|
||||
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
} /* DetectCorsairCmdrProControllers() */
|
||||
|
||||
}
|
||||
@@ -126,7 +126,7 @@ void PatriotViperController::SetLEDEffectColor(unsigned int led, unsigned char r
|
||||
ViperRegisterWrite(VIPER_REG_MODE, 0xFA, 0x00, 0x00);
|
||||
}
|
||||
|
||||
void PatriotViperController::SetLEDColor(unsigned int slot, unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
|
||||
void PatriotViperController::SetLEDColor(unsigned int /*slot*/, unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
ViperRegisterWrite(VIPER_REG_START, 0xFF, 0xFF, 0xFF);
|
||||
ViperRegisterWrite(VIPER_REG_STATIC, 0x04, 0x00, 0x00);
|
||||
@@ -136,7 +136,7 @@ void PatriotViperController::SetLEDColor(unsigned int slot, unsigned int led, un
|
||||
ViperRegisterWrite(VIPER_REG_APPLY, 0x01, 0x00, 0x00);
|
||||
}
|
||||
|
||||
void PatriotViperController::SetLEDEffectColor(unsigned int slot, unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
|
||||
void PatriotViperController::SetLEDEffectColor(unsigned int /*slot*/, unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
ViperRegisterWrite(VIPER_REG_START, 0xFF, 0xFF, 0xFF);
|
||||
ViperRegisterWrite(VIPER_REG_STATIC, 0x04, 0x00, 0x00);
|
||||
|
||||
@@ -25,20 +25,20 @@ PolychromeController::PolychromeController(i2c_smbus_interface* bus, polychrome_
|
||||
|
||||
case FIRMWARE_VER_2_PT_00:
|
||||
led_count = 1;
|
||||
asr_led = false;
|
||||
strcpy(device_name, "ASRock Polychrome FW 2.00");
|
||||
asr_led = true;
|
||||
strcpy(device_name, "ASRock ASR LED FW 2.00");
|
||||
break;
|
||||
|
||||
case FIRMWARE_VER_2_PT_08:
|
||||
led_count = 1;
|
||||
asr_led = false;
|
||||
strcpy(device_name, "ASRock Polychrome FW 2.08");
|
||||
asr_led = true;
|
||||
strcpy(device_name, "ASRock ASR LED FW 2.08");
|
||||
break;
|
||||
|
||||
case FIRMWARE_VER_2_PT_10:
|
||||
led_count = 1;
|
||||
asr_led = true;
|
||||
strcpy(device_name, "ASRock Polychrome FW 2.10");
|
||||
strcpy(device_name, "ASRock ASR LED FW 2.10");
|
||||
break;
|
||||
|
||||
case FIRMWARE_VER_3_PT_00:
|
||||
@@ -47,6 +47,12 @@ PolychromeController::PolychromeController(i2c_smbus_interface* bus, polychrome_
|
||||
strcpy(device_name, "ASRock Polychrome FW 3.00");
|
||||
break;
|
||||
|
||||
case FIRMWARE_VER_3_PT_04:
|
||||
led_count = 1;
|
||||
asr_led = false;
|
||||
strcpy(device_name, "ASRock Polychrome FW 3.04");
|
||||
break;
|
||||
|
||||
default:
|
||||
led_count = 0;
|
||||
strcpy(device_name, "");
|
||||
|
||||
@@ -21,6 +21,7 @@ enum
|
||||
FIRMWARE_VER_2_PT_08 = 0x0208, /* Firmware nu51_2.08 */
|
||||
FIRMWARE_VER_2_PT_10 = 0x020A, /* Firmware nu51_2.10 */
|
||||
FIRMWARE_VER_3_PT_00 = 0x0300, /* Firmware nu51_3.00 */
|
||||
FIRMWARE_VER_3_PT_04 = 0x0304, /* Firmware nu51_3.04 */
|
||||
};
|
||||
|
||||
enum
|
||||
|
||||
@@ -56,6 +56,8 @@ void PoseidonZRGBController::SetMode(unsigned char mode, unsigned char direction
|
||||
POSEIDONZ_BRIGHTNESS_MAX,
|
||||
active_speed
|
||||
);
|
||||
|
||||
Sleep(200);
|
||||
}
|
||||
|
||||
void PoseidonZRGBController::SetLEDsDirect(std::vector<RGBColor> colors)
|
||||
@@ -104,6 +106,9 @@ void PoseidonZRGBController::SetLEDsDirect(std::vector<RGBColor> colors)
|
||||
| Send packets |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_send_feature_report(dev, red_grn_buf, 264);
|
||||
|
||||
Sleep(5);
|
||||
|
||||
hid_send_feature_report(dev, blu_buf, 264);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBFusion2Controller.cpp |
|
||||
| |
|
||||
| Driver for Gigabyte Aorus RGB Fusion 2.0 |
|
||||
| lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 1/15/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBFusion2Controller.h"
|
||||
#include <cstring>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
RGBFusion2Controller::RGBFusion2Controller(hid_device* dev_handle)
|
||||
{
|
||||
dev = dev_handle;
|
||||
|
||||
// Set Device name
|
||||
strcpy(device_name, "Gigabyte Motherboard");
|
||||
|
||||
// Set LED count
|
||||
led_count = 8;
|
||||
}
|
||||
|
||||
RGBFusion2Controller::~RGBFusion2Controller()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string RGBFusion2Controller::GetDeviceName()
|
||||
{
|
||||
return(device_name);
|
||||
}
|
||||
|
||||
std::string RGBFusion2Controller::GetDeviceLocation()
|
||||
{
|
||||
return("");
|
||||
}
|
||||
|
||||
unsigned int RGBFusion2Controller::GetLEDCount()
|
||||
{
|
||||
return(led_count);
|
||||
}
|
||||
|
||||
unsigned char RGBFusion2Controller::GetMode()
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
void RGBFusion2Controller::SetAllColors(unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
}
|
||||
|
||||
void RGBFusion2Controller::SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
unsigned char usb_buf[] =
|
||||
{
|
||||
0xCC, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01,
|
||||
0x5A, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
usb_buf[0x01] = (0x20 | led);
|
||||
usb_buf[0x02] = (0x01 << led );
|
||||
|
||||
usb_buf[0x0E] = blue;
|
||||
usb_buf[0x0F] = green;
|
||||
usb_buf[0x10] = red;
|
||||
|
||||
hid_send_feature_report(dev, usb_buf, 64);
|
||||
|
||||
SendApply();
|
||||
}
|
||||
|
||||
void RGBFusion2Controller::SendApply()
|
||||
{
|
||||
unsigned char usb_buf[] =
|
||||
{
|
||||
0xCC, 0x28, 0xFF, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
hid_send_feature_report(dev, usb_buf, 64);
|
||||
}
|
||||
|
||||
void RGBFusion2Controller::SetMode(unsigned char mode)
|
||||
{
|
||||
}
|
||||
|
||||
void RGBFusion2Controller::dump()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBFusion2Controller.h |
|
||||
| |
|
||||
| Definitions and types for Gigabyte Aorus |
|
||||
| RGB Fusion 2.0 lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 1/15/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include <string>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
class RGBFusion2Controller
|
||||
{
|
||||
public:
|
||||
RGBFusion2Controller(hid_device* dev_handle);
|
||||
~RGBFusion2Controller();
|
||||
|
||||
std::string GetDeviceName();
|
||||
std::string GetDeviceLocation();
|
||||
unsigned int GetLEDCount();
|
||||
unsigned char GetMode();
|
||||
void SetAllColors(unsigned char red, unsigned char green, unsigned char blue);
|
||||
void SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue);
|
||||
void SetMode(unsigned char mode);
|
||||
|
||||
private:
|
||||
void dump();
|
||||
|
||||
char device_name[32];
|
||||
unsigned int led_count;
|
||||
|
||||
void SendApply();
|
||||
|
||||
hid_device* dev;
|
||||
};
|
||||
@@ -1,36 +0,0 @@
|
||||
#include "RGBFusion2Controller.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_RGBFusion2.h"
|
||||
#include <vector>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#define RGB_FUSION_2_VID 0x048D
|
||||
#define RGB_FUSION_2_PID 0x8297
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectRGBFusion2Controllers *
|
||||
* *
|
||||
* Detect RGB Fusion 2.0 controllers on the USB interface. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectRGBFusion2Controllers(std::vector<RGBController*>& rgb_controllers)
|
||||
{
|
||||
hid_device* dev;
|
||||
|
||||
//Look for RGB Fusion 2.0 Controller
|
||||
hid_init();
|
||||
|
||||
dev = hid_open(RGB_FUSION_2_VID, RGB_FUSION_2_PID, 0);
|
||||
|
||||
if( dev )
|
||||
{
|
||||
RGBFusion2Controller* controller = new RGBFusion2Controller(dev);
|
||||
|
||||
RGBController_RGBFusion2* rgb_controller = new RGBController_RGBFusion2(controller);
|
||||
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
|
||||
} /* DetectRGBFusionControllers() */
|
||||
@@ -0,0 +1,290 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBFusion2USBController.cpp |
|
||||
| |
|
||||
| Driver for Gigabyte Aorus RGB Fusion 2.0 |
|
||||
| USB lighting controller |
|
||||
| |
|
||||
| jackun 1/8/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBFusion2USBController.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
static LEDCount LedCountToEnum(unsigned int c)
|
||||
{
|
||||
if (c <= 32)
|
||||
return(LEDS_32);
|
||||
if (c <= 64)
|
||||
return(LEDS_64);
|
||||
if (c <= 256)
|
||||
return(LEDS_256);
|
||||
if (c <= 512)
|
||||
return(LEDS_512);
|
||||
|
||||
return(LEDS_1024);
|
||||
}
|
||||
|
||||
RGBFusion2USBController::RGBFusion2USBController(hid_device* handle, const char *path) : dev(handle)
|
||||
{
|
||||
int res = 0;
|
||||
char text[64] {};
|
||||
unsigned char buffer[64] {};
|
||||
|
||||
if( dev ) {
|
||||
|
||||
SetCalibration();
|
||||
|
||||
// hid report read needs 0x60 packet or it gives IO error
|
||||
SendPacket(0x60, 0x00);
|
||||
|
||||
buffer[0] = report_id;
|
||||
res = hid_get_feature_report(dev, buffer, 64);
|
||||
if( res > 0 )
|
||||
{
|
||||
report = *reinterpret_cast<IT8297Report*>(buffer);
|
||||
|
||||
name = std::string(report.str_product, 32);
|
||||
name.erase(std::find(name.begin(), name.end(), '\0'), name.end());
|
||||
|
||||
snprintf(text, 11, "0x%08X", report.fw_ver);
|
||||
version = text;
|
||||
|
||||
snprintf(text, 11, "0x%08X", report.chip_id);
|
||||
chip_id = text;
|
||||
}
|
||||
|
||||
loc = path;
|
||||
|
||||
EnableBeat(false);
|
||||
}
|
||||
}
|
||||
|
||||
RGBFusion2USBController::~RGBFusion2USBController()
|
||||
{
|
||||
if( dev ) {
|
||||
hid_close(dev);
|
||||
}
|
||||
}
|
||||
|
||||
void RGBFusion2USBController::SetMode(int m)
|
||||
{
|
||||
mode = m;
|
||||
}
|
||||
|
||||
// Sets RGB color mapping to LED pins.
|
||||
// "Custom" RGB packets don't seem to get remapped so use report.byteorderN and do it manually.
|
||||
// Of course it all depends how we send data to the controller, but bios/rgb fusion 2 itself
|
||||
// set it up like this.
|
||||
void RGBFusion2USBController::SetCalibration()
|
||||
{
|
||||
uint8_t buffer[64] {};
|
||||
buffer[0] = report_id;
|
||||
buffer[1] = 0x33;
|
||||
|
||||
// D_LED1 WS2812 GRB, 0x00RRGGBB to 0x00GGRRBB
|
||||
buffer[2] = 0x02; // B
|
||||
buffer[3] = 0x00; // G
|
||||
buffer[4] = 0x01; // R
|
||||
buffer[5] = 0x00;
|
||||
|
||||
// D_LED2 WS2812 GRB
|
||||
buffer[6] = 0x02;
|
||||
buffer[7] = 0x00;
|
||||
buffer[8] = 0x01;
|
||||
buffer[9] = 0x00;
|
||||
|
||||
// LED C1/C2 12vGRB, seems pins already connect to LEDs correctly
|
||||
buffer[10] = 0x00;
|
||||
buffer[11] = 0x01;
|
||||
buffer[12] = 0x02;
|
||||
buffer[13] = 0x00;
|
||||
|
||||
SendPacket(buffer);
|
||||
}
|
||||
|
||||
void RGBFusion2USBController::SetLedCount(unsigned int count)
|
||||
{
|
||||
LEDCount s0 = LedCountToEnum(count);
|
||||
SendPacket(0x34, s0 | (s0 << 4)); // D_LED1 | D_LED2
|
||||
}
|
||||
|
||||
bool RGBFusion2USBController::DisableBuiltinEffect(int enable_bit, int mask)
|
||||
{
|
||||
if(effect_disabled & enable_bit)
|
||||
return(true);
|
||||
|
||||
effect_disabled &= ~mask;
|
||||
effect_disabled |= enable_bit;
|
||||
|
||||
int res = SendPacket(0x32, effect_disabled);
|
||||
// Sometimes effect doesn't apply at first, delay a little and let MCU to react, if this packet is the cause
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
return res;
|
||||
}
|
||||
|
||||
bool RGBFusion2USBController::EnableBeat(bool e)
|
||||
{
|
||||
return SendPacket(0x31, e ? 1 : 0);
|
||||
}
|
||||
|
||||
std::string RGBFusion2USBController::GetDeviceName()
|
||||
{
|
||||
return(name);
|
||||
}
|
||||
|
||||
std::string RGBFusion2USBController::GetFWVersion()
|
||||
{
|
||||
return(version);
|
||||
}
|
||||
|
||||
std::string RGBFusion2USBController::GetDeviceLocation()
|
||||
{
|
||||
return(loc);
|
||||
}
|
||||
|
||||
std::string RGBFusion2USBController::GetSerial()
|
||||
{
|
||||
return(chip_id);
|
||||
}
|
||||
|
||||
void RGBFusion2USBController::SetStripColors
|
||||
(
|
||||
unsigned int hdr,
|
||||
RGBColor * colors,
|
||||
unsigned int num_colors,
|
||||
int single_led
|
||||
)
|
||||
{
|
||||
PktRGB pkt;
|
||||
pkt.Init(hdr, report_id);
|
||||
|
||||
// FIXME assuming that LED strips ports are 0x58/0x59 for all boards
|
||||
uint32_t byteorder = hdr == HDR_D_LED1_RGB ? report.byteorder0 : report.byteorder1;
|
||||
|
||||
unsigned char bo_r = byteorder >> 16;
|
||||
unsigned char bo_g = byteorder >> 8;
|
||||
unsigned char bo_b = byteorder & 0xFF;
|
||||
|
||||
int res;
|
||||
int leds_left = num_colors;
|
||||
int sent_data = 0;
|
||||
int k = 0;
|
||||
int leds_in_pkt = sizeof(pkt.s.leds) / sizeof(*pkt.s.leds); /* 19 */
|
||||
|
||||
// other leds stay at whatever the builtin effect was doing at that moment
|
||||
// if breathing/pulse effect faded out then they stay dark
|
||||
if(single_led > -1)
|
||||
{
|
||||
leds_left = 1;
|
||||
k = single_led;
|
||||
sent_data = k * 3;
|
||||
leds_in_pkt = 1;
|
||||
}
|
||||
|
||||
while(leds_left > 0)
|
||||
{
|
||||
leds_in_pkt = (std::min)(leds_in_pkt, leds_left);
|
||||
leds_left -= leds_in_pkt;
|
||||
|
||||
pkt.s.bcount = leds_in_pkt * 3;
|
||||
pkt.s.boffset = sent_data;
|
||||
sent_data += pkt.s.bcount;
|
||||
|
||||
for(int i = 0; i < leds_in_pkt; i++)
|
||||
{
|
||||
RGBColor color = colors[k];
|
||||
unsigned char red = RGBGetRValue(color);
|
||||
unsigned char grn = RGBGetGValue(color);
|
||||
unsigned char blu = RGBGetBValue(color);
|
||||
|
||||
pkt.buffer[5 + i * 3 + bo_r] = red;
|
||||
pkt.buffer[5 + i * 3 + bo_g] = grn;
|
||||
pkt.buffer[5 + i * 3 + bo_b] = blu;
|
||||
k++;
|
||||
}
|
||||
|
||||
res = SendPacket(pkt.buffer);
|
||||
if(res < 0)
|
||||
return;
|
||||
}
|
||||
|
||||
if (hdr == HDR_D_LED1_RGB)
|
||||
DisableBuiltinEffect(0x01, 0x01);
|
||||
else
|
||||
DisableBuiltinEffect(0x02, 0x02);
|
||||
}
|
||||
|
||||
static const std::array< std::array<int, 3>, 5> speeds = {
|
||||
{
|
||||
{1600, 1600, 200},
|
||||
{1200, 1200, 200},
|
||||
{800, 800, 200},
|
||||
{400, 400, 200},
|
||||
{200, 200, 200},
|
||||
},
|
||||
};
|
||||
|
||||
void RGBFusion2USBController::SetLEDEffect(unsigned int led, int mode, unsigned int speed, bool random, unsigned char r, unsigned char g, unsigned char b)
|
||||
{
|
||||
PktEffect pkt;
|
||||
pkt.Init(led, report_id);
|
||||
pkt.e.effect_type = mode;
|
||||
pkt.e.color0 = r << 16 | g << 8 | b;
|
||||
|
||||
if (speed < speeds.size()) {
|
||||
const auto& s = speeds[speed];
|
||||
pkt.e.period0 = s[0];
|
||||
pkt.e.period1 = s[1];
|
||||
pkt.e.period2 = s[2];
|
||||
}
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
case 0: break;
|
||||
case 1: break; // static
|
||||
case 2: // breathing
|
||||
case 3: // blink
|
||||
if (random)
|
||||
pkt.e.effect_param0 = 7; // cycle through up to 7 (max?) colors
|
||||
break;
|
||||
case 4: // color cycle
|
||||
pkt.e.effect_param0 = 7; // cycle through up to 7 (max?) colors
|
||||
break;
|
||||
|
||||
// "fake" effects
|
||||
case 10: // flashing, flashing color cycle
|
||||
pkt.e.period0 = 200;
|
||||
pkt.e.period1 = 200;
|
||||
pkt.e.period2 = 5000 - 1000 * speed; // time between flashing, doesn't seem to be affected by period0/period1
|
||||
pkt.e.effect_type = 3;
|
||||
pkt.e.effect_param2 = 2; // flash twice
|
||||
if (random)
|
||||
pkt.e.effect_param0 = 7;
|
||||
break;
|
||||
}
|
||||
|
||||
SendPacket(pkt.buffer);
|
||||
}
|
||||
|
||||
bool RGBFusion2USBController::ApplyEffect()
|
||||
{
|
||||
return SendPacket(0x28, 0xFF);
|
||||
}
|
||||
|
||||
bool RGBFusion2USBController::SendPacket(uint8_t a, uint8_t b, uint8_t c)
|
||||
{
|
||||
unsigned char buffer[64] {};
|
||||
buffer[0] = report_id;
|
||||
buffer[1] = a;
|
||||
buffer[2] = b;
|
||||
buffer[3] = c;
|
||||
return (SendPacket(buffer) == 64);
|
||||
}
|
||||
|
||||
int RGBFusion2USBController::SendPacket(unsigned char* packet)
|
||||
{
|
||||
return hid_send_feature_report(dev, packet, 64);
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBFusion2USBController.h |
|
||||
| |
|
||||
| Definitions and types for Gigabyte Aorus |
|
||||
| RGB Fusion 2.0 USB lighting controller |
|
||||
| |
|
||||
| jackun 1/8/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
#include <cstring>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
// LED "headers" 0x20..0x27, As seen on Gigabyte X570 Elite board
|
||||
const uint8_t HDR_BACK_IO = 0x20;
|
||||
const uint8_t HDR_CPU = 0x21;
|
||||
const uint8_t HDR_LED_2 = 0x22;
|
||||
const uint8_t HDR_PCIE = 0x23;
|
||||
const uint8_t HDR_LED_C1C2 = 0x24;
|
||||
const uint8_t HDR_D_LED1 = 0x25;
|
||||
const uint8_t HDR_D_LED2 = 0x26;
|
||||
const uint8_t HDR_LED_7 = 0x27;
|
||||
|
||||
const uint8_t HDR_D_LED1_RGB = 0x58; // FIXME assuming that it is 0x58 for all boards
|
||||
const uint8_t HDR_D_LED2_RGB = 0x59;
|
||||
|
||||
enum EffectType
|
||||
{
|
||||
EFFECT_NONE = 0,
|
||||
EFFECT_STATIC = 1,
|
||||
EFFECT_PULSE = 2,
|
||||
EFFECT_BLINKING = 3,
|
||||
EFFECT_COLORCYCLE = 4,
|
||||
// to be continued...
|
||||
};
|
||||
|
||||
enum LEDCount
|
||||
{
|
||||
LEDS_32 = 0,
|
||||
LEDS_64,
|
||||
LEDS_256,
|
||||
LEDS_512,
|
||||
LEDS_1024,
|
||||
};
|
||||
|
||||
struct LEDs
|
||||
{
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
};
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
union PktRGB
|
||||
{
|
||||
unsigned char buffer[64];
|
||||
struct RGBData
|
||||
{
|
||||
uint8_t report_id;
|
||||
uint8_t header;
|
||||
uint16_t boffset; // in bytes, absolute
|
||||
uint8_t bcount;
|
||||
LEDs leds[19];
|
||||
uint16_t padding0;
|
||||
} s;
|
||||
|
||||
PktRGB() : s {}
|
||||
{
|
||||
}
|
||||
|
||||
void Init(uint8_t header, uint8_t report_id)
|
||||
{
|
||||
s.report_id = report_id;
|
||||
s.header = header;
|
||||
s.boffset = 0;
|
||||
s.bcount = 0;
|
||||
memset(s.leds, 0, sizeof(s.leds));
|
||||
}
|
||||
};
|
||||
|
||||
union PktEffect
|
||||
{
|
||||
unsigned char buffer[64];
|
||||
struct Effect
|
||||
{
|
||||
uint8_t report_id;
|
||||
uint8_t header;
|
||||
uint32_t zone0; // rgb fusion seems to set it to pow(2, header - 0x20)
|
||||
uint32_t zone1;
|
||||
uint8_t reserved0;
|
||||
uint8_t effect_type;
|
||||
uint8_t max_brightness;
|
||||
uint8_t min_brightness;
|
||||
uint32_t color0;
|
||||
uint32_t color1;
|
||||
uint16_t period0; // fade in
|
||||
uint16_t period1; // fade out
|
||||
uint16_t period2; // hold
|
||||
uint16_t period3;
|
||||
uint8_t effect_param0;
|
||||
uint8_t effect_param1;
|
||||
uint8_t effect_param2;
|
||||
uint8_t effect_param3;
|
||||
uint8_t padding0[30];
|
||||
} e;
|
||||
|
||||
PktEffect() : e {}
|
||||
{
|
||||
}
|
||||
|
||||
void Init(int header, uint8_t report_id)
|
||||
{
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
e.report_id = report_id;
|
||||
if (header < 8)
|
||||
e.header = 32 + header; // set as default
|
||||
else
|
||||
e.header = header;
|
||||
e.zone0 = (uint32_t)(1 << (e.header - 32));
|
||||
e.effect_type = EFFECT_STATIC;
|
||||
e.max_brightness = 100;
|
||||
e.min_brightness = 0;
|
||||
e.color0 = 0x00FF2100; //orange
|
||||
e.period0 = 1200;
|
||||
e.period1 = 1200;
|
||||
e.period2 = 200;
|
||||
e.period3 = 200;
|
||||
e.effect_param0 = 0; // ex color count to cycle through (max seems to be 7)
|
||||
e.effect_param1 = 0;
|
||||
e.effect_param2 = 1; // ex flash repeat count
|
||||
e.effect_param3 = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct IT8297Report
|
||||
{
|
||||
uint8_t report_id;
|
||||
uint8_t product;
|
||||
uint8_t device_num;
|
||||
uint8_t total_leds;
|
||||
uint32_t fw_ver;
|
||||
uint16_t curr_led_count;
|
||||
uint16_t reserved0;
|
||||
char str_product[32]; // might be 28 and an extra byteorder3
|
||||
uint32_t byteorder0; // is little-endian 0x00RRGGBB ?
|
||||
uint32_t byteorder1;
|
||||
uint32_t byteorder2;
|
||||
uint32_t chip_id;
|
||||
uint32_t reserved1;
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
class RGBFusion2USBController
|
||||
{
|
||||
public:
|
||||
RGBFusion2USBController(hid_device* handle, const char *path);
|
||||
~RGBFusion2USBController();
|
||||
|
||||
void SetStripColors
|
||||
(
|
||||
unsigned int hdr,
|
||||
RGBColor * colors,
|
||||
unsigned int num_colors,
|
||||
int single_led = -1
|
||||
);
|
||||
|
||||
void SetLEDEffect(unsigned int led, int mode, unsigned int speed, bool random, unsigned char red, unsigned char green, unsigned char blue);
|
||||
void SetLedCount(unsigned int count);
|
||||
void SetMode(int mode);
|
||||
bool ApplyEffect();
|
||||
bool DisableBuiltinEffect(int enable_bit, int mask);
|
||||
void SetCalibration();
|
||||
std::string GetDeviceName();
|
||||
std::string GetDeviceLocation();
|
||||
std::string GetFWVersion();
|
||||
std::string GetSerial();
|
||||
|
||||
private:
|
||||
bool EnableBeat(bool enable);
|
||||
bool SendPacket(uint8_t a, uint8_t b, uint8_t c = 0);
|
||||
int SendPacket(unsigned char* packet);
|
||||
|
||||
hid_device* dev;
|
||||
int mode;
|
||||
IT8297Report report;
|
||||
std::string name;
|
||||
std::string loc;
|
||||
std::string version;
|
||||
std::string chip_id;
|
||||
int effect_disabled = 0;
|
||||
int report_id = 0xCC;
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "RGBFusion2USBController.h"
|
||||
#include "RGBController_RGBFusion2USB.h"
|
||||
|
||||
#define IT8297_VID 0x048D
|
||||
#define IT8297_PID 0x8297
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectRGBFusion2USBControllers *
|
||||
* *
|
||||
* Detect RGB Fusion 2 devices that use IT8297 RGB controller *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectRGBFusion2USBControllers(std::vector<RGBController*> &rgb_controllers)
|
||||
{
|
||||
if (hid_init() < 0)
|
||||
return;
|
||||
|
||||
hid_device_info * device_list = hid_enumerate(IT8297_VID, IT8297_PID);
|
||||
if (!device_list)
|
||||
return;
|
||||
|
||||
hid_device_info * device = device_list;
|
||||
while (device)
|
||||
{
|
||||
hid_device * dev = hid_open_path(device->path);
|
||||
if (dev) {
|
||||
RGBFusion2USBController * controller = new RGBFusion2USBController(dev, device_list->path);
|
||||
RGBController_RGBFusion2USB * rgb_controller = new RGBController_RGBFusion2USB(controller);
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
device = device->next;
|
||||
}
|
||||
|
||||
hid_free_enumeration(device_list);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBFusionGPUController.cpp |
|
||||
| |
|
||||
| Driver for Gigabyte Aorus RGB Fusion GPU |
|
||||
| lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 2/20/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBFusionGPUController.h"
|
||||
|
||||
RGBFusionGPUController::RGBFusionGPUController(i2c_smbus_interface* bus, rgb_fusion_dev_id dev)
|
||||
{
|
||||
this->bus = bus;
|
||||
this->dev = dev;
|
||||
}
|
||||
|
||||
RGBFusionGPUController::~RGBFusionGPUController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string RGBFusionGPUController::GetDeviceLocation()
|
||||
{
|
||||
std::string return_string(bus->device_name);
|
||||
char addr[5];
|
||||
snprintf(addr, 5, "0x%02X", dev);
|
||||
return_string.append(", address ");
|
||||
return_string.append(addr);
|
||||
return(return_string);
|
||||
}
|
||||
|
||||
void RGBFusionGPUController::SetColor(unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
bus->i2c_smbus_write_byte(dev, RGB_FUSION_GPU_REG_COLOR);
|
||||
bus->i2c_smbus_write_byte(dev, red);
|
||||
bus->i2c_smbus_write_byte(dev, green);
|
||||
bus->i2c_smbus_write_byte(dev, blue);
|
||||
}
|
||||
|
||||
void RGBFusionGPUController::SetMode(unsigned char mode, unsigned char speed)
|
||||
{
|
||||
bus->i2c_smbus_write_byte(dev, RGB_FUSION_GPU_REG_MODE);
|
||||
bus->i2c_smbus_write_byte(dev, mode);
|
||||
bus->i2c_smbus_write_byte(dev, speed);
|
||||
bus->i2c_smbus_write_byte(dev, 0x63);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBFusionGPUController.h |
|
||||
| |
|
||||
| Definitions and types for Gigabyte Aorus |
|
||||
| RGB Fusion GPU lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 2/20/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include <string>
|
||||
#include "i2c_smbus.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef unsigned char rgb_fusion_dev_id;
|
||||
|
||||
enum
|
||||
{
|
||||
RGB_FUSION_GPU_REG_COLOR = 0x40,
|
||||
RGB_FUSION_GPU_REG_MODE = 0x88
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
RGB_FUSION_GPU_MODE_STATIC = 0x01,
|
||||
RGB_FUSION_GPU_MODE_BREATHING = 0x02,
|
||||
RGB_FUSION_GPU_MODE_FLASHING = 0x04,
|
||||
RGB_FUSION_GPU_MODE_DUAL_FLASHING = 0x08,
|
||||
RGB_FUSION_GPU_MODE_SPECTRUM_CYCLE = 0x11
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
RGB_FUSION_GPU_SPEED_SLOWEST = 0x00,
|
||||
RGB_FUSION_GPU_SPEED_NORMAL = 0x05,
|
||||
RGB_FUSION_GPU_SPEED_FASTEST = 0x09
|
||||
};
|
||||
|
||||
class RGBFusionGPUController
|
||||
{
|
||||
public:
|
||||
RGBFusionGPUController(i2c_smbus_interface* bus, rgb_fusion_dev_id dev);
|
||||
~RGBFusionGPUController();
|
||||
|
||||
std::string GetDeviceLocation();
|
||||
|
||||
void SetColor(unsigned char red, unsigned char green, unsigned char blue);
|
||||
void SetMode(unsigned char mode, unsigned char speed);
|
||||
|
||||
private:
|
||||
i2c_smbus_interface* bus;
|
||||
rgb_fusion_dev_id dev;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,83 @@
|
||||
#include "RGBFusionGPUController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_RGBFusionGPU.h"
|
||||
#include "i2c_smbus.h"
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* TestForRGBFusionGPUController *
|
||||
* *
|
||||
* Tests the given address to see if an RGB Fusion controller exists there. First *
|
||||
* does a quick write to test for a response *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
bool TestForRGBFusionGPUController(i2c_smbus_interface* bus, unsigned char address)
|
||||
{
|
||||
bool pass = false;
|
||||
int res;
|
||||
|
||||
//Write out 0xAB 0x00 0x00 0x00 sequence
|
||||
res = bus->i2c_smbus_write_byte(address, 0xAB);
|
||||
|
||||
if (res >= 0)
|
||||
{
|
||||
bus->i2c_smbus_write_byte(address, 0x00);
|
||||
bus->i2c_smbus_write_byte(address, 0x00);
|
||||
bus->i2c_smbus_write_byte(address, 0x00);
|
||||
|
||||
pass = true;
|
||||
|
||||
res = bus->i2c_smbus_read_byte(address);
|
||||
|
||||
if (res != 0xAB)
|
||||
{
|
||||
pass = false;
|
||||
}
|
||||
|
||||
res = bus->i2c_smbus_read_byte(address);
|
||||
|
||||
if(res != 0x14)
|
||||
{
|
||||
pass = false;
|
||||
}
|
||||
|
||||
bus->i2c_smbus_read_byte(address);
|
||||
bus->i2c_smbus_read_byte(address);
|
||||
}
|
||||
|
||||
return(pass);
|
||||
|
||||
} /* TestForRGBFusionGPUController() */
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectRGBFusionGPUControllers *
|
||||
* *
|
||||
* Detect RGB Fusion controllers on the enumerated I2C busses at address 0x47. *
|
||||
* *
|
||||
* bus - pointer to i2c_smbus_interface where RGB Fusion device is connected *
|
||||
* dev - I2C address of RGB Fusion device *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectRGBFusionGPUControllers(std::vector<i2c_smbus_interface*>& busses, std::vector<RGBController*>& rgb_controllers)
|
||||
{
|
||||
RGBFusionGPUController* new_rgb_fusion;
|
||||
RGBController_RGBFusionGPU* new_controller;
|
||||
|
||||
for (unsigned int bus = 0; bus < busses.size(); bus++)
|
||||
{
|
||||
// Check for RGB Fusion controller at 0x47
|
||||
if (TestForRGBFusionGPUController(busses[bus], 0x47))
|
||||
{
|
||||
new_rgb_fusion = new RGBFusionGPUController(busses[bus], 0x47);
|
||||
new_controller = new RGBController_RGBFusionGPU(new_rgb_fusion);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
}
|
||||
|
||||
} /* DetectRGBFusionGPUControllers() */
|
||||
@@ -0,0 +1,117 @@
|
||||
#include "RedragonK556Controller.h"
|
||||
#include "RedragonM711Controller.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_RedragonK556.h"
|
||||
#include "RGBController_RedragonM711.h"
|
||||
#include <vector>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Keyboard product IDs |
|
||||
\*-----------------------------------------------------*/
|
||||
#define REDRAGON_KEYBOARD_VID 0x0C45
|
||||
#define REDRAGON_K550_PID 0x5204
|
||||
#define REDRAGON_K556_PID 0x5004
|
||||
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Mouse product IDs |
|
||||
\*-----------------------------------------------------*/
|
||||
#define REDRAGON_MOUSE_VID 0x04D9
|
||||
#define REDRAGON_M711_PID 0xFC30
|
||||
#define REDRAGON_M715_PID 0xFC39
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned short usb_vid;
|
||||
unsigned short usb_pid;
|
||||
unsigned char usb_interface;
|
||||
device_type type;
|
||||
const char * name;
|
||||
} redragon_device;
|
||||
|
||||
#define REDRAGON_NUM_DEVICES (sizeof(device_list) / sizeof(device_list[ 0 ]))
|
||||
|
||||
static const redragon_device device_list[] =
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------------------------*\
|
||||
| Keyboards |
|
||||
\*-----------------------------------------------------------------------------------------------------*/
|
||||
{ REDRAGON_KEYBOARD_VID, REDRAGON_K550_PID, 1, DEVICE_TYPE_KEYBOARD, "Redragon K550 Yama" },
|
||||
{ REDRAGON_KEYBOARD_VID, REDRAGON_K556_PID, 1, DEVICE_TYPE_KEYBOARD, "Redragon K556 Devarajas" },
|
||||
/*-----------------------------------------------------------------------------------------------------*\
|
||||
| Mice |
|
||||
\*-----------------------------------------------------------------------------------------------------*/
|
||||
{ REDRAGON_MOUSE_VID, REDRAGON_M711_PID, 2, DEVICE_TYPE_MOUSE, "Redragon M711 Cobra" },
|
||||
{ REDRAGON_MOUSE_VID, REDRAGON_M715_PID, 2, DEVICE_TYPE_MOUSE, "Redragon M715 Dagger" },
|
||||
/*-----------------------------------------------------------------------------------------------------*\
|
||||
| Mousemats |
|
||||
\*-----------------------------------------------------------------------------------------------------*/
|
||||
};
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectRedragonControllers *
|
||||
* *
|
||||
* Tests the USB address to see if a Redragon RGB Keyboard controller exists there. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectRedragonControllers(std::vector<RGBController*>& rgb_controllers)
|
||||
{
|
||||
hid_device_info* info;
|
||||
hid_device* dev;
|
||||
|
||||
hid_init();
|
||||
|
||||
for(int device_idx = 0; device_idx < REDRAGON_NUM_DEVICES; device_idx++)
|
||||
{
|
||||
dev = NULL;
|
||||
|
||||
info = hid_enumerate(device_list[device_idx].usb_vid, device_list[device_idx].usb_pid);
|
||||
|
||||
//Look for Redragon RGB Peripheral
|
||||
while(info)
|
||||
{
|
||||
if((info->vendor_id == device_list[device_idx].usb_vid)
|
||||
&&(info->product_id == device_list[device_idx].usb_pid)
|
||||
&&(info->interface_number == device_list[device_idx].usb_interface))
|
||||
{
|
||||
dev = hid_open_path(info->path);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
info = info->next;
|
||||
}
|
||||
}
|
||||
|
||||
if( dev )
|
||||
{
|
||||
switch(device_list[device_idx].type)
|
||||
{
|
||||
case DEVICE_TYPE_KEYBOARD:
|
||||
{
|
||||
RedragonK556Controller* controller = new RedragonK556Controller(dev);
|
||||
|
||||
RGBController_RedragonK556* rgb_controller = new RGBController_RedragonK556(controller);
|
||||
|
||||
rgb_controller->name = device_list[device_idx].name;
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
break;
|
||||
|
||||
case DEVICE_TYPE_MOUSE:
|
||||
{
|
||||
RedragonM711Controller* controller = new RedragonM711Controller(dev);
|
||||
|
||||
RGBController_RedragonM711* rgb_controller = new RGBController_RedragonM711(controller);
|
||||
|
||||
rgb_controller->name = device_list[device_idx].name;
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
#include "RedragonK556Controller.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
RedragonK556Controller::RedragonK556Controller(hid_device* dev_handle)
|
||||
{
|
||||
dev = dev_handle;
|
||||
}
|
||||
|
||||
void RedragonK556Controller::SetKeyboardColors
|
||||
(
|
||||
unsigned char * color_data,
|
||||
unsigned int size
|
||||
)
|
||||
{
|
||||
unsigned int packet_size = 0;
|
||||
unsigned int packet_offset = 0;
|
||||
|
||||
while(size > 0)
|
||||
{
|
||||
if(size >= REDRAGON_K556_MAX_PACKET_SIZE)
|
||||
{
|
||||
packet_size = REDRAGON_K556_MAX_PACKET_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
packet_size = size;
|
||||
}
|
||||
|
||||
SendKeyboardData
|
||||
(
|
||||
&color_data[packet_offset],
|
||||
packet_size,
|
||||
packet_offset
|
||||
);
|
||||
|
||||
size -= packet_size;
|
||||
packet_offset += packet_size;
|
||||
}
|
||||
}
|
||||
|
||||
void RedragonK556Controller::SendKeyboardMode
|
||||
(
|
||||
unsigned char mode
|
||||
)
|
||||
{
|
||||
SendKeyboardParameter(REDRAGON_K556_PARAMETER_MODE, 1, &mode);
|
||||
}
|
||||
|
||||
void RedragonK556Controller::SendKeyboardModeEx
|
||||
(
|
||||
unsigned char mode,
|
||||
unsigned char brightness,
|
||||
unsigned char speed,
|
||||
unsigned char direction,
|
||||
unsigned char random_flag,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
)
|
||||
{
|
||||
unsigned char parameter_data[8];
|
||||
|
||||
parameter_data[0] = mode;
|
||||
parameter_data[1] = brightness;
|
||||
parameter_data[2] = speed;
|
||||
parameter_data[3] = direction;
|
||||
parameter_data[4] = random_flag;
|
||||
parameter_data[5] = red;
|
||||
parameter_data[6] = green;
|
||||
parameter_data[7] = blue;
|
||||
|
||||
SendKeyboardParameter(0, 8, parameter_data);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------------------------------*\
|
||||
| Private packet sending functions. |
|
||||
\*-------------------------------------------------------------------------------------------------*/
|
||||
|
||||
void RedragonK556Controller::ComputeChecksum
|
||||
(
|
||||
char usb_buf[64]
|
||||
)
|
||||
{
|
||||
unsigned short checksum = 0;
|
||||
|
||||
for(unsigned int byte_idx = 0x03; byte_idx < 64; byte_idx++)
|
||||
{
|
||||
checksum += usb_buf[byte_idx];
|
||||
}
|
||||
|
||||
usb_buf[0x01] = checksum & 0xFF;
|
||||
usb_buf[0x02] = checksum >> 8;
|
||||
}
|
||||
|
||||
void RedragonK556Controller::SendKeyboardBegin()
|
||||
{
|
||||
char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Keyboard Begin (0x01) packet |
|
||||
| Note: Not computing checksum as packet contents are |
|
||||
| fixed |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x04;
|
||||
usb_buf[0x01] = REDRAGON_K556_COMMAND_BEGIN;
|
||||
usb_buf[0x02] = 0x00;
|
||||
usb_buf[0x03] = REDRAGON_K556_COMMAND_BEGIN;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, (unsigned char *)usb_buf, 64);
|
||||
hid_read(dev, (unsigned char *)usb_buf, 64);
|
||||
}
|
||||
|
||||
void RedragonK556Controller::SendKeyboardEnd()
|
||||
{
|
||||
char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Keyboard End (0x02) packet |
|
||||
| Note: Not computing checksum as packet contents are |
|
||||
| fixed |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x04;
|
||||
usb_buf[0x01] = REDRAGON_K556_COMMAND_END;
|
||||
usb_buf[0x02] = 0x00;
|
||||
usb_buf[0x03] = REDRAGON_K556_COMMAND_END;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, (unsigned char *)usb_buf, 64);
|
||||
hid_read(dev, (unsigned char *)usb_buf, 64);
|
||||
}
|
||||
|
||||
void RedragonK556Controller::SendKeyboardData
|
||||
(
|
||||
unsigned char * data,
|
||||
unsigned char data_size,
|
||||
unsigned short data_offset
|
||||
)
|
||||
{
|
||||
char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Keyboard Color Data (0x11) packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x04;
|
||||
usb_buf[0x03] = 0x11;
|
||||
|
||||
usb_buf[0x04] = data_size;
|
||||
usb_buf[0x05] = data_offset & 0x00FF;
|
||||
usb_buf[0x06] = data_offset >> 8;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in data bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(&usb_buf[0x08], data, data_size);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Compute Checksum |
|
||||
\*-----------------------------------------------------*/
|
||||
ComputeChecksum(usb_buf);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, (unsigned char *)usb_buf, 64);
|
||||
hid_read(dev, (unsigned char *)usb_buf, 64);
|
||||
}
|
||||
|
||||
void RedragonK556Controller::SendKeyboardParameter
|
||||
(
|
||||
unsigned char parameter,
|
||||
unsigned char parameter_size,
|
||||
unsigned char* parameter_data
|
||||
)
|
||||
{
|
||||
char usb_buf[64];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Keyboard Parameter (0x06) packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x04;
|
||||
usb_buf[0x03] = REDRAGON_K556_COMMAND_SET_PARAMETER;
|
||||
usb_buf[0x04] = parameter_size;
|
||||
usb_buf[0x05] = parameter;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in data bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(&usb_buf[0x08], parameter_data, parameter_size);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Compute Checksum |
|
||||
\*-----------------------------------------------------*/
|
||||
ComputeChecksum(usb_buf);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, (unsigned char *)usb_buf, 64);
|
||||
hid_read(dev, (unsigned char *)usb_buf, 64);
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
/*-----------------------------------------*\
|
||||
| RedragonK556Controller.h |
|
||||
| |
|
||||
| Definitions and types for Redragon K556 |
|
||||
| Devarajas keyboard lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 3/15/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
|
||||
#include <string>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
#define REDRAGON_K556_MAX_PACKET_SIZE ( 0x36 ) /* max packet size for color*/
|
||||
/* update packets */
|
||||
enum
|
||||
{
|
||||
REDRAGON_K556_COMMAND_BEGIN = 0x01, /* Begin packet command */
|
||||
REDRAGON_K556_COMMAND_END = 0x02, /* End packet command */
|
||||
REDRAGON_K556_COMMAND_SET_PARAMETER = 0x06, /* Set parameter command */
|
||||
REDRAGON_K556_COMMAND_READ_CUSTOM_COLOR_DATA = 0x10, /* Read custom color data */
|
||||
REDRAGON_K556_COMMAND_WRITE_CUSTOM_COLOR_DATA = 0x11, /* Write custom color data */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
REDRAGON_K556_PARAMETER_MODE = 0x00, /* Mode parameter */
|
||||
REDRAGON_K556_PARAMETER_BRIGHTNESS = 0x01, /* Brightness parameter */
|
||||
REDRAGON_K556_PARAMETER_SPEED = 0x02, /* Speed parameter */
|
||||
REDRAGON_K556_PARAMETER_DIRECTION = 0x03, /* Direction parameter */
|
||||
REDRAGON_K556_PARAMETER_RANDOM_COLOR_FLAG = 0x04, /* Random color parameter */
|
||||
REDRAGON_K556_PARAMETER_MODE_COLOR = 0x05, /* Mode color (RGB) */
|
||||
REDRAGON_K556_PARAMETER_POLLING_RATE = 0x0F, /* Polling rate */
|
||||
REDRAGON_K556_PARAMETER_SURMOUNT_MODE_COLOR = 0x11, /* Surmount mode color */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
REDRAGON_K556_MODE_COLOR_WAVE_SHORT = 0x01, /* "Go with the stream" */
|
||||
REDRAGON_K556_MODE_COLOR_WAVE_LONG = 0x02, /* "Clouds fly" */
|
||||
REDRAGON_K556_MODE_COLOR_WHEEL = 0x03, /* "Winding paths" */
|
||||
REDRAGON_K556_MODE_SPECTRUM_CYCLE = 0x04, /* "The trial of light" */
|
||||
REDRAGON_K556_MODE_BREATHING = 0x05, /* "Breathing" */
|
||||
REDRAGON_K556_MODE_STATIC = 0x06, /* "Normally on" */
|
||||
REDRAGON_K556_MODE_REACTIVE = 0x07, /* "Pass without trace" */
|
||||
REDRAGON_K556_MODE_REACTIVE_RIPPLE = 0x08, /* "Ripple graff" */
|
||||
REDRAGON_K556_MODE_REACTIVE_LINE = 0x09, /* "Fast run without trace" */
|
||||
REDRAGON_K556_MODE_STARLIGHT_FAST = 0x0A, /* "Swift action" */
|
||||
REDRAGON_K556_MODE_BLOOMING = 0x0B, /* "Flowers blooming" */
|
||||
REDRAGON_K556_MODE_RAINBOW_WAVE_VERTICAL = 0x0C, /* "Snow winter jasmine" */
|
||||
REDRAGON_K556_MODE_HURRICANE = 0x0D, /* "Hurricane" */
|
||||
REDRAGON_K556_MODE_ACCUMULATE = 0x0E, /* "Accumulate" */
|
||||
REDRAGON_K556_MODE_STARLIGHT_SLOW = 0x0F, /* "Digital times" */
|
||||
REDRAGON_K556_MODE_VISOR = 0x10, /* "Both ways" */
|
||||
REDRAGON_K556_MODE_SURMOUNT = 0x11, /* "Surmount" */
|
||||
REDRAGON_K556_MODE_RAINBOW_WAVE_CIRCLE = 0x12, /* "Fast and the Furious" */
|
||||
REDRAGON_K556_MODE_CUSTOM = 0x14, /* "Coastal" */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
REDRAGON_K556_BRIGHTNESS_LOWEST = 0x00, /* Lowest brightness (off) */
|
||||
REDRAGON_K556_BRIGHTNESS_HIGHEST = 0x05, /* Highest brightness */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
REDRAGON_K556_SPEED_SLOWEST = 0x05, /* Slowest speed setting */
|
||||
REDRAGON_K556_SPEED_NORMAL = 0x03, /* Normal speed setting */
|
||||
REDRAGON_K556_SPEED_FASTEST = 0x00, /* Fastest speed setting */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
REDRAGON_K556_SURMOUNT_MODE_COLOR_RED = 0x01, /* Red surmount color */
|
||||
REDRAGON_K556_SURMOUNT_MODE_COLOR_YELLOW = 0x02, /* Yellow surmount color */
|
||||
REDRAGON_K556_SURMOUNT_MODE_COLOR_GREEN = 0x03, /* Green surmount color */
|
||||
REDRAGON_K556_SURMOUNT_MODE_COLOR_BLUE = 0x04, /* Blue surmount color */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
REDRAGON_K556_POLLING_RATE_125HZ = 0x00, /* 125Hz polling rate */
|
||||
REDRAGON_K556_POLLING_RATE_250HZ = 0x01, /* 250Hz polling rate */
|
||||
REDRAGON_K556_POLLING_RATE_500HZ = 0x02, /* 500Hz polling rate */
|
||||
REDRAGON_K556_POLLING_RATE_1000HZ = 0x03, /* 1000Hz polling rate */
|
||||
};
|
||||
|
||||
class RedragonK556Controller
|
||||
{
|
||||
public:
|
||||
RedragonK556Controller(hid_device* dev_handle);
|
||||
~RedragonK556Controller();
|
||||
|
||||
void SetKeyboardColors
|
||||
(
|
||||
unsigned char * color_data,
|
||||
unsigned int size
|
||||
);
|
||||
|
||||
void SendKeyboardBegin();
|
||||
|
||||
void SendKeyboardMode
|
||||
(
|
||||
unsigned char mode
|
||||
);
|
||||
|
||||
void SendKeyboardModeEx
|
||||
(
|
||||
unsigned char mode,
|
||||
unsigned char brightness,
|
||||
unsigned char speed,
|
||||
unsigned char direction,
|
||||
unsigned char random_flag,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
);
|
||||
|
||||
void SendKeyboardData
|
||||
(
|
||||
unsigned char * data,
|
||||
unsigned char data_size,
|
||||
unsigned short data_offset
|
||||
);
|
||||
|
||||
void SendKeyboardEnd();
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
|
||||
void ComputeChecksum
|
||||
(
|
||||
char usb_buf[64]
|
||||
);
|
||||
|
||||
void SendKeyboardParameter
|
||||
(
|
||||
unsigned char parameter,
|
||||
unsigned char parameter_size,
|
||||
unsigned char* parameter_data
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,90 @@
|
||||
#include "RedragonM711Controller.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
static void send_usb_msg(hid_device* dev, char * data_pkt, unsigned int size)
|
||||
{
|
||||
char* usb_pkt = new char[size + 1];
|
||||
|
||||
usb_pkt[0] = 0x00;
|
||||
for(int i = 1; i < size + 1; i++)
|
||||
{
|
||||
usb_pkt[i] = data_pkt[i-1];
|
||||
}
|
||||
|
||||
hid_send_feature_report(dev, (unsigned char *)usb_pkt, size + 1);
|
||||
|
||||
delete usb_pkt;
|
||||
}
|
||||
|
||||
RedragonM711Controller::RedragonM711Controller(hid_device* dev_handle)
|
||||
{
|
||||
dev = dev_handle;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------------------------------*\
|
||||
| Private packet sending functions. |
|
||||
\*-------------------------------------------------------------------------------------------------*/
|
||||
|
||||
void RedragonM711Controller::SendMouseApply()
|
||||
{
|
||||
char usb_buf[16];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Apply packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x02;
|
||||
usb_buf[0x01] = 0xF1;
|
||||
usb_buf[0x02] = 0x02;
|
||||
usb_buf[0x03] = 0x04;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
send_usb_msg(dev, usb_buf, 16);
|
||||
}
|
||||
|
||||
void RedragonM711Controller::SendMouseMode
|
||||
(
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
)
|
||||
{
|
||||
char usb_buf[16];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Lighting Control packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x02;
|
||||
usb_buf[0x01] = 0xF3;
|
||||
usb_buf[0x02] = 0x49;
|
||||
usb_buf[0x03] = 0x04;
|
||||
usb_buf[0x04] = 0x06;
|
||||
|
||||
usb_buf[0x08] = red;
|
||||
usb_buf[0x09] = green;
|
||||
usb_buf[0x0A] = blue;
|
||||
|
||||
usb_buf[0x0B] = 0x01; //on
|
||||
|
||||
usb_buf[0x0C] = speed;
|
||||
usb_buf[0x0D] = mode;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
send_usb_msg(dev, usb_buf, 16);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*-----------------------------------------*\
|
||||
| RedragonM711Controller.h |
|
||||
| |
|
||||
| Definitions and types for Redragon M711 |
|
||||
| Cobra mouse lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 3/15/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
|
||||
#include <string>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
enum
|
||||
{
|
||||
REDRAGON_M711_MODE_WAVE = 0x00,
|
||||
REDRAGON_M711_MODE_RANDOM_BREATHING = 0x01,
|
||||
REDRAGON_M711_MODE_STATIC = 0x02,
|
||||
REDRAGON_M711_MODE_BREATHING = 0x04,
|
||||
REDRAGON_M711_MODE_RAINBOW = 0x08,
|
||||
REDRAGON_M711_MODE_FLASHING = 0x10,
|
||||
};
|
||||
|
||||
class RedragonM711Controller
|
||||
{
|
||||
public:
|
||||
RedragonM711Controller(hid_device* dev_handle);
|
||||
~RedragonM711Controller();
|
||||
|
||||
void SendMouseApply();
|
||||
|
||||
void SendMouseMode
|
||||
(
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
);
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
};
|
||||
@@ -16,12 +16,6 @@ ThermaltakeRiingController::ThermaltakeRiingController(libusb_device_handle* dev
|
||||
dev = dev_handle;
|
||||
|
||||
SendInit();
|
||||
|
||||
channel_leds[0] = 9;
|
||||
channel_leds[1] = 9;
|
||||
channel_leds[2] = 9;
|
||||
channel_leds[3] = 0;
|
||||
channel_leds[4] = 0;
|
||||
}
|
||||
|
||||
ThermaltakeRiingController::~ThermaltakeRiingController()
|
||||
@@ -29,11 +23,11 @@ ThermaltakeRiingController::~ThermaltakeRiingController()
|
||||
|
||||
}
|
||||
|
||||
void ThermaltakeRiingController::SetChannelLEDs(unsigned char channel, std::vector<RGBColor> colors)
|
||||
void ThermaltakeRiingController::SetChannelLEDs(unsigned char channel, RGBColor * colors, unsigned int num_colors)
|
||||
{
|
||||
unsigned char* color_data = new unsigned char[3 * colors.size()];
|
||||
unsigned char* color_data = new unsigned char[3 * num_colors];
|
||||
|
||||
for(int color = 0; color < colors.size(); color++)
|
||||
for(std::size_t color = 0; color < num_colors; color++)
|
||||
{
|
||||
int color_idx = color * 3;
|
||||
color_data[color_idx + 0] = RGBGetGValue(colors[color]);
|
||||
@@ -41,7 +35,7 @@ void ThermaltakeRiingController::SetChannelLEDs(unsigned char channel, std::vect
|
||||
color_data[color_idx + 2] = RGBGetBValue(colors[color]);
|
||||
}
|
||||
|
||||
SendRGB(channel, current_mode, current_speed, colors.size(), color_data);
|
||||
SendRGB(channel + 1, current_mode, current_speed, num_colors, color_data);
|
||||
|
||||
delete[] color_data;
|
||||
}
|
||||
|
||||
@@ -42,16 +42,16 @@ enum
|
||||
THERMALTAKE_SPEED_EXTREME = 0x00
|
||||
};
|
||||
|
||||
#define THERMALTAKE_NUM_CHANNELS 5
|
||||
|
||||
class ThermaltakeRiingController
|
||||
{
|
||||
public:
|
||||
ThermaltakeRiingController(libusb_device_handle* dev_handle);
|
||||
~ThermaltakeRiingController();
|
||||
|
||||
void SetChannelLEDs(unsigned char channel, std::vector<RGBColor> colors);
|
||||
void SetChannelLEDs(unsigned char channel, RGBColor * colors, unsigned int num_colors);
|
||||
void SetMode(unsigned char mode, unsigned char speed);
|
||||
|
||||
unsigned int channel_leds[5];
|
||||
|
||||
private:
|
||||
libusb_device_handle* dev;
|
||||
|
||||
@@ -0,0 +1,429 @@
|
||||
/*-----------------------------------------*\
|
||||
| NetworkClient.cpp |
|
||||
| |
|
||||
| Client code for OpenRGB SDK |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 5/9/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "NetworkClient.h"
|
||||
#include "RGBController_Network.h"
|
||||
#include <cstring>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
|
||||
static void Sleep(unsigned int milliseconds)
|
||||
{
|
||||
usleep(1000 * milliseconds);
|
||||
}
|
||||
#endif
|
||||
|
||||
NetworkClient::NetworkClient(std::vector<RGBController *>& control) : controllers(control)
|
||||
{
|
||||
strcpy(port_ip, "127.0.0.1");
|
||||
port_num = 1337;
|
||||
server_connected = false;
|
||||
server_controller_count = 0;
|
||||
}
|
||||
|
||||
unsigned short NetworkClient::GetPort()
|
||||
{
|
||||
return port_num;
|
||||
}
|
||||
|
||||
bool NetworkClient::GetOnline()
|
||||
{
|
||||
return server_connected;
|
||||
}
|
||||
|
||||
void NetworkClient::SetIP(const char *new_ip)
|
||||
{
|
||||
if(server_connected == false)
|
||||
{
|
||||
strcpy(port_ip, new_ip);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::SetName(const char *new_name)
|
||||
{
|
||||
client_name = new_name;
|
||||
|
||||
if(server_connected == true)
|
||||
{
|
||||
SendData_ClientString();
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::SetPort(unsigned short new_port)
|
||||
{
|
||||
if(server_connected == false)
|
||||
{
|
||||
port_num = new_port;
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::StartClient()
|
||||
{
|
||||
unsigned int requested_controllers;
|
||||
|
||||
//Start a TCP server and launch threads
|
||||
char port_str[6];
|
||||
snprintf(port_str, 6, "%d", port_num);
|
||||
|
||||
port.tcp_client(port_ip, port_str);
|
||||
|
||||
requested_controllers = 0;
|
||||
|
||||
//Start the connection thread
|
||||
ConnectionThread = new std::thread(&NetworkClient::ConnectionThreadFunction, this);
|
||||
|
||||
//Start the listener thread
|
||||
ListenThread = new std::thread(&NetworkClient::ListenThreadFunction, this);
|
||||
|
||||
//Wait for server to connect
|
||||
while(!server_connected)
|
||||
{
|
||||
Sleep(100);
|
||||
}
|
||||
|
||||
//Once server is connected, send client string
|
||||
SendData_ClientString();
|
||||
|
||||
//Request number of controllers
|
||||
SendRequest_ControllerCount();
|
||||
|
||||
//Wait for server controller count
|
||||
while(server_controller_count == 0)
|
||||
{
|
||||
Sleep(100);
|
||||
}
|
||||
|
||||
printf("Client: Received controller count from server: %d\r\n", server_controller_count);
|
||||
|
||||
//Once count is received, request controllers
|
||||
while(requested_controllers < server_controller_count)
|
||||
{
|
||||
printf("Client: Requesting controller %d\r\n", requested_controllers);
|
||||
|
||||
SendRequest_ControllerData(requested_controllers);
|
||||
|
||||
//Wait until controller is received
|
||||
while(server_controllers.size() == requested_controllers)
|
||||
{
|
||||
Sleep(100);
|
||||
}
|
||||
|
||||
requested_controllers++;
|
||||
}
|
||||
|
||||
//All controllers received, add them to master list
|
||||
printf("Client: All controllers received, adding them to master list\r\n");
|
||||
for(std::size_t controller_idx = 0; controller_idx < server_controllers.size(); controller_idx++)
|
||||
{
|
||||
controllers.push_back(server_controllers[controller_idx]);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::StopClient()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NetworkClient::ConnectionThreadFunction()
|
||||
{
|
||||
//This thread manages the connection to the server
|
||||
while(1)
|
||||
{
|
||||
//Connect to server and reconnect if the connection is lost
|
||||
|
||||
//Try to connect to server
|
||||
port.tcp_client_connect();
|
||||
|
||||
printf( "Connected to server\n" );
|
||||
|
||||
server_connected = true;
|
||||
break;
|
||||
|
||||
//Wait 1 second between tries;
|
||||
Sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::ListenThreadFunction()
|
||||
{
|
||||
printf("Network client listener started\n");
|
||||
//This thread handles messages received from the server
|
||||
while(1)
|
||||
{
|
||||
NetPacketHeader header;
|
||||
char * data = NULL;
|
||||
int bytes_read = 0;
|
||||
|
||||
//Read first byte of magic
|
||||
do
|
||||
{
|
||||
bytes_read = port.tcp_listen(&header.pkt_magic[0], 1);
|
||||
} while(bytes_read == 0);
|
||||
|
||||
//Test first character of magic - 'O'
|
||||
if(header.pkt_magic[0] != 'O')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//Read second byte of magic
|
||||
do
|
||||
{
|
||||
bytes_read = port.tcp_listen(&header.pkt_magic[1], 1);
|
||||
} while(bytes_read == 0);
|
||||
|
||||
//Test second character of magic - 'R'
|
||||
if(header.pkt_magic[1] != 'R')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//Read third byte of magic
|
||||
do
|
||||
{
|
||||
bytes_read = port.tcp_listen(&header.pkt_magic[2], 1);
|
||||
} while(bytes_read == 0);
|
||||
|
||||
//Test third character of magic - 'G'
|
||||
if(header.pkt_magic[2] != 'G')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//Read fourth byte of magic
|
||||
do
|
||||
{
|
||||
bytes_read = port.tcp_listen(&header.pkt_magic[3], 1);
|
||||
} while(bytes_read == 0);
|
||||
|
||||
//Test fourth character of magic - 'B'
|
||||
if(header.pkt_magic[3] != 'B')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//If we get to this point, the magic is correct. Read the rest of the header
|
||||
bytes_read = 0;
|
||||
do
|
||||
{
|
||||
bytes_read += port.tcp_listen((char *)&header.pkt_dev_idx + bytes_read, sizeof(header) - sizeof(header.pkt_magic) - bytes_read);
|
||||
} while(bytes_read != sizeof(header) - sizeof(header.pkt_magic));
|
||||
|
||||
printf( "Client: Received header, now receiving data of size %d\r\n", header.pkt_size);
|
||||
|
||||
//Header received, now receive the data
|
||||
if(header.pkt_size > 0)
|
||||
{
|
||||
unsigned int bytes_read = 0;
|
||||
|
||||
data = new char[header.pkt_size];
|
||||
|
||||
do
|
||||
{
|
||||
bytes_read += port.tcp_listen(&data[bytes_read], header.pkt_size - bytes_read);
|
||||
} while (bytes_read < header.pkt_size);
|
||||
}
|
||||
|
||||
printf( "Client: Received header and data\r\n" );
|
||||
printf( "Client: Packet ID: %d \r\n", header.pkt_id);
|
||||
|
||||
//Entire request received, select functionality based on request ID
|
||||
switch(header.pkt_id)
|
||||
{
|
||||
case NET_PACKET_ID_REQUEST_CONTROLLER_COUNT:
|
||||
printf( "Client: NET_PACKET_ID_REQUEST_CONTROLLER_COUNT\r\n" );
|
||||
|
||||
ProcessReply_ControllerCount(header.pkt_size, data);
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_REQUEST_CONTROLLER_DATA:
|
||||
printf( "Client: NET_PACKET_ID_REQUEST_CONTROLLER_DATA\r\n");
|
||||
|
||||
ProcessReply_ControllerData(header.pkt_size, data, header.pkt_dev_idx);
|
||||
break;
|
||||
}
|
||||
|
||||
delete[] data;
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::ProcessReply_ControllerCount(unsigned int data_size, char * data)
|
||||
{
|
||||
if(data_size == sizeof(unsigned int))
|
||||
{
|
||||
memcpy(&server_controller_count, data, sizeof(unsigned int));
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::ProcessReply_ControllerData(unsigned int data_size, char * data, unsigned int dev_idx)
|
||||
{
|
||||
RGBController_Network * new_controller = new RGBController_Network(this, dev_idx);
|
||||
|
||||
new_controller->ReadDeviceDescription((unsigned char *)data);
|
||||
|
||||
printf("Received controller: %s\r\n", new_controller->name.c_str());
|
||||
|
||||
server_controllers.push_back(new_controller);
|
||||
}
|
||||
|
||||
void NetworkClient::SendData_ClientString()
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = 0;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_SET_CLIENT_NAME;
|
||||
reply_hdr.pkt_size = strlen(client_name.c_str()) + 1;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
port.tcp_client_write((char *)client_name.c_str(), reply_hdr.pkt_size);
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_ControllerCount()
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = 0;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_REQUEST_CONTROLLER_COUNT;
|
||||
reply_hdr.pkt_size = 0;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_ControllerData(unsigned int dev_idx)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_REQUEST_CONTROLLER_DATA;
|
||||
reply_hdr.pkt_size = 0;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_ResizeZone(unsigned int dev_idx, int zone, int new_size)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
int reply_data[2];
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE;
|
||||
reply_hdr.pkt_size = sizeof(reply_data);
|
||||
|
||||
reply_data[0] = zone;
|
||||
reply_data[1] = new_size;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
port.tcp_client_write((char *)&reply_data, sizeof(reply_data));
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS;
|
||||
reply_hdr.pkt_size = size;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
port.tcp_client_write((char *)data, size);
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_UpdateZoneLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS;
|
||||
reply_hdr.pkt_size = size;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
port.tcp_client_write((char *)data, size);
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_UpdateSingleLED(unsigned int dev_idx, unsigned char * data, unsigned int size)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED;
|
||||
reply_hdr.pkt_size = size;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
port.tcp_client_write((char *)data, size);
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_SetCustomMode(unsigned int dev_idx)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE;
|
||||
reply_hdr.pkt_size = 0;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_UpdateMode(unsigned int dev_idx, unsigned char * data, unsigned int size)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE;
|
||||
reply_hdr.pkt_size = size;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
port.tcp_client_write((char *)data, size);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*-----------------------------------------*\
|
||||
| NetworkClient.h |
|
||||
| |
|
||||
| Client header for OpenRGB SDK |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 5/9/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "NetworkProtocol.h"
|
||||
#include "net_port.h"
|
||||
|
||||
#include <thread>
|
||||
|
||||
#pragma once
|
||||
|
||||
class NetworkClient
|
||||
{
|
||||
public:
|
||||
NetworkClient(std::vector<RGBController *>& control);
|
||||
|
||||
const char * GetIP();
|
||||
unsigned short GetPort();
|
||||
bool GetOnline();
|
||||
|
||||
void SetIP(const char *new_ip);
|
||||
void SetName(const char *new_name);
|
||||
void SetPort(unsigned short new_port);
|
||||
|
||||
void StartClient();
|
||||
void StopClient();
|
||||
|
||||
void ConnectionThreadFunction();
|
||||
void ListenThreadFunction();
|
||||
|
||||
void ProcessReply_ControllerCount(unsigned int data_size, char * data);
|
||||
void ProcessReply_ControllerData(unsigned int data_size, char * data, unsigned int dev_idx);
|
||||
|
||||
void SendData_ClientString();
|
||||
|
||||
void SendRequest_ControllerCount();
|
||||
void SendRequest_ControllerData(unsigned int dev_idx);
|
||||
|
||||
void SendRequest_RGBController_ResizeZone(unsigned int dev_idx, int zone, int new_size);
|
||||
|
||||
void SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_UpdateZoneLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_UpdateSingleLED(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
|
||||
void SendRequest_RGBController_SetCustomMode(unsigned int dev_idx);
|
||||
|
||||
void SendRequest_RGBController_UpdateMode(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
|
||||
protected:
|
||||
std::vector<RGBController *>& controllers;
|
||||
std::vector<RGBController *> server_controllers;
|
||||
|
||||
private:
|
||||
std::string client_name;
|
||||
net_port port;
|
||||
char port_ip[20];
|
||||
unsigned short port_num;
|
||||
bool server_connected;
|
||||
unsigned int server_controller_count;
|
||||
|
||||
std::thread * ConnectionThread;
|
||||
std::thread * ListenThread;
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "NetworkProtocol.h"
|
||||
|
||||
NetPacketHeader * InitNetPacketHeader
|
||||
(
|
||||
unsigned int pkt_dev_idx,
|
||||
unsigned int pkt_id,
|
||||
unsigned int pkt_size
|
||||
)
|
||||
{
|
||||
NetPacketHeader * new_header = new NetPacketHeader;
|
||||
|
||||
new_header->pkt_magic[0] = 'O';
|
||||
new_header->pkt_magic[1] = 'R';
|
||||
new_header->pkt_magic[2] = 'G';
|
||||
new_header->pkt_magic[3] = 'B';
|
||||
|
||||
new_header->pkt_dev_idx = pkt_dev_idx;
|
||||
new_header->pkt_id = pkt_id;
|
||||
new_header->pkt_size = pkt_size;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*-----------------------------------------*\
|
||||
| NetworkProtocol.h |
|
||||
| |
|
||||
| Protocol header for OpenRGB SDK |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 5/9/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef struct NetPacketHeader
|
||||
{
|
||||
char pkt_magic[4]; /* Magic value "ORGB" identifies beginning of packet */
|
||||
unsigned int pkt_dev_idx; /* Device index */
|
||||
unsigned int pkt_id; /* Packet ID */
|
||||
unsigned int pkt_size; /* Packet size */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
/*----------------------------------------------------------------------------------------------------------*\
|
||||
| Network requests |
|
||||
\*----------------------------------------------------------------------------------------------------------*/
|
||||
NET_PACKET_ID_REQUEST_CONTROLLER_COUNT = 0, /* Request RGBController device count from server */
|
||||
NET_PACKET_ID_REQUEST_CONTROLLER_DATA = 1, /* Request RGBController data block */
|
||||
NET_PACKET_ID_SET_CLIENT_NAME = 50, /* Send client name string to server */
|
||||
|
||||
/*----------------------------------------------------------------------------------------------------------*\
|
||||
| RGBController class functions |
|
||||
\*----------------------------------------------------------------------------------------------------------*/
|
||||
NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE = 1000, /* RGBController::ResizeZone() */
|
||||
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS = 1050, /* RGBController::UpdateLEDs() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS = 1051, /* RGBController::UpdateZoneLEDs() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED = 1052, /* RGBController::UpdateSingleLED() */
|
||||
|
||||
NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE = 1100, /* RGBController::SetCustomMode() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE = 1101, /* RGBController::UpdateMode() */
|
||||
};
|
||||
@@ -0,0 +1,611 @@
|
||||
/*-----------------------------------------*\
|
||||
| NetworkServer.cpp |
|
||||
| |
|
||||
| Server code for OpenRGB SDK |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 5/9/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "NetworkServer.h"
|
||||
#include <cstring>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <sys/ioctl.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <sys/types.h>
|
||||
#include <arpa/inet.h>
|
||||
#else
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
#include <memory.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
|
||||
const char yes = 1;
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
|
||||
static void Sleep(unsigned int milliseconds)
|
||||
{
|
||||
usleep(1000 * milliseconds);
|
||||
}
|
||||
#endif
|
||||
|
||||
NetworkServer::NetworkServer(std::vector<RGBController *>& control) : controllers(control)
|
||||
{
|
||||
port_num = 1337;
|
||||
server_online = false;
|
||||
}
|
||||
|
||||
void NetworkServer::ClientInfoChanged()
|
||||
{
|
||||
ClientInfoChangeMutex.lock();
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Client info has changed, call the callbacks |
|
||||
\*-------------------------------------------------*/
|
||||
for(unsigned int callback_idx = 0; callback_idx < ClientInfoChangeCallbacks.size(); callback_idx++)
|
||||
{
|
||||
ClientInfoChangeCallbacks[callback_idx](ClientInfoChangeCallbackArgs[callback_idx]);
|
||||
}
|
||||
|
||||
ClientInfoChangeMutex.unlock();
|
||||
}
|
||||
|
||||
unsigned short NetworkServer::GetPort()
|
||||
{
|
||||
return port_num;
|
||||
}
|
||||
|
||||
bool NetworkServer::GetOnline()
|
||||
{
|
||||
return server_online;
|
||||
}
|
||||
|
||||
unsigned int NetworkServer::GetNumClients()
|
||||
{
|
||||
return ServerClients.size();
|
||||
}
|
||||
|
||||
const char * NetworkServer::GetClientString(unsigned int client_num)
|
||||
{
|
||||
if(client_num < ServerClients.size())
|
||||
{
|
||||
return ServerClients[client_num]->client_string.c_str();
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
const char * NetworkServer::GetClientIP(unsigned int client_num)
|
||||
{
|
||||
if(client_num < ServerClients.size())
|
||||
{
|
||||
return ServerClients[client_num]->client_ip;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkServer::RegisterClientInfoChangeCallback(NetServerCallback new_callback, void * new_callback_arg)
|
||||
{
|
||||
ClientInfoChangeCallbacks.push_back(new_callback);
|
||||
ClientInfoChangeCallbackArgs.push_back(new_callback_arg);
|
||||
}
|
||||
|
||||
void NetworkServer::SetPort(unsigned short new_port)
|
||||
{
|
||||
if(server_online == false)
|
||||
{
|
||||
port_num = new_port;
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkServer::StartServer()
|
||||
{
|
||||
//Start a TCP server and launch threads
|
||||
char port_str[6];
|
||||
snprintf(port_str, 6, "%d", port_num);
|
||||
|
||||
sockaddr_in myAddress;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Windows requires WSAStartup before using sockets |
|
||||
\*-------------------------------------------------*/
|
||||
#ifdef WIN32
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR)
|
||||
{
|
||||
WSACleanup();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Create the server socket |
|
||||
\*-------------------------------------------------*/
|
||||
server_sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (server_sock == INVALID_SOCKET)
|
||||
{
|
||||
WSACleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Fill in server address info with port value |
|
||||
\*-------------------------------------------------*/
|
||||
myAddress.sin_family = AF_INET;
|
||||
myAddress.sin_addr.s_addr = inet_addr("0.0.0.0");
|
||||
myAddress.sin_port = htons(atoi(port_str));
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Bind the server socket |
|
||||
\*-------------------------------------------------*/
|
||||
if (bind(server_sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR)
|
||||
{
|
||||
WSACleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Set socket options - no delay |
|
||||
\*-------------------------------------------------*/
|
||||
setsockopt(server_sock, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
|
||||
|
||||
server_online = true;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Start the connection thread |
|
||||
\*-------------------------------------------------*/
|
||||
ConnectionThread = new std::thread(&NetworkServer::ConnectionThreadFunction, this);
|
||||
}
|
||||
|
||||
void NetworkServer::StopServer()
|
||||
{
|
||||
server_online = false;
|
||||
|
||||
for(unsigned int client_idx = 0; client_idx < ServerClients.size(); client_idx++)
|
||||
{
|
||||
shutdown(ServerClients[client_idx]->client_sock, SD_RECEIVE);
|
||||
closesocket(ServerClients[client_idx]->client_sock);
|
||||
ServerClients[client_idx]->client_listen_thread->join();
|
||||
}
|
||||
|
||||
shutdown(server_sock, SD_RECEIVE);
|
||||
closesocket(server_sock);
|
||||
|
||||
ConnectionThread->join();
|
||||
|
||||
for(unsigned int client_idx = 0; client_idx < ServerClients.size(); client_idx++)
|
||||
{
|
||||
delete[] ServerClients[client_idx];
|
||||
}
|
||||
|
||||
ServerClients.clear();
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Client info has changed, call the callbacks |
|
||||
\*-------------------------------------------------*/
|
||||
ClientInfoChanged();
|
||||
}
|
||||
|
||||
void NetworkServer::ConnectionThreadFunction()
|
||||
{
|
||||
//This thread handles client connections
|
||||
|
||||
printf("Network connection thread started\n");
|
||||
while(server_online == true)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Create new socket for client connection |
|
||||
\*-------------------------------------------------*/
|
||||
NetworkClientInfo * client_info = new NetworkClientInfo();
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Listen for incoming client connection on the |
|
||||
| server socket. This call blocks until a |
|
||||
| connection is established |
|
||||
\*-------------------------------------------------*/
|
||||
if(listen(server_sock, 10) < 0)
|
||||
{
|
||||
printf("Connection thread closed\r\n");
|
||||
server_online = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Accept the client connection |
|
||||
\*-------------------------------------------------*/
|
||||
struct sockaddr_in client_addr;
|
||||
socklen_t client_addr_len = sizeof(client_addr);
|
||||
client_info->client_sock = accept_select(server_sock, (struct sockaddr *)&client_addr, &client_addr_len);
|
||||
|
||||
if(client_info->client_sock < 0)
|
||||
{
|
||||
printf("Connection thread closed\r\n");
|
||||
server_online = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Get the new client socket and store it in the |
|
||||
| clients vector |
|
||||
\*-------------------------------------------------*/
|
||||
u_long arg = 0;
|
||||
ioctlsocket(client_info->client_sock, FIONBIO, &arg);
|
||||
setsockopt(client_info->client_sock, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
|
||||
|
||||
inet_ntop(AF_INET, &client_addr.sin_addr, client_info->client_ip, INET_ADDRSTRLEN);
|
||||
|
||||
client_info->client_string = "Client";
|
||||
|
||||
//Start a listener thread for the new client socket
|
||||
client_info->client_listen_thread = new std::thread(&NetworkServer::ListenThreadFunction, this, client_info);
|
||||
|
||||
ServerClients.push_back(client_info);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Client info has changed, call the callbacks |
|
||||
\*-------------------------------------------------*/
|
||||
ClientInfoChanged();
|
||||
}
|
||||
|
||||
printf("Connection thread closed\r\n");
|
||||
server_online = false;
|
||||
}
|
||||
|
||||
int NetworkServer::accept_select(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
|
||||
{
|
||||
fd_set set;
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 5;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
while(1)
|
||||
{
|
||||
FD_ZERO(&set); /* clear the set */
|
||||
FD_SET(sockfd, &set); /* add our file descriptor to the set */
|
||||
|
||||
int rv = select(sockfd + 1, &set, NULL, NULL, &timeout);
|
||||
|
||||
if(rv == SOCKET_ERROR || server_online == false)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if(rv == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// socket has something to read
|
||||
return(accept(sockfd, addr, addrlen));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int NetworkServer::recv_select(SOCKET s, char *buf, int len, int flags)
|
||||
{
|
||||
fd_set set;
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 5;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
while(1)
|
||||
{
|
||||
FD_ZERO(&set); /* clear the set */
|
||||
FD_SET(s, &set); /* add our file descriptor to the set */
|
||||
|
||||
int rv = select(s + 1, &set, NULL, NULL, &timeout);
|
||||
|
||||
if(rv == SOCKET_ERROR || server_online == false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if(rv == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// socket has something to read
|
||||
return(recv(s, buf, len, flags));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
|
||||
{
|
||||
SOCKET client_sock = client_info->client_sock;
|
||||
|
||||
printf("Network server started\n");
|
||||
//This thread handles messages received from clients
|
||||
while(server_online == true)
|
||||
{
|
||||
NetPacketHeader header;
|
||||
int bytes_read = 0;
|
||||
char * data = NULL;
|
||||
|
||||
//Read first byte of magic
|
||||
bytes_read = recv_select(client_sock, &header.pkt_magic[0], 1, 0);
|
||||
|
||||
if(bytes_read == 0)
|
||||
{
|
||||
goto listen_done;
|
||||
}
|
||||
|
||||
//Test first character of magic - 'O'
|
||||
if(header.pkt_magic[0] != 'O')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//Read second byte of magic
|
||||
bytes_read = recv_select(client_sock, &header.pkt_magic[1], 1, 0);
|
||||
|
||||
if(bytes_read == 0)
|
||||
{
|
||||
goto listen_done;
|
||||
}
|
||||
|
||||
//Test second character of magic - 'R'
|
||||
if(header.pkt_magic[1] != 'R')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//Read third byte of magic
|
||||
bytes_read = recv_select(client_sock, &header.pkt_magic[2], 1, 0);
|
||||
|
||||
if(bytes_read == 0)
|
||||
{
|
||||
goto listen_done;
|
||||
}
|
||||
|
||||
//Test third character of magic - 'G'
|
||||
if(header.pkt_magic[2] != 'G')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//Read fourth byte of magic
|
||||
bytes_read = recv_select(client_sock, &header.pkt_magic[3], 1, 0);
|
||||
|
||||
if(bytes_read == 0)
|
||||
{
|
||||
goto listen_done;
|
||||
}
|
||||
|
||||
//Test fourth character of magic - 'B'
|
||||
if(header.pkt_magic[3] != 'B')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//If we get to this point, the magic is correct. Read the rest of the header
|
||||
bytes_read = 0;
|
||||
do
|
||||
{
|
||||
int tmp_bytes_read = 0;
|
||||
|
||||
tmp_bytes_read = recv_select(client_sock, (char *)&header.pkt_dev_idx + bytes_read, sizeof(header) - sizeof(header.pkt_magic) - bytes_read, 0);
|
||||
|
||||
bytes_read += tmp_bytes_read;
|
||||
|
||||
if(tmp_bytes_read == 0)
|
||||
{
|
||||
goto listen_done;
|
||||
}
|
||||
|
||||
} while(bytes_read != sizeof(header) - sizeof(header.pkt_magic));
|
||||
|
||||
//printf( "Server: Received header, now receiving data of size %d\r\n", header.pkt_size);
|
||||
|
||||
//Header received, now receive the data
|
||||
if(header.pkt_size > 0)
|
||||
{
|
||||
bytes_read = 0;
|
||||
|
||||
data = new char[header.pkt_size];
|
||||
|
||||
do
|
||||
{
|
||||
int tmp_bytes_read = 0;
|
||||
|
||||
tmp_bytes_read = recv_select(client_sock, &data[bytes_read], header.pkt_size - bytes_read, 0);
|
||||
|
||||
if(tmp_bytes_read == 0)
|
||||
{
|
||||
goto listen_done;
|
||||
}
|
||||
bytes_read += tmp_bytes_read;
|
||||
|
||||
} while (bytes_read < header.pkt_size);
|
||||
}
|
||||
|
||||
//printf( "Server: Received header and data\r\n" );
|
||||
//printf( "Server: Packet ID: %d \r\n", header.pkt_id);
|
||||
|
||||
//Entire request received, select functionality based on request ID
|
||||
switch(header.pkt_id)
|
||||
{
|
||||
case NET_PACKET_ID_REQUEST_CONTROLLER_COUNT:
|
||||
//printf( "NET_PACKET_ID_REQUEST_CONTROLLER_COUNT\r\n" );
|
||||
SendReply_ControllerCount(client_sock);
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_REQUEST_CONTROLLER_DATA:
|
||||
//printf( "NET_PACKET_ID_REQUEST_CONTROLLER_DATA\r\n" );
|
||||
SendReply_ControllerData(client_sock, header.pkt_dev_idx);
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_SET_CLIENT_NAME:
|
||||
printf( "NET_PACKET_ID_SET_CLIENT_NAME\r\n" );
|
||||
ProcessRequest_ClientString(client_sock, header.pkt_size, data);
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE:
|
||||
//printf( "NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE\r\n" );
|
||||
|
||||
if((header.pkt_dev_idx < controllers.size()) && (header.pkt_size == (2 * sizeof(int))))
|
||||
{
|
||||
int zone;
|
||||
int new_size;
|
||||
|
||||
memcpy(&zone, data, sizeof(int));
|
||||
memcpy(&new_size, data + sizeof(int), sizeof(int));
|
||||
|
||||
controllers[header.pkt_dev_idx]->ResizeZone(zone, new_size);
|
||||
}
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS:
|
||||
//printf( "NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS\r\n" );
|
||||
|
||||
if(header.pkt_dev_idx < controllers.size())
|
||||
{
|
||||
controllers[header.pkt_dev_idx]->SetColorDescription((unsigned char *)data);
|
||||
controllers[header.pkt_dev_idx]->UpdateLEDs();
|
||||
}
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS:
|
||||
//printf( "NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS\r\n" );
|
||||
|
||||
if(header.pkt_dev_idx < controllers.size())
|
||||
{
|
||||
int zone;
|
||||
|
||||
memcpy(&zone, &data[sizeof(unsigned int)], sizeof(int));
|
||||
|
||||
controllers[header.pkt_dev_idx]->SetZoneColorDescription((unsigned char *)data);
|
||||
controllers[header.pkt_dev_idx]->UpdateZoneLEDs(zone);
|
||||
}
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED:
|
||||
//printf( "NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED\r\n" );
|
||||
|
||||
if(header.pkt_dev_idx < controllers.size())
|
||||
{
|
||||
int led;
|
||||
|
||||
memcpy(&led, data, sizeof(int));
|
||||
|
||||
controllers[header.pkt_dev_idx]->SetSingleLEDColorDescription((unsigned char *)data);
|
||||
controllers[header.pkt_dev_idx]->UpdateSingleLED(led);
|
||||
}
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE:
|
||||
//printf( "NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE\r\n" );
|
||||
|
||||
if(header.pkt_dev_idx < controllers.size())
|
||||
{
|
||||
controllers[header.pkt_dev_idx]->SetCustomMode();
|
||||
}
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE:
|
||||
//printf( "NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE\r\n" );
|
||||
|
||||
if(header.pkt_dev_idx < controllers.size())
|
||||
{
|
||||
controllers[header.pkt_dev_idx]->SetModeDescription((unsigned char *)data);
|
||||
controllers[header.pkt_dev_idx]->UpdateMode();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
listen_done:
|
||||
printf("Server connection closed\r\n");
|
||||
shutdown(client_info->client_sock, SD_RECEIVE);
|
||||
closesocket(client_info->client_sock);
|
||||
|
||||
for(unsigned int this_idx = 0; this_idx < ServerClients.size(); this_idx++)
|
||||
{
|
||||
if(ServerClients[this_idx] == client_info)
|
||||
{
|
||||
ServerClients.erase(ServerClients.begin() + this_idx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Client info has changed, call the callbacks |
|
||||
\*-------------------------------------------------*/
|
||||
ClientInfoChanged();
|
||||
}
|
||||
|
||||
void NetworkServer::ProcessRequest_ClientString(SOCKET client_sock, unsigned int data_size, char * data)
|
||||
{
|
||||
for(unsigned int this_idx = 0; this_idx < ServerClients.size(); this_idx++)
|
||||
{
|
||||
if(ServerClients[this_idx]->client_sock == client_sock)
|
||||
{
|
||||
ServerClients[this_idx]->client_string = data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Client info has changed, call the callbacks |
|
||||
\*-------------------------------------------------*/
|
||||
ClientInfoChanged();
|
||||
}
|
||||
|
||||
void NetworkServer::SendReply_ControllerCount(SOCKET client_sock)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
unsigned int reply_data;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = 0;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_REQUEST_CONTROLLER_COUNT;
|
||||
reply_hdr.pkt_size = sizeof(unsigned int);
|
||||
|
||||
reply_data = controllers.size();
|
||||
|
||||
send(client_sock, (const char *)&reply_hdr, sizeof(NetPacketHeader), 0);
|
||||
send(client_sock, (const char *)&reply_data, sizeof(unsigned int), 0);
|
||||
}
|
||||
|
||||
void NetworkServer::SendReply_ControllerData(SOCKET client_sock, unsigned int dev_idx)
|
||||
{
|
||||
if(dev_idx < controllers.size())
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
unsigned char *reply_data = controllers[dev_idx]->GetDeviceDescription();
|
||||
unsigned int reply_size;
|
||||
|
||||
memcpy(&reply_size, reply_data, sizeof(reply_size));
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_REQUEST_CONTROLLER_DATA;
|
||||
reply_hdr.pkt_size = reply_size;
|
||||
|
||||
send(client_sock, (const char *)&reply_hdr, sizeof(NetPacketHeader), 0);
|
||||
send(client_sock, (const char *)reply_data, reply_size, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*-----------------------------------------*\
|
||||
| NetworkServer.h |
|
||||
| |
|
||||
| Server header for OpenRGB SDK |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 5/9/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "NetworkProtocol.h"
|
||||
#include "net_port.h"
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef void (*NetServerCallback)(void *);
|
||||
|
||||
struct NetworkClientInfo
|
||||
{
|
||||
SOCKET client_sock;
|
||||
std::thread * client_listen_thread;
|
||||
std::string client_string;
|
||||
char client_ip[INET_ADDRSTRLEN];
|
||||
};
|
||||
|
||||
class NetworkServer
|
||||
{
|
||||
public:
|
||||
NetworkServer(std::vector<RGBController *>& control);
|
||||
|
||||
unsigned short GetPort();
|
||||
bool GetOnline();
|
||||
unsigned int GetNumClients();
|
||||
const char * GetClientString(unsigned int client_num);
|
||||
const char * GetClientIP(unsigned int client_num);
|
||||
|
||||
void ClientInfoChanged();
|
||||
void RegisterClientInfoChangeCallback(NetServerCallback, void * new_callback_arg);
|
||||
|
||||
void SetPort(unsigned short new_port);
|
||||
|
||||
void StartServer();
|
||||
void StopServer();
|
||||
|
||||
void ConnectionThreadFunction();
|
||||
void ListenThreadFunction(NetworkClientInfo * client_sock);
|
||||
|
||||
void ProcessRequest_ClientString(SOCKET client_sock, unsigned int data_size, char * data);
|
||||
|
||||
void SendReply_ControllerCount(SOCKET client_sock);
|
||||
void SendReply_ControllerData(SOCKET client_sock, unsigned int dev_idx);
|
||||
|
||||
protected:
|
||||
unsigned short port_num;
|
||||
bool server_online;
|
||||
|
||||
std::vector<RGBController *>& controllers;
|
||||
|
||||
std::vector<NetworkClientInfo *> ServerClients;
|
||||
std::thread * ConnectionThread;
|
||||
|
||||
std::mutex ClientInfoChangeMutex;
|
||||
std::vector<NetServerCallback> ClientInfoChangeCallbacks;
|
||||
std::vector<void *> ClientInfoChangeCallbackArgs;
|
||||
|
||||
private:
|
||||
#ifdef WIN32
|
||||
WSADATA wsa;
|
||||
#endif
|
||||
|
||||
SOCKET server_sock;
|
||||
|
||||
int accept_select(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
int recv_select(SOCKET s, char *buf, int len, int flags);
|
||||
};
|
||||
+77
-33
@@ -17,6 +17,7 @@
|
||||
#include "i2c_smbus_piix4.h"
|
||||
#include "i2c_smbus_i801.h"
|
||||
#include "i2c_smbus_nct6775.h"
|
||||
#include "i2c_smbus_nvapi.h"
|
||||
#include "super_io.h"
|
||||
#include "wmi.h"
|
||||
#else /* WIN32 */
|
||||
@@ -56,6 +57,7 @@ void DetectNuvotonI2CBusses()
|
||||
case SIO_NCT6102_ID:
|
||||
case SIO_NCT6793_ID:
|
||||
case SIO_NCT6796_ID:
|
||||
case SIO_NCT6798_ID:
|
||||
bus = new i2c_smbus_nct6775();
|
||||
|
||||
// Set logical device register to get SMBus base address
|
||||
@@ -80,6 +82,9 @@ void DetectNuvotonI2CBusses()
|
||||
case SIO_NCT6796_ID:
|
||||
sprintf(bus->device_name, "Nuvoton NCT6796D SMBus at %X", smba);
|
||||
break;
|
||||
case SIO_NCT6798_ID:
|
||||
sprintf(bus->device_name, "Nuvoton NCT6798D SMBus at %X", smba);
|
||||
break;
|
||||
}
|
||||
|
||||
busses.push_back(bus);
|
||||
@@ -87,6 +92,33 @@ void DetectNuvotonI2CBusses()
|
||||
|
||||
} /* DetectNuvotonI2CBusses() */
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectNvAPII2CBusses (Windows) *
|
||||
* *
|
||||
* Detects available NVidia NvAPI I2C adapters and enumerates *
|
||||
* i2c_smbus_interface objects for them. Only enumerates the first bus for each GPU *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectNvAPII2CBusses()
|
||||
{
|
||||
static NV_PHYSICAL_GPU_HANDLE gpu_handles[64];
|
||||
static NV_S32 gpu_count = 0;
|
||||
|
||||
NV_STATUS initialize = NvAPI_Initialize();
|
||||
|
||||
NvAPI_EnumPhysicalGPUs(gpu_handles, &gpu_count);
|
||||
|
||||
for(NV_S32 gpu_idx = 0; gpu_idx < gpu_count; gpu_idx++)
|
||||
{
|
||||
i2c_smbus_nvapi * nvapi_bus = new i2c_smbus_nvapi(gpu_handles[gpu_idx]);
|
||||
|
||||
sprintf(nvapi_bus->device_name, "NVidia NvAPI I2C on GPU %d", gpu_idx);
|
||||
|
||||
busses.push_back(nvapi_bus);
|
||||
}
|
||||
} /* DetectNvAPII2CBusses() */
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
@@ -170,6 +202,9 @@ void DetectI2CBusses()
|
||||
// Detect Nuvoton Super IO SMBus adapters
|
||||
DetectNuvotonI2CBusses();
|
||||
|
||||
// Detect NVidia NvAPI I2C adapters
|
||||
DetectNvAPII2CBusses();
|
||||
|
||||
} /* DetectI2CBusses() */
|
||||
|
||||
#else /* WIN32 */
|
||||
@@ -216,30 +251,24 @@ void DetectI2CBusses()
|
||||
|
||||
if(test_fd)
|
||||
{
|
||||
memset(device_string, 0x00, sizeof(device_string));
|
||||
read(test_fd, device_string, sizeof(device_string));
|
||||
device_string[strlen(device_string) - 1] = 0x00;
|
||||
|
||||
close(test_fd);
|
||||
|
||||
//ignore nvidia adapters for now
|
||||
if(strncmp(device_string, "NVIDIA", 6) == 0)
|
||||
{
|
||||
ent = readdir(dir);
|
||||
continue;
|
||||
}
|
||||
|
||||
bus = new i2c_smbus_linux();
|
||||
strcpy(bus->device_name, device_string);
|
||||
|
||||
strcpy(device_string, "/dev/");
|
||||
strcat(device_string, ent->d_name);
|
||||
test_fd = open(device_string, O_RDWR);
|
||||
|
||||
if (test_fd < 0)
|
||||
{
|
||||
delete bus;
|
||||
ent = readdir(dir);
|
||||
continue;
|
||||
}
|
||||
|
||||
bus = new i2c_smbus_linux();
|
||||
strcpy(bus->device_name, device_string);
|
||||
bus->handle = test_fd;
|
||||
busses.push_back(bus);
|
||||
}
|
||||
@@ -252,30 +281,37 @@ void DetectI2CBusses()
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
void DetectAuraControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectCorsairControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectCorsairProControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectAuraSMBusControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectAuraGPUControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectCorsairVengeanceControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectCorsairVengeanceProControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectCrucialControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectHyperXControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectHyperXDRAMControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectPatriotViperControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectPolychromeControllers(std::vector<i2c_smbus_interface*>& busses, std::vector<RGBController*>& rgb_controllers);
|
||||
void DetectRGBFusionControllers(std::vector<i2c_smbus_interface*>& busses, std::vector<RGBController*>& rgb_controllers);
|
||||
void DetectRGBFusionGPUControllers(std::vector<i2c_smbus_interface*>& busses, std::vector<RGBController*>& rgb_controllers);
|
||||
void DetectMSIMysticLightControllers(std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectMSIRGBControllers(std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectAuraAddressableControllers(std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectAuraCoreControllers(std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectLEDStripControllers(std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectHue2Controllers(std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectHuePlusControllers(std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectOpenRazerControllers(std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectRazerChromaSDKControllers(std::vector<RGBController*>& rgb_controllers);
|
||||
void DetectE131Controllers(std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectAMDWraithPrismControllers(std::vector<RGBController*>& rgb_controllers);
|
||||
void DetectAorusGPUControllers(std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectCoolerMasterControllers(std::vector<RGBController*>& rgb_controllers);
|
||||
void DetectMSI3ZoneControllers(std::vector<RGBController*>& rgb_controllers);
|
||||
void DetectPoseidonZRGBControllers(std::vector<RGBController*>& rgb_controllers);
|
||||
void DetectCorsairCmdrProControllers(std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectCorsairKeyboardControllers(std::vector<RGBController*>& rgb_controllers);
|
||||
void DetectCorsairNodeProControllers(std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectCorsairPeripheralControllers(std::vector<RGBController*>& rgb_controllers);
|
||||
void DetectCorsairLightingNodeControllers(std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectFaustusControllers(std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectHyperXKeyboardControllers(std::vector<RGBController*>& rgb_controllers);
|
||||
void DetectThermaltakeRiingControllers(std::vector<RGBController*>& rgb_controllers);
|
||||
void DetectRGBFusion2USBControllers(std::vector<RGBController*> &rgb_controllers);
|
||||
void DetectRedragonControllers(std::vector<RGBController*>& rgb_controllers);
|
||||
void DetectNZXTKrakenControllers(std::vector<RGBController*>& rgb_controllers);
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
@@ -289,42 +325,50 @@ void DetectRGBControllers(void)
|
||||
{
|
||||
DetectI2CBusses();
|
||||
|
||||
DetectAuraControllers(busses, rgb_controllers);
|
||||
DetectCorsairControllers(busses, rgb_controllers);
|
||||
DetectCorsairProControllers(busses, rgb_controllers);
|
||||
DetectAuraSMBusControllers(busses, rgb_controllers);
|
||||
DetectAuraGPUControllers(busses, rgb_controllers);
|
||||
DetectCorsairVengeanceControllers(busses, rgb_controllers);
|
||||
DetectCorsairVengeanceProControllers(busses, rgb_controllers);
|
||||
DetectCrucialControllers(busses, rgb_controllers);
|
||||
DetectHyperXControllers(busses, rgb_controllers);
|
||||
DetectHyperXDRAMControllers(busses, rgb_controllers);
|
||||
DetectPatriotViperControllers(busses, rgb_controllers);
|
||||
DetectPolychromeControllers(busses, rgb_controllers);
|
||||
DetectRGBFusionControllers(busses, rgb_controllers);
|
||||
DetectRGBFusionGPUControllers(busses, rgb_controllers);
|
||||
|
||||
DetectRGBFusionControllers(busses, rgb_controllers);
|
||||
DetectMSIMysticLightControllers(rgb_controllers);
|
||||
DetectMSIRGBControllers(rgb_controllers);
|
||||
|
||||
DetectAuraAddressableControllers(rgb_controllers);
|
||||
DetectAuraCoreControllers(rgb_controllers);
|
||||
DetectLEDStripControllers(rgb_controllers);
|
||||
DetectHue2Controllers(rgb_controllers);
|
||||
DetectHuePlusControllers(rgb_controllers);
|
||||
|
||||
DetectAMDWraithPrismControllers(rgb_controllers);
|
||||
DetectCoolerMasterControllers(rgb_controllers);
|
||||
DetectMSI3ZoneControllers(rgb_controllers);
|
||||
DetectPoseidonZRGBControllers(rgb_controllers);
|
||||
DetectHyperXKeyboardControllers(rgb_controllers);
|
||||
DetectCorsairCmdrProControllers(rgb_controllers);
|
||||
DetectCorsairKeyboardControllers(rgb_controllers);
|
||||
DetectCorsairNodeProControllers(rgb_controllers);
|
||||
DetectCorsairPeripheralControllers(rgb_controllers);
|
||||
DetectCorsairLightingNodeControllers(rgb_controllers);
|
||||
DetectThermaltakeRiingControllers(rgb_controllers);
|
||||
|
||||
DetectRGBFusion2USBControllers(rgb_controllers);
|
||||
DetectRedragonControllers(rgb_controllers);
|
||||
DetectNZXTKrakenControllers(rgb_controllers);
|
||||
|
||||
DetectE131Controllers(rgb_controllers);
|
||||
|
||||
DetectOpenRazerControllers(rgb_controllers);
|
||||
|
||||
/*-------------------------------------*\
|
||||
| Windows-only devices |
|
||||
\*-------------------------------------*/
|
||||
#ifdef WIN32
|
||||
DetectRazerChromaSDKControllers(rgb_controllers);
|
||||
//DetectAorusGPUControllers(rgb_controllers);
|
||||
|
||||
/*-------------------------------------*\
|
||||
| Linux-only devices |
|
||||
\*-------------------------------------*/
|
||||
#else
|
||||
DetectOpenRazerControllers(rgb_controllers);
|
||||
DetectFaustusControllers(rgb_controllers);
|
||||
#endif
|
||||
|
||||
|
||||
+44
-14
@@ -1,8 +1,8 @@
|
||||
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
|
||||
index 09367fc014c3..25c0e02b3344 100644
|
||||
index 2ddca08f8a76..72647850f08e 100644
|
||||
--- a/drivers/i2c/busses/Kconfig
|
||||
+++ b/drivers/i2c/busses/Kconfig
|
||||
@@ -216,6 +216,15 @@ config I2C_CHT_WC
|
||||
@@ -217,6 +217,15 @@ config I2C_CHT_WC
|
||||
combined with a FUSB302 Type-C port-controller as such it is advised
|
||||
to also select CONFIG_TYPEC_FUSB302=m.
|
||||
|
||||
@@ -19,7 +19,7 @@ index 09367fc014c3..25c0e02b3344 100644
|
||||
tristate "Nvidia nForce2, nForce3 and nForce4"
|
||||
depends on PCI
|
||||
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
|
||||
index 80c23895eaaf..57a2daf0b94e 100644
|
||||
index 25d60889713c..3c2a9b237ac6 100644
|
||||
--- a/drivers/i2c/busses/Makefile
|
||||
+++ b/drivers/i2c/busses/Makefile
|
||||
@@ -17,6 +17,7 @@ obj-$(CONFIG_I2C_CHT_WC) += i2c-cht-wc.o
|
||||
@@ -32,10 +32,10 @@ index 80c23895eaaf..57a2daf0b94e 100644
|
||||
obj-$(CONFIG_I2C_NVIDIA_GPU) += i2c-nvidia-gpu.o
|
||||
diff --git a/drivers/i2c/busses/i2c-nct6775.c b/drivers/i2c/busses/i2c-nct6775.c
|
||||
new file mode 100644
|
||||
index 000000000000..e2b491a4b9f6
|
||||
index 000000000000..0462f0952043
|
||||
--- /dev/null
|
||||
+++ b/drivers/i2c/busses/i2c-nct6775.c
|
||||
@@ -0,0 +1,617 @@
|
||||
@@ -0,0 +1,647 @@
|
||||
+/*
|
||||
+ * i2c-nct6775 - Driver for the SMBus master functionality of
|
||||
+ * Nuvoton NCT677x Super-I/O chips
|
||||
@@ -71,6 +71,7 @@ index 000000000000..e2b491a4b9f6
|
||||
+#include <linux/hwmon-vid.h>
|
||||
+#include <linux/err.h>
|
||||
+#include <linux/mutex.h>
|
||||
+#include <linux/delay.h>
|
||||
+#include <linux/ioport.h>
|
||||
+#include <linux/i2c.h>
|
||||
+#include <linux/acpi.h>
|
||||
@@ -115,6 +116,9 @@ index 000000000000..e2b491a4b9f6
|
||||
+
|
||||
+#define NCT6775_LD_SMBUS 0x0B
|
||||
+
|
||||
+/* Other settings */
|
||||
+#define MAX_RETRIES 400
|
||||
+
|
||||
+enum kinds { nct6106, nct6775, nct6776, nct6779, nct6791, nct6792, nct6793,
|
||||
+ nct6795, nct6796, nct6798 };
|
||||
+
|
||||
@@ -237,10 +241,13 @@ index 000000000000..e2b491a4b9f6
|
||||
+ struct i2c_nct6775_adapdata *adapdata = i2c_get_adapdata(adap);
|
||||
+ unsigned short nuvoton_nct6793d_smba = adapdata->smba;
|
||||
+ int i, len, cnt;
|
||||
+ union i2c_smbus_data tmp_data;
|
||||
+ int timeout = 0;
|
||||
+
|
||||
+ tmp_data.word = 0;
|
||||
+ cnt = 0;
|
||||
+ len = 0;
|
||||
+
|
||||
+
|
||||
+ outb_p(NCT6793D_SOFT_RESET, SMBHSTCTL);
|
||||
+
|
||||
+ switch (size) {
|
||||
@@ -248,13 +255,14 @@ index 000000000000..e2b491a4b9f6
|
||||
+ outb_p((addr << 1) | read_write,
|
||||
+ SMBHSTADD);
|
||||
+ break;
|
||||
+ case I2C_SMBUS_BYTE:
|
||||
+ case I2C_SMBUS_BYTE_DATA:
|
||||
+ tmp_data.byte = data->byte;
|
||||
+ case I2C_SMBUS_BYTE:
|
||||
+ outb_p((addr << 1) | read_write,
|
||||
+ SMBHSTADD);
|
||||
+ outb_p(command, SMBHSTIDX);
|
||||
+ if (read_write == I2C_SMBUS_WRITE) {
|
||||
+ outb_p(data->byte, SMBHSTDAT);
|
||||
+ outb_p(tmp_data.byte, SMBHSTDAT);
|
||||
+ outb_p(NCT6793D_WRITE_BYTE, SMBHSTCMD);
|
||||
+ }
|
||||
+ else {
|
||||
@@ -268,7 +276,7 @@ index 000000000000..e2b491a4b9f6
|
||||
+ if (read_write == I2C_SMBUS_WRITE) {
|
||||
+ outb_p(data->word & 0xff, SMBHSTDAT);
|
||||
+ outb_p((data->word & 0xff00) >> 8, SMBHSTDAT);
|
||||
+ outb_p(NCT6793D_WRITE_WORD, SMBHSTCMD);
|
||||
+ outb_p(NCT6793D_WRITE_WORD, SMBHSTCMD);
|
||||
+ }
|
||||
+ else {
|
||||
+ outb_p(NCT6793D_READ_WORD, SMBHSTCMD);
|
||||
@@ -316,7 +324,16 @@ index 000000000000..e2b491a4b9f6
|
||||
+
|
||||
+ while ((size == I2C_SMBUS_BLOCK_DATA) && (len > 0)) {
|
||||
+ if (read_write == I2C_SMBUS_WRITE) {
|
||||
+ while ((inb_p(SMBHSTSTS) & NCT6793D_FIFO_EMPTY) == 0);
|
||||
+ timeout = 0;
|
||||
+ while ((inb_p(SMBHSTSTS) & NCT6793D_FIFO_EMPTY) == 0)
|
||||
+ {
|
||||
+ if(timeout > MAX_RETRIES)
|
||||
+ {
|
||||
+ return -ETIMEDOUT;
|
||||
+ }
|
||||
+ usleep_range(250, 500);
|
||||
+ timeout++;
|
||||
+ }
|
||||
+
|
||||
+ //Load more bytes into FIFO
|
||||
+ if (len >= 4) {
|
||||
@@ -335,10 +352,23 @@ index 000000000000..e2b491a4b9f6
|
||||
+ len = 0;
|
||||
+ }
|
||||
+ }
|
||||
+ else {
|
||||
+ return -ENOTSUPP;
|
||||
+ }
|
||||
+
|
||||
+ }
|
||||
+
|
||||
+ //wait for manual mode to complete
|
||||
+ while ((inb_p(SMBHSTSTS) & NCT6793D_MANUAL_ACTIVE) != 0);
|
||||
+ timeout = 0;
|
||||
+ while ((inb_p(SMBHSTSTS) & NCT6793D_MANUAL_ACTIVE) != 0)
|
||||
+ {
|
||||
+ if(timeout > MAX_RETRIES)
|
||||
+ {
|
||||
+ return -ETIMEDOUT;
|
||||
+ }
|
||||
+ usleep_range(250, 500);
|
||||
+ timeout++;
|
||||
+ }
|
||||
+
|
||||
+ if ((inb_p(SMBHSTERR) & NCT6793D_NO_ACK) != 0) {
|
||||
+ return -ENXIO;
|
||||
@@ -654,10 +684,10 @@ index 000000000000..e2b491a4b9f6
|
||||
+module_init(i2c_nct6775_init);
|
||||
+module_exit(i2c_nct6775_exit);
|
||||
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
|
||||
index c46c4bddc7ca..8565d08178a2 100644
|
||||
index 30ded6422e7b..e25ce84c26af 100644
|
||||
--- a/drivers/i2c/busses/i2c-piix4.c
|
||||
+++ b/drivers/i2c/busses/i2c-piix4.c
|
||||
@@ -468,11 +468,11 @@ static int piix4_transaction(struct i2c_adapter *piix4_adapter)
|
||||
@@ -467,11 +467,11 @@ static int piix4_transaction(struct i2c_adapter *piix4_adapter)
|
||||
if (srvrworks_csb5_delay) /* Extra delay for SERVERWORKS_CSB5 */
|
||||
usleep_range(2000, 2100);
|
||||
else
|
||||
@@ -671,7 +701,7 @@ index c46c4bddc7ca..8565d08178a2 100644
|
||||
|
||||
/* If the SMBus is still busy, we give up */
|
||||
if (timeout == MAX_TIMEOUT) {
|
||||
@@ -963,6 +963,11 @@ static int piix4_probe(struct pci_dev *dev, const struct pci_device_id *id)
|
||||
@@ -981,6 +981,11 @@ static int piix4_probe(struct pci_dev *dev, const struct pci_device_id *id)
|
||||
retval = piix4_setup_sb800(dev, id, 1);
|
||||
}
|
||||
|
||||
|
||||
+188
-76
@@ -5,7 +5,25 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
TARGET = OpenRGB
|
||||
TEMPLATE = app
|
||||
|
||||
VERSION = 0.11
|
||||
win32:BUILDDATE = $$system(date /t)
|
||||
unix:BUILDDATE = $$system(date -R)
|
||||
GIT_COMMIT_ID = $$system(git --git-dir $$_PRO_FILE_PWD_/.git --work-tree $$_PRO_FILE_PWD_ rev-parse HEAD)
|
||||
GIT_COMMIT_DATE = $$system(git --git-dir $$_PRO_FILE_PWD_/.git --work-tree $$_PRO_FILE_PWD_ show -s --format=%ci HEAD)
|
||||
GIT_BRANCH = $$system(git --git-dir $$_PRO_FILE_PWD_/.git --work-tree $$_PRO_FILE_PWD_ rev-parse --abbrev-ref HEAD)
|
||||
|
||||
DEFINES += \
|
||||
VERSION_STRING=\\"\"\"$$VERSION\\"\"\" \
|
||||
BUILDDATE_STRING=\\"\"\"$$BUILDDATE\\"\"\" \
|
||||
GIT_COMMIT_ID=\\"\"\"$$GIT_COMMIT_ID\\"\"\" \
|
||||
GIT_COMMIT_DATE=\\"\"\"$$GIT_COMMIT_DATE\\"\"\" \
|
||||
GIT_BRANCH=\\"\"\"$$GIT_BRANCH\\"\"\"
|
||||
|
||||
RC_ICONS = qt/OpenRGB.ico
|
||||
|
||||
INCLUDEPATH += \
|
||||
dependencies/ColorWheel \
|
||||
dependencies/hidapi \
|
||||
dependencies/libe131/src/ \
|
||||
i2c_smbus/ \
|
||||
i2c_tools/ \
|
||||
@@ -13,32 +31,46 @@ INCLUDEPATH += \
|
||||
serial_port/ \
|
||||
super_io/ \
|
||||
Controllers/AMDWraithPrismController/ \
|
||||
Controllers/AuraController/ \
|
||||
Controllers/CorsairController/ \
|
||||
Controllers/CorsairCmdrProController/ \
|
||||
Controllers/CorsairKeyboardController/ \
|
||||
Controllers/CorsairNodeProController/ \
|
||||
Controllers/CorsairProController/ \
|
||||
Controllers/AuraAddressableController/ \
|
||||
Controllers/AuraCoreController/ \
|
||||
Controllers/AuraGPUController/ \
|
||||
Controllers/AuraSMBusController/ \
|
||||
Controllers/CoolerMasterController/ \
|
||||
Controllers/CorsairPeripheralController/ \
|
||||
Controllers/CorsairLightingNodeController/ \
|
||||
Controllers/CorsairVengeanceController/ \
|
||||
Controllers/CorsairVengeanceProController/ \
|
||||
Controllers/CrucialController/ \
|
||||
Controllers/Hue2Controller/ \
|
||||
Controllers/HuePlusController/ \
|
||||
Controllers/HyperXController/ \
|
||||
Controllers/HyperXDRAMController/ \
|
||||
Controllers/HyperXKeyboardController/ \
|
||||
Controllers/LEDStripController/ \
|
||||
Controllers/MSI3ZoneController/ \
|
||||
Controllers/MSIMysticLightController/ \
|
||||
Controllers/MSIRGBController/ \
|
||||
Controllers/NZXTKrakenController/ \
|
||||
Controllers/PatriotViperController/ \
|
||||
Controllers/PolychromeController/ \
|
||||
Controllers/PoseidonZRGBController/ \
|
||||
Controllers/RedragonController/ \
|
||||
Controllers/RGBFusionController/ \
|
||||
Controllers/RGBFusion2Controller/ \
|
||||
Controllers/RGBFusion2USBController/ \
|
||||
Controllers/RGBFusionGPUController/ \
|
||||
Controllers/ThermaltakeRiingController/ \
|
||||
RGBController/ \
|
||||
qt/
|
||||
|
||||
SOURCES += \
|
||||
dependencies/ColorWheel/ColorWheel.cpp \
|
||||
dependencies/hidapi/hidapi.c \
|
||||
dependencies/libe131/src/e131.c \
|
||||
main.cpp \
|
||||
cli.cpp \
|
||||
OpenRGB.cpp \
|
||||
NetworkClient.cpp \
|
||||
NetworkServer.cpp \
|
||||
ProfileManager.cpp \
|
||||
qt/OpenRGBDeviceInfoPage.cpp \
|
||||
qt/OpenRGBDevicePage.cpp \
|
||||
qt/OpenRGBDialog.cpp \
|
||||
@@ -46,38 +78,54 @@ SOURCES += \
|
||||
i2c_tools/i2c_tools.cpp \
|
||||
net_port/net_port.cpp \
|
||||
qt/OpenRGBDialog2.cpp \
|
||||
qt/OpenRGBProfileSaveDialog.cpp \
|
||||
qt/OpenRGBServerInfoPage.cpp \
|
||||
qt/OpenRGBSoftwareInfoPage.cpp \
|
||||
qt/OpenRGBSystemInfoPage.cpp \
|
||||
qt/OpenRGBZoneResizeDialog.cpp \
|
||||
qt/hsv.cpp \
|
||||
serial_port/serial_port.cpp \
|
||||
super_io/super_io.cpp \
|
||||
Controllers/AMDWraithPrismController/AMDWraithPrismController.cpp \
|
||||
Controllers/AMDWraithPrismController/AMDWraithPrismControllerDetect.cpp \
|
||||
Controllers/AuraController/AuraController.cpp \
|
||||
Controllers/AuraController/AuraControllerDetect.cpp \
|
||||
Controllers/CorsairController/CorsairController.cpp \
|
||||
Controllers/CorsairController/CorsairControllerDetect.cpp \
|
||||
Controllers/CorsairCmdrProController/CorsairCmdrProController.cpp \
|
||||
Controllers/CorsairCmdrProController/CorsairCmdrProControllerDetect.cpp \
|
||||
Controllers/CorsairKeyboardController/CorsairKeyboardController.cpp \
|
||||
Controllers/CorsairKeyboardController/CorsairKeyboardControllerDetect.cpp \
|
||||
Controllers/CorsairNodeProController/CorsairNodeProController.cpp \
|
||||
Controllers/CorsairNodeProController/CorsairNodeProControllerDetect.cpp \
|
||||
Controllers/CorsairProController/CorsairProController.cpp \
|
||||
Controllers/CorsairProController/CorsairProControllerDetect.cpp \
|
||||
Controllers/AuraAddressableController/AuraAddressableController.cpp \
|
||||
Controllers/AuraAddressableController/AuraAddressableControllerDetect.cpp \
|
||||
Controllers/AuraCoreController/AuraCoreController.cpp \
|
||||
Controllers/AuraCoreController/AuraCoreControllerDetect.cpp \
|
||||
Controllers/AuraGPUController/AuraGPUController.cpp \
|
||||
Controllers/AuraGPUController/AuraGPUControllerDetect.cpp \
|
||||
Controllers/AuraSMBusController/AuraSMBusController.cpp \
|
||||
Controllers/AuraSMBusController/AuraSMBusControllerDetect.cpp \
|
||||
Controllers/CoolerMasterController/CMMP750Controller.cpp \
|
||||
Controllers/CoolerMasterController/CoolerMasterControllerDetect.cpp \
|
||||
Controllers/CorsairLightingNodeController/CorsairLightingNodeController.cpp \
|
||||
Controllers/CorsairLightingNodeController/CorsairLightingNodeControllerDetect.cpp \
|
||||
Controllers/CorsairPeripheralController/CorsairPeripheralController.cpp \
|
||||
Controllers/CorsairPeripheralController/CorsairPeripheralControllerDetect.cpp \
|
||||
Controllers/CorsairVengeanceController/CorsairVengeanceController.cpp \
|
||||
Controllers/CorsairVengeanceController/CorsairVengeanceControllerDetect.cpp \
|
||||
Controllers/CorsairVengeanceProController/CorsairVengeanceProController.cpp \
|
||||
Controllers/CorsairVengeanceProController/CorsairVengeanceProControllerDetect.cpp \
|
||||
Controllers/CrucialController/CrucialController.cpp \
|
||||
Controllers/CrucialController/CrucialControllerDetect.cpp \
|
||||
Controllers/Hue2Controller/Hue2Controller.cpp \
|
||||
Controllers/Hue2Controller/Hue2ControllerDetect.cpp \
|
||||
Controllers/HuePlusController/HuePlusController.cpp \
|
||||
Controllers/HuePlusController/HuePlusControllerDetect.cpp \
|
||||
Controllers/HyperXController/HyperXController.cpp \
|
||||
Controllers/HyperXController/HyperXControllerDetect.cpp \
|
||||
Controllers/HyperXDRAMController/HyperXDRAMController.cpp \
|
||||
Controllers/HyperXDRAMController/HyperXDRAMControllerDetect.cpp \
|
||||
Controllers/HyperXKeyboardController/HyperXKeyboardController.cpp \
|
||||
Controllers/HyperXKeyboardController/HyperXKeyboardControllerDetect.cpp \
|
||||
Controllers/LEDStripController/LEDStripController.cpp \
|
||||
Controllers/LEDStripController/LEDStripControllerDetect.cpp \
|
||||
Controllers/MSI3ZoneController/MSI3ZoneController.cpp \
|
||||
Controllers/MSI3ZoneController/MSI3ZoneControllerDetect.cpp \
|
||||
Controllers/MSIMysticLightController/MSIMysticLightController.cpp \
|
||||
Controllers/MSIMysticLightController/MSIMysticLightControllerDetect.cpp \
|
||||
Controllers/MSIRGBController/MSIRGBController.cpp \
|
||||
Controllers/MSIRGBController/MSIRGBControllerDetect.cpp \
|
||||
Controllers/NZXTKrakenController/NZXTKrakenController.cpp \
|
||||
Controllers/NZXTKrakenController/NZXTKrakenControllerDetect.cpp \
|
||||
Controllers/PatriotViperController/PatriotViperController.cpp \
|
||||
Controllers/PatriotViperController/PatriotViperControllerDetect.cpp \
|
||||
Controllers/PolychromeController/PolychromeController.cpp \
|
||||
@@ -86,35 +134,56 @@ SOURCES += \
|
||||
Controllers/PoseidonZRGBController/PoseidonZRGBControllerDetect.cpp \
|
||||
Controllers/RGBFusionController/RGBFusionController.cpp \
|
||||
Controllers/RGBFusionController/RGBFusionControllerDetect.cpp \
|
||||
Controllers/RGBFusion2Controller/RGBFusion2Controller.cpp \
|
||||
Controllers/RGBFusion2Controller/RGBFusion2ControllerDetect.cpp \
|
||||
Controllers/RGBFusion2USBController/RGBFusion2USBController.cpp \
|
||||
Controllers/RGBFusion2USBController/RGBFusion2USBControllerDetect.cpp \
|
||||
Controllers/RGBFusionGPUController/RGBFusionGPUController.cpp \
|
||||
Controllers/RGBFusionGPUController/RGBFusionGPUControllerDetect.cpp \
|
||||
Controllers/RedragonController/RedragonK556Controller.cpp \
|
||||
Controllers/RedragonController/RedragonM711Controller.cpp \
|
||||
Controllers/RedragonController/RedragonControllerDetect.cpp \
|
||||
Controllers/ThermaltakeRiingController/ThermaltakeRiingController.cpp \
|
||||
Controllers/ThermaltakeRiingController/ThermaltakeRiingControllerDetect.cpp \
|
||||
RGBController/RGBController.cpp \
|
||||
RGBController/E131ControllerDetect.cpp \
|
||||
RGBController/RGBController_AMDWraithPrism.cpp \
|
||||
RGBController/RGBController_Aura.cpp \
|
||||
RGBController/RGBController_Corsair.cpp \
|
||||
RGBController/RGBController_CorsairCmdrPro.cpp \
|
||||
RGBController/RGBController_CorsairKeyboard.cpp \
|
||||
RGBController/RGBController_CorsairNodePro.cpp \
|
||||
RGBController/RGBController_CorsairPro.cpp \
|
||||
RGBController/RGBController_AuraAddressable.cpp \
|
||||
RGBController/RGBController_AuraCore.cpp \
|
||||
RGBController/RGBController_AuraGPU.cpp \
|
||||
RGBController/RGBController_AuraSMBus.cpp \
|
||||
RGBController/RGBController_CMMP750Controller.cpp \
|
||||
RGBController/RGBController_CorsairLightingNode.cpp \
|
||||
RGBController/RGBController_CorsairPeripheral.cpp \
|
||||
RGBController/RGBController_CorsairVengeance.cpp \
|
||||
RGBController/RGBController_CorsairVengeancePro.cpp \
|
||||
RGBController/RGBController_Crucial.cpp \
|
||||
RGBController/RGBController_Dummy.cpp \
|
||||
RGBController/RGBController_Hue2.cpp \
|
||||
RGBController/RGBController_HuePlus.cpp \
|
||||
RGBController/RGBController_HyperX.cpp \
|
||||
RGBController/RGBController_HyperXDRAM.cpp \
|
||||
RGBController/RGBController_HyperXKeyboard.cpp \
|
||||
RGBController/RGBController_E131.cpp \
|
||||
RGBController/RGBController_LEDStrip.cpp \
|
||||
RGBController/RGBController_MSI3Zone.cpp \
|
||||
RGBController/RGBController_MSIMysticLight.cpp \
|
||||
RGBController/RGBController_MSIRGB.cpp \
|
||||
RGBController/RGBController_Network.cpp \
|
||||
RGBController/RGBController_NZXTKraken.cpp \
|
||||
RGBController/RGBController_PatriotViper.cpp \
|
||||
RGBController/RGBController_Polychrome.cpp \
|
||||
RGBController/RGBController_PoseidonZRGB.cpp \
|
||||
RGBController/RGBController_RedragonK556.cpp \
|
||||
RGBController/RGBController_RedragonM711.cpp \
|
||||
RGBController/RGBController_RGBFusion.cpp \
|
||||
RGBController/RGBController_RGBFusion2.cpp \
|
||||
RGBController/RGBController_RGBFusion2USB.cpp \
|
||||
RGBController/RGBController_RGBFusionGPU.cpp \
|
||||
RGBController/RGBController_ThermaltakeRiing.cpp \
|
||||
|
||||
HEADERS += \
|
||||
dependencies/ColorWheel/ColorWheel.h \
|
||||
NetworkClient.h \
|
||||
NetworkProtocol.h \
|
||||
NetworkServer.h \
|
||||
ProfileManager.h \
|
||||
qt/OpenRGBDeviceInfoPage.h \
|
||||
qt/OpenRGBDevicePage.h \
|
||||
qt/OpenRGBDialog.h \
|
||||
@@ -122,97 +191,133 @@ HEADERS += \
|
||||
i2c_tools/i2c_tools.h \
|
||||
net_port/net_port.h \
|
||||
qt/OpenRGBDialog2.h \
|
||||
qt/OpenRGBProfileSaveDialog.h \
|
||||
qt/OpenRGBServerInfoPage.h \
|
||||
qt/OpenRGBSoftwareInfoPage.h \
|
||||
qt/OpenRGBSystemInfoPage.h \
|
||||
qt/OpenRGBZoneResizeDialog.h \
|
||||
serial_port/find_usb_serial_port.h \
|
||||
serial_port/serial_port.h \
|
||||
super_io/super_io.h \
|
||||
Controllers/AMDWraithPrismController/AMDWraithPrismController.h \
|
||||
Controllers/AuraController/AuraController.h \
|
||||
Controllers/CorsairController/CorsairController.h \
|
||||
Controllers/CorsairCmdrProController/CorsairCmdrProController.h \
|
||||
Controllers/CorsairKeyboardController/CorsairKeyboardController.h \
|
||||
Controllers/CorsairNodeProController/CorsairNodeProController.h \
|
||||
Controllers/CorsairProController/CorsairProController.h \
|
||||
Controllers/AuraAddressableController/AuraAddressableController.h \
|
||||
Controllers/AuraCoreController/AuraCoreController.h \
|
||||
Controllers/AuraGPUController/AuraGPUController.h \
|
||||
Controllers/AuraSMBusController/AuraSMBusController.h \
|
||||
Controllers/CoolerMasterController/CMMP750Controller.h \
|
||||
Controllers/CorsairLightingNodeController/CorsairLightingNodeController.h \
|
||||
Controllers/CorsairPeripheralController/CorsairPeripheralController.h \
|
||||
Controllers/CorsairVengeanceController/CorsairVengeanceController.h \
|
||||
Controllers/CorsairVengeanceProController/CorsairVengeanceProController.h \
|
||||
Controllers/CrucialController/CrucialController.h \
|
||||
Controllers/Hue2Controller/Hue2Controller.h \
|
||||
Controllers/HuePlusController/HuePlusController.h \
|
||||
Controllers/HyperXController/HyperXController.h \
|
||||
Controllers/HyperXDRAMController/HyperXDRAMController.h \
|
||||
Controllers/HyperXKeyboardController/HyperXKeyboardController.h \
|
||||
Controllers/LEDStripController/LEDStripController.h \
|
||||
Controllers/MSI3ZoneController/MSI3ZoneController.h \
|
||||
Controllers/MSIMysticLightController/MSIMysticLightController.h \
|
||||
Controllers/MSIRGBController/MSIRGBController.h \
|
||||
Controllers/PatriotViperController/PatriotViperController.h \
|
||||
Controllers/PolychromeController/PolychromeController.h \
|
||||
Controllers/PoseidonZRGBController/PoseidonZRGBController.h \
|
||||
Controllers/RGBFusionController/RGBFusionController.h \
|
||||
Controllers/RGBFusion2Controller/RGBFusion2Controller.h \
|
||||
Controllers/RGBFusion2USBController/RGBFusion2USBController.h \
|
||||
Controllers/RGBFusionGPUController/RGBFusionGPUController.h \
|
||||
Controllers/RedragonController/RedragonK556Controller.h \
|
||||
Controllers/RedragonController/RedragonM711Controller.h \
|
||||
Controllers/ThermaltakeRiingController/ThermaltakeRiingController.h \
|
||||
RGBController/RGBController.h \
|
||||
RGBController/RGBController_AMDWraithPrism.h \
|
||||
RGBController/RGBController_Aura.h \
|
||||
RGBController/RGBController_Corsair.h \
|
||||
RGBController/RGBController_CorsairCmdrPro.h \
|
||||
RGBController/RGBController_CorsairNodePro.h \
|
||||
RGBController/RGBController_CorsairPro.h \
|
||||
RGBController/RGBController_AuraAddressable.h \
|
||||
RGBController/RGBController_AuraCore.h \
|
||||
RGBController/RGBController_AuraGPU.h \
|
||||
RGBController/RGBController_AuraSMBus.h \
|
||||
RGBController/RGBController_CMMP750Controller.h \
|
||||
RGBController/RGBController_CorsairLightingNode.h \
|
||||
RGBController/RGBController_CorsairPeripheral.h \
|
||||
RGBController/RGBController_CorsairVengeance.h \
|
||||
RGBController/RGBController_CorsairVengeancePro.h \
|
||||
RGBController/RGBController_Crucial.h \
|
||||
RGBController/RGBController_Dummy.h \
|
||||
RGBController/RGBController_E131.h \
|
||||
RGBController/RGBController_Hue2.h \
|
||||
RGBController/RGBController_HuePlus.h \
|
||||
RGBController/RGBController_HyperX.h \
|
||||
RGBController/RGBController_HyperXDRAM.h \
|
||||
RGBController/RGBController_HyperXKeyboard.h \
|
||||
RGBController/RGBController_LEDStrip.h \
|
||||
RGBController/RGBController_MSI3Zone.h \
|
||||
RGBController/RGBController_MSIMysticLight.h \
|
||||
RGBController/RGBController_MSIRGB.h \
|
||||
RGBController/RGBController_Network.h \
|
||||
RGBController/RGBController_PatriotViper.h \
|
||||
RGBController/RGBController_Polychrome.h \
|
||||
RGBController/RGBController_PoseidonZRGB.h \
|
||||
RGBController/RGBController_RedragonK556.h \
|
||||
RGBController/RGBController_RedragonM711.h \
|
||||
RGBController/RGBController_RGBFusion.h \
|
||||
RGBController/RGBController_RGBFusion2.h \
|
||||
RGBController/RGBController_RGBFusion2USB.h \
|
||||
RGBController/RGBController_RGBFusionGPU.h \
|
||||
RGBController/RGBController_ThermaltakeRiing.h \
|
||||
|
||||
RESOURCES += \
|
||||
qt/resources.qrc
|
||||
|
||||
FORMS += \
|
||||
qt/OpenRGBDeviceInfoPage.ui \
|
||||
qt/OpenRGBDevicePage.ui \
|
||||
qt/OpenRGBDialog.ui \
|
||||
qt/OpenRGBDialog2.ui \
|
||||
qt/OpenRGBSystemInfoPage.ui
|
||||
qt/OpenRGBDeviceInfoPage.ui \
|
||||
qt/OpenRGBDevicePage.ui \
|
||||
qt/OpenRGBDialog.ui \
|
||||
qt/OpenRGBDialog2.ui \
|
||||
qt/OpenRGBProfileSaveDialog.ui \
|
||||
qt/OpenRGBServerInfoPage.ui \
|
||||
qt/OpenRGBSoftwareInfoPage.ui \
|
||||
qt/OpenRGBSystemInfoPage.ui \
|
||||
qt/OpenRGBZoneResizeDialog.ui \
|
||||
|
||||
#-----------------------------------------------
|
||||
# Windows specific project configuration
|
||||
#-----------------------------------------------
|
||||
win32:INCLUDEPATH += \
|
||||
dependencies/inpout32_1501/Win32/ \
|
||||
dependencies/razer-chroma-2.9.0/inc \
|
||||
dependencies/libusb-1.0.22/include \
|
||||
dependencies/hidapi \
|
||||
dependencies/NVFC \
|
||||
dependencies/openrazer-win32 \
|
||||
wmi/ \
|
||||
|
||||
win32:SOURCES += \
|
||||
dependencies/NVFC/nvapi.cpp \
|
||||
i2c_smbus/i2c_smbus_i801.cpp \
|
||||
i2c_smbus/i2c_smbus_nct6775.cpp \
|
||||
i2c_smbus/i2c_smbus_nvapi.cpp \
|
||||
i2c_smbus/i2c_smbus_piix4.cpp \
|
||||
serial_port/find_usb_serial_port_win.cpp \
|
||||
wmi/wmi.cpp \
|
||||
RGBController/AorusGPUDetect.cpp \
|
||||
RGBController/RGBController_AorusGPU.cpp \
|
||||
RGBController/RazerChromaSDKDetect.cpp \
|
||||
RGBController/RGBController_RazerChromaSDK.cpp \
|
||||
RGBController/OpenRazerWindowsDetect.cpp \
|
||||
RGBController/RGBController_OpenRazerWindows.cpp \
|
||||
|
||||
win32:HEADERS += \
|
||||
dependencies/inpout32_1501/Win32/inpout32.h \
|
||||
dependencies/NVFC/nvapi.h \
|
||||
i2c_smbus/i2c_smbus_i801.h \
|
||||
i2c_smbus/i2c_smbus_nct6775.h \
|
||||
i2c_smbus/i2c_smbus_nvapi.h \
|
||||
i2c_smbus/i2c_smbus_piix4.h \
|
||||
wmi/wmi.h \
|
||||
RGBController/RGBController_AorusGPU.h \
|
||||
RGBController/RGBController_RazerChromaSDK.h \
|
||||
RGBController/RGBController_OpenRazerWindows.h \
|
||||
|
||||
win32:LIBS += \
|
||||
-lws2_32 \
|
||||
-L"$$PWD/dependencies/inpout32_1501/Win32/" -linpout32 \
|
||||
-L"$$PWD/dependencies/libusb-1.0.22/MS32/dll" -llibusb-1.0 \
|
||||
-L"$$PWD/dependencies/hidapi-win/x86/" -lhidapi
|
||||
win32:contains(QMAKE_TARGET.arch, x86_64) {
|
||||
LIBS += \
|
||||
-lws2_32 \
|
||||
-L"$$PWD/dependencies/inpout32_1501/x64/" -linpoutx64 \
|
||||
-L"$$PWD/dependencies/libusb-1.0.22/MS64/dll" -llibusb-1.0 \
|
||||
}
|
||||
|
||||
win32:contains(QMAKE_TARGET.arch, x86) {
|
||||
LIBS += \
|
||||
-lws2_32 \
|
||||
-L"$$PWD/dependencies/inpout32_1501/Win32/" -linpout32 \
|
||||
-L"$$PWD/dependencies/libusb-1.0.22/MS32/dll" -llibusb-1.0 \
|
||||
}
|
||||
|
||||
win32:DEFINES -= \
|
||||
UNICODE
|
||||
@@ -224,6 +329,23 @@ win32:DEFINES += \
|
||||
_WINSOCK_DEPRECATED_NO_WARNINGS \
|
||||
WIN32_LEAN_AND_MEAN
|
||||
|
||||
# Copy OpenRazer.dll to output directory
|
||||
win32:contains(QMAKE_TARGET.arch, x86_64) {
|
||||
copydata.commands = $(COPY_FILE) \"$$shell_path($$PWD\\dependencies\\openrazer-win32\\OpenRazer64.dll)\" \"$$shell_path($$OUT_PWD)\"
|
||||
first.depends = $(first) copydata
|
||||
export(first.depends)
|
||||
export(copydata.commands)
|
||||
QMAKE_EXTRA_TARGETS += first copydata
|
||||
}
|
||||
|
||||
win32:contains(QMAKE_TARGET.arch, x86) {
|
||||
copydata.commands = $(COPY_FILE) \"$$shell_path($$PWD\\dependencies\\openrazer-win32\\OpenRazer.dll)\" \"$$shell_path($$OUT_PWD)\"
|
||||
first.depends = $(first) copydata
|
||||
export(first.depends)
|
||||
export(copydata.commands)
|
||||
QMAKE_EXTRA_TARGETS += first copydata
|
||||
}
|
||||
|
||||
#-----------------------------------------------
|
||||
# Linux specific project configuration
|
||||
#-----------------------------------------------
|
||||
@@ -235,17 +357,7 @@ unix:HEADERS += \
|
||||
|
||||
unix:LIBS += \
|
||||
-lusb-1.0 \
|
||||
|
||||
packagesExist(hidapi-libusb){
|
||||
unix:LIBS += -lhidapi-libusb
|
||||
} else {
|
||||
packagesExist(hidapi) {
|
||||
unix:LIBS += -lhidapi
|
||||
} else {
|
||||
unix:LIBS += -lhidapi-libusb
|
||||
}
|
||||
}
|
||||
|
||||
-lstdc++fs \
|
||||
|
||||
unix:SOURCES += \
|
||||
i2c_smbus/i2c_smbus_linux.cpp \
|
||||
|
||||
@@ -0,0 +1,300 @@
|
||||
#include "ProfileManager.h"
|
||||
#include "RGBController_Dummy.h"
|
||||
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
|
||||
#include <experimental/filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
namespace fs = std::experimental::filesystem;
|
||||
|
||||
ProfileManager::ProfileManager(std::vector<RGBController *>& control) : controllers(control)
|
||||
{
|
||||
UpdateProfileList();
|
||||
}
|
||||
|
||||
ProfileManager::~ProfileManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool ProfileManager::SaveProfile(std::string profile_name)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| If a name was entered, save the profile file |
|
||||
\*---------------------------------------------------------*/
|
||||
if(profile_name != "")
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Open an output file in binary mode |
|
||||
\*---------------------------------------------------------*/
|
||||
std::ofstream controller_file(profile_name, std::ios::out | std::ios::binary);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Write header |
|
||||
| 16 bytes - "OPENRGB_PROFILE" |
|
||||
| 4 bytes - Version, unsigned int |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned int profile_version = 1;
|
||||
controller_file.write("OPENRGB_PROFILE", 16);
|
||||
controller_file.write((char *)&profile_version, sizeof(unsigned int));
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Write controller data for each controller |
|
||||
\*---------------------------------------------------------*/
|
||||
for(std::size_t controller_index = 0; controller_index < controllers.size(); controller_index++)
|
||||
{
|
||||
unsigned char *controller_data = controllers[controller_index]->GetDeviceDescription();
|
||||
unsigned int controller_size;
|
||||
|
||||
memcpy(&controller_size, controller_data, sizeof(controller_size));
|
||||
|
||||
controller_file.write((const char *)controller_data, controller_size);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Close the file when done |
|
||||
\*---------------------------------------------------------*/
|
||||
controller_file.close();
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Update the profile list |
|
||||
\*---------------------------------------------------------*/
|
||||
UpdateProfileList();
|
||||
|
||||
return(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
bool ProfileManager::LoadProfile(std::string profile_name)
|
||||
{
|
||||
return(LoadProfileWithOptions(profile_name, false, true));
|
||||
}
|
||||
|
||||
bool ProfileManager::LoadSizeFromProfile(std::string profile_name)
|
||||
{
|
||||
return(LoadProfileWithOptions(profile_name, true, false));
|
||||
}
|
||||
|
||||
bool ProfileManager::LoadProfileWithOptions
|
||||
(
|
||||
std::string profile_name,
|
||||
bool load_size,
|
||||
bool load_settings
|
||||
)
|
||||
{
|
||||
std::vector<RGBController*> temp_controllers;
|
||||
std::vector<bool> temp_controller_used;
|
||||
unsigned int controller_size;
|
||||
unsigned int controller_offset = 0;
|
||||
bool ret_val = false;
|
||||
|
||||
std::string filename = profile_name;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Open input file in binary mode |
|
||||
\*---------------------------------------------------------*/
|
||||
std::ifstream controller_file(filename, std::ios::in | std::ios::binary);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Read and verify file header |
|
||||
\*---------------------------------------------------------*/
|
||||
char header_string[16];
|
||||
unsigned int header_version;
|
||||
|
||||
controller_file.read(header_string, 16);
|
||||
controller_file.read((char *)&header_version, sizeof(unsigned int));
|
||||
|
||||
controller_offset += 16 + sizeof(unsigned int);
|
||||
controller_file.seekg(controller_offset);
|
||||
|
||||
if(strcmp(header_string, "OPENRGB_PROFILE") == 0)
|
||||
{
|
||||
if(header_version == 1)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Read controller data from file until EOF |
|
||||
\*---------------------------------------------------------*/
|
||||
while(!(controller_file.peek() == EOF))
|
||||
{
|
||||
controller_file.read((char *)&controller_size, sizeof(controller_size));
|
||||
|
||||
unsigned char *controller_data = new unsigned char[controller_size];
|
||||
|
||||
controller_file.seekg(controller_offset);
|
||||
|
||||
controller_file.read((char *)controller_data, controller_size);
|
||||
|
||||
RGBController_Dummy *temp_controller = new RGBController_Dummy();
|
||||
|
||||
temp_controller->ReadDeviceDescription(controller_data);
|
||||
|
||||
temp_controllers.push_back(temp_controller);
|
||||
temp_controller_used.push_back(false);
|
||||
|
||||
delete[] controller_data;
|
||||
|
||||
controller_offset += controller_size;
|
||||
controller_file.seekg(controller_offset);
|
||||
|
||||
ret_val = true;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Loop through all controllers. For each controller, search|
|
||||
| all saved controllers until a match is found |
|
||||
\*---------------------------------------------------------*/
|
||||
for(std::size_t controller_index = 0; controller_index < controllers.size(); controller_index++)
|
||||
{
|
||||
RGBController *controller_ptr = controllers[controller_index];
|
||||
|
||||
for(std::size_t temp_index = 0; temp_index < temp_controllers.size(); temp_index++)
|
||||
{
|
||||
RGBController *temp_controller = temp_controllers[temp_index];
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Test if saved controller data matches this controller |
|
||||
\*---------------------------------------------------------*/
|
||||
if((temp_controller_used[temp_index] == false )
|
||||
&&(temp_controller->type == controller_ptr->type )
|
||||
&&(temp_controller->name == controller_ptr->name )
|
||||
&&(temp_controller->description == controller_ptr->description)
|
||||
&&(temp_controller->version == controller_ptr->version )
|
||||
&&(temp_controller->serial == controller_ptr->serial )
|
||||
&&(temp_controller->location == controller_ptr->location ))
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Update zone sizes if requested |
|
||||
\*---------------------------------------------------------*/
|
||||
if(load_size)
|
||||
{
|
||||
if(temp_controller->zones.size() == controller_ptr->zones.size())
|
||||
{
|
||||
for(std::size_t zone_idx = 0; zone_idx < temp_controller->zones.size(); zone_idx++)
|
||||
{
|
||||
if((temp_controller->zones[zone_idx].name == controller_ptr->zones[zone_idx].name )
|
||||
&&(temp_controller->zones[zone_idx].type == controller_ptr->zones[zone_idx].type )
|
||||
&&(temp_controller->zones[zone_idx].leds_min == controller_ptr->zones[zone_idx].leds_min )
|
||||
&&(temp_controller->zones[zone_idx].leds_max == controller_ptr->zones[zone_idx].leds_max )
|
||||
&&(temp_controller->zones[zone_idx].leds_count != controller_ptr->zones[zone_idx].leds_count))
|
||||
{
|
||||
controller_ptr->ResizeZone(zone_idx, temp_controller->zones[zone_idx].leds_count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Update settings if requested |
|
||||
\*---------------------------------------------------------*/
|
||||
if(load_settings)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Update all modes |
|
||||
\*---------------------------------------------------------*/
|
||||
if(temp_controller->modes.size() == controller_ptr->modes.size())
|
||||
{
|
||||
for(std::size_t mode_index = 0; mode_index < temp_controller->modes.size(); mode_index++)
|
||||
{
|
||||
if((temp_controller->modes[mode_index].name == controller_ptr->modes[mode_index].name )
|
||||
&&(temp_controller->modes[mode_index].value == controller_ptr->modes[mode_index].value )
|
||||
&&(temp_controller->modes[mode_index].flags == controller_ptr->modes[mode_index].flags )
|
||||
&&(temp_controller->modes[mode_index].speed_min == controller_ptr->modes[mode_index].speed_min )
|
||||
&&(temp_controller->modes[mode_index].speed_max == controller_ptr->modes[mode_index].speed_max )
|
||||
&&(temp_controller->modes[mode_index].colors_min == controller_ptr->modes[mode_index].colors_min)
|
||||
&&(temp_controller->modes[mode_index].colors_max == controller_ptr->modes[mode_index].colors_max))
|
||||
{
|
||||
controller_ptr->modes[mode_index].speed = temp_controller->modes[mode_index].speed;
|
||||
controller_ptr->modes[mode_index].direction = temp_controller->modes[mode_index].direction;
|
||||
controller_ptr->modes[mode_index].color_mode = temp_controller->modes[mode_index].color_mode;
|
||||
|
||||
controller_ptr->modes[mode_index].colors.resize(temp_controller->modes[mode_index].colors.size());
|
||||
|
||||
for(std::size_t mode_color_index = 0; mode_color_index < temp_controller->modes[mode_index].colors.size(); mode_color_index++)
|
||||
{
|
||||
controller_ptr->modes[mode_index].colors[mode_color_index] = temp_controller->modes[mode_index].colors[mode_color_index];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
controller_ptr->active_mode = temp_controller->active_mode;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Update all colors |
|
||||
\*---------------------------------------------------------*/
|
||||
if(temp_controller->colors.size() == controller_ptr->colors.size())
|
||||
{
|
||||
for(std::size_t color_index = 0; color_index < temp_controller->colors.size(); color_index++)
|
||||
{
|
||||
controller_ptr->colors[color_index] = temp_controller->colors[color_index];
|
||||
}
|
||||
}
|
||||
|
||||
temp_controller_used[temp_index] = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return(ret_val);
|
||||
}
|
||||
|
||||
void ProfileManager::DeleteProfile(std::string profile_name)
|
||||
{
|
||||
remove(profile_name.c_str());
|
||||
|
||||
UpdateProfileList();
|
||||
}
|
||||
|
||||
void ProfileManager::UpdateProfileList()
|
||||
{
|
||||
profile_list.clear();
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Load profiles by looking for .orp files in current dir |
|
||||
\*---------------------------------------------------------*/
|
||||
for(const auto & entry : fs::directory_iterator("."))
|
||||
{
|
||||
std::string filename = entry.path().filename().string();
|
||||
|
||||
if(filename.find(".orp") != std::string::npos)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Open input file in binary mode |
|
||||
\*---------------------------------------------------------*/
|
||||
std::ifstream profile_file(filename, std::ios::in | std::ios::binary);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Read and verify file header |
|
||||
\*---------------------------------------------------------*/
|
||||
char header_string[16];
|
||||
unsigned int header_version;
|
||||
|
||||
profile_file.read(header_string, 16);
|
||||
profile_file.read((char *)&header_version, sizeof(unsigned int));
|
||||
|
||||
if(strcmp(header_string, "OPENRGB_PROFILE") == 0)
|
||||
{
|
||||
if(header_version == 1)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Add this profile to the list |
|
||||
\*---------------------------------------------------------*/
|
||||
profile_list.push_back(filename);
|
||||
}
|
||||
}
|
||||
|
||||
profile_file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "RGBController.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
class ProfileManager
|
||||
{
|
||||
public:
|
||||
ProfileManager(std::vector<RGBController *>& control);
|
||||
~ProfileManager();
|
||||
|
||||
bool SaveProfile(std::string profile_name);
|
||||
bool LoadProfile(std::string profile_name);
|
||||
bool LoadSizeFromProfile(std::string profile_name);
|
||||
void DeleteProfile(std::string profile_name);
|
||||
|
||||
std::vector<std::string> profile_list;
|
||||
|
||||
protected:
|
||||
std::vector<RGBController *>& controllers;
|
||||
|
||||
private:
|
||||
void UpdateProfileList();
|
||||
bool LoadProfileWithOptions
|
||||
(
|
||||
std::string profile_name,
|
||||
bool load_size,
|
||||
bool load_settings
|
||||
);
|
||||
};
|
||||
@@ -1,56 +1,137 @@
|
||||
# OpenRGB (formerly OpenAuraSDK)
|
||||
##  (formerly OpenAuraSDK)
|
||||
|
||||
The goal of this project is to create an easy-to-use open source software program and library for accessing and controlling RGB lights on various PC hardware including motherboards, RAM modules, graphics cards, cooling devices, and peripherals.
|
||||
|
||||
This project originally focused only on ASUS Aura. It was spun off of Keyboard Visualizer's AsusAuraWindows branch to learn more about the details behind the Aura protocol and to develop a more flexible, compatible, and reliable driver for Aura. Our Aura implementation is now quite solid and supports multiple generations of Aura controller across both Intel and AMD platforms. It also supports Aura-compatible controllers used across multiple manufacturers of RGB memory modules including G.Skill Trident Z RGB and others. It is still lacking a few capabilities, namely saving settings to persist across reboots, but the core functionality of setting colors and modes is there.
|
||||
|
||||
After getting a solid Aura implementation, the project branched out into other manufacturers and categories of RGB devices. A major focus was to develop a software API that could reliably represent as many RGB devices as possible, exposing their various modes and describing their LED layouts via zones, that was generic enough to write a user application without specifically targeting any one manufacturer. To this extent, the generic_rgb_interface_test branch was created which became the foundation of OpenRGB. The goal of OpenRGB is to both develop new drivers for unsupported devices and integrate existing open source drivers for devices that do have some sort of open support. The goal is to be the one-stop solution to open source RGB lighting control!
|
||||
One of the biggest complaints about RGB is the software ecosystem surrounding it. Every manufacturer has their own app, their own brand, their own style. If you want to mix and match devices, you end up with a ton of conflicting, functionally identical apps competing for your background resources. On top of that, these apps are proprietary and Windows-only. Some even require online accounts. What if there was a way to control all of your RGB devices from a single app, on both Windows and Linux, without any nonsense? That is what OpenRGB sets out to achieve. One app to rule them all.
|
||||
OpenRGB is still in its early stages and already supports quite a few products. I'm always on the lookout for good deals on more popular RGB devices to add support for.
|
||||
|
||||
## Supported Devices
|
||||
|
||||
See the [Project Wiki](https://gitlab.com/CalcProgrammer1/OpenRGB/-/wikis/home) for the current list of supported devices.
|
||||
|
||||
## Installation
|
||||
#### Windows
|
||||
1. Download the latest Visual Studio Community Edition and Qt Creator.
|
||||
2. Update the submodules: git submodule update --init --recursive
|
||||
3. Open the OpenRGB_Win.pro project.
|
||||
4. Build the project for `x86` Architecture. The InpOut32 library I use does not support x64.
|
||||
5. Copy InpOut32.dll from dependencies to the same path as OpenAuraSDK.exe along with the Qt libraries.
|
||||
## WARNING!
|
||||
|
||||
**You must run the application as Administrator the first time to allow InpOut32 to set up. It can be run as a normal user afterwards**
|
||||
This project provides a tool to probe the SMBus. This is a potentially dangerous operation if you don't know what you're doing. Exercise caution when clicking the Detect Devices or Dump Device buttons. There have been reports of Gigabyte motherboards having serious issues (bricking the RGB or bricking the entire board) when dumping certain devices. On the same lines, exercise the same caution when using the i2cdump and i2cdetect commands on Linux, as they perform the same functionality. OpenRGB is not liable for damage caused by improper SMBus access.
|
||||
|
||||
#### Linux:
|
||||
1. Either open the project using QT Creator or build it using qmake. You will need the libusb-1.0-0 (or equivalent) and libhidapi development packages from your distribution's package manager installed.
|
||||
As of now, only Gigabyte RGB Fusion 2.0 boards have been reported to have issues.
|
||||
|
||||

|
||||
|
||||
## Windows
|
||||
* Pre-built binaries are available under the Releases section on GitLab.
|
||||
|
||||
* If you wish to build the application yourself:
|
||||
|
||||
1. Download the latest Visual Studio Community Edition and Qt Creator.
|
||||
2. Open the OpenRGB.pro project in Qt Creator.
|
||||
3. Use the MSVC compiler kit, either 32- or 64-bit, to build the application.
|
||||
4. Run the project from Qt Creator. If you want to use your custom build standalone, download the latest matching Release package and replace the OpenRGB.exe in it with your new build.
|
||||
|
||||
* **You must run the application as Administrator the first time to allow InpOut32 to set up. It can be run as a normal user afterwards**
|
||||
|
||||
### USB Access
|
||||
|
||||
* Some USB devices (especially keyboards and mice) require installation of the WinUSB driver. You can do this with Zadig:
|
||||
- Download Zadig: https://zadig.akeo.ie/
|
||||
- Select "list all devices" from the menu
|
||||
- Select the last interface of your device
|
||||
- With "WinUSB" selected, click Install
|
||||
|
||||
## Linux
|
||||
* Pre-built binaries are not currently available for Linux
|
||||
|
||||
* You can build the project using Qt Creator or on the command line. The commands listed here work for Debian-based distros.
|
||||
|
||||
1. sudo apt install build-essential qtcreator qt5-default libusb-1.0-0-dev
|
||||
2. git clone https://gitlab.com/CalcProgrammer1/OpenRGB
|
||||
3. cd OpenRGB
|
||||
4. qmake OpenRGB.pro
|
||||
5. make -j8
|
||||
|
||||
* sudo apt install qt5-default libusb-1.0-0-dev libhidapi-dev
|
||||
|
||||
* git clone https://gitlab.com/CalcProgrammer1/OpenRGB
|
||||
|
||||
* cd OpenRGB
|
||||
|
||||
* git submodule update --init --recursive
|
||||
|
||||
* qmake OpenRGB.pro
|
||||
|
||||
* make -j8
|
||||
|
||||
* ./OpenRGB
|
||||
* Run the application with ./OpenRGB
|
||||
|
||||
### SMBus Access
|
||||
|
||||
2. Allow access to SMBus:<br>
|
||||
* SMBus access is necessary for controlling RGB RAM and certain motherboard on-board LEDs.
|
||||
|
||||
- This can be identified by your motherboard
|
||||
##### Intel
|
||||
- `modprobe i2c-dev i2c-i801`
|
||||
- Asus used the SMBus controller on the Super IO chip for on-board Aura chips on Intel motherboards. I have a kernel patch to add a driver for this chip [here](https://gitlab.com/CalcProgrammer1/OpenAuraSDK/issues/22). After patching the kernel, enable the Nuvoton NCT67xx SMBus driver in your kernel configuration. The driver may be loaded with `modprobe i2c-nct6775`
|
||||
##### AMD
|
||||
- `modprobe i2c-dev i2c-piix4`
|
||||
- The second SMBus isn't currently picked up by the kernel driver and that seems to be where Asus wired the Aura controllers so I have a kernel patch [here](https://gitlab.com/CalcProgrammer1/OpenAuraSDK/issues/9) that will allow the kernel to use the second bus (at `0x0b20`).
|
||||
* If you are not trying to use OpenRGB to control RGB RAM or motherboard LEDs, you may skip this section.
|
||||
|
||||
- You'll have to enable user access to your SMbus if you don't run as root.
|
||||
- List all SMBus controllers: `sudo i2cdetect -l`
|
||||
- Find out which control your Aura devices (PIIX4, I801, and NCT67xx)
|
||||
- Give user access to those controllers, for instance: `sudo chmod 777 /dev/i2c-0`
|
||||
* ASUS and ASRock motherboards have their RGB controller on an SMBus interface that is not accessible by an unmodified Linux kernel (for now). I am working on getting patches submitted upstream, but for now you must patch your kernel with the provided OpenRGB.patch file.
|
||||
|
||||
* Allowing access to SMBus:
|
||||
|
||||
1. Load the i2c-dev module: `sudo modprobe i2c-dev`
|
||||
|
||||
2. Load the i2c driver for your chipset:
|
||||
- Intel:
|
||||
- `sudo modprobe i2c-i801`
|
||||
- `sudo modprobe i2c-nct6775` - Secondary controller for motherboard LEDs (requires patch)
|
||||
- AMD:
|
||||
- `modprobe i2c-piix4`
|
||||
- Unmodified kernel will have one interface, patched kernel will have two. The first at 0x0B00 and the second at 0x0B20. The 0x0B20 interface is for motherboard LEDs.
|
||||
|
||||
* Instructions on patching the kernel:
|
||||
- https://gitlab.com/CalcProgrammer1/OpenRGB/-/wikis/OpenRGB-Kernel-Patch
|
||||
|
||||
* Some Gigabyte/Aorus motherboards have an ACPI conflict with the SMBus controller.
|
||||
- Add `acpi_enforce_resources=lax` to your kernel command line and reboot. The controller should now show up.
|
||||
|
||||
* You'll have to enable user access to your SMBus if you don't run as root.
|
||||
- List all SMBus controllers: `sudo i2cdetect -l`
|
||||
- Note the number for PIIX4, I801, and NCT6775 controllers.
|
||||
- Give user access to those controllers, for instance: `sudo chmod 777 /dev/i2c-0`
|
||||
|
||||
### USB Access
|
||||
|
||||
* USB devices require udev rules to access as a normal user.
|
||||
|
||||
* You can run OpenRGB as root to detect all USB devices.
|
||||
|
||||
* Udev rules can be found here:
|
||||
- https://drive.google.com/drive/folders/1tWVbeOLiLns_IhgyNDWqSK3ZKtP-6oYM?usp=sharing
|
||||
- Copy the .rules files to /etc/udev/rules.d/
|
||||
- Reload rules with `sudo udevadm control --reload-rules && sudo udevadm trigger`
|
||||
- Add your user to the `plugdev` group: `sudo adduser username plugdev`
|
||||
|
||||
## Projects Used
|
||||
|
||||
* InpOutx64: http://www.highrez.co.uk/downloads/inpout32/
|
||||
|
||||
* libusb: https://github.com/libusb/libusb
|
||||
|
||||
* hidapi: https://github.com/libusb/hidapi
|
||||
|
||||
* libe131: https://github.com/hhromic/libe131
|
||||
|
||||
* NVFC: https://github.com/graphitemaster/NVFC
|
||||
|
||||
* OpenRazer: https://github.com/openrazer/openrazer
|
||||
|
||||
* OpenRazer-Win32: https://github.com/CalcProgrammer1/openrazer-win32
|
||||
|
||||
* Qt-Plus (ColorWheel): https://github.com/liuyanghejerry/Qt-Plus
|
||||
|
||||
## Projects Researched
|
||||
|
||||
While no code from these projects directly made its way into OpenRGB, these projects have been invaluable resources for protocol information.
|
||||
|
||||
* ckb-next: https://github.com/ckb-next/ckb-next
|
||||
|
||||
* linux_thermaltake_riing: https://github.com/chestm007/linux_thermaltake_riing
|
||||
|
||||
* Aura Addressable Header Controller: https://gitlab.com/cneil02/aura-addressable-header-controller
|
||||
|
||||
* OpenPyAURA: https://gitlab.com/thelastguardian/openpyaura
|
||||
|
||||
* AsrLed: https://github.com/EUA/AsrLed
|
||||
|
||||
* asrock-leds: https://github.com/RattyDAVE/asrock-leds
|
||||
|
||||
* hue-plus: https://github.com/kusti8/hue-plus
|
||||
|
||||
* rogauracore: https://github.com/wroberts/rogauracore
|
||||
|
||||
* msi-rgb: https://github.com/nagisa/msi-rgb
|
||||
|
||||
* OpenCorsairLink: https://github.com/audiohacked/OpenCorsairLink
|
||||
|
||||
* msi-keyboard: https://github.com/bparker06/msi-keyboard
|
||||
@@ -1,21 +0,0 @@
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_AorusGPU.h"
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectAorusGPUControllers *
|
||||
* *
|
||||
* Detect devices supported by the Aorus GPU driver *
|
||||
* * *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectAorusGPUControllers(std::vector<RGBController*> &rgb_controllers)
|
||||
{
|
||||
RGBController_AorusGPU * aorus_rgb = new RGBController_AorusGPU();
|
||||
|
||||
rgb_controllers.push_back(aorus_rgb);
|
||||
} /* DetectLEDStripControllers() */
|
||||
@@ -58,7 +58,7 @@ void DetectOpenRazerControllers(std::vector<RGBController*> &rgb_controllers)
|
||||
break;
|
||||
|
||||
case 7:
|
||||
strcpy(driver_path, "/sys/bus/hid/drivers/razerchromahdk/");
|
||||
strcpy(driver_path, "/sys/bus/hid/drivers/razeraccessory/");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -68,8 +68,6 @@ void DetectOpenRazerControllers(std::vector<RGBController*> &rgb_controllers)
|
||||
|
||||
if(dir == NULL)
|
||||
{
|
||||
closedir(dir);
|
||||
|
||||
driver_to_read++;
|
||||
continue;
|
||||
}
|
||||
@@ -102,7 +100,7 @@ void DetectOpenRazerControllers(std::vector<RGBController*> &rgb_controllers)
|
||||
|
||||
RGBController_OpenRazer * razer_rgb = new RGBController_OpenRazer(device_string);
|
||||
|
||||
if(razer_rgb->device != -1)
|
||||
if(razer_rgb->device_index != -1)
|
||||
{
|
||||
rgb_controllers.push_back(razer_rgb);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,252 @@
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_OpenRazerWindows.h"
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <Windows.h>
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/hid.h>
|
||||
|
||||
#ifdef _WIN64
|
||||
#define OPENRAZERDLL "OpenRazer64.dll"
|
||||
#elif WIN32
|
||||
#define OPENRAZERDLL "OpenRazer.dll"
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct device_attribute* dev_attr_list[44];
|
||||
} device_fn_list_type;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| This is a table of device attribute names. It should |
|
||||
| always match the order of the entries in the structure |
|
||||
\*---------------------------------------------------------*/
|
||||
static const char* device_fn_names[] =
|
||||
{
|
||||
"device_type",
|
||||
"device_serial",
|
||||
"firmware_version",
|
||||
|
||||
"matrix_custom_frame",
|
||||
"matrix_brightness",
|
||||
|
||||
"matrix_effect_custom",
|
||||
"matrix_effect_none",
|
||||
"matrix_effect_static",
|
||||
"matrix_effect_breath",
|
||||
"matrix_effect_spectrum",
|
||||
"matrix_effect_reactive",
|
||||
"matrix_effect_wave",
|
||||
|
||||
"logo_led_brightness",
|
||||
"logo_matrix_effect_none",
|
||||
"logo_matrix_effect_static",
|
||||
"logo_matrix_effect_breath",
|
||||
"logo_matrix_effect_spectrum",
|
||||
"logo_matrix_effect_reactive",
|
||||
|
||||
"scroll_led_brightness",
|
||||
"scroll_matrix_effect_none",
|
||||
"scroll_matrix_effect_static",
|
||||
"scroll_matrix_effect_breath",
|
||||
"scroll_matrix_effect_spectrum",
|
||||
"scroll_matrix_effect_reactive",
|
||||
|
||||
"left_led_brightness",
|
||||
"left_matrix_effect_none",
|
||||
"left_matrix_effect_static",
|
||||
"left_matrix_effect_breath",
|
||||
"left_matrix_effect_spectrum",
|
||||
"left_matrix_effect_reactive",
|
||||
"left_matrix_effect_wave",
|
||||
|
||||
"right_led_brightness",
|
||||
"right_matrix_effect_none",
|
||||
"right_matrix_effect_static",
|
||||
"right_matrix_effect_breath",
|
||||
"right_matrix_effect_spectrum",
|
||||
"right_matrix_effect_reactive",
|
||||
"right_matrix_effect_wave",
|
||||
|
||||
"logo_led_effect",
|
||||
"logo_led_rgb",
|
||||
"logo_led_state",
|
||||
|
||||
"scroll_led_effect",
|
||||
"scroll_led_rgb",
|
||||
"scroll_led_state"
|
||||
};
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| This function searches the device attribute list of a |
|
||||
| given device to fill in a device_fn_type structure |
|
||||
\*---------------------------------------------------------*/
|
||||
static void load_device_fn(device_fn_type* device_fn, device* dev)
|
||||
{
|
||||
memset(device_fn, 0, sizeof(device_fn_type));
|
||||
|
||||
for (int table_idx = 0; table_idx < 44; table_idx++)
|
||||
{
|
||||
for (int list_idx = 0; list_idx < dev->attr_count; list_idx++)
|
||||
{
|
||||
if (strcmp(device_fn_names[table_idx], dev->attr_list[list_idx]->name) == 0)
|
||||
{
|
||||
((device_fn_list_type*)device_fn)->dev_attr_list[table_idx] = dev->attr_list[list_idx];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectOpenRazerControllers *
|
||||
* *
|
||||
* Detect devices supported by the OpenRazer kernel drivers *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectOpenRazerControllers(std::vector<RGBController*> &rgb_controllers)
|
||||
{
|
||||
static HMODULE module = LoadLibrary(OPENRAZERDLL);
|
||||
|
||||
if(module == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Map DLL functions |
|
||||
\*---------------------------------------------------------*/
|
||||
typedef unsigned int(*INITRAZERDRIVER)(struct hid_device** hdev);
|
||||
|
||||
INITRAZERDRIVER init_razer_kbd_driver = reinterpret_cast<INITRAZERDRIVER>(GetProcAddress(module, "init_razer_kbd_driver"));
|
||||
INITRAZERDRIVER init_razer_mousemat_driver = reinterpret_cast<INITRAZERDRIVER>(GetProcAddress(module, "init_razer_mousemat_driver"));
|
||||
INITRAZERDRIVER init_razer_mouse_driver = reinterpret_cast<INITRAZERDRIVER>(GetProcAddress(module, "init_razer_mouse_driver"));
|
||||
INITRAZERDRIVER init_razer_accessory_driver = reinterpret_cast<INITRAZERDRIVER>(GetProcAddress(module, "init_razer_accessory_driver"));
|
||||
INITRAZERDRIVER init_razer_kraken_driver = reinterpret_cast<INITRAZERDRIVER>(GetProcAddress(module, "init_razer_kraken_driver"));
|
||||
INITRAZERDRIVER init_razer_core_driver = reinterpret_cast<INITRAZERDRIVER>(GetProcAddress(module, "init_razer_core_driver"));
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Initialize all OpenRazer driver modules and store devices |
|
||||
\*---------------------------------------------------------*/
|
||||
struct hid_device* hdev;
|
||||
unsigned int num;
|
||||
|
||||
hdev = NULL;
|
||||
num = init_razer_kbd_driver(&hdev);
|
||||
for (unsigned int i = 0; i < num; i++)
|
||||
{
|
||||
device_fn_type* device_fn = new device_fn_type;
|
||||
load_device_fn(device_fn, &hdev[i].dev);
|
||||
|
||||
RGBController_OpenRazer * razer_rgb = new RGBController_OpenRazer(&hdev[i].dev, device_fn);
|
||||
|
||||
if(razer_rgb->device_index != -1)
|
||||
{
|
||||
rgb_controllers.push_back(razer_rgb);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete razer_rgb;
|
||||
}
|
||||
}
|
||||
|
||||
hdev = NULL;
|
||||
num = init_razer_mouse_driver(&hdev);
|
||||
for (unsigned int i = 0; i < num; i++)
|
||||
{
|
||||
device_fn_type* device_fn = new device_fn_type;
|
||||
load_device_fn(device_fn, &hdev[i].dev);
|
||||
|
||||
RGBController_OpenRazer * razer_rgb = new RGBController_OpenRazer(&hdev[i].dev, device_fn);
|
||||
|
||||
if(razer_rgb->device_index != -1)
|
||||
{
|
||||
rgb_controllers.push_back(razer_rgb);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete razer_rgb;
|
||||
}
|
||||
}
|
||||
|
||||
hdev = NULL;
|
||||
num = init_razer_mousemat_driver(&hdev);
|
||||
for (unsigned int i = 0; i < num; i++)
|
||||
{
|
||||
device_fn_type* device_fn = new device_fn_type;
|
||||
load_device_fn(device_fn, &hdev[i].dev);
|
||||
|
||||
RGBController_OpenRazer * razer_rgb = new RGBController_OpenRazer(&hdev[i].dev, device_fn);
|
||||
|
||||
if(razer_rgb->device_index != -1)
|
||||
{
|
||||
rgb_controllers.push_back(razer_rgb);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete razer_rgb;
|
||||
}
|
||||
}
|
||||
|
||||
hdev = NULL;
|
||||
num = init_razer_accessory_driver(&hdev);
|
||||
for (unsigned int i = 0; i < num; i++)
|
||||
{
|
||||
device_fn_type* device_fn = new device_fn_type;
|
||||
load_device_fn(device_fn, &hdev[i].dev);
|
||||
|
||||
RGBController_OpenRazer * razer_rgb = new RGBController_OpenRazer(&hdev[i].dev, device_fn);
|
||||
|
||||
if(razer_rgb->device_index != -1)
|
||||
{
|
||||
rgb_controllers.push_back(razer_rgb);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete razer_rgb;
|
||||
}
|
||||
}
|
||||
|
||||
hdev = NULL;
|
||||
num = init_razer_kraken_driver(&hdev);
|
||||
for (unsigned int i = 0; i < num; i++)
|
||||
{
|
||||
device_fn_type* device_fn = new device_fn_type;
|
||||
load_device_fn(device_fn, &hdev[i].dev);
|
||||
|
||||
RGBController_OpenRazer * razer_rgb = new RGBController_OpenRazer(&hdev[i].dev, device_fn);
|
||||
|
||||
if(razer_rgb->device_index != -1)
|
||||
{
|
||||
rgb_controllers.push_back(razer_rgb);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete razer_rgb;
|
||||
}
|
||||
}
|
||||
|
||||
hdev = NULL;
|
||||
num = init_razer_core_driver(&hdev);
|
||||
for (unsigned int i = 0; i < num; i++)
|
||||
{
|
||||
device_fn_type* device_fn = new device_fn_type;
|
||||
load_device_fn(device_fn, &hdev[i].dev);
|
||||
|
||||
RGBController_OpenRazer * razer_rgb = new RGBController_OpenRazer(&hdev[i].dev, device_fn);
|
||||
|
||||
if(razer_rgb->device_index != -1)
|
||||
{
|
||||
rgb_controllers.push_back(razer_rgb);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete razer_rgb;
|
||||
}
|
||||
}
|
||||
|
||||
} /* DetectOpenRazerControllers() */
|
||||
+1304
-10
File diff suppressed because it is too large
Load Diff
@@ -9,8 +9,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
typedef unsigned int RGBColor;
|
||||
|
||||
@@ -25,14 +27,14 @@ typedef unsigned int RGBColor;
|
||||
\*------------------------------------------------------------------*/
|
||||
enum
|
||||
{
|
||||
MODE_FLAG_HAS_SPEED = (1 << 0), /* Mode has speed parameter */
|
||||
MODE_FLAG_HAS_DIRECTION_LR = (1 << 1), /* Mode has left/right parameter */
|
||||
MODE_FLAG_HAS_DIRECTION_UD = (1 << 2), /* Mode has up/down parameter */
|
||||
MODE_FLAG_HAS_DIRECTION_HV = (1 << 3), /* Mode has horiz/vert parameter */
|
||||
MODE_FLAG_HAS_BRIGHTNESS = (1 << 4), /* Mode has brightness parameter */
|
||||
MODE_FLAG_HAS_COLOR = (1 << 5), /* Mode has custom color parameter */
|
||||
MODE_FLAG_RANDOM_COLOR = (1 << 6), /* Mode has random color option */
|
||||
MODE_FLAG_PER_LED_COLOR = (1 << 7), /* Mode uses device LED colors */
|
||||
MODE_FLAG_HAS_SPEED = (1 << 0), /* Mode has speed parameter */
|
||||
MODE_FLAG_HAS_DIRECTION_LR = (1 << 1), /* Mode has left/right parameter */
|
||||
MODE_FLAG_HAS_DIRECTION_UD = (1 << 2), /* Mode has up/down parameter */
|
||||
MODE_FLAG_HAS_DIRECTION_HV = (1 << 3), /* Mode has horiz/vert parameter */
|
||||
MODE_FLAG_HAS_BRIGHTNESS = (1 << 4), /* Mode has brightness parameter */
|
||||
MODE_FLAG_HAS_PER_LED_COLOR = (1 << 5), /* Mode has per-LED colors */
|
||||
MODE_FLAG_HAS_MODE_SPECIFIC_COLOR = (1 << 6), /* Mode has mode specific colors */
|
||||
MODE_FLAG_HAS_RANDOM_COLOR = (1 << 7), /* Mode has random color option */
|
||||
};
|
||||
|
||||
/*------------------------------------------------------------------*\
|
||||
@@ -48,6 +50,14 @@ enum
|
||||
MODE_DIRECTION_VERTICAL = 5, /* Mode direction vertical */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
MODE_COLORS_NONE = 0, /* Mode has no colors */
|
||||
MODE_COLORS_PER_LED = 1, /* Mode has per LED colors selected */
|
||||
MODE_COLORS_MODE_SPECIFIC = 2, /* Mode specific colors selected */
|
||||
MODE_COLORS_RANDOM = 3, /* Mode has random colors selected */
|
||||
};
|
||||
|
||||
/*------------------------------------------------------------------*\
|
||||
| Mode Type |
|
||||
\*------------------------------------------------------------------*/
|
||||
@@ -61,18 +71,23 @@ typedef struct
|
||||
unsigned int flags; /* Mode flags bitfield */
|
||||
unsigned int speed_min; /* speed minimum value */
|
||||
unsigned int speed_max; /* speed maximum value */
|
||||
unsigned int colors_min; /* minimum number of mode colors*/
|
||||
unsigned int colors_max; /* maximum numver of mode colors*/
|
||||
|
||||
/*--------------------------------------------------------------*\
|
||||
| Mode Settings |
|
||||
\*--------------------------------------------------------------*/
|
||||
unsigned int speed; /* Mode speed parameter value */
|
||||
unsigned int direction; /* Mode direction value */
|
||||
bool random; /* Random color mode enabled */
|
||||
unsigned int color_mode; /* Mode color selection */
|
||||
std::vector<RGBColor>
|
||||
colors; /* mode-specific colors */
|
||||
} mode;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
std::string name; /* LED name */
|
||||
std::string name; /* LED name */
|
||||
unsigned int value; /* Device-specific LED value */
|
||||
} led;
|
||||
|
||||
typedef int zone_type;
|
||||
@@ -100,12 +115,26 @@ enum
|
||||
DEVICE_TYPE_UNKNOWN
|
||||
};
|
||||
|
||||
std::string device_type_to_str(device_type type);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
std::string name; /* Zone name */
|
||||
zone_type type; /* Zone type */
|
||||
std::vector<std::vector<int>>
|
||||
map; /* LED index map */
|
||||
unsigned int height;
|
||||
unsigned int width;
|
||||
unsigned int * map;
|
||||
} matrix_map_type;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
std::string name; /* Zone name */
|
||||
zone_type type; /* Zone type */
|
||||
led * leds; /* List of LEDs in zone */
|
||||
RGBColor * colors; /* Colors of LEDs in zone */
|
||||
unsigned int start_idx; /* Start index of led/color */
|
||||
unsigned int leds_count; /* Number of LEDs in zone */
|
||||
unsigned int leds_min; /* Minimum number of LEDs */
|
||||
unsigned int leds_max; /* Maximum number of LEDs */
|
||||
matrix_map_type * matrix_map; /* Matrix map pointer */
|
||||
} zone;
|
||||
|
||||
class RGBController
|
||||
@@ -123,26 +152,68 @@ public:
|
||||
device_type type; /* device type */
|
||||
int active_mode = 0;/* active mode */
|
||||
|
||||
virtual ~RGBController() = default;
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController base class constructor |
|
||||
\*---------------------------------------------------------*/
|
||||
RGBController();
|
||||
~RGBController();
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Generic functions implemented in RGBController.cpp |
|
||||
\*---------------------------------------------------------*/
|
||||
RGBColor GetLED(int led);
|
||||
void SetLED(int led, RGBColor color);
|
||||
void SetupColors();
|
||||
|
||||
RGBColor GetLED(unsigned int led);
|
||||
void SetLED(unsigned int led, RGBColor color);
|
||||
void SetAllLEDs(RGBColor color);
|
||||
void SetAllZoneLEDs(int zone, RGBColor color);
|
||||
|
||||
int GetMode();
|
||||
void SetMode(int mode);
|
||||
|
||||
unsigned char * GetDeviceDescription();
|
||||
void ReadDeviceDescription(unsigned char* data_buf);
|
||||
|
||||
unsigned char * GetModeDescription(int mode);
|
||||
void SetModeDescription(unsigned char* data_buf);
|
||||
|
||||
unsigned char * GetColorDescription();
|
||||
void SetColorDescription(unsigned char* data_buf);
|
||||
|
||||
unsigned char * GetZoneColorDescription(int zone);
|
||||
void SetZoneColorDescription(unsigned char* data_buf);
|
||||
|
||||
unsigned char * GetSingleLEDColorDescription(int led);
|
||||
void SetSingleLEDColorDescription(unsigned char* data_buf);
|
||||
|
||||
void UpdateLEDs();
|
||||
//void UpdateZoneLEDs(int zone);
|
||||
//void UpdateSingleLED(int led);
|
||||
|
||||
//void UpdateMode();
|
||||
|
||||
void DeviceCallThreadFunction();
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Functions to be implemented in device implementation |
|
||||
\*---------------------------------------------------------*/
|
||||
virtual void UpdateLEDs() = 0;
|
||||
virtual void SetupZones() = 0;
|
||||
|
||||
virtual void ResizeZone(int zone, int new_size) = 0;
|
||||
|
||||
virtual void DeviceUpdateLEDs() = 0;
|
||||
virtual void UpdateZoneLEDs(int zone) = 0;
|
||||
virtual void UpdateSingleLED(int led) = 0;
|
||||
|
||||
virtual void SetCustomMode() = 0;
|
||||
virtual void UpdateMode() = 0;
|
||||
|
||||
virtual void SetCustomMode() = 0;
|
||||
|
||||
private:
|
||||
std::thread* DeviceCallThread;
|
||||
std::atomic<bool> CallFlag_UpdateLEDs;
|
||||
std::atomic<bool> DeviceThreadRunning;
|
||||
//bool CallFlag_UpdateZoneLEDs = false;
|
||||
//bool CallFlag_UpdateSingleLED = false;
|
||||
//bool CallFlag_UpdateMode = false;
|
||||
};
|
||||
|
||||
@@ -13,115 +13,79 @@ RGBController_AMDWraithPrism::RGBController_AMDWraithPrism(AMDWraithPrismControl
|
||||
{
|
||||
wraith = wraith_ptr;
|
||||
|
||||
name = "AMD Wraith Prism";
|
||||
type = DEVICE_TYPE_COOLER;
|
||||
version = wraith->GetFirmwareVersionString();
|
||||
name = "AMD Wraith Prism";
|
||||
type = DEVICE_TYPE_COOLER;
|
||||
description = "AMD Wraith Prism Device";
|
||||
version = wraith->GetFirmwareVersionString();
|
||||
|
||||
mode Static;
|
||||
Static.name = "Static";
|
||||
Static.value = AMD_WRAITH_PRISM_EFFECT_CHANNEL_STATIC;
|
||||
Static.flags = MODE_FLAG_HAS_COLOR | MODE_FLAG_PER_LED_COLOR;
|
||||
Static.random = false;
|
||||
Static.name = "Static";
|
||||
Static.value = AMD_WRAITH_PRISM_EFFECT_CHANNEL_STATIC;
|
||||
Static.flags = MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
Static.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Static);
|
||||
|
||||
mode Breathing;
|
||||
Breathing.name = "Breathing";
|
||||
Breathing.value = AMD_WRAITH_PRISM_EFFECT_CHANNEL_BREATHING;
|
||||
Breathing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_COLOR | MODE_FLAG_PER_LED_COLOR | MODE_FLAG_RANDOM_COLOR;
|
||||
Breathing.speed_min = AMD_WRAITH_PRISM_SPEED_SLOWEST;
|
||||
Breathing.speed_max = AMD_WRAITH_PRISM_SPEED_FASTEST;
|
||||
Breathing.random = false;
|
||||
Breathing.speed = AMD_WRAITH_PRISM_SPEED_NORMAL;
|
||||
Breathing.name = "Breathing";
|
||||
Breathing.value = AMD_WRAITH_PRISM_EFFECT_CHANNEL_BREATHING;
|
||||
Breathing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_RANDOM_COLOR;
|
||||
Breathing.speed_min = AMD_WRAITH_PRISM_SPEED_SLOWEST;
|
||||
Breathing.speed_max = AMD_WRAITH_PRISM_SPEED_FASTEST;
|
||||
Breathing.color_mode = MODE_COLORS_PER_LED;
|
||||
Breathing.speed = AMD_WRAITH_PRISM_SPEED_NORMAL;
|
||||
modes.push_back(Breathing);
|
||||
|
||||
mode ColorCycle;
|
||||
ColorCycle.name = "Color Cycle";
|
||||
ColorCycle.value = AMD_WRAITH_PRISM_EFFECT_CHANNEL_COLOR_CYCLE;
|
||||
ColorCycle.flags = MODE_FLAG_HAS_SPEED;
|
||||
ColorCycle.speed_min = AMD_WRAITH_PRISM_SPEED_SLOWEST;
|
||||
ColorCycle.speed_max = AMD_WRAITH_PRISM_SPEED_FASTEST;
|
||||
ColorCycle.random = false;
|
||||
ColorCycle.speed = AMD_WRAITH_PRISM_SPEED_NORMAL;
|
||||
ColorCycle.name = "Color Cycle";
|
||||
ColorCycle.value = AMD_WRAITH_PRISM_EFFECT_CHANNEL_COLOR_CYCLE;
|
||||
ColorCycle.flags = MODE_FLAG_HAS_SPEED;
|
||||
ColorCycle.speed_min = AMD_WRAITH_PRISM_SPEED_SLOWEST;
|
||||
ColorCycle.speed_max = AMD_WRAITH_PRISM_SPEED_FASTEST;
|
||||
ColorCycle.color_mode = MODE_COLORS_NONE;
|
||||
ColorCycle.speed = AMD_WRAITH_PRISM_SPEED_NORMAL;
|
||||
modes.push_back(ColorCycle);
|
||||
|
||||
mode Rainbow;
|
||||
Rainbow.name = "Rainbow";
|
||||
Rainbow.value = AMD_WRAITH_PRISM_EFFECT_CHANNEL_RAINBOW;
|
||||
Rainbow.flags = MODE_FLAG_HAS_SPEED;
|
||||
Rainbow.speed_min = AMD_WRAITH_PRISM_SPEED_SLOWEST;
|
||||
Rainbow.speed_max = AMD_WRAITH_PRISM_SPEED_FASTEST;
|
||||
Rainbow.random = false;
|
||||
Rainbow.speed = AMD_WRAITH_PRISM_SPEED_NORMAL;
|
||||
Rainbow.name = "Rainbow";
|
||||
Rainbow.value = AMD_WRAITH_PRISM_EFFECT_CHANNEL_RAINBOW;
|
||||
Rainbow.flags = MODE_FLAG_HAS_SPEED;
|
||||
Rainbow.speed_min = AMD_WRAITH_PRISM_SPEED_SLOWEST;
|
||||
Rainbow.speed_max = AMD_WRAITH_PRISM_SPEED_FASTEST;
|
||||
Rainbow.color_mode = MODE_COLORS_NONE;
|
||||
Rainbow.speed = AMD_WRAITH_PRISM_SPEED_NORMAL;
|
||||
modes.push_back(Rainbow);
|
||||
|
||||
mode Bounce;
|
||||
Bounce.name = "Bounce";
|
||||
Bounce.value = AMD_WRAITH_PRISM_EFFECT_CHANNEL_BOUNCE;
|
||||
Bounce.flags = MODE_FLAG_HAS_SPEED;
|
||||
Bounce.speed_min = AMD_WRAITH_PRISM_SPEED_SLOWEST;
|
||||
Bounce.speed_max = AMD_WRAITH_PRISM_SPEED_FASTEST;
|
||||
Bounce.random = true;
|
||||
Bounce.speed = AMD_WRAITH_PRISM_SPEED_NORMAL;
|
||||
Bounce.name = "Bounce";
|
||||
Bounce.value = AMD_WRAITH_PRISM_EFFECT_CHANNEL_BOUNCE;
|
||||
Bounce.flags = MODE_FLAG_HAS_SPEED;
|
||||
Bounce.speed_min = AMD_WRAITH_PRISM_SPEED_SLOWEST;
|
||||
Bounce.speed_max = AMD_WRAITH_PRISM_SPEED_FASTEST;
|
||||
Bounce.color_mode = MODE_COLORS_NONE;
|
||||
Bounce.speed = AMD_WRAITH_PRISM_SPEED_NORMAL;
|
||||
modes.push_back(Bounce);
|
||||
|
||||
mode Chase;
|
||||
Chase.name = "Chase";
|
||||
Chase.value = AMD_WRAITH_PRISM_EFFECT_CHANNEL_CHASE;
|
||||
Chase.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_COLOR | MODE_FLAG_PER_LED_COLOR | MODE_FLAG_RANDOM_COLOR;
|
||||
Chase.speed_min = AMD_WRAITH_PRISM_SPEED_SLOWEST;
|
||||
Chase.speed_max = AMD_WRAITH_PRISM_SPEED_FASTEST;
|
||||
Chase.random = false;
|
||||
Chase.speed = AMD_WRAITH_PRISM_SPEED_NORMAL;
|
||||
Chase.name = "Chase";
|
||||
Chase.value = AMD_WRAITH_PRISM_EFFECT_CHANNEL_CHASE;
|
||||
Chase.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_RANDOM_COLOR;
|
||||
Chase.speed_min = AMD_WRAITH_PRISM_SPEED_SLOWEST;
|
||||
Chase.speed_max = AMD_WRAITH_PRISM_SPEED_FASTEST;
|
||||
Chase.color_mode = MODE_COLORS_PER_LED;
|
||||
Chase.speed = AMD_WRAITH_PRISM_SPEED_NORMAL;
|
||||
modes.push_back(Chase);
|
||||
|
||||
mode Swirl;
|
||||
Swirl.name = "Swirl";
|
||||
Swirl.value = AMD_WRAITH_PRISM_EFFECT_CHANNEL_SWIRL;
|
||||
Swirl.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_COLOR | MODE_FLAG_PER_LED_COLOR | MODE_FLAG_RANDOM_COLOR;
|
||||
Swirl.speed_min = AMD_WRAITH_PRISM_SPEED_SLOWEST;
|
||||
Swirl.speed_max = AMD_WRAITH_PRISM_SPEED_FASTEST;
|
||||
Swirl.random = false;
|
||||
Swirl.speed = AMD_WRAITH_PRISM_SPEED_NORMAL;
|
||||
Swirl.name = "Swirl";
|
||||
Swirl.value = AMD_WRAITH_PRISM_EFFECT_CHANNEL_SWIRL;
|
||||
Swirl.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_RANDOM_COLOR;
|
||||
Swirl.speed_min = AMD_WRAITH_PRISM_SPEED_SLOWEST;
|
||||
Swirl.speed_max = AMD_WRAITH_PRISM_SPEED_FASTEST;
|
||||
Swirl.color_mode = MODE_COLORS_PER_LED;
|
||||
Swirl.speed = AMD_WRAITH_PRISM_SPEED_NORMAL;
|
||||
modes.push_back(Swirl);
|
||||
|
||||
led logo_led;
|
||||
logo_led.name = "Logo";
|
||||
leds.push_back(logo_led);
|
||||
colors.push_back(0x00000000);
|
||||
|
||||
zone logo_zone;
|
||||
logo_zone.name = "Logo";
|
||||
logo_zone.type = ZONE_TYPE_SINGLE;
|
||||
std::vector<int> logo_zone_map;
|
||||
logo_zone_map.push_back(0);
|
||||
logo_zone.map.push_back(logo_zone_map);
|
||||
zones.push_back(logo_zone);
|
||||
|
||||
led fan_led;
|
||||
fan_led.name = "Fan";
|
||||
leds.push_back(fan_led);
|
||||
colors.push_back(0x00000000);
|
||||
|
||||
zone fan_zone;
|
||||
fan_zone.name = "Fan";
|
||||
fan_zone.type = ZONE_TYPE_SINGLE;
|
||||
std::vector<int> fan_zone_map;
|
||||
fan_zone_map.push_back(1);
|
||||
fan_zone.map.push_back(fan_zone_map);
|
||||
zones.push_back(fan_zone);
|
||||
|
||||
led ring_led;
|
||||
ring_led.name = "Ring";
|
||||
leds.push_back(ring_led);
|
||||
colors.push_back(0x00000000);
|
||||
|
||||
zone ring_zone;
|
||||
ring_zone.name = "Ring";
|
||||
ring_zone.type = ZONE_TYPE_SINGLE;
|
||||
std::vector<int> ring_zone_map;
|
||||
ring_zone_map.push_back(2);
|
||||
ring_zone.map.push_back(ring_zone_map);
|
||||
zones.push_back(ring_zone);
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
RGBController_AMDWraithPrism::~RGBController_AMDWraithPrism()
|
||||
@@ -129,7 +93,64 @@ RGBController_AMDWraithPrism::~RGBController_AMDWraithPrism()
|
||||
|
||||
}
|
||||
|
||||
void RGBController_AMDWraithPrism::UpdateLEDs()
|
||||
void RGBController_AMDWraithPrism::SetupZones()
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Set up zones |
|
||||
\*---------------------------------------------------------*/
|
||||
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);
|
||||
|
||||
zone fan_zone;
|
||||
fan_zone.name = "Fan";
|
||||
fan_zone.type = ZONE_TYPE_SINGLE;
|
||||
fan_zone.leds_min = 1;
|
||||
fan_zone.leds_max = 1;
|
||||
fan_zone.leds_count = 1;
|
||||
fan_zone.matrix_map = NULL;
|
||||
zones.push_back(fan_zone);
|
||||
|
||||
zone ring_zone;
|
||||
ring_zone.name = "Ring";
|
||||
ring_zone.type = ZONE_TYPE_SINGLE;
|
||||
ring_zone.leds_min = 1;
|
||||
ring_zone.leds_max = 1;
|
||||
ring_zone.leds_count = 1;
|
||||
ring_zone.matrix_map = NULL;
|
||||
zones.push_back(ring_zone);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Set up LEDs |
|
||||
\*---------------------------------------------------------*/
|
||||
led logo_led;
|
||||
logo_led.name = "Logo LED";
|
||||
leds.push_back(logo_led);
|
||||
|
||||
led fan_led;
|
||||
fan_led.name = "Fan LED";
|
||||
leds.push_back(fan_led);
|
||||
|
||||
led ring_led;
|
||||
ring_led.name = "Ring LED";
|
||||
leds.push_back(ring_led);
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_AMDWraithPrism::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_AMDWraithPrism::DeviceUpdateLEDs()
|
||||
{
|
||||
unsigned char red = RGBGetRValue(colors[0]);
|
||||
unsigned char grn = RGBGetGValue(colors[0]);
|
||||
@@ -180,35 +201,37 @@ void RGBController_AMDWraithPrism::SetCustomMode()
|
||||
|
||||
void RGBController_AMDWraithPrism::UpdateMode()
|
||||
{
|
||||
wraith->SetRingMode(modes[active_mode].value, modes[active_mode].speed, modes[active_mode].direction, modes[active_mode].random);
|
||||
bool random = (modes[active_mode].color_mode == MODE_COLORS_RANDOM);
|
||||
|
||||
wraith->SetRingMode(modes[active_mode].value, modes[active_mode].speed, modes[active_mode].direction, random);
|
||||
|
||||
switch(modes[active_mode].value)
|
||||
{
|
||||
case AMD_WRAITH_PRISM_EFFECT_CHANNEL_COLOR_CYCLE:
|
||||
case AMD_WRAITH_PRISM_EFFECT_CHANNEL_RAINBOW:
|
||||
case AMD_WRAITH_PRISM_EFFECT_CHANNEL_BOUNCE:
|
||||
wraith->SetFanMode(AMD_WRAITH_PRISM_FAN_LOGO_MODE_COLOR_CYCLE, modes[active_mode].speed, modes[active_mode].random);
|
||||
wraith->SetLogoMode(AMD_WRAITH_PRISM_FAN_LOGO_MODE_COLOR_CYCLE, modes[active_mode].speed, modes[active_mode].random);
|
||||
wraith->SetFanMode(AMD_WRAITH_PRISM_FAN_LOGO_MODE_COLOR_CYCLE, modes[active_mode].speed, random);
|
||||
wraith->SetLogoMode(AMD_WRAITH_PRISM_FAN_LOGO_MODE_COLOR_CYCLE, modes[active_mode].speed, random);
|
||||
break;
|
||||
|
||||
case AMD_WRAITH_PRISM_EFFECT_CHANNEL_BREATHING:
|
||||
wraith->SetFanMode(AMD_WRAITH_PRISM_FAN_LOGO_MODE_BREATHING, modes[active_mode].speed, modes[active_mode].random);
|
||||
wraith->SetLogoMode(AMD_WRAITH_PRISM_FAN_LOGO_MODE_BREATHING, modes[active_mode].speed, modes[active_mode].random);
|
||||
wraith->SetFanMode(AMD_WRAITH_PRISM_FAN_LOGO_MODE_BREATHING, modes[active_mode].speed, random);
|
||||
wraith->SetLogoMode(AMD_WRAITH_PRISM_FAN_LOGO_MODE_BREATHING, modes[active_mode].speed, random);
|
||||
break;
|
||||
|
||||
default:
|
||||
if(modes[active_mode].random)
|
||||
if(random)
|
||||
{
|
||||
wraith->SetFanMode(AMD_WRAITH_PRISM_FAN_LOGO_MODE_COLOR_CYCLE, modes[active_mode].speed, modes[active_mode].random);
|
||||
wraith->SetLogoMode(AMD_WRAITH_PRISM_FAN_LOGO_MODE_COLOR_CYCLE, modes[active_mode].speed, modes[active_mode].random);
|
||||
wraith->SetFanMode(AMD_WRAITH_PRISM_FAN_LOGO_MODE_COLOR_CYCLE, modes[active_mode].speed, random);
|
||||
wraith->SetLogoMode(AMD_WRAITH_PRISM_FAN_LOGO_MODE_COLOR_CYCLE, modes[active_mode].speed, random);
|
||||
}
|
||||
else
|
||||
{
|
||||
wraith->SetFanMode(AMD_WRAITH_PRISM_FAN_LOGO_MODE_STATIC, modes[active_mode].speed, modes[active_mode].random);
|
||||
wraith->SetLogoMode(AMD_WRAITH_PRISM_FAN_LOGO_MODE_STATIC, modes[active_mode].speed, modes[active_mode].random);
|
||||
wraith->SetFanMode(AMD_WRAITH_PRISM_FAN_LOGO_MODE_STATIC, modes[active_mode].speed, random);
|
||||
wraith->SetLogoMode(AMD_WRAITH_PRISM_FAN_LOGO_MODE_STATIC, modes[active_mode].speed, random);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateLEDs();
|
||||
}
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,12 @@ class RGBController_AMDWraithPrism : public RGBController
|
||||
public:
|
||||
RGBController_AMDWraithPrism(AMDWraithPrismController* wraith_ptr);
|
||||
~RGBController_AMDWraithPrism();
|
||||
void UpdateLEDs();
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBController_AorusGPU.cpp |
|
||||
| |
|
||||
| Generic RGB Interface for OpenAuraSDK |
|
||||
| Aorus GPU |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 6/17/2019 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController_AorusGPU.h"
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
static HMODULE handle;
|
||||
static unsigned char data[] = { 0x8E, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x40, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00,
|
||||
0x64, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00 };
|
||||
|
||||
void RGBController_AorusGPU::UpdateLEDs()
|
||||
{
|
||||
RGBColor color = colors[0];
|
||||
data[9] = RGBGetRValue(color);
|
||||
data[10] = RGBGetGValue(color);
|
||||
data[11] = RGBGetBValue(color);
|
||||
|
||||
GvWriteI2C(0x00000000, data, 0x00000000);
|
||||
}
|
||||
|
||||
void RGBController_AorusGPU::UpdateZoneLEDs(int zone)
|
||||
{
|
||||
UpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_AorusGPU::UpdateSingleLED(int led)
|
||||
{
|
||||
UpdateLEDs();
|
||||
}
|
||||
|
||||
RGBController_AorusGPU::RGBController_AorusGPU()
|
||||
{
|
||||
name = "Aorus GPU";
|
||||
type = DEVICE_TYPE_GPU;
|
||||
|
||||
handle = LoadLibrary("GvDisplay.dll");
|
||||
|
||||
GvWriteI2C = (_GvWriteI2C)GetProcAddress(handle, "GvWriteI2C");
|
||||
GvFreeDispLib = (_GvFreeDispLib)GetProcAddress(handle, "GvFreeDispLib");
|
||||
GvInitDispLib = (_GvInitDispLib)GetProcAddress(handle, "GvInitDispLib");
|
||||
|
||||
GvFreeDispLib();
|
||||
GvInitDispLib();
|
||||
|
||||
colors.push_back(0x00000000);
|
||||
|
||||
mode aorus_mode;
|
||||
aorus_mode.name = "Static";
|
||||
modes.push_back(aorus_mode);
|
||||
|
||||
led aorus_led;
|
||||
aorus_led.name = "GPU LED";
|
||||
leds.push_back(aorus_led);
|
||||
|
||||
zone aorus_zone;
|
||||
aorus_zone.name = "GPU LED";
|
||||
std::vector<int> aorus_zone_map;
|
||||
aorus_zone_map.push_back(0);
|
||||
aorus_zone.map.push_back(aorus_zone_map);
|
||||
zones.push_back(aorus_zone);
|
||||
}
|
||||
|
||||
void RGBController_AorusGPU::SetCustomMode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RGBController_AorusGPU::UpdateMode()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBController_AorusGPU.h |
|
||||
| |
|
||||
| Generic RGB Interface for OpenAuraSDK |
|
||||
| Aorus GPU |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 6/17/2019 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
#include "RGBController.h"
|
||||
|
||||
typedef unsigned int uint32;
|
||||
typedef uint32(*_GvWriteI2C)(uint32, void*, uint32);
|
||||
typedef void (*_GvFreeDispLib)();
|
||||
typedef void (*_GvInitDispLib)();
|
||||
|
||||
class RGBController_AorusGPU : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_AorusGPU();
|
||||
void UpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void SetCustomMode();
|
||||
void UpdateMode();
|
||||
|
||||
private:
|
||||
_GvWriteI2C GvWriteI2C;
|
||||
_GvFreeDispLib GvFreeDispLib;
|
||||
_GvInitDispLib GvInitDispLib;
|
||||
};
|
||||
@@ -1,294 +0,0 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBController_Aura.cpp |
|
||||
| |
|
||||
| Generic RGB Interface for OpenAuraSDK |
|
||||
| Asus Aura driver |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 6/13/2019 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController_Aura.h"
|
||||
|
||||
int RGBController_Aura::GetDeviceMode()
|
||||
{
|
||||
int dev_mode = aura->AuraRegisterRead(AURA_REG_MODE);
|
||||
bool random = false;
|
||||
|
||||
switch(dev_mode)
|
||||
{
|
||||
case AURA_MODE_SPECTRUM_CYCLE_CHASE:
|
||||
dev_mode = AURA_MODE_CHASE;
|
||||
random = true;
|
||||
break;
|
||||
|
||||
case AURA_MODE_SPECTRUM_CYCLE_BREATHING:
|
||||
dev_mode = AURA_MODE_BREATHING;
|
||||
random = true;
|
||||
break;
|
||||
|
||||
case AURA_MODE_SPECTRUM_CYCLE_CHASE_FADE:
|
||||
dev_mode = AURA_MODE_CHASE_FADE;
|
||||
random = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (aura->AuraRegisterRead(AURA_REG_DIRECT))
|
||||
{
|
||||
dev_mode = 0xFFFF;
|
||||
}
|
||||
|
||||
for(int mode = 0; mode < modes.size(); mode++)
|
||||
{
|
||||
if(modes[mode].value == dev_mode)
|
||||
{
|
||||
active_mode = mode;
|
||||
modes[mode].random = random;
|
||||
}
|
||||
}
|
||||
|
||||
return(active_mode);
|
||||
}
|
||||
|
||||
void RGBController_Aura::UpdateLEDs()
|
||||
{
|
||||
for(std::size_t led = 0; led < colors.size(); led++)
|
||||
{
|
||||
unsigned char red = RGBGetRValue(colors[led]);
|
||||
unsigned char grn = RGBGetGValue(colors[led]);
|
||||
unsigned char blu = RGBGetBValue(colors[led]);
|
||||
|
||||
if (GetMode() == 0)
|
||||
{
|
||||
aura->SetLEDColorDirect(led, red, grn, blu);
|
||||
}
|
||||
else
|
||||
{
|
||||
aura->SetLEDColorEffect(led, red, grn, blu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_Aura::UpdateZoneLEDs(int zone)
|
||||
{
|
||||
for (std::size_t x = 0; x < zones[zone].map.size(); x++)
|
||||
{
|
||||
for (std::size_t y = 0; y < zones[zone].map[x].size(); y++)
|
||||
{
|
||||
int led = zones[zone].map[x][y];
|
||||
RGBColor color = colors[led];
|
||||
unsigned char red = RGBGetRValue(color);
|
||||
unsigned char grn = RGBGetGValue(color);
|
||||
unsigned char blu = RGBGetBValue(color);
|
||||
|
||||
if (GetMode() == 0)
|
||||
{
|
||||
aura->SetLEDColorDirect(led, red, grn, blu);
|
||||
}
|
||||
else
|
||||
{
|
||||
aura->SetLEDColorEffect(led, red, grn, blu);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_Aura::UpdateSingleLED(int led)
|
||||
{
|
||||
RGBColor color = colors[led];
|
||||
unsigned char red = RGBGetRValue(color);
|
||||
unsigned char grn = RGBGetGValue(color);
|
||||
unsigned char blu = RGBGetBValue(color);
|
||||
|
||||
if (GetMode() == 0)
|
||||
{
|
||||
aura->SetLEDColorDirect(led, red, grn, blu);
|
||||
}
|
||||
else
|
||||
{
|
||||
aura->SetLEDColorEffect(led, red, grn, blu);
|
||||
}
|
||||
}
|
||||
|
||||
RGBController_Aura::RGBController_Aura(AuraController * aura_ptr)
|
||||
{
|
||||
std::vector<unsigned char> aura_channels;
|
||||
|
||||
aura = aura_ptr;
|
||||
|
||||
version = aura->GetDeviceName();
|
||||
location = aura->GetDeviceLocation();
|
||||
if((version.find("DIMM_LED") != std::string::npos) || (version.find("AUDA") != std::string::npos) )
|
||||
{
|
||||
type = DEVICE_TYPE_DRAM;
|
||||
name = "ASUS Aura DRAM";
|
||||
}
|
||||
else
|
||||
{
|
||||
type = DEVICE_TYPE_MOTHERBOARD;
|
||||
name = "ASUS Aura Motherboard";
|
||||
}
|
||||
|
||||
mode Direct;
|
||||
Direct.name = "Direct";
|
||||
Direct.value = 0xFFFF;
|
||||
Direct.flags = MODE_FLAG_HAS_COLOR | MODE_FLAG_PER_LED_COLOR;
|
||||
modes.push_back(Direct);
|
||||
|
||||
mode Off;
|
||||
Off.name = "Off";
|
||||
Off.value = AURA_MODE_OFF;
|
||||
Off.flags = 0;
|
||||
modes.push_back(Off);
|
||||
|
||||
mode Static;
|
||||
Static.name = "Static";
|
||||
Static.value = AURA_MODE_STATIC;
|
||||
Static.flags = MODE_FLAG_HAS_COLOR | MODE_FLAG_PER_LED_COLOR;
|
||||
modes.push_back(Static);
|
||||
|
||||
mode Breathing;
|
||||
Breathing.name = "Breathing";
|
||||
Breathing.value = AURA_MODE_BREATHING;
|
||||
Breathing.flags = MODE_FLAG_HAS_COLOR | MODE_FLAG_RANDOM_COLOR | MODE_FLAG_PER_LED_COLOR;
|
||||
modes.push_back(Breathing);
|
||||
|
||||
mode Flashing;
|
||||
Flashing.name = "Flashing";
|
||||
Flashing.value = AURA_MODE_FLASHING;
|
||||
Flashing.flags = MODE_FLAG_HAS_COLOR | MODE_FLAG_PER_LED_COLOR;
|
||||
modes.push_back(Flashing);
|
||||
|
||||
mode SpectrumCycle;
|
||||
SpectrumCycle.name = "Spectrum Cycle";
|
||||
SpectrumCycle.value = AURA_MODE_SPECTRUM_CYCLE;
|
||||
SpectrumCycle.flags = 0;
|
||||
modes.push_back(SpectrumCycle);
|
||||
|
||||
mode Rainbow;
|
||||
Rainbow.name = "Rainbow";
|
||||
Rainbow.value = AURA_MODE_RAINBOW;
|
||||
Rainbow.flags = 0;
|
||||
modes.push_back(Rainbow);
|
||||
|
||||
mode ChaseFade;
|
||||
ChaseFade.name = "Chase Fade";
|
||||
ChaseFade.value = AURA_MODE_CHASE_FADE;
|
||||
ChaseFade.flags = MODE_FLAG_HAS_COLOR | MODE_FLAG_RANDOM_COLOR | MODE_FLAG_PER_LED_COLOR;
|
||||
modes.push_back(ChaseFade);
|
||||
|
||||
mode Chase;
|
||||
Chase.name = "Chase";
|
||||
Chase.value = AURA_MODE_CHASE;
|
||||
Chase.flags = MODE_FLAG_HAS_COLOR | MODE_FLAG_RANDOM_COLOR | MODE_FLAG_PER_LED_COLOR;
|
||||
modes.push_back(Chase);
|
||||
|
||||
mode RandomFlicker;
|
||||
RandomFlicker.name = "Random Flicker";
|
||||
RandomFlicker.value = AURA_MODE_RANDOM_FLICKER;
|
||||
RandomFlicker.flags = 0;
|
||||
modes.push_back(RandomFlicker);
|
||||
|
||||
colors.resize(aura->GetLEDCount());
|
||||
|
||||
for (std::size_t i = 0; i < aura->GetLEDCount(); i++)
|
||||
{
|
||||
aura_channels.push_back(aura->GetChannel(i));
|
||||
|
||||
led* new_led = new led();
|
||||
|
||||
new_led->name = aura->GetChannelName(i);
|
||||
|
||||
leds.push_back(*new_led);
|
||||
|
||||
unsigned char red = aura->GetLEDRed(i);
|
||||
unsigned char grn = aura->GetLEDGreen(i);
|
||||
unsigned char blu = aura->GetLEDBlue(i);
|
||||
|
||||
colors[i] = ToRGBColor(red, grn, blu);
|
||||
}
|
||||
|
||||
std::vector<unsigned char> aura_zones;
|
||||
|
||||
// Search through all LEDs and create zones for each channel type
|
||||
for (std::size_t i = 0; i < aura_channels.size(); i++)
|
||||
{
|
||||
bool matched = false;
|
||||
|
||||
// Search through existing zones to make sure we don't create a duplicate zone
|
||||
for (std::size_t j = 0; j < aura_zones.size(); j++)
|
||||
{
|
||||
if (aura_channels[i] == aura_zones[j])
|
||||
{
|
||||
matched = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If zone does not already exist, create it
|
||||
if (matched == false)
|
||||
{
|
||||
zone* new_zone = new zone();
|
||||
std::vector<int>* zone_row = new std::vector<int>();
|
||||
|
||||
// Set zone name to channel name
|
||||
new_zone->name = aura->GetChannelName(i);
|
||||
|
||||
// Find all LEDs with this channel type and add them to zone
|
||||
for (std::size_t j = 0; j < aura->GetLEDCount(); j++)
|
||||
{
|
||||
if (aura->GetChannel(j) == aura_channels[i])
|
||||
{
|
||||
zone_row->push_back(j);
|
||||
}
|
||||
}
|
||||
|
||||
// Aura devices can be either single or linear, never matrix
|
||||
// That means only one row is needed
|
||||
new_zone->map.push_back(*zone_row);
|
||||
|
||||
// Save channel to aura_zones so we know not to create another zone with this channel
|
||||
aura_zones.push_back(aura_channels[i]);
|
||||
|
||||
// Push new zone to zones vector
|
||||
zones.push_back(*new_zone);
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize active mode
|
||||
active_mode = GetDeviceMode();
|
||||
}
|
||||
|
||||
void RGBController_Aura::SetCustomMode()
|
||||
{
|
||||
active_mode = 0;
|
||||
}
|
||||
|
||||
void RGBController_Aura::UpdateMode()
|
||||
{
|
||||
if (modes[active_mode].value == 0xFFFF)
|
||||
{
|
||||
aura->SetDirect(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
int new_mode = modes[active_mode].value;
|
||||
|
||||
if(modes[active_mode].random == true)
|
||||
{
|
||||
switch(new_mode)
|
||||
{
|
||||
case AURA_MODE_CHASE:
|
||||
new_mode = AURA_MODE_SPECTRUM_CYCLE_CHASE;
|
||||
break;
|
||||
case AURA_MODE_BREATHING:
|
||||
new_mode = AURA_MODE_SPECTRUM_CYCLE_BREATHING;
|
||||
break;
|
||||
case AURA_MODE_CHASE_FADE:
|
||||
new_mode = AURA_MODE_SPECTRUM_CYCLE_CHASE_FADE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
aura->SetMode(new_mode);
|
||||
aura->SetDirect(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBController_AuraAddressable.cpp |
|
||||
| |
|
||||
| Generic RGB Interface for Asus Aura |
|
||||
| addressable controller driver |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 1/18/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController_AuraAddressable.h"
|
||||
|
||||
RGBController_AuraAddressable::RGBController_AuraAddressable(AuraAddressableController* aura_ptr)
|
||||
{
|
||||
aura = aura_ptr;
|
||||
|
||||
name = "ASUS Aura Addressable";
|
||||
version = aura->GetDeviceName();
|
||||
type = DEVICE_TYPE_MOTHERBOARD;
|
||||
description = "ASUS Aura Addressable Device";
|
||||
|
||||
mode Direct;
|
||||
Direct.name = "Direct";
|
||||
Direct.value = AURA_MODE_DIRECT;
|
||||
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
Direct.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Direct);
|
||||
|
||||
mode Off;
|
||||
Off.name = "Off";
|
||||
Off.value = AURA_MODE_OFF;
|
||||
Off.flags = 0;
|
||||
Off.color_mode = MODE_COLORS_NONE;
|
||||
modes.push_back(Off);
|
||||
|
||||
mode Static;
|
||||
Static.name = "Static";
|
||||
Static.value = AURA_MODE_STATIC;
|
||||
Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
|
||||
Static.colors_min = 1;
|
||||
Static.colors_max = 1;
|
||||
Static.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
Static.colors.resize(1);
|
||||
modes.push_back(Static);
|
||||
|
||||
mode Breathing;
|
||||
Breathing.name = "Breathing";
|
||||
Breathing.value = AURA_MODE_BREATHING;
|
||||
Breathing.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
|
||||
Breathing.colors_min = 1;
|
||||
Breathing.colors_max = 1;
|
||||
Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
Breathing.colors.resize(1);
|
||||
modes.push_back(Breathing);
|
||||
|
||||
mode Flashing;
|
||||
Flashing.name = "Flashing";
|
||||
Flashing.value = AURA_MODE_FLASHING;
|
||||
Flashing.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
|
||||
Flashing.colors_min = 1;
|
||||
Flashing.colors_max = 1;
|
||||
Flashing.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
Flashing.colors.resize(1);
|
||||
modes.push_back(Flashing);
|
||||
|
||||
mode SpectrumCycle;
|
||||
SpectrumCycle.name = "Spectrum Cycle";
|
||||
SpectrumCycle.value = AURA_MODE_SPECTRUM_CYCLE;
|
||||
SpectrumCycle.flags = 0;
|
||||
SpectrumCycle.color_mode = MODE_COLORS_NONE;
|
||||
modes.push_back(SpectrumCycle);
|
||||
|
||||
mode Rainbow;
|
||||
Rainbow.name = "Rainbow";
|
||||
Rainbow.value = AURA_MODE_RAINBOW;
|
||||
Rainbow.flags = 0;
|
||||
Rainbow.color_mode = MODE_COLORS_NONE;
|
||||
modes.push_back(Rainbow);
|
||||
|
||||
mode ChaseFade;
|
||||
ChaseFade.name = "Chase Fade";
|
||||
ChaseFade.value = AURA_MODE_CHASE_FADE;
|
||||
ChaseFade.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
|
||||
ChaseFade.colors_min = 1;
|
||||
ChaseFade.colors_max = 1;
|
||||
ChaseFade.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
ChaseFade.colors.resize(1);
|
||||
modes.push_back(ChaseFade);
|
||||
|
||||
mode Chase;
|
||||
Chase.name = "Chase";
|
||||
Chase.value = AURA_MODE_CHASE;
|
||||
Chase.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
|
||||
Chase.colors_min = 1;
|
||||
Chase.colors_max = 1;
|
||||
Chase.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
Chase.colors.resize(1);
|
||||
modes.push_back(Chase);
|
||||
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
RGBController_AuraAddressable::~RGBController_AuraAddressable()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RGBController_AuraAddressable::SetupZones()
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Only set LED count on the first run |
|
||||
\*-------------------------------------------------*/
|
||||
bool first_run = false;
|
||||
|
||||
if(zones.size() == 0)
|
||||
{
|
||||
first_run = true;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Clear any existing color/LED configuration |
|
||||
\*-------------------------------------------------*/
|
||||
leds.clear();
|
||||
colors.clear();
|
||||
zones.resize(aura->GetChannelCount());
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Set zones and leds |
|
||||
\*-------------------------------------------------*/
|
||||
for (unsigned int channel_idx = 0; channel_idx < zones.size(); channel_idx++)
|
||||
{
|
||||
char ch_idx_string[2];
|
||||
sprintf(ch_idx_string, "%d", channel_idx + 1);
|
||||
|
||||
zones[channel_idx].name = "Aura Channel ";
|
||||
zones[channel_idx].name.append(ch_idx_string);
|
||||
zones[channel_idx].type = ZONE_TYPE_LINEAR;
|
||||
|
||||
zones[channel_idx].leds_min = 0;
|
||||
zones[channel_idx].leds_max = AURA_ADDRESSABLE_MAX_LEDS;
|
||||
|
||||
if(first_run)
|
||||
{
|
||||
zones[channel_idx].leds_count = 0;
|
||||
}
|
||||
|
||||
for (unsigned int led_ch_idx = 0; led_ch_idx < zones[channel_idx].leds_count; led_ch_idx++)
|
||||
{
|
||||
char led_idx_string[4];
|
||||
sprintf(led_idx_string, "%d", led_ch_idx + 1);
|
||||
|
||||
led new_led;
|
||||
new_led.name = "Aura Channel ";
|
||||
new_led.name.append(ch_idx_string);
|
||||
new_led.name.append(", LED ");
|
||||
new_led.name.append(led_idx_string);
|
||||
new_led.value = channel_idx;
|
||||
|
||||
leds.push_back(new_led);
|
||||
}
|
||||
|
||||
zones[channel_idx].matrix_map = NULL;
|
||||
}
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_AuraAddressable::ResizeZone(int zone, int new_size)
|
||||
{
|
||||
if(((unsigned int)new_size >= zones[zone].leds_min) && ((unsigned int)new_size <= zones[zone].leds_max))
|
||||
{
|
||||
zones[zone].leds_count = new_size;
|
||||
|
||||
SetupZones();
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_AuraAddressable::DeviceUpdateLEDs()
|
||||
{
|
||||
for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
|
||||
{
|
||||
aura->SetChannelLEDs(zone_idx, zones[zone_idx].colors, zones[zone_idx].leds_count);
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_AuraAddressable::UpdateZoneLEDs(int zone)
|
||||
{
|
||||
aura->SetChannelLEDs(zone, zones[zone].colors, zones[zone].leds_count);
|
||||
}
|
||||
|
||||
void RGBController_AuraAddressable::UpdateSingleLED(int led)
|
||||
{
|
||||
unsigned int channel = leds[led].value;
|
||||
|
||||
aura->SetChannelLEDs(channel, zones[channel].colors, zones[channel].leds_count);
|
||||
}
|
||||
|
||||
void RGBController_AuraAddressable::SetCustomMode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RGBController_AuraAddressable::UpdateMode()
|
||||
{
|
||||
unsigned char red = 0;
|
||||
unsigned char grn = 0;
|
||||
unsigned char blu = 0;
|
||||
|
||||
if(modes[active_mode].color_mode == MODE_COLORS_MODE_SPECIFIC)
|
||||
{
|
||||
red = RGBGetRValue(modes[active_mode].colors[0]);
|
||||
grn = RGBGetGValue(modes[active_mode].colors[0]);
|
||||
blu = RGBGetBValue(modes[active_mode].colors[0]);
|
||||
}
|
||||
|
||||
aura->SetMode(modes[active_mode].value, red, grn, blu);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBController_AuraAddressable.h |
|
||||
| |
|
||||
| Generic RGB Interface for Asus Aura |
|
||||
| addressable controller driver |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 1/18/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
#include "RGBController.h"
|
||||
#include "AuraAddressableController.h"
|
||||
|
||||
#define AURA_ADDRESSABLE_MAX_LEDS 120
|
||||
|
||||
class RGBController_AuraAddressable : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_AuraAddressable(AuraAddressableController* aura_ptr);
|
||||
~RGBController_AuraAddressable();
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void SetCustomMode();
|
||||
void UpdateMode();
|
||||
|
||||
private:
|
||||
AuraAddressableController* aura;
|
||||
std::vector<unsigned int> leds_channel;
|
||||
std::vector<unsigned int> zones_channel;
|
||||
};
|
||||
@@ -0,0 +1,106 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBController_AuraCore.cpp |
|
||||
| |
|
||||
| Generic RGB Interface for ROG Aura Core |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 4/17/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController_AuraCore.h"
|
||||
|
||||
RGBController_AuraCore::RGBController_AuraCore(AuraCoreController* aura_ptr)
|
||||
{
|
||||
aura = aura_ptr;
|
||||
|
||||
name = "ASUS Aura Core";
|
||||
type = DEVICE_TYPE_KEYBOARD;
|
||||
description = "ASUS Aura Core Device";
|
||||
|
||||
mode Static;
|
||||
Static.name = "Static";
|
||||
Static.value = AURA_CORE_MODE_STATIC;
|
||||
Static.flags = MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
modes.push_back(Static);
|
||||
|
||||
mode Breathing;
|
||||
Breathing.name = "Breathing";
|
||||
Breathing.value = AURA_CORE_MODE_BREATHING;
|
||||
Breathing.flags = MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
modes.push_back(Breathing);
|
||||
|
||||
mode ColorCycle;
|
||||
ColorCycle.name = "Color Cycle";
|
||||
ColorCycle.value = AURA_CORE_MODE_SPECTRUM_CYCLE;
|
||||
ColorCycle.flags = 0;
|
||||
ColorCycle.color_mode = MODE_COLORS_NONE;
|
||||
modes.push_back(ColorCycle);
|
||||
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
void RGBController_AuraCore::SetupZones()
|
||||
{
|
||||
zone Keyboard;
|
||||
Keyboard.name = "Keyboard";
|
||||
Keyboard.type = ZONE_TYPE_SINGLE;
|
||||
Keyboard.leds_min = 4;
|
||||
Keyboard.leds_max = 4;
|
||||
Keyboard.leds_count = 4;
|
||||
Keyboard.matrix_map = NULL;
|
||||
zones.push_back(Keyboard);
|
||||
|
||||
for(int led_idx = 0; led_idx < Keyboard.leds_count; led_idx++)
|
||||
{
|
||||
led KeyLED;
|
||||
KeyLED.name = "Keyboard LED ";
|
||||
KeyLED.name.append(std::to_string(led_idx + 1));
|
||||
leds.push_back(KeyLED);
|
||||
}
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_AuraCore::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_AuraCore::DeviceUpdateLEDs()
|
||||
{
|
||||
UpdateZoneLEDs(0);
|
||||
}
|
||||
|
||||
void RGBController_AuraCore::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
for(int led_idx = 0; led_idx < leds.size(); led_idx++)
|
||||
{
|
||||
UpdateSingleLED(led_idx);
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_AuraCore::UpdateSingleLED(int led)
|
||||
{
|
||||
aura->SendUpdate
|
||||
(
|
||||
led + 1,
|
||||
modes[active_mode].value,
|
||||
AURA_CORE_SPEED_NORMAL,
|
||||
RGBGetRValue(colors[led]),
|
||||
RGBGetGValue(colors[led]),
|
||||
RGBGetBValue(colors[led])
|
||||
);
|
||||
aura->SendSet();
|
||||
aura->SendApply();
|
||||
}
|
||||
|
||||
void RGBController_AuraCore::SetCustomMode()
|
||||
{
|
||||
active_mode = 0;
|
||||
}
|
||||
|
||||
void RGBController_AuraCore::UpdateMode()
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user