Compare commits
75
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13414ec9b8 | ||
|
|
74faee0f73 | ||
|
|
3f0027aa90 | ||
|
|
d22aa1ed6c | ||
|
|
23d51f65d0 | ||
|
|
cad356efca | ||
|
|
70e83c13cc | ||
|
|
7ca0a1b6ab | ||
|
|
9bd5536d07 | ||
|
|
eaa3b9a368 | ||
|
|
599c468de8 | ||
|
|
9f21814395 | ||
|
|
cb8a551683 | ||
|
|
7f1156d81c | ||
|
|
5beee08166 | ||
|
|
1334129078 | ||
|
|
216b492f24 | ||
|
|
1b65bb9cc3 | ||
|
|
0f4ddd164f | ||
|
|
e6aadc414b | ||
|
|
883a78ad9d | ||
|
|
15d23d3009 | ||
|
|
e2c2b8c1df | ||
|
|
5133c30242 | ||
|
|
69e1e19bf9 | ||
|
|
46f08f7423 | ||
|
|
352b9928ca | ||
|
|
87854d5781 | ||
|
|
1b3f8f9eb4 | ||
|
|
6438c15dd3 | ||
|
|
dbe29991f0 | ||
|
|
a5e9a3de05 | ||
|
|
edf1b251c0 | ||
|
|
9ff4314840 | ||
|
|
3ad0986ae7 | ||
|
|
6bfc9dd9db | ||
|
|
9b8a0d465e | ||
|
|
119741b736 | ||
|
|
2fe958783c | ||
|
|
1c59ef6b80 | ||
|
|
9e44e4ba4f | ||
|
|
b8e14ea067 | ||
|
|
525071c205 | ||
|
|
bfe03b0564 | ||
|
|
04b87ce2eb | ||
|
|
81acc47cd6 | ||
|
|
6e426b1403 | ||
|
|
6509e53a9b | ||
|
|
5b42b3d11d | ||
|
|
8bd515296d | ||
|
|
2bbf66c0ee | ||
|
|
d716973642 | ||
|
|
25f7a87a79 | ||
|
|
0619a16be2 | ||
|
|
4a3802f344 | ||
|
|
105f5642ef | ||
|
|
54ab57cea6 | ||
|
|
e3e6c0347e | ||
|
|
4d6706ce61 | ||
|
|
39c5aff864 | ||
|
|
450f438538 | ||
|
|
0270c745ce | ||
|
|
e2dfcd5b0f | ||
|
|
68fa3c2def | ||
|
|
cde7469191 | ||
|
|
7c1a1396ca | ||
|
|
7f052f21aa | ||
|
|
dff667751b | ||
|
|
2625807c1a | ||
|
|
7af283fdbf | ||
|
|
c7ffe3b926 | ||
|
|
46339c5f86 | ||
|
|
cf69598fd1 | ||
|
|
594f66ab23 | ||
|
|
01e0808e41 |
@@ -1,47 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
-114
@@ -10,23 +10,9 @@
|
||||
#include "AuraAddressableController.h"
|
||||
#include <cstring>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
|
||||
static void Sleep(unsigned int milliseconds)
|
||||
AuraAddressableController::AuraAddressableController(hid_device* dev_handle) : AuraUSBController(dev_handle)
|
||||
{
|
||||
usleep(1000 * milliseconds);
|
||||
}
|
||||
#endif
|
||||
|
||||
AuraAddressableController::AuraAddressableController(hid_device* dev_handle)
|
||||
{
|
||||
dev = dev_handle;
|
||||
|
||||
GetFirmwareVersion();
|
||||
GetConfigTable();
|
||||
channel_count = config_table[2];
|
||||
}
|
||||
|
||||
AuraAddressableController::~AuraAddressableController()
|
||||
@@ -34,16 +20,6 @@ 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];
|
||||
@@ -81,93 +57,21 @@ void AuraAddressableController::SetChannelLEDs(unsigned char channel, RGBColor *
|
||||
|
||||
void AuraAddressableController::SetMode
|
||||
(
|
||||
unsigned char mode,
|
||||
unsigned char red,
|
||||
unsigned char grn,
|
||||
unsigned char blu
|
||||
unsigned char channel,
|
||||
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);
|
||||
}
|
||||
SendEffect
|
||||
(
|
||||
channel,
|
||||
mode,
|
||||
red,
|
||||
grn,
|
||||
blu
|
||||
);
|
||||
}
|
||||
|
||||
void AuraAddressableController::SendEffect
|
||||
@@ -190,7 +94,7 @@ void AuraAddressableController::SendEffect
|
||||
| Set up message packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0xEC;
|
||||
usb_buf[0x01] = AURA_CONTROL_MODE_EFFECT;
|
||||
usb_buf[0x01] = AURA_ADDRESSABLE_CONTROL_MODE_EFFECT;
|
||||
usb_buf[0x02] = channel;
|
||||
usb_buf[0x03] = 0x00;
|
||||
usb_buf[0x04] = mode;
|
||||
@@ -227,7 +131,7 @@ void AuraAddressableController::SendDirect
|
||||
| Set up message packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0xEC;
|
||||
usb_buf[0x01] = AURA_CONTROL_MODE_DIRECT;
|
||||
usb_buf[0x01] = AURA_ADDRESSABLE_CONTROL_MODE_DIRECT;
|
||||
usb_buf[0x02] = device;
|
||||
usb_buf[0x03] = start_led;
|
||||
usb_buf[0x04] = led_count;
|
||||
@@ -259,7 +163,7 @@ void AuraAddressableController::SendDirectApply
|
||||
| Set up message packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0xEC;
|
||||
usb_buf[0x01] = AURA_CONTROL_MODE_DIRECT;
|
||||
usb_buf[0x01] = AURA_ADDRESSABLE_CONTROL_MODE_DIRECT;
|
||||
usb_buf[0x02] = 0x80 | channel;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
@@ -0,0 +1,69 @@
|
||||
/*-----------------------------------------*\
|
||||
| AuraAddressableController.h |
|
||||
| |
|
||||
| Definitions and types for ASUS Aura |
|
||||
| Addressable RGB lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 1/18/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "AuraUSBController.h"
|
||||
|
||||
#include <string>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
enum
|
||||
{
|
||||
AURA_ADDRESSABLE_CONTROL_MODE_EFFECT = 0x3B, /* Effect control mode */
|
||||
AURA_ADDRESSABLE_CONTROL_MODE_DIRECT = 0x40, /* Direct control mode */
|
||||
};
|
||||
|
||||
class AuraAddressableController : public AuraUSBController
|
||||
{
|
||||
public:
|
||||
AuraAddressableController(hid_device* dev_handle);
|
||||
~AuraAddressableController();
|
||||
|
||||
void SetChannelLEDs
|
||||
(
|
||||
unsigned char channel,
|
||||
RGBColor * colors,
|
||||
unsigned int num_colors
|
||||
);
|
||||
|
||||
void SetMode
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
unsigned char red,
|
||||
unsigned char grn,
|
||||
unsigned char blu
|
||||
);
|
||||
|
||||
private:
|
||||
|
||||
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,176 @@
|
||||
/*-----------------------------------------*\
|
||||
| AuraMainboardController.cpp |
|
||||
| |
|
||||
| Driver for ASUS Aura RGB USB mainboard |
|
||||
| lighting controller |
|
||||
| |
|
||||
| Martin Hartl (inlart) 4/25/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "AuraMainboardController.h"
|
||||
#include <cstring>
|
||||
|
||||
AuraMainboardController::AuraMainboardController(hid_device* dev_handle) : AuraUSBController(dev_handle), mode(AURA_MODE_DIRECT)
|
||||
{
|
||||
channel_count = 5;
|
||||
}
|
||||
|
||||
AuraMainboardController::~AuraMainboardController()
|
||||
{
|
||||
}
|
||||
|
||||
void AuraMainboardController::SetChannelLEDs(unsigned char channel, RGBColor * colors, unsigned int num_colors)
|
||||
{
|
||||
unsigned char led_data[60];
|
||||
unsigned int leds_sent = 0;
|
||||
|
||||
SendEffect(channel, mode);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
SendCommit();
|
||||
}
|
||||
|
||||
void AuraMainboardController::SetMode
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
unsigned char red,
|
||||
unsigned char grn,
|
||||
unsigned char blu
|
||||
)
|
||||
{
|
||||
this->mode = mode;
|
||||
unsigned char led_data[3];
|
||||
led_data[0] = red;
|
||||
led_data[1] = grn;
|
||||
led_data[2] = blu;
|
||||
|
||||
SendEffect
|
||||
(
|
||||
channel,
|
||||
mode
|
||||
);
|
||||
SendDirect
|
||||
(
|
||||
channel,
|
||||
0,
|
||||
1,
|
||||
led_data
|
||||
);
|
||||
SendCommit();
|
||||
}
|
||||
|
||||
void AuraMainboardController::SendEffect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode
|
||||
)
|
||||
{
|
||||
unsigned char usb_buf[65];
|
||||
|
||||
if(mode == AURA_MODE_DIRECT) {
|
||||
mode = AURA_MODE_STATIC;
|
||||
}
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up message packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0xEC;
|
||||
usb_buf[0x01] = AURA_MAINBOARD_CONTROL_MODE_EFFECT;
|
||||
usb_buf[0x02] = 0x00;
|
||||
usb_buf[0x03] = 0x00;
|
||||
usb_buf[0x04] = channel;
|
||||
usb_buf[0x05] = mode;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, usb_buf, 65);
|
||||
}
|
||||
|
||||
void AuraMainboardController::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_MAINBOARD_CONTROL_MODE_DIRECT;
|
||||
usb_buf[0x02] = start_led;
|
||||
usb_buf[0x03] = 0xff;
|
||||
usb_buf[0x04] = 0x00;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in color data bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(&usb_buf[0x05], led_data, led_count * 3);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, usb_buf, 65);
|
||||
}
|
||||
|
||||
void AuraMainboardController::SendCommit()
|
||||
{
|
||||
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_MAINBOARD_CONTROL_MODE_COMMIT;
|
||||
usb_buf[0x02] = 0x55;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, usb_buf, 65);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*-----------------------------------------*\
|
||||
| AuraMainboardController.h |
|
||||
| |
|
||||
| Definitions and types for ASUS Aura |
|
||||
| USB Mainboard RGB lighting controller |
|
||||
| |
|
||||
| Martin Hartl (inlart) 4/25/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "AuraUSBController.h"
|
||||
|
||||
#include <string>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
enum
|
||||
{
|
||||
AURA_MAINBOARD_CONTROL_MODE_EFFECT = 0x35, /* Effect control mode */
|
||||
AURA_MAINBOARD_CONTROL_MODE_DIRECT = 0x36, /* Direct control mode */
|
||||
AURA_MAINBOARD_CONTROL_MODE_COMMIT = 0x3F, /* Direct control mode */
|
||||
};
|
||||
|
||||
class AuraMainboardController : public AuraUSBController
|
||||
{
|
||||
public:
|
||||
AuraMainboardController(hid_device* dev_handle);
|
||||
~AuraMainboardController();
|
||||
|
||||
void SetChannelLEDs
|
||||
(
|
||||
unsigned char channel,
|
||||
RGBColor * colors,
|
||||
unsigned int num_colors
|
||||
);
|
||||
|
||||
void SetMode
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
unsigned char red,
|
||||
unsigned char grn,
|
||||
unsigned char blu
|
||||
);
|
||||
|
||||
private:
|
||||
unsigned int mode;
|
||||
|
||||
void SendEffect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode
|
||||
);
|
||||
|
||||
void SendDirect
|
||||
(
|
||||
unsigned char device,
|
||||
unsigned char start_led,
|
||||
unsigned char led_count,
|
||||
unsigned char* led_data
|
||||
);
|
||||
|
||||
void SendCommit();
|
||||
};
|
||||
@@ -0,0 +1,104 @@
|
||||
/*-----------------------------------------*\
|
||||
| AuraUSBController.cpp |
|
||||
| |
|
||||
| Driver for ASUS Aura RGB USB |
|
||||
| lighting controller |
|
||||
| |
|
||||
| Martin Hartl (inlart) 4/25/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "AuraUSBController.h"
|
||||
#include <cstring>
|
||||
|
||||
AuraUSBController::AuraUSBController(hid_device* dev_handle)
|
||||
{
|
||||
dev = dev_handle;
|
||||
|
||||
GetFirmwareVersion();
|
||||
GetConfigTable();
|
||||
}
|
||||
|
||||
AuraUSBController::~AuraUSBController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
unsigned int AuraUSBController::GetChannelCount()
|
||||
{
|
||||
return( channel_count );
|
||||
}
|
||||
|
||||
std::string AuraUSBController::GetDeviceName()
|
||||
{
|
||||
return(device_name);
|
||||
}
|
||||
|
||||
void AuraUSBController::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 AuraUSBController::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);
|
||||
}
|
||||
}
|
||||
+21
-41
@@ -1,10 +1,10 @@
|
||||
/*-----------------------------------------*\
|
||||
| AuraAddressableController.h |
|
||||
| AuraUSBController.h |
|
||||
| |
|
||||
| Definitions and types for ASUS Aura |
|
||||
| Addressable RGB lighting controller |
|
||||
| USB RGB lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 1/18/2020 |
|
||||
| Martin Hartl (inlart) 4/25/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
@@ -36,66 +36,46 @@ enum
|
||||
|
||||
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
|
||||
class AuraUSBController
|
||||
{
|
||||
public:
|
||||
AuraAddressableController(hid_device* dev_handle);
|
||||
~AuraAddressableController();
|
||||
AuraUSBController(hid_device* dev_handle);
|
||||
virtual ~AuraUSBController();
|
||||
|
||||
unsigned int GetChannelCount();
|
||||
|
||||
std::string GetDeviceName();
|
||||
|
||||
void SetChannelLEDs
|
||||
virtual void SetChannelLEDs
|
||||
(
|
||||
unsigned char channel,
|
||||
RGBColor * colors,
|
||||
unsigned int num_colors
|
||||
);
|
||||
) = 0;
|
||||
|
||||
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
|
||||
virtual void SetMode
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
unsigned char red,
|
||||
unsigned char grn,
|
||||
unsigned char blu
|
||||
);
|
||||
) = 0;
|
||||
|
||||
void SendDirect
|
||||
(
|
||||
unsigned char device,
|
||||
unsigned char start_led,
|
||||
unsigned char led_count,
|
||||
unsigned char* led_data
|
||||
);
|
||||
protected:
|
||||
hid_device* dev;
|
||||
unsigned int channel_count;
|
||||
unsigned char config_table[60];
|
||||
|
||||
void SendDirectApply
|
||||
(
|
||||
unsigned char channel
|
||||
);
|
||||
private:
|
||||
char device_name[16];
|
||||
unsigned int led_count;
|
||||
|
||||
void GetConfigTable();
|
||||
|
||||
void GetFirmwareVersion();
|
||||
};
|
||||
@@ -0,0 +1,68 @@
|
||||
#include "AuraAddressableController.h"
|
||||
#include "AuraMainboardController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_AuraUSB.h"
|
||||
#include <vector>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#define AURA_USB_VID 0x0B05
|
||||
|
||||
#define NUM_ADDRESSABLE_PIDS 4
|
||||
static const unsigned short addressable_pid_table[] =
|
||||
{
|
||||
0x1867,
|
||||
0x1872,
|
||||
0x1889,
|
||||
0x18A3
|
||||
};
|
||||
|
||||
#define NUM_MAINBOARD_PIDS 1
|
||||
static const unsigned short mainboard_pid_table[] =
|
||||
{
|
||||
0x18f3
|
||||
};
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectAuraUSBControllers *
|
||||
* *
|
||||
* Tests the USB address to see if an Asus Aura USB RGB header controller *
|
||||
* exists there. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectAuraUSBControllers(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_ADDRESSABLE_PIDS; pid_idx++)
|
||||
{
|
||||
dev = hid_open(AURA_USB_VID, addressable_pid_table[pid_idx], 0);
|
||||
|
||||
if( dev )
|
||||
{
|
||||
AuraAddressableController* controller = new AuraAddressableController(dev);
|
||||
|
||||
RGBController_AuraUSB* rgb_controller = new RGBController_AuraUSB(controller);
|
||||
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
}
|
||||
|
||||
for(int pid_idx = 0; pid_idx < NUM_MAINBOARD_PIDS; pid_idx++)
|
||||
{
|
||||
dev = hid_open(AURA_USB_VID, mainboard_pid_table[pid_idx], 0);
|
||||
|
||||
if( dev )
|
||||
{
|
||||
AuraMainboardController* controller = new AuraMainboardController(dev);
|
||||
|
||||
RGBController_AuraUSB* rgb_controller = new RGBController_AuraUSB(controller);
|
||||
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,17 @@
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
|
||||
static void Sleep(unsigned int milliseconds)
|
||||
{
|
||||
usleep(1000 * milliseconds);
|
||||
}
|
||||
#endif
|
||||
|
||||
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,
|
||||
@@ -30,6 +41,8 @@ static void send_usb_msg(hid_device* dev, char * data_pkt)
|
||||
}
|
||||
int bytes = hid_send_feature_report(dev, (unsigned char *)usb_pkt, 65);
|
||||
bytes++;
|
||||
|
||||
Sleep(2);
|
||||
}
|
||||
|
||||
CorsairPeripheralController::CorsairPeripheralController(hid_device* dev_handle)
|
||||
|
||||
@@ -15,49 +15,31 @@ PolychromeController::PolychromeController(i2c_smbus_interface* bus, polychrome_
|
||||
this->bus = bus;
|
||||
this->dev = dev;
|
||||
|
||||
switch (GetFirmwareVersion())
|
||||
unsigned short fw_version = GetFirmwareVersion();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Determine whether the device uses ASR LED or |
|
||||
| Polychrome protocol by checking firmware version. |
|
||||
| Versions 1.xx and 2.xx use ASR LED, 3.xx uses |
|
||||
| Polychrome |
|
||||
\*-----------------------------------------------------*/
|
||||
if(((fw_version >> 8) < 0x03) && ((fw_version >> 8) > 0x00))
|
||||
{
|
||||
case FIRMWARE_VER_1_PT_10:
|
||||
led_count = 1;
|
||||
asr_led = true;
|
||||
strcpy(device_name, "ASRock ASR LED FW 1.10");
|
||||
break;
|
||||
|
||||
case FIRMWARE_VER_2_PT_00:
|
||||
led_count = 1;
|
||||
asr_led = true;
|
||||
strcpy(device_name, "ASRock ASR LED FW 2.00");
|
||||
break;
|
||||
|
||||
case FIRMWARE_VER_2_PT_08:
|
||||
led_count = 1;
|
||||
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 ASR LED FW 2.10");
|
||||
break;
|
||||
|
||||
case FIRMWARE_VER_3_PT_00:
|
||||
led_count = 1;
|
||||
asr_led = false;
|
||||
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, "");
|
||||
break;
|
||||
snprintf(device_name, 32, "ASRock ASR LED FW %d.%02d", (fw_version >> 8), (fw_version & 0xFF));
|
||||
led_count = 1;
|
||||
asr_led = true;
|
||||
}
|
||||
else if(fw_version == 0x03)
|
||||
{
|
||||
snprintf(device_name, 32, "ASRock Polychrome FW %d.%02d", (fw_version >> 8), (fw_version & 0xFF));
|
||||
led_count = 1;
|
||||
asr_led = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
led_count = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PolychromeController::~PolychromeController()
|
||||
|
||||
@@ -14,16 +14,6 @@
|
||||
|
||||
typedef unsigned char polychrome_dev_id;
|
||||
|
||||
enum
|
||||
{
|
||||
FIRMWARE_VER_1_PT_10 = 0x010A, /* Firmware nu51_1.10 */
|
||||
FIRMWARE_VER_2_PT_00 = 0x0200, /* Firmware nu51_2.00 */
|
||||
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
|
||||
{
|
||||
ASRLED_REG_FIRMWARE_VER = 0x00, /* Firmware version Major.Minor */
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBFusion2SMBusController.cpp |
|
||||
| |
|
||||
| Driver for Gigabyte Aorus RGB Fusion 2 |
|
||||
| SMBus lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 3/12/2020 |
|
||||
| Matt Harper 5/5/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBFusion2SMBusController.h"
|
||||
#include <cstring>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#endif
|
||||
|
||||
RGBFusion2SMBusController::RGBFusion2SMBusController(i2c_smbus_interface* bus, rgb_fusion_dev_id dev)
|
||||
{
|
||||
this->bus = bus;
|
||||
this->dev = dev;
|
||||
|
||||
memset(led_data, 0, 10*16);
|
||||
|
||||
led_count = 10; // Protocol supports 10 'slots'
|
||||
}
|
||||
|
||||
unsigned int RGBFusion2SMBusController::GetLEDCount()
|
||||
{
|
||||
return(led_count);
|
||||
}
|
||||
|
||||
std::string RGBFusion2SMBusController::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);
|
||||
}
|
||||
|
||||
/* Writes are performed in 32 byte chunks. If we need to write the second 16 bytes,
|
||||
* we must necessarily write the first 16 as well. Given that reading the existing state
|
||||
* from the device is not yet possible, unfortunately we may overwrite existing device
|
||||
* states if the state transition did not occur within in the same OpenRGB instance.
|
||||
* That is to say, the current behavior is non-deal but the best we have
|
||||
*/
|
||||
void RGBFusion2SMBusController::WriteLED(int led)
|
||||
{
|
||||
unsigned short register_offset = led / 2; // Relying on integer division to truncate
|
||||
unsigned short write_register = RGB_FUSION_2_LED_START_ADDR + 2*register_offset;
|
||||
|
||||
// Adjust if we are writing the second 16 bytes
|
||||
if(led % 2)
|
||||
{
|
||||
led -= 1;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
std::cout << std::hex << write_register << "\t";
|
||||
for(int i = 0; i < 2; i++)
|
||||
{
|
||||
for(int j = 0; j < 16; j++)
|
||||
{
|
||||
std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)led_data[led+i][j] << " ";
|
||||
}
|
||||
std::cout << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
#endif
|
||||
|
||||
bus->i2c_smbus_write_block_data(RGB_FUSION_2_SMBUS_ADDR, write_register, 32, led_data[led]);
|
||||
}
|
||||
|
||||
void RGBFusion2SMBusController::Apply()
|
||||
{
|
||||
// Protocol expects terminating sequence 0x01ff written to register 0x17
|
||||
bus->i2c_smbus_write_word_data(RGB_FUSION_2_SMBUS_ADDR,
|
||||
RGB_FUSION_2_APPLY_ADDR,
|
||||
RGB_FUSION_2_ACTION_APPLY);
|
||||
}
|
||||
|
||||
void RGBFusion2SMBusController::SetLEDEffect
|
||||
(
|
||||
unsigned int led,
|
||||
int mode,
|
||||
unsigned int speed,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
)
|
||||
{
|
||||
led_data[led][RGB_FUSION_2_IDX_MODE] = mode;
|
||||
led_data[led][RGB_FUSION_2_IDX_RED] = red;
|
||||
led_data[led][RGB_FUSION_2_IDX_GREEN] = green;
|
||||
led_data[led][RGB_FUSION_2_IDX_BLUE] = blue;
|
||||
led_data[led][RGB_FUSION_2_IDX_BRIGHTNESS] = 0x64;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case RGB_FUSION_2_MODE_PULSE:
|
||||
// Timer 1: On time
|
||||
// Timer 2: Off time
|
||||
led_data[led][RGB_FUSION_2_TIMER_1_LSB] = 0x20 * speed;
|
||||
led_data[led][RGB_FUSION_2_TIMER_1_MSB] = 0x03 * speed;
|
||||
led_data[led][RGB_FUSION_2_TIMER_2_LSB] = 0x20 * speed;
|
||||
led_data[led][RGB_FUSION_2_TIMER_2_MSB] = 0x03 * speed;
|
||||
break;
|
||||
|
||||
case RGB_FUSION_2_MODE_COLOR_CYCLE:
|
||||
// Timer 1: Cycle time
|
||||
led_data[led][RGB_FUSION_2_TIMER_1_LSB] = 0x00;
|
||||
led_data[led][RGB_FUSION_2_TIMER_1_MSB] = 0x03 * speed;
|
||||
led_data[led][RGB_FUSION_2_IDX_OPT_1] = 0x07; // Number of colors to cycle through. Valid range [1-7]
|
||||
led_data[led][RGB_FUSION_2_IDX_OPT_2] = 0x00; // Color cycle, or color cycle and pulse. [0,1]
|
||||
break;
|
||||
|
||||
case RGB_FUSION_2_MODE_FLASHING:
|
||||
/* Timer 1: On time
|
||||
* Timer 2: Interval
|
||||
* Timer 3: Cycle time */
|
||||
led_data[led][RGB_FUSION_2_TIMER_1_LSB] = 0x64;
|
||||
led_data[led][RGB_FUSION_2_TIMER_1_MSB] = 0;
|
||||
led_data[led][RGB_FUSION_2_TIMER_2_LSB] = 0xc8;
|
||||
led_data[led][RGB_FUSION_2_TIMER_2_MSB] = 0;
|
||||
led_data[led][RGB_FUSION_2_TIMER_3_LSB] = 0xd0;
|
||||
led_data[led][RGB_FUSION_2_TIMER_3_MSB] = 0x07;
|
||||
|
||||
led_data[led][RGB_FUSION_2_IDX_OPT_1] = speed; // Controls number of flashes
|
||||
break;
|
||||
}
|
||||
|
||||
WriteLED(led);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBFusion2SMBusController.h |
|
||||
| |
|
||||
| Definitions and types for Gigabyte Aorus |
|
||||
| RGB Fusion 2 SMBus lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 3/12/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include <string>
|
||||
#include "i2c_smbus.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef unsigned char rgb_fusion_dev_id;
|
||||
|
||||
enum
|
||||
{
|
||||
RGB_FUSION_2_IDX_MODE = 0x01, /* Mode index */
|
||||
RGB_FUSION_2_IDX_BRIGHTNESS = 0x02, /* Brightness index */
|
||||
RGB_FUSION_2_IDX_MAX_BRIGHTNESS = 0x02, /* Max brightness index */
|
||||
RGB_FUSION_2_IDX_MIN_BRIGHTNESS = 0x03, /* Minimum brightness index */
|
||||
RGB_FUSION_2_IDX_BLUE = 0x04, /* Blue index */
|
||||
RGB_FUSION_2_IDX_GREEN = 0x05, /* Green index */
|
||||
RGB_FUSION_2_IDX_RED = 0x06, /* Red index */
|
||||
RGB_FUSION_2_IDX_WHITE = 0x07, /* White index */
|
||||
RGB_FUSION_2_TIMER_1_LSB = 0x08, /* Timer 1 LSB. Valid timer values [0-65535] */
|
||||
RGB_FUSION_2_TIMER_1_MSB = 0x09, /* Timer 1 MSB. Timer unis are milliseconds */
|
||||
RGB_FUSION_2_TIMER_2_LSB = 0x0A, /* Timer 2 LSB */
|
||||
RGB_FUSION_2_TIMER_2_MSB = 0x0B, /* Timer 2 MSB */
|
||||
RGB_FUSION_2_TIMER_3_LSB = 0x0C, /* Timer 3 LSB */
|
||||
RGB_FUSION_2_TIMER_3_MSB = 0x0D, /* Timer 3 MSB */
|
||||
RGB_FUSION_2_IDX_OPT_1 = 0x0E, /* Option 1. Use case varies by mode */
|
||||
RGB_FUSION_2_IDX_OPT_2 = 0x0F, /* Option 2. Use case varies by mode */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
RGB_FUSION_2_APPLY_ADDR = 0x17,
|
||||
RGB_FUSION_2_LED_START_ADDR = 0x20,
|
||||
RGB_FUSION_2_SMBUS_ADDR = 0x68,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
RGB_FUSION_2_ACTION_APPLY = 0x01ff,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
RGB_FUSION_2_MODE_PULSE = 0x01, /* Pulse mode */
|
||||
RGB_FUSION_2_MODE_MUSIC = 0x02, /* Music mode */
|
||||
RGB_FUSION_2_MODE_COLOR_CYCLE = 0x03, /* Color cycle mode */
|
||||
RGB_FUSION_2_MODE_STATIC = 0x04, /* Static color mode */
|
||||
RGB_FUSION_2_MODE_FLASHING = 0x05, /* Flashing / Double Flashing mode */
|
||||
RGB_FUSION_2_MODE_TRANSITION = 0x09, /* Gradual transition from current */
|
||||
RGB_FUSION_2_MODE_DIGITAL_A = 0x0A, /* Wave mode */
|
||||
RGB_FUSION_2_MODE_DIGITAL_B = 0x0B, /* */
|
||||
RGB_FUSION_2_MODE_DIGITAL_C = 0x0C, /* */
|
||||
RGB_FUSION_2_MODE_DIGITAL_D = 0x0D, /* */
|
||||
RGB_FUSION_2_MODE_DIGITAL_E = 0x0E, /* */
|
||||
RGB_FUSION_2_MODE_DIGITAL_F = 0x0F, /* */
|
||||
RGB_FUSION_2_MODE_DIGITAL_G = 0x10, /* */
|
||||
RGB_FUSION_2_MODE_DIGITAL_H = 0x11, /* */
|
||||
RGB_FUSION_2_MODE_DIGITAL_I = 0x12, /* */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
RGB_FUSION_2_SPEED_FAST = 0x01,
|
||||
RGB_FUSION_2_SPEED_NORMAL = 0x02,
|
||||
RGB_FUSION_2_SPEED_SLOW = 0x04,
|
||||
};
|
||||
|
||||
class RGBFusion2SMBusController
|
||||
{
|
||||
public:
|
||||
RGBFusion2SMBusController(i2c_smbus_interface* bus, rgb_fusion_dev_id dev);
|
||||
~RGBFusion2SMBusController();
|
||||
|
||||
std::string GetDeviceLocation();
|
||||
unsigned int GetLEDCount();
|
||||
void Apply();
|
||||
|
||||
void SetLEDEffect
|
||||
(
|
||||
unsigned int led,
|
||||
int mode,
|
||||
unsigned int speed,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
);
|
||||
|
||||
private:
|
||||
unsigned int led_count;
|
||||
i2c_smbus_interface* bus;
|
||||
rgb_fusion_dev_id dev;
|
||||
|
||||
unsigned char led_data[10][16];
|
||||
|
||||
void WriteLED(int);
|
||||
};
|
||||
@@ -0,0 +1,73 @@
|
||||
#include "RGBFusion2SMBusController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_RGBFusion2SMBus.h"
|
||||
#include "i2c_smbus.h"
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* TestForRGBFusion2SMBusController *
|
||||
* *
|
||||
* Tests the given address to see if an RGB 2 Fusion controller exists there. First *
|
||||
* does a quick write to test for a response *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
bool TestForRGBFusion2SMBusController(i2c_smbus_interface* bus, unsigned char address)
|
||||
{
|
||||
bool pass = false;
|
||||
|
||||
int res = bus->i2c_smbus_write_quick(address, I2C_SMBUS_WRITE);
|
||||
if (res >= 0)
|
||||
{
|
||||
pass = true;
|
||||
|
||||
// res = bus->i2c_smbus_read_byte_data(address, 0xF2);
|
||||
|
||||
// if (res != 0xC4)
|
||||
// {
|
||||
// pass = false;
|
||||
// }
|
||||
}
|
||||
|
||||
return(pass);
|
||||
|
||||
} /* TestForRGBFusion2SMBusController() */
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectRGBFusion2SMBusControllers *
|
||||
* *
|
||||
* Detect RGB Fusion 2 controllers on the enumerated I2C busses at address 0x68. *
|
||||
* *
|
||||
* bus - pointer to i2c_smbus_interface where RGB Fusion device is connected *
|
||||
* dev - I2C address of RGB Fusion device *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectRGBFusion2SMBusControllers(std::vector<i2c_smbus_interface*>& busses, std::vector<RGBController*>& rgb_controllers)
|
||||
{
|
||||
RGBFusion2SMBusController* new_rgb_fusion;
|
||||
RGBController_RGBFusion2SMBus* new_controller;
|
||||
|
||||
for (unsigned int bus = 0; bus < busses.size(); bus++)
|
||||
{
|
||||
// TODO - Is this necessary? Or an artifact of my own system?
|
||||
// Skip dmcd devices
|
||||
std::string device_name = std::string(busses[bus]->device_name);
|
||||
if (device_name.find("dmdc") == std::string::npos)
|
||||
{
|
||||
// Check for RGB Fusion 2 controller at 0x68
|
||||
if (TestForRGBFusion2SMBusController(busses[bus], 0x68))
|
||||
{
|
||||
new_rgb_fusion = new RGBFusion2SMBusController(busses[bus], 0x68);
|
||||
new_controller = new RGBController_RGBFusion2SMBus(new_rgb_fusion);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} /* DetectRGBFusion2SMBusControllers() */
|
||||
@@ -0,0 +1,569 @@
|
||||
/*-----------------------------------------*\
|
||||
| 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>
|
||||
#define MSG_NOSIGNAL 0
|
||||
#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;
|
||||
}
|
||||
|
||||
void NetworkClient::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();
|
||||
}
|
||||
|
||||
const char * NetworkClient::GetIP()
|
||||
{
|
||||
return(port_ip);
|
||||
}
|
||||
|
||||
unsigned short NetworkClient::GetPort()
|
||||
{
|
||||
return port_num;
|
||||
}
|
||||
|
||||
bool NetworkClient::GetOnline()
|
||||
{
|
||||
return server_connected;
|
||||
}
|
||||
|
||||
void NetworkClient::RegisterClientInfoChangeCallback(NetClientCallback new_callback, void * new_callback_arg)
|
||||
{
|
||||
ClientInfoChangeCallbacks.push_back(new_callback);
|
||||
ClientInfoChangeCallbackArgs.push_back(new_callback_arg);
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
//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);
|
||||
|
||||
//Start the connection thread
|
||||
ConnectionThread = new std::thread(&NetworkClient::ConnectionThreadFunction, this);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Client info has changed, call the callbacks |
|
||||
\*-------------------------------------------------*/
|
||||
ClientInfoChanged();
|
||||
}
|
||||
|
||||
void NetworkClient::StopClient()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NetworkClient::ConnectionThreadFunction()
|
||||
{
|
||||
unsigned int requested_controllers;
|
||||
|
||||
//This thread manages the connection to the server
|
||||
while(1)
|
||||
{
|
||||
if(server_connected == false)
|
||||
{
|
||||
//Connect to server and reconnect if the connection is lost
|
||||
server_initialized = false;
|
||||
|
||||
//Try to connect to server
|
||||
if(port.tcp_client_connect() == true)
|
||||
{
|
||||
client_sock = port.sock;
|
||||
printf( "Connected to server\n" );
|
||||
|
||||
//Server is now connected
|
||||
server_connected = true;
|
||||
|
||||
//Start the listener thread
|
||||
ListenThread = new std::thread(&NetworkClient::ListenThreadFunction, this);
|
||||
|
||||
//Server is not initialized
|
||||
server_initialized = false;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Client info has changed, call the callbacks |
|
||||
\*-------------------------------------------------*/
|
||||
ClientInfoChanged();
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "Connection attempt failed\n" );
|
||||
}
|
||||
}
|
||||
|
||||
if(server_initialized == false && server_connected == true)
|
||||
{
|
||||
requested_controllers = 0;
|
||||
server_controller_count = 0;
|
||||
|
||||
//Wait for server to connect
|
||||
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]);
|
||||
}
|
||||
|
||||
server_initialized = true;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Client info has changed, call the callbacks |
|
||||
\*-------------------------------------------------*/
|
||||
ClientInfoChanged();
|
||||
}
|
||||
|
||||
Sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
int NetworkClient::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_connected == false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if(rv == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// socket has something to read
|
||||
return(recv(s, buf, len, flags));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::ListenThreadFunction()
|
||||
{
|
||||
printf("Network client listener started\n");
|
||||
//This thread handles messages received from the server
|
||||
while(server_connected = 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( "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)
|
||||
{
|
||||
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( "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;
|
||||
}
|
||||
|
||||
listen_done:
|
||||
printf( "Client socket has been closed");
|
||||
server_initialized = false;
|
||||
server_connected = false;
|
||||
|
||||
for(int server_controller_idx = 0; server_controller_idx < server_controllers.size(); server_controller_idx++)
|
||||
{
|
||||
for(int controller_idx = 0; controller_idx < controllers.size(); controller_idx++)
|
||||
{
|
||||
if(controllers[controller_idx] == server_controllers[server_controller_idx])
|
||||
{
|
||||
controllers.erase(controllers.begin() + controller_idx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete server_controllers[server_controller_idx];
|
||||
}
|
||||
|
||||
server_controllers.clear();
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Client info has changed, call the callbacks |
|
||||
\*-------------------------------------------------*/
|
||||
ClientInfoChanged();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)client_name.c_str(), reply_hdr.pkt_size, MSG_NOSIGNAL);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)&reply_data, sizeof(reply_data), MSG_NOSIGNAL);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)data, size, 0);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)data, size, MSG_NOSIGNAL);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)data, size, MSG_NOSIGNAL);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)data, size, MSG_NOSIGNAL);
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*-----------------------------------------*\
|
||||
| NetworkClient.h |
|
||||
| |
|
||||
| Client 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 (*NetClientCallback)(void *);
|
||||
|
||||
class NetworkClient
|
||||
{
|
||||
public:
|
||||
NetworkClient(std::vector<RGBController *>& control);
|
||||
|
||||
void ClientInfoChanged();
|
||||
|
||||
const char * GetIP();
|
||||
unsigned short GetPort();
|
||||
bool GetOnline();
|
||||
|
||||
void RegisterClientInfoChangeCallback(NetClientCallback new_callback, void * new_callback_arg);
|
||||
|
||||
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);
|
||||
|
||||
std::vector<RGBController *> server_controllers;
|
||||
|
||||
protected:
|
||||
std::vector<RGBController *>& controllers;
|
||||
|
||||
|
||||
private:
|
||||
SOCKET client_sock;
|
||||
std::string client_name;
|
||||
net_port port;
|
||||
char port_ip[20];
|
||||
unsigned short port_num;
|
||||
bool server_connected;
|
||||
bool server_initialized;
|
||||
unsigned int server_controller_count;
|
||||
|
||||
std::thread * ConnectionThread;
|
||||
std::thread * ListenThread;
|
||||
|
||||
std::mutex ClientInfoChangeMutex;
|
||||
std::vector<NetClientCallback> ClientInfoChangeCallbacks;
|
||||
std::vector<void *> ClientInfoChangeCallbackArgs;
|
||||
|
||||
int recv_select(SOCKET s, char *buf, int len, int flags);
|
||||
};
|
||||
@@ -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);
|
||||
};
|
||||
+9
-7
@@ -254,11 +254,8 @@ void DetectI2CBusses()
|
||||
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);
|
||||
|
||||
bus = new i2c_smbus_linux();
|
||||
strcpy(bus->device_name, device_string);
|
||||
|
||||
strcpy(device_string, "/dev/");
|
||||
strcat(device_string, ent->d_name);
|
||||
@@ -266,11 +263,12 @@ void DetectI2CBusses()
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -293,9 +291,10 @@ void DetectPatriotViperControllers(std::vector<i2c_smbus_interface*> &busses, st
|
||||
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 DetectRGBFusion2SMBusControllers(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 DetectAuraUSBControllers(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);
|
||||
@@ -337,11 +336,14 @@ void DetectRGBControllers(void)
|
||||
DetectPolychromeControllers(busses, rgb_controllers);
|
||||
DetectRGBFusionGPUControllers(busses, rgb_controllers);
|
||||
|
||||
//TODO: Implement better detection before enabling this controller
|
||||
//DetectRGBFusion2SMBusControllers(busses, rgb_controllers);
|
||||
|
||||
DetectRGBFusionControllers(busses, rgb_controllers);
|
||||
DetectMSIMysticLightControllers(rgb_controllers);
|
||||
DetectMSIRGBControllers(rgb_controllers);
|
||||
|
||||
DetectAuraAddressableControllers(rgb_controllers);
|
||||
DetectAuraUSBControllers(rgb_controllers);
|
||||
DetectAuraCoreControllers(rgb_controllers);
|
||||
DetectLEDStripControllers(rgb_controllers);
|
||||
DetectHue2Controllers(rgb_controllers);
|
||||
|
||||
+35
-15
@@ -5,7 +5,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
TARGET = OpenRGB
|
||||
TEMPLATE = app
|
||||
|
||||
VERSION = 0.11
|
||||
VERSION = 0.2
|
||||
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)
|
||||
@@ -31,7 +31,7 @@ INCLUDEPATH += \
|
||||
serial_port/ \
|
||||
super_io/ \
|
||||
Controllers/AMDWraithPrismController/ \
|
||||
Controllers/AuraAddressableController/ \
|
||||
Controllers/AuraUSBController/ \
|
||||
Controllers/AuraCoreController/ \
|
||||
Controllers/AuraGPUController/ \
|
||||
Controllers/AuraSMBusController/ \
|
||||
@@ -55,6 +55,7 @@ INCLUDEPATH += \
|
||||
Controllers/PoseidonZRGBController/ \
|
||||
Controllers/RedragonController/ \
|
||||
Controllers/RGBFusionController/ \
|
||||
Controllers/RGBFusion2SMBusController/ \
|
||||
Controllers/RGBFusion2USBController/ \
|
||||
Controllers/RGBFusionGPUController/ \
|
||||
Controllers/ThermaltakeRiingController/ \
|
||||
@@ -68,6 +69,8 @@ SOURCES += \
|
||||
main.cpp \
|
||||
cli.cpp \
|
||||
OpenRGB.cpp \
|
||||
NetworkClient.cpp \
|
||||
NetworkServer.cpp \
|
||||
ProfileManager.cpp \
|
||||
qt/OpenRGBDeviceInfoPage.cpp \
|
||||
qt/OpenRGBDevicePage.cpp \
|
||||
@@ -77,6 +80,7 @@ SOURCES += \
|
||||
net_port/net_port.cpp \
|
||||
qt/OpenRGBDialog2.cpp \
|
||||
qt/OpenRGBProfileSaveDialog.cpp \
|
||||
qt/OpenRGBServerInfoPage.cpp \
|
||||
qt/OpenRGBSoftwareInfoPage.cpp \
|
||||
qt/OpenRGBSystemInfoPage.cpp \
|
||||
qt/OpenRGBZoneResizeDialog.cpp \
|
||||
@@ -85,8 +89,10 @@ SOURCES += \
|
||||
super_io/super_io.cpp \
|
||||
Controllers/AMDWraithPrismController/AMDWraithPrismController.cpp \
|
||||
Controllers/AMDWraithPrismController/AMDWraithPrismControllerDetect.cpp \
|
||||
Controllers/AuraAddressableController/AuraAddressableController.cpp \
|
||||
Controllers/AuraAddressableController/AuraAddressableControllerDetect.cpp \
|
||||
Controllers/AuraUSBController/AuraUSBController.cpp \
|
||||
Controllers/AuraUSBController/AuraAddressableController.cpp \
|
||||
Controllers/AuraUSBController/AuraMainboardController.cpp \
|
||||
Controllers/AuraUSBController/AuraUSBControllerDetect.cpp \
|
||||
Controllers/AuraCoreController/AuraCoreController.cpp \
|
||||
Controllers/AuraCoreController/AuraCoreControllerDetect.cpp \
|
||||
Controllers/AuraGPUController/AuraGPUController.cpp \
|
||||
@@ -133,6 +139,8 @@ SOURCES += \
|
||||
Controllers/RGBFusionController/RGBFusionControllerDetect.cpp \
|
||||
Controllers/RGBFusion2USBController/RGBFusion2USBController.cpp \
|
||||
Controllers/RGBFusion2USBController/RGBFusion2USBControllerDetect.cpp \
|
||||
Controllers/RGBFusion2SMBusController/RGBFusion2SMBusController.cpp \
|
||||
Controllers/RGBFusion2SMBusController/RGBFusion2SMBusControllerDetect.cpp \
|
||||
Controllers/RGBFusionGPUController/RGBFusionGPUController.cpp \
|
||||
Controllers/RGBFusionGPUController/RGBFusionGPUControllerDetect.cpp \
|
||||
Controllers/RedragonController/RedragonK556Controller.cpp \
|
||||
@@ -143,7 +151,7 @@ SOURCES += \
|
||||
RGBController/RGBController.cpp \
|
||||
RGBController/E131ControllerDetect.cpp \
|
||||
RGBController/RGBController_AMDWraithPrism.cpp \
|
||||
RGBController/RGBController_AuraAddressable.cpp \
|
||||
RGBController/RGBController_AuraUSB.cpp \
|
||||
RGBController/RGBController_AuraCore.cpp \
|
||||
RGBController/RGBController_AuraGPU.cpp \
|
||||
RGBController/RGBController_AuraSMBus.cpp \
|
||||
@@ -163,6 +171,7 @@ SOURCES += \
|
||||
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 \
|
||||
@@ -170,12 +179,16 @@ SOURCES += \
|
||||
RGBController/RGBController_RedragonK556.cpp \
|
||||
RGBController/RGBController_RedragonM711.cpp \
|
||||
RGBController/RGBController_RGBFusion.cpp \
|
||||
RGBController/RGBController_RGBFusion2SMBus.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 \
|
||||
@@ -185,6 +198,7 @@ HEADERS += \
|
||||
net_port/net_port.h \
|
||||
qt/OpenRGBDialog2.h \
|
||||
qt/OpenRGBProfileSaveDialog.h \
|
||||
qt/OpenRGBServerInfoPage.h \
|
||||
qt/OpenRGBSoftwareInfoPage.h \
|
||||
qt/OpenRGBSystemInfoPage.h \
|
||||
qt/OpenRGBZoneResizeDialog.h \
|
||||
@@ -192,7 +206,9 @@ HEADERS += \
|
||||
serial_port/serial_port.h \
|
||||
super_io/super_io.h \
|
||||
Controllers/AMDWraithPrismController/AMDWraithPrismController.h \
|
||||
Controllers/AuraAddressableController/AuraAddressableController.h \
|
||||
Controllers/AuraUSBController/AuraUSBController.h \
|
||||
Controllers/AuraUSBController/AuraAddressableController.h \
|
||||
Controllers/AuraUSBController/AuraMainboardController.h \
|
||||
Controllers/AuraCoreController/AuraCoreController.h \
|
||||
Controllers/AuraGPUController/AuraGPUController.h \
|
||||
Controllers/AuraSMBusController/AuraSMBusController.h \
|
||||
@@ -215,13 +231,14 @@ HEADERS += \
|
||||
Controllers/PoseidonZRGBController/PoseidonZRGBController.h \
|
||||
Controllers/RGBFusionController/RGBFusionController.h \
|
||||
Controllers/RGBFusion2USBController/RGBFusion2USBController.h \
|
||||
Controllers/RGBFusion2SMBusController/RGBFusion2SMBusController.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_AuraAddressable.h \
|
||||
RGBController/RGBController_AuraUSB.h \
|
||||
RGBController/RGBController_AuraCore.h \
|
||||
RGBController/RGBController_AuraGPU.h \
|
||||
RGBController/RGBController_AuraSMBus.h \
|
||||
@@ -241,12 +258,14 @@ HEADERS += \
|
||||
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_RGBFusion2SMBus.h \
|
||||
RGBController/RGBController_RGBFusion2USB.h \
|
||||
RGBController/RGBController_RGBFusionGPU.h \
|
||||
RGBController/RGBController_ThermaltakeRiing.h \
|
||||
@@ -255,14 +274,15 @@ RESOURCES += \
|
||||
qt/resources.qrc
|
||||
|
||||
FORMS += \
|
||||
qt/OpenRGBDeviceInfoPage.ui \
|
||||
qt/OpenRGBDevicePage.ui \
|
||||
qt/OpenRGBDialog.ui \
|
||||
qt/OpenRGBDialog2.ui \
|
||||
qt/OpenRGBProfileSaveDialog.ui \
|
||||
qt/OpenRGBSoftwareInfoPage.ui \
|
||||
qt/OpenRGBSystemInfoPage.ui \
|
||||
qt/OpenRGBZoneResizeDialog.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
|
||||
|
||||
@@ -199,7 +199,7 @@ static const razer_zone blackwidow_chroma_v2_zone =
|
||||
|
||||
static const razer_device blackwidow_chroma_v2_device =
|
||||
{
|
||||
"Razer Blackwidow Chroma V2",
|
||||
"Razer BlackWidow Chroma V2",
|
||||
DEVICE_TYPE_KEYBOARD,
|
||||
true,
|
||||
6,
|
||||
|
||||
@@ -1,6 +1,29 @@
|
||||
#include "RGBController.h"
|
||||
#include <cstring>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
|
||||
static void Sleep(unsigned int milliseconds)
|
||||
{
|
||||
usleep(1000 * milliseconds);
|
||||
}
|
||||
#endif
|
||||
|
||||
RGBController::RGBController()
|
||||
{
|
||||
DeviceThreadRunning = true;
|
||||
DeviceCallThread = new std::thread(&RGBController::DeviceCallThreadFunction, this);
|
||||
}
|
||||
|
||||
RGBController::~RGBController()
|
||||
{
|
||||
DeviceThreadRunning = false;
|
||||
DeviceCallThread->join();
|
||||
}
|
||||
|
||||
unsigned char * RGBController::GetDeviceDescription()
|
||||
{
|
||||
unsigned int data_ptr = 0;
|
||||
@@ -23,6 +46,7 @@ unsigned char * RGBController::GetDeviceDescription()
|
||||
unsigned short *zone_name_len = new unsigned short[num_zones];
|
||||
unsigned short *led_name_len = new unsigned short[num_leds];
|
||||
|
||||
unsigned short *zone_matrix_len = new unsigned short[num_zones];
|
||||
unsigned short *mode_num_colors = new unsigned short[num_modes];
|
||||
|
||||
data_size += sizeof(data_size);
|
||||
@@ -66,6 +90,18 @@ unsigned char * RGBController::GetDeviceDescription()
|
||||
data_size += sizeof(zones[zone_index].leds_min);
|
||||
data_size += sizeof(zones[zone_index].leds_max);
|
||||
data_size += sizeof(zones[zone_index].leds_count);
|
||||
|
||||
if(zones[zone_index].matrix_map == NULL)
|
||||
{
|
||||
zone_matrix_len[zone_index] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
zone_matrix_len[zone_index] = (2 * sizeof(unsigned int)) + (zones[zone_index].matrix_map->height * zones[zone_index].matrix_map->width * sizeof(unsigned int));
|
||||
}
|
||||
|
||||
data_size += sizeof(zone_matrix_len[zone_index]);
|
||||
data_size += zone_matrix_len[zone_index];
|
||||
}
|
||||
|
||||
data_size += sizeof(num_leds);
|
||||
@@ -286,6 +322,39 @@ unsigned char * RGBController::GetDeviceDescription()
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &zones[zone_index].leds_count, sizeof(zones[zone_index].leds_count));
|
||||
data_ptr += sizeof(zones[zone_index].leds_count);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in size of zone matrix |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &zone_matrix_len[zone_index], sizeof(zone_matrix_len[zone_index]));
|
||||
data_ptr += sizeof(zone_matrix_len[zone_index]);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in matrix data if size is nonzero |
|
||||
\*---------------------------------------------------------*/
|
||||
if(zone_matrix_len[zone_index] > 0)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in matrix height |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &zones[zone_index].matrix_map->height, sizeof(zones[zone_index].matrix_map->height));
|
||||
data_ptr += sizeof(zones[zone_index].matrix_map->height);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in matrix width |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &zones[zone_index].matrix_map->width, sizeof(zones[zone_index].matrix_map->width));
|
||||
data_ptr += sizeof(zones[zone_index].matrix_map->width);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in matrix map |
|
||||
\*---------------------------------------------------------*/
|
||||
for(int matrix_idx = 0; matrix_idx < (zones[zone_index].matrix_map->height * zones[zone_index].matrix_map->width); matrix_idx++)
|
||||
{
|
||||
memcpy(&data_buf[data_ptr], &zones[zone_index].matrix_map->map[matrix_idx], sizeof(zones[zone_index].matrix_map->map[matrix_idx]));
|
||||
data_ptr += sizeof(zones[zone_index].matrix_map->map[matrix_idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
@@ -334,11 +403,11 @@ unsigned char * RGBController::GetDeviceDescription()
|
||||
data_ptr += sizeof(colors[color_index]);
|
||||
}
|
||||
|
||||
|
||||
delete[] mode_name_len;
|
||||
delete[] zone_name_len;
|
||||
delete[] led_name_len;
|
||||
|
||||
delete[] zone_matrix_len;
|
||||
delete[] mode_num_colors;
|
||||
|
||||
return(data_buf);
|
||||
@@ -563,6 +632,54 @@ void RGBController::ReadDeviceDescription(unsigned char* data_buf)
|
||||
memcpy(&new_zone.leds_count, &data_buf[data_ptr], sizeof(new_zone.leds_count));
|
||||
data_ptr += sizeof(new_zone.leds_count);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in size of zone matrix |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned short zone_matrix_len;
|
||||
memcpy(&zone_matrix_len, &data_buf[data_ptr], sizeof(zone_matrix_len));
|
||||
data_ptr += sizeof(zone_matrix_len);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in matrix data if size is nonzero |
|
||||
\*---------------------------------------------------------*/
|
||||
if(zone_matrix_len > 0)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Create a map data structure to fill in and attach it to |
|
||||
| the new zone |
|
||||
\*---------------------------------------------------------*/
|
||||
matrix_map_type * new_map = new matrix_map_type;
|
||||
|
||||
new_zone.matrix_map = new_map;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in matrix height |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&new_map->height, &data_buf[data_ptr], sizeof(new_map->height));
|
||||
data_ptr += sizeof(new_map->height);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in matrix width |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&new_map->width, &data_buf[data_ptr], sizeof(new_map->width));
|
||||
data_ptr += sizeof(new_map->width);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in matrix map |
|
||||
\*---------------------------------------------------------*/
|
||||
new_map->map = new unsigned int[new_map->height * new_map->width];
|
||||
|
||||
for(int matrix_idx = 0; matrix_idx < (new_map->height * new_map->width); matrix_idx++)
|
||||
{
|
||||
memcpy(&new_map->map[matrix_idx], &data_buf[data_ptr], sizeof(new_map->map[matrix_idx]));
|
||||
data_ptr += sizeof(new_map->map[matrix_idx]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
new_zone.matrix_map = NULL;
|
||||
}
|
||||
|
||||
zones.push_back(new_zone);
|
||||
}
|
||||
|
||||
@@ -621,6 +738,457 @@ void RGBController::ReadDeviceDescription(unsigned char* data_buf)
|
||||
|
||||
colors.push_back(new_color);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Setup colors |
|
||||
\*---------------------------------------------------------*/
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
unsigned char * RGBController::GetModeDescription(int mode)
|
||||
{
|
||||
unsigned int data_ptr = 0;
|
||||
unsigned int data_size = 0;
|
||||
|
||||
unsigned short mode_name_len;
|
||||
unsigned short mode_num_colors;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Calculate data size |
|
||||
\*---------------------------------------------------------*/
|
||||
mode_name_len = strlen(modes[mode].name.c_str()) + 1;
|
||||
mode_num_colors = modes[mode].colors.size();
|
||||
|
||||
data_size += sizeof(data_size);
|
||||
data_size += sizeof(mode);
|
||||
data_size += sizeof(mode_name_len);
|
||||
data_size += mode_name_len;
|
||||
data_size += sizeof(modes[mode].value);
|
||||
data_size += sizeof(modes[mode].flags);
|
||||
data_size += sizeof(modes[mode].speed_min);
|
||||
data_size += sizeof(modes[mode].speed_max);
|
||||
data_size += sizeof(modes[mode].colors_min);
|
||||
data_size += sizeof(modes[mode].colors_max);
|
||||
data_size += sizeof(modes[mode].speed);
|
||||
data_size += sizeof(modes[mode].direction);
|
||||
data_size += sizeof(modes[mode].color_mode);
|
||||
data_size += sizeof(mode_num_colors);
|
||||
data_size += (mode_num_colors * sizeof(RGBColor));
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Create data buffer |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned char *data_buf = new unsigned char[data_size];
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in data size |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &data_size, sizeof(data_size));
|
||||
data_ptr += sizeof(data_size);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode index |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &mode, sizeof(int));
|
||||
data_ptr += sizeof(int);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode name (size+data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &mode_name_len, sizeof(unsigned short));
|
||||
data_ptr += sizeof(unsigned short);
|
||||
|
||||
strcpy((char *)&data_buf[data_ptr], modes[mode].name.c_str());
|
||||
data_ptr += mode_name_len;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode value (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &modes[mode].value, sizeof(modes[mode].value));
|
||||
data_ptr += sizeof(modes[mode].value);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode flags (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &modes[mode].flags, sizeof(modes[mode].flags));
|
||||
data_ptr += sizeof(modes[mode].flags);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode speed_min (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &modes[mode].speed_min, sizeof(modes[mode].speed_min));
|
||||
data_ptr += sizeof(modes[mode].speed_min);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode speed_max (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &modes[mode].speed_max, sizeof(modes[mode].speed_max));
|
||||
data_ptr += sizeof(modes[mode].speed_max);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode colors_min (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &modes[mode].colors_min, sizeof(modes[mode].colors_min));
|
||||
data_ptr += sizeof(modes[mode].colors_min);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode colors_max (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &modes[mode].colors_max, sizeof(modes[mode].colors_max));
|
||||
data_ptr += sizeof(modes[mode].colors_max);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode speed (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &modes[mode].speed, sizeof(modes[mode].speed));
|
||||
data_ptr += sizeof(modes[mode].speed);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode direction (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &modes[mode].direction, sizeof(modes[mode].direction));
|
||||
data_ptr += sizeof(modes[mode].direction);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode color_mode (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &modes[mode].color_mode, sizeof(modes[mode].color_mode));
|
||||
data_ptr += sizeof(modes[mode].color_mode);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode number of colors |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &mode_num_colors, sizeof(unsigned short));
|
||||
data_ptr += sizeof(unsigned short);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode mode colors |
|
||||
\*---------------------------------------------------------*/
|
||||
for(int color_index = 0; color_index < mode_num_colors; color_index++)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in color (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &modes[mode].colors[color_index], sizeof(modes[mode].colors[color_index]));
|
||||
data_ptr += sizeof(modes[mode].colors[color_index]);
|
||||
}
|
||||
|
||||
return(data_buf);
|
||||
}
|
||||
|
||||
void RGBController::SetModeDescription(unsigned char* data_buf)
|
||||
{
|
||||
int mode_idx;
|
||||
unsigned int data_ptr = sizeof(unsigned int);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode index |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&mode_idx, &data_buf[data_ptr], sizeof(int));
|
||||
data_ptr += sizeof(int);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Get pointer to target mode |
|
||||
\*---------------------------------------------------------*/
|
||||
mode * new_mode = &modes[mode_idx];
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Set active mode to the new mode |
|
||||
\*---------------------------------------------------------*/
|
||||
active_mode = mode_idx;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode name (size+data) |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned short modename_len;
|
||||
memcpy(&modename_len, &data_buf[data_ptr], sizeof(unsigned short));
|
||||
data_ptr += sizeof(unsigned short);
|
||||
|
||||
new_mode->name = (char *)&data_buf[data_ptr];
|
||||
data_ptr += modename_len;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode value (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&new_mode->value, &data_buf[data_ptr], sizeof(new_mode->value));
|
||||
data_ptr += sizeof(new_mode->value);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode flags (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&new_mode->flags, &data_buf[data_ptr], sizeof(new_mode->flags));
|
||||
data_ptr += sizeof(new_mode->flags);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode speed_min (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&new_mode->speed_min, &data_buf[data_ptr], sizeof(new_mode->speed_min));
|
||||
data_ptr += sizeof(new_mode->speed_min);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode speed_max (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&new_mode->speed_max, &data_buf[data_ptr], sizeof(new_mode->speed_max));
|
||||
data_ptr += sizeof(new_mode->speed_max);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode colors_min (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&new_mode->colors_min, &data_buf[data_ptr], sizeof(new_mode->colors_min));
|
||||
data_ptr += sizeof(new_mode->colors_min);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode colors_max (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&new_mode->colors_max, &data_buf[data_ptr], sizeof(new_mode->colors_max));
|
||||
data_ptr += sizeof(new_mode->colors_max);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode speed (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&new_mode->speed, &data_buf[data_ptr], sizeof(new_mode->speed));
|
||||
data_ptr += sizeof(new_mode->speed);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode direction (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&new_mode->direction, &data_buf[data_ptr], sizeof(new_mode->direction));
|
||||
data_ptr += sizeof(new_mode->direction);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode color_mode (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&new_mode->color_mode, &data_buf[data_ptr], sizeof(new_mode->color_mode));
|
||||
data_ptr += sizeof(new_mode->color_mode);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode number of colors |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned short mode_num_colors;
|
||||
memcpy(&mode_num_colors, &data_buf[data_ptr], sizeof(unsigned short));
|
||||
data_ptr += sizeof(unsigned short);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in mode mode colors |
|
||||
\*---------------------------------------------------------*/
|
||||
new_mode->colors.clear();
|
||||
for(int color_index = 0; color_index < mode_num_colors; color_index++)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in color (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
RGBColor new_color;
|
||||
memcpy(&new_color, &data_buf[data_ptr], sizeof(RGBColor));
|
||||
data_ptr += sizeof(RGBColor);
|
||||
|
||||
new_mode->colors.push_back(new_color);
|
||||
}
|
||||
|
||||
printf("read data ptr %d\r\n", data_ptr);
|
||||
}
|
||||
|
||||
unsigned char * RGBController::GetColorDescription()
|
||||
{
|
||||
unsigned int data_ptr = 0;
|
||||
unsigned int data_size = 0;
|
||||
|
||||
unsigned short num_colors = colors.size();
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Calculate data size |
|
||||
\*---------------------------------------------------------*/
|
||||
data_size += sizeof(data_size);
|
||||
data_size += sizeof(num_colors);
|
||||
data_size += num_colors * sizeof(RGBColor);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Create data buffer |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned char *data_buf = new unsigned char[data_size];
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in data size |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &data_size, sizeof(data_size));
|
||||
data_ptr += sizeof(data_size);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in number of colors (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &num_colors, sizeof(unsigned short));
|
||||
data_ptr += sizeof(unsigned short);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in colors |
|
||||
\*---------------------------------------------------------*/
|
||||
for(int color_index = 0; color_index < num_colors; color_index++)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in color (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &colors[color_index], sizeof(colors[color_index]));
|
||||
data_ptr += sizeof(colors[color_index]);
|
||||
}
|
||||
|
||||
return(data_buf);
|
||||
}
|
||||
|
||||
void RGBController::SetColorDescription(unsigned char* data_buf)
|
||||
{
|
||||
unsigned int data_ptr = sizeof(unsigned int);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in number of colors (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned short num_colors;
|
||||
memcpy(&num_colors, &data_buf[data_ptr], sizeof(unsigned short));
|
||||
data_ptr += sizeof(unsigned short);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in colors |
|
||||
\*---------------------------------------------------------*/
|
||||
for(int color_index = 0; color_index < num_colors; color_index++)
|
||||
{
|
||||
RGBColor new_color;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in color (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&new_color, &data_buf[data_ptr], sizeof(RGBColor));
|
||||
data_ptr += sizeof(RGBColor);
|
||||
|
||||
colors[color_index] = new_color;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char * RGBController::GetZoneColorDescription(int zone)
|
||||
{
|
||||
unsigned int data_ptr = 0;
|
||||
unsigned int data_size = 0;
|
||||
|
||||
unsigned short num_colors = zones[zone].leds_count;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Calculate data size |
|
||||
\*---------------------------------------------------------*/
|
||||
data_size += sizeof(data_size);
|
||||
data_size += sizeof(zone);
|
||||
data_size += sizeof(num_colors);
|
||||
data_size += num_colors * sizeof(RGBColor);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Create data buffer |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned char *data_buf = new unsigned char[data_size];
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in data size |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &data_size, sizeof(data_size));
|
||||
data_ptr += sizeof(data_size);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in zone index |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &zone, sizeof(zone));
|
||||
data_ptr += sizeof(zone);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in number of colors (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &num_colors, sizeof(unsigned short));
|
||||
data_ptr += sizeof(unsigned short);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in colors |
|
||||
\*---------------------------------------------------------*/
|
||||
for(int color_index = 0; color_index < num_colors; color_index++)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in color (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &zones[zone].colors[color_index], sizeof(zones[zone].colors[color_index]));
|
||||
data_ptr += sizeof(zones[zone].colors[color_index]);
|
||||
}
|
||||
|
||||
return(data_buf);
|
||||
}
|
||||
|
||||
void RGBController::SetZoneColorDescription(unsigned char* data_buf)
|
||||
{
|
||||
unsigned int data_ptr = sizeof(unsigned int);
|
||||
unsigned int zone_idx;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in zone index |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&zone_idx, &data_buf[data_ptr], sizeof(zone_idx));
|
||||
data_ptr += sizeof(zone_idx);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in number of colors (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned short num_colors;
|
||||
memcpy(&num_colors, &data_buf[data_ptr], sizeof(unsigned short));
|
||||
data_ptr += sizeof(unsigned short);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in colors |
|
||||
\*---------------------------------------------------------*/
|
||||
for(int color_index = 0; color_index < num_colors; color_index++)
|
||||
{
|
||||
RGBColor new_color;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in color (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&new_color, &data_buf[data_ptr], sizeof(RGBColor));
|
||||
data_ptr += sizeof(RGBColor);
|
||||
|
||||
zones[zone_idx].colors[color_index] = new_color;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char * RGBController::GetSingleLEDColorDescription(int led)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Fixed size descrption: |
|
||||
| int: LED index |
|
||||
| RGBColor: LED color |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned char *data_buf = new unsigned char[sizeof(int) + sizeof(RGBColor)];
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in LED index |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[0], &led, sizeof(int));
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in LED color |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[sizeof(led)], &colors[led], sizeof(RGBColor));
|
||||
|
||||
return(data_buf);
|
||||
}
|
||||
|
||||
void RGBController::SetSingleLEDColorDescription(unsigned char* data_buf)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Fixed size descrption: |
|
||||
| int: LED index |
|
||||
| RGBColor: LED color |
|
||||
\*---------------------------------------------------------*/
|
||||
int led_idx;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in LED index |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&led_idx, &data_buf[0], sizeof(led_idx));
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in LED color |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&colors[led_idx], &data_buf[sizeof(led_idx)], sizeof(RGBColor));
|
||||
}
|
||||
|
||||
void RGBController::SetupColors()
|
||||
@@ -728,6 +1296,34 @@ void RGBController::SetMode(int mode)
|
||||
UpdateMode();
|
||||
}
|
||||
|
||||
void RGBController::UpdateLEDs()
|
||||
{
|
||||
CallFlag_UpdateLEDs = true;
|
||||
}
|
||||
|
||||
void RGBController::DeviceUpdateLEDs()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RGBController::DeviceCallThreadFunction()
|
||||
{
|
||||
CallFlag_UpdateLEDs = false;
|
||||
|
||||
while(DeviceThreadRunning.load() == true)
|
||||
{
|
||||
if(CallFlag_UpdateLEDs.load() == true)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
CallFlag_UpdateLEDs = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Sleep(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string device_type_to_str(device_type type)
|
||||
{
|
||||
switch(type)
|
||||
|
||||
@@ -9,8 +9,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
typedef unsigned int RGBColor;
|
||||
|
||||
@@ -115,6 +117,13 @@ enum
|
||||
|
||||
std::string device_type_to_str(device_type type);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int height;
|
||||
unsigned int width;
|
||||
unsigned int * map;
|
||||
} matrix_map_type;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
std::string name; /* Zone name */
|
||||
@@ -125,6 +134,7 @@ typedef struct
|
||||
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
|
||||
@@ -142,7 +152,11 @@ 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 |
|
||||
@@ -160,6 +174,26 @@ public:
|
||||
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 |
|
||||
\*---------------------------------------------------------*/
|
||||
@@ -167,10 +201,19 @@ public:
|
||||
|
||||
virtual void ResizeZone(int zone, int new_size) = 0;
|
||||
|
||||
virtual void UpdateLEDs() = 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;
|
||||
};
|
||||
|
||||
@@ -104,6 +104,7 @@ void RGBController_AMDWraithPrism::SetupZones()
|
||||
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;
|
||||
@@ -112,6 +113,7 @@ void RGBController_AMDWraithPrism::SetupZones()
|
||||
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;
|
||||
@@ -120,6 +122,7 @@ void RGBController_AMDWraithPrism::SetupZones()
|
||||
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);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
@@ -147,7 +150,7 @@ void RGBController_AMDWraithPrism::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_AMDWraithPrism::UpdateLEDs()
|
||||
void RGBController_AMDWraithPrism::DeviceUpdateLEDs()
|
||||
{
|
||||
unsigned char red = RGBGetRValue(colors[0]);
|
||||
unsigned char grn = RGBGetGValue(colors[0]);
|
||||
@@ -230,5 +233,5 @@ void RGBController_AMDWraithPrism::UpdateMode()
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ void RGBController_AuraCore::SetupZones()
|
||||
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++)
|
||||
@@ -66,7 +67,7 @@ void RGBController_AuraCore::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_AuraCore::UpdateLEDs()
|
||||
void RGBController_AuraCore::DeviceUpdateLEDs()
|
||||
{
|
||||
UpdateZoneLEDs(0);
|
||||
}
|
||||
@@ -101,5 +102,5 @@ void RGBController_AuraCore::SetCustomMode()
|
||||
|
||||
void RGBController_AuraCore::UpdateMode()
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -110,6 +110,7 @@ void RGBController_AuraGPU::SetupZones()
|
||||
aura_gpu_zone.leds_min = 1;
|
||||
aura_gpu_zone.leds_max = 1;
|
||||
aura_gpu_zone.leds_count = 1;
|
||||
aura_gpu_zone.matrix_map = NULL;
|
||||
zones.push_back(aura_gpu_zone);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
@@ -138,7 +139,7 @@ void RGBController_AuraGPU::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_AuraGPU::UpdateLEDs()
|
||||
void RGBController_AuraGPU::DeviceUpdateLEDs()
|
||||
{
|
||||
for(std::size_t led = 0; led < colors.size(); led++)
|
||||
{
|
||||
@@ -159,12 +160,12 @@ void RGBController_AuraGPU::UpdateLEDs()
|
||||
|
||||
void RGBController_AuraGPU::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_AuraGPU::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_AuraGPU::SetCustomMode()
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ int RGBController_AuraSMBus::GetDeviceMode()
|
||||
return(active_mode);
|
||||
}
|
||||
|
||||
void RGBController_AuraSMBus::UpdateLEDs()
|
||||
void RGBController_AuraSMBus::DeviceUpdateLEDs()
|
||||
{
|
||||
for(std::size_t led = 0; led < colors.size(); led++)
|
||||
{
|
||||
@@ -275,6 +275,8 @@ void RGBController_AuraSMBus::SetupZones()
|
||||
new_zone->type = ZONE_TYPE_SINGLE;
|
||||
}
|
||||
|
||||
new_zone->matrix_map = NULL;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Push new zone to zones vector |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
+23
-15
@@ -1,22 +1,22 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBController_AuraAddressable.cpp |
|
||||
| RGBController_AuraUSB.cpp |
|
||||
| |
|
||||
| Generic RGB Interface for Asus Aura |
|
||||
| addressable controller driver |
|
||||
| USB controller driver |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 1/18/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController_AuraAddressable.h"
|
||||
#include "RGBController_AuraUSB.h"
|
||||
|
||||
RGBController_AuraAddressable::RGBController_AuraAddressable(AuraAddressableController* aura_ptr)
|
||||
RGBController_AuraUSB::RGBController_AuraUSB(AuraUSBController* aura_ptr)
|
||||
{
|
||||
aura = aura_ptr;
|
||||
|
||||
name = "ASUS Aura Addressable";
|
||||
name = "ASUS Aura USB";
|
||||
version = aura->GetDeviceName();
|
||||
type = DEVICE_TYPE_MOTHERBOARD;
|
||||
description = "ASUS Aura Addressable Device";
|
||||
description = "ASUS Aura USB Device";
|
||||
|
||||
mode Direct;
|
||||
Direct.name = "Direct";
|
||||
@@ -99,12 +99,12 @@ RGBController_AuraAddressable::RGBController_AuraAddressable(AuraAddressableCont
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
RGBController_AuraAddressable::~RGBController_AuraAddressable()
|
||||
RGBController_AuraUSB::~RGBController_AuraUSB()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RGBController_AuraAddressable::SetupZones()
|
||||
void RGBController_AuraUSB::SetupZones()
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Only set LED count on the first run |
|
||||
@@ -157,12 +157,14 @@ void RGBController_AuraAddressable::SetupZones()
|
||||
|
||||
leds.push_back(new_led);
|
||||
}
|
||||
|
||||
zones[channel_idx].matrix_map = NULL;
|
||||
}
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_AuraAddressable::ResizeZone(int zone, int new_size)
|
||||
void RGBController_AuraUSB::ResizeZone(int zone, int new_size)
|
||||
{
|
||||
if(((unsigned int)new_size >= zones[zone].leds_min) && ((unsigned int)new_size <= zones[zone].leds_max))
|
||||
{
|
||||
@@ -172,7 +174,7 @@ void RGBController_AuraAddressable::ResizeZone(int zone, int new_size)
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_AuraAddressable::UpdateLEDs()
|
||||
void RGBController_AuraUSB::DeviceUpdateLEDs()
|
||||
{
|
||||
for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
|
||||
{
|
||||
@@ -180,24 +182,24 @@ void RGBController_AuraAddressable::UpdateLEDs()
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_AuraAddressable::UpdateZoneLEDs(int zone)
|
||||
void RGBController_AuraUSB::UpdateZoneLEDs(int zone)
|
||||
{
|
||||
aura->SetChannelLEDs(zone, zones[zone].colors, zones[zone].leds_count);
|
||||
}
|
||||
|
||||
void RGBController_AuraAddressable::UpdateSingleLED(int led)
|
||||
void RGBController_AuraUSB::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_AuraUSB::SetCustomMode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RGBController_AuraAddressable::UpdateMode()
|
||||
void RGBController_AuraUSB::UpdateMode()
|
||||
{
|
||||
unsigned char red = 0;
|
||||
unsigned char grn = 0;
|
||||
@@ -210,5 +212,11 @@ void RGBController_AuraAddressable::UpdateMode()
|
||||
blu = RGBGetBValue(modes[active_mode].colors[0]);
|
||||
}
|
||||
|
||||
aura->SetMode(modes[active_mode].value, red, grn, blu);
|
||||
for(unsigned int zone_idx; zone_idx < zones.size(); zone_idx++)
|
||||
{
|
||||
if(zones[zone_idx].leds_count > 0)
|
||||
{
|
||||
aura->SetMode(zone_idx, modes[active_mode].value, red, grn, blu);
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-8
@@ -1,29 +1,29 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBController_AuraAddressable.h |
|
||||
| RGBController_AuraUSB.h |
|
||||
| |
|
||||
| Generic RGB Interface for Asus Aura |
|
||||
| addressable controller driver |
|
||||
| USB controller driver |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 1/18/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
#include "RGBController.h"
|
||||
#include "AuraAddressableController.h"
|
||||
#include "AuraUSBController.h"
|
||||
|
||||
#define AURA_ADDRESSABLE_MAX_LEDS 120
|
||||
|
||||
class RGBController_AuraAddressable : public RGBController
|
||||
class RGBController_AuraUSB : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_AuraAddressable(AuraAddressableController* aura_ptr);
|
||||
~RGBController_AuraAddressable();
|
||||
RGBController_AuraUSB(AuraUSBController* aura_ptr);
|
||||
~RGBController_AuraUSB();
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
void UpdateMode();
|
||||
|
||||
private:
|
||||
AuraAddressableController* aura;
|
||||
AuraUSBController* aura;
|
||||
std::vector<unsigned int> leds_channel;
|
||||
std::vector<unsigned int> zones_channel;
|
||||
};
|
||||
@@ -83,6 +83,7 @@ void RGBController_CMMP750Controller::SetupZones()
|
||||
MP_zone.leds_min = 1;
|
||||
MP_zone.leds_max = 1;
|
||||
MP_zone.leds_count = 1;
|
||||
MP_zone.matrix_map = NULL;
|
||||
zones.push_back(MP_zone);
|
||||
|
||||
led MP_led;
|
||||
@@ -99,7 +100,7 @@ void RGBController_CMMP750Controller::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_CMMP750Controller::UpdateLEDs()
|
||||
void RGBController_CMMP750Controller::DeviceUpdateLEDs()
|
||||
{
|
||||
unsigned char red = RGBGetRValue(colors[0]);
|
||||
unsigned char grn = RGBGetGValue(colors[0]);
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
void SetupZones();
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -208,6 +208,8 @@ void RGBController_CorsairLightingNode::SetupZones()
|
||||
zones[channel_idx].leds_count = 0;
|
||||
}
|
||||
|
||||
zones[channel_idx].matrix_map = NULL;
|
||||
|
||||
for (unsigned int led_ch_idx = 0; led_ch_idx < zones[channel_idx].leds_count; led_ch_idx++)
|
||||
{
|
||||
char led_idx_string[4];
|
||||
@@ -237,7 +239,7 @@ void RGBController_CorsairLightingNode::ResizeZone(int zone, int new_size)
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_CorsairLightingNode::UpdateLEDs()
|
||||
void RGBController_CorsairLightingNode::DeviceUpdateLEDs()
|
||||
{
|
||||
for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
|
||||
{
|
||||
@@ -266,7 +268,7 @@ void RGBController_CorsairLightingNode::UpdateMode()
|
||||
{
|
||||
if(modes[active_mode].value == 0xFFFF)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -9,16 +9,30 @@
|
||||
|
||||
#include "RGBController_CorsairPeripheral.h"
|
||||
|
||||
//0xFFFFFFFF indicates an unused entry in matrix
|
||||
#define NA 0xFFFFFFFF
|
||||
|
||||
static unsigned int matrix_map[6][23] =
|
||||
{ { 0, NA, 10, 18, 28, 36, NA, 46, 55, 64, 74, NA, 84, 93, 102, 6, 15, 24, 33, 26, 35, 44, 53 },
|
||||
{ 1, 11, 19, 29, 37, 47, 56, 65, 75, 85, 94, NA, 103, 7, 25, NA, 42, 51, 60, 62, 72, 82, 91 },
|
||||
{ 2, NA, 12, 20, 30, 38, NA, 48, 57, 66, 76, 86, 95, 104, 70, 80, 34, 43, 52, 9, 17, 27, 100 },
|
||||
{ 3, NA, 13, 21, 31, 39, NA, 49, 58, 67, 77, 87, 96, 105, 98, NA, NA, NA, NA, 45, 54, 63, NA },
|
||||
{ 4, NA, 22, 32, 40, 50, NA, 59, NA, 68, 78, 88, 97, 106, 61, NA, NA, 81, NA, 73, 83, 92, 109 },
|
||||
{ 5, 14, 23, NA, NA, NA, NA, 41, NA, NA, NA, NA, 69, 79, 89, 71, 90, 99, 108, 101, NA, 110, NA } };
|
||||
|
||||
static const char* zone_names[] =
|
||||
{
|
||||
"Keyboard",
|
||||
"Media Keys"
|
||||
"Keyboard"
|
||||
};
|
||||
|
||||
static const unsigned int zone_sizes[] =
|
||||
{
|
||||
104,
|
||||
7
|
||||
111
|
||||
};
|
||||
|
||||
static const zone_type zone_types[] =
|
||||
{
|
||||
ZONE_TYPE_MATRIX
|
||||
};
|
||||
|
||||
static const char* led_names[] =
|
||||
@@ -134,7 +148,6 @@ static const char* led_names[] =
|
||||
"Key: Right Arrow", //139
|
||||
"Key: Number Pad Enter",//140
|
||||
"Key: Number Pad .", //141
|
||||
"Key: F12"
|
||||
};
|
||||
|
||||
RGBController_CorsairPeripheral::RGBController_CorsairPeripheral(CorsairPeripheralController* corsair_ptr)
|
||||
@@ -172,7 +185,7 @@ void RGBController_CorsairPeripheral::SetupZones()
|
||||
switch(type)
|
||||
{
|
||||
case DEVICE_TYPE_KEYBOARD:
|
||||
num_zones = 2;
|
||||
num_zones = 1;
|
||||
break;
|
||||
|
||||
case DEVICE_TYPE_MOUSE:
|
||||
@@ -191,18 +204,41 @@ void RGBController_CorsairPeripheral::SetupZones()
|
||||
switch(type)
|
||||
{
|
||||
case DEVICE_TYPE_KEYBOARD:
|
||||
new_zone.name = zone_names[zone_idx];
|
||||
new_zone.leds_min = zone_sizes[zone_idx];
|
||||
new_zone.leds_max = zone_sizes[zone_idx];
|
||||
new_zone.leds_count = zone_sizes[zone_idx];
|
||||
new_zone.name = zone_names[zone_idx];
|
||||
new_zone.type = zone_types[zone_idx];
|
||||
new_zone.leds_min = zone_sizes[zone_idx];
|
||||
new_zone.leds_max = zone_sizes[zone_idx];
|
||||
new_zone.leds_count = zone_sizes[zone_idx];
|
||||
|
||||
if(zone_types[zone_idx] == ZONE_TYPE_MATRIX)
|
||||
{
|
||||
new_zone.matrix_map = new matrix_map_type;
|
||||
new_zone.matrix_map->height = 6;
|
||||
new_zone.matrix_map->width = 23;
|
||||
new_zone.matrix_map->map = (unsigned int *)&matrix_map;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_zone.matrix_map = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case DEVICE_TYPE_MOUSE:
|
||||
case DEVICE_TYPE_MOUSEMAT:
|
||||
new_zone.name = "Mousemat Zone";
|
||||
new_zone.type = ZONE_TYPE_SINGLE;
|
||||
new_zone.leds_min = 15;
|
||||
new_zone.leds_max = 15;
|
||||
new_zone.leds_count = 15;
|
||||
new_zone.matrix_map = NULL;
|
||||
break;
|
||||
|
||||
case DEVICE_TYPE_MOUSEMAT:
|
||||
new_zone.name = "Mousemat Zone";
|
||||
new_zone.type = ZONE_TYPE_LINEAR;
|
||||
new_zone.leds_min = 15;
|
||||
new_zone.leds_max = 15;
|
||||
new_zone.leds_count = 15;
|
||||
new_zone.matrix_map = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -241,7 +277,7 @@ void RGBController_CorsairPeripheral::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_CorsairPeripheral::UpdateLEDs()
|
||||
void RGBController_CorsairPeripheral::DeviceUpdateLEDs()
|
||||
{
|
||||
corsair->SetLEDs(colors);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ void RGBController_CorsairVengeance::SetupZones()
|
||||
new_zone.leds_min = corsair->GetLEDCount();
|
||||
new_zone.leds_max = corsair->GetLEDCount();
|
||||
new_zone.leds_count = corsair->GetLEDCount();
|
||||
new_zone.matrix_map = NULL;
|
||||
zones.push_back(new_zone);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
@@ -75,7 +76,7 @@ void RGBController_CorsairVengeance::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_CorsairVengeance::UpdateLEDs()
|
||||
void RGBController_CorsairVengeance::DeviceUpdateLEDs()
|
||||
{
|
||||
RGBColor color = colors[0];
|
||||
unsigned char red = RGBGetRValue(color);
|
||||
@@ -87,12 +88,12 @@ void RGBController_CorsairVengeance::UpdateLEDs()
|
||||
|
||||
void RGBController_CorsairVengeance::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_CorsairVengeance::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_CorsairVengeance::SetCustomMode()
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -160,6 +160,7 @@ void RGBController_CorsairVengeancePro::SetupZones()
|
||||
new_zone.leds_min = corsair->GetLEDCount();
|
||||
new_zone.leds_max = corsair->GetLEDCount();
|
||||
new_zone.leds_count = corsair->GetLEDCount();
|
||||
new_zone.matrix_map = NULL;
|
||||
zones.push_back(new_zone);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
@@ -183,7 +184,7 @@ void RGBController_CorsairVengeancePro::ResizeZone(int /*zone*/, int /*new_size*
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_CorsairVengeancePro::UpdateLEDs()
|
||||
void RGBController_CorsairVengeancePro::DeviceUpdateLEDs()
|
||||
{
|
||||
for (std::size_t led = 0; led < colors.size(); led++)
|
||||
{
|
||||
@@ -199,7 +200,7 @@ void RGBController_CorsairVengeancePro::UpdateLEDs()
|
||||
|
||||
void RGBController_CorsairVengeancePro::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_CorsairVengeancePro::UpdateSingleLED(int led)
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -126,6 +126,7 @@ void RGBController_Crucial::SetupZones()
|
||||
new_zone.leds_min = 8;
|
||||
new_zone.leds_max = 8;
|
||||
new_zone.leds_count = 8;
|
||||
new_zone.matrix_map = NULL;
|
||||
zones.push_back(new_zone);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
@@ -149,7 +150,7 @@ void RGBController_Crucial::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_Crucial::UpdateLEDs()
|
||||
void RGBController_Crucial::DeviceUpdateLEDs()
|
||||
{
|
||||
if(modes[active_mode].value == 0xFFFF)
|
||||
{
|
||||
@@ -163,12 +164,12 @@ void RGBController_Crucial::UpdateLEDs()
|
||||
|
||||
void RGBController_Crucial::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_Crucial::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_Crucial::SetCustomMode()
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ void RGBController_Dummy::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
|
||||
}
|
||||
|
||||
void RGBController_Dummy::UpdateLEDs()
|
||||
void RGBController_Dummy::DeviceUpdateLEDs()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@ void RGBController_E131::SetupZones()
|
||||
led_zone.leds_min = devices[zone_idx].num_leds;
|
||||
led_zone.leds_max = devices[zone_idx].num_leds;
|
||||
led_zone.leds_count = devices[zone_idx].num_leds;
|
||||
led_zone.matrix_map = NULL;
|
||||
|
||||
zones.push_back(led_zone);
|
||||
}
|
||||
@@ -109,7 +110,7 @@ void RGBController_E131::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_E131::UpdateLEDs()
|
||||
void RGBController_E131::DeviceUpdateLEDs()
|
||||
{
|
||||
int color_idx = 0;
|
||||
|
||||
@@ -172,12 +173,12 @@ void RGBController_E131::UpdateLEDs()
|
||||
|
||||
void RGBController_E131::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_E131::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_E131::SetCustomMode()
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ void RGBController_Faustus::SetupZones()
|
||||
zones[0].leds_min = 1;
|
||||
zones[0].leds_max = 1;
|
||||
zones[0].leds_count = 1;
|
||||
zones[0].matrix_map = NULL;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Set up LED |
|
||||
@@ -85,7 +86,7 @@ void RGBController_Faustus::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_Faustus::UpdateLEDs()
|
||||
void RGBController_Faustus::DeviceUpdateLEDs()
|
||||
{
|
||||
int rv = uint8_t(RGBGetRValue(colors[0]));
|
||||
int gv = uint8_t(RGBGetGValue(colors[0]));
|
||||
@@ -130,12 +131,12 @@ void RGBController_Faustus::UpdateLEDs()
|
||||
|
||||
void RGBController_Faustus::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_Faustus::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_Faustus::SetCustomMode()
|
||||
@@ -145,7 +146,7 @@ void RGBController_Faustus::SetCustomMode()
|
||||
|
||||
void RGBController_Faustus::UpdateMode()
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void DetectFaustusControllers(std::vector<RGBController*> &rgb_controllers)
|
||||
|
||||
@@ -35,7 +35,7 @@ class RGBController_Faustus : public RGBController
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -144,6 +144,7 @@ void RGBController_Hue2::SetupZones()
|
||||
new_zone->leds_min = 0;
|
||||
new_zone->leds_max = 40;
|
||||
new_zone->leds_count = hue2->channel_leds[zone_idx];
|
||||
new_zone->matrix_map = NULL;
|
||||
|
||||
zones.push_back(*new_zone);
|
||||
}
|
||||
@@ -174,7 +175,7 @@ void RGBController_Hue2::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
|
||||
}
|
||||
|
||||
void RGBController_Hue2::UpdateLEDs()
|
||||
void RGBController_Hue2::DeviceUpdateLEDs()
|
||||
{
|
||||
for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
|
||||
{
|
||||
@@ -203,7 +204,7 @@ void RGBController_Hue2::UpdateMode()
|
||||
{
|
||||
if(modes[active_mode].value == 0xFFFF)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -189,6 +189,7 @@ void RGBController_HuePlus::SetupZones()
|
||||
zones[zone_idx].type = ZONE_TYPE_LINEAR;
|
||||
zones[zone_idx].leds_min = 0;
|
||||
zones[zone_idx].leds_max = 40;
|
||||
zones[zone_idx].matrix_map = NULL;
|
||||
|
||||
if(first_run)
|
||||
{
|
||||
@@ -227,7 +228,7 @@ void RGBController_HuePlus::ResizeZone(int zone, int new_size)
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_HuePlus::UpdateLEDs()
|
||||
void RGBController_HuePlus::DeviceUpdateLEDs()
|
||||
{
|
||||
for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
|
||||
{
|
||||
@@ -256,7 +257,7 @@ void RGBController_HuePlus::UpdateMode()
|
||||
{
|
||||
if(modes[active_mode].value == HUE_PLUS_MODE_FIXED)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -136,6 +136,7 @@ void RGBController_HyperXDRAM::SetupZones()
|
||||
new_zone->leds_min = 5;
|
||||
new_zone->leds_max = 5;
|
||||
new_zone->leds_count = 5;
|
||||
new_zone->matrix_map = NULL;
|
||||
|
||||
zones.push_back(*new_zone);
|
||||
}
|
||||
@@ -167,7 +168,7 @@ void RGBController_HyperXDRAM::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_HyperXDRAM::UpdateLEDs()
|
||||
void RGBController_HyperXDRAM::DeviceUpdateLEDs()
|
||||
{
|
||||
if(hyperx->GetMode() == HYPERX_MODE_DIRECT)
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -44,6 +44,17 @@ THREAD keepalive_thread(void *param)
|
||||
THREADRETURN
|
||||
}
|
||||
|
||||
//0xFFFFFFFF indicates an unused entry in matrix
|
||||
#define NA 0xFFFFFFFF
|
||||
|
||||
static unsigned int matrix_map[6][23] =
|
||||
{ { 0, NA, 15, 28, 42, 52, NA, 63, 73, 82, 93, NA, 8, 21, 36, 6, 20, 34, 47, NA, NA, NA, NA },
|
||||
{ 1, 16, 29, 43, 53, 64, 74, 83, 94, 9, 22, NA, 37, 7, 35, NA, 58, 68, 78, 50, 61, 71, 80 },
|
||||
{ 2, NA, 17, 30, 44, 54, NA, 65, 75, 84, 95, 10, 23, 38, 88, 99, 48, 59, 69, 49, 60, 70, 91 },
|
||||
{ 3, NA, 18, 31, 45, 55, NA, 66, 76, 85, 96, 11, 24, 39, 26, NA, NA, NA, NA, 90, 101, 51, NA },
|
||||
{ 4, NA, 32, 46, 56, 67, NA, 77, NA, 86, 97, 12, 25, 40, 79, NA, NA, 100, NA, 62, 72, 81, 102 },
|
||||
{ 5, 19, 33, NA, NA, NA, NA, 57, NA, NA, NA, NA, 87, 98, 13, 89, 14, 27, 41, 92, NA, 103, NA } };
|
||||
|
||||
static const char* zone_names[] =
|
||||
{
|
||||
"Keyboard",
|
||||
@@ -51,6 +62,13 @@ static const char* zone_names[] =
|
||||
"Media Keys"
|
||||
};
|
||||
|
||||
static zone_type zone_types[] =
|
||||
{
|
||||
ZONE_TYPE_MATRIX,
|
||||
ZONE_TYPE_LINEAR,
|
||||
ZONE_TYPE_SINGLE
|
||||
};
|
||||
|
||||
static const unsigned int zone_sizes[] =
|
||||
{
|
||||
104,
|
||||
@@ -264,10 +282,24 @@ void RGBController_HyperXKeyboard::SetupZones()
|
||||
for(unsigned int zone_idx = 0; zone_idx < 3; zone_idx++)
|
||||
{
|
||||
zone new_zone;
|
||||
new_zone.name = zone_names[zone_idx];
|
||||
new_zone.leds_min = zone_sizes[zone_idx];
|
||||
new_zone.leds_max = zone_sizes[zone_idx];
|
||||
new_zone.leds_count = zone_sizes[zone_idx];
|
||||
new_zone.name = zone_names[zone_idx];
|
||||
new_zone.type = zone_types[zone_idx];
|
||||
new_zone.leds_min = zone_sizes[zone_idx];
|
||||
new_zone.leds_max = zone_sizes[zone_idx];
|
||||
new_zone.leds_count = zone_sizes[zone_idx];
|
||||
|
||||
if(zone_types[zone_idx] == ZONE_TYPE_MATRIX)
|
||||
{
|
||||
new_zone.matrix_map = new matrix_map_type;
|
||||
new_zone.matrix_map->height = 6;
|
||||
new_zone.matrix_map->width = 23;
|
||||
new_zone.matrix_map->map = (unsigned int *)&matrix_map;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_zone.matrix_map = NULL;
|
||||
}
|
||||
|
||||
zones.push_back(new_zone);
|
||||
|
||||
total_led_count += zone_sizes[zone_idx];
|
||||
@@ -290,7 +322,7 @@ void RGBController_HyperXKeyboard::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_HyperXKeyboard::UpdateLEDs()
|
||||
void RGBController_HyperXKeyboard::DeviceUpdateLEDs()
|
||||
{
|
||||
if(active_mode == 0)
|
||||
{
|
||||
@@ -304,12 +336,12 @@ void RGBController_HyperXKeyboard::UpdateLEDs()
|
||||
|
||||
void RGBController_HyperXKeyboard::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_HyperXKeyboard::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_HyperXKeyboard::SetCustomMode()
|
||||
@@ -336,7 +368,7 @@ void RGBController_HyperXKeyboard::KeepaliveThread()
|
||||
{
|
||||
if(active_mode == 0)
|
||||
{
|
||||
hyperx->SetLEDsDirect(colors);
|
||||
UpdateLEDs();
|
||||
}
|
||||
Sleep(100);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ void RGBController_LEDStrip::SetupZones()
|
||||
led_zone.leds_min = strip->num_leds;
|
||||
led_zone.leds_max = strip->num_leds;
|
||||
led_zone.leds_count = strip->num_leds;
|
||||
led_zone.matrix_map = NULL;
|
||||
zones.push_back(led_zone);
|
||||
|
||||
for(int led_idx = 0; led_idx < strip->num_leds; led_idx++)
|
||||
@@ -57,7 +58,7 @@ void RGBController_LEDStrip::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_LEDStrip::UpdateLEDs()
|
||||
void RGBController_LEDStrip::DeviceUpdateLEDs()
|
||||
{
|
||||
strip->SetLEDs(colors);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ void RGBController_MSI3Zone::SetupZones()
|
||||
keyboard_zone.leds_min = 3;
|
||||
keyboard_zone.leds_max = 3;
|
||||
keyboard_zone.leds_count = 3;
|
||||
keyboard_zone.matrix_map = NULL;
|
||||
zones.push_back(keyboard_zone);
|
||||
|
||||
led left_led;
|
||||
@@ -66,6 +67,7 @@ void RGBController_MSI3Zone::SetupZones()
|
||||
aux_zone.leds_min = 1;
|
||||
aux_zone.leds_max = 1;
|
||||
aux_zone.leds_count = 1;
|
||||
aux_zone.matrix_map = NULL;
|
||||
zones.push_back(aux_zone);
|
||||
|
||||
led aux_led;
|
||||
@@ -82,7 +84,7 @@ void RGBController_MSI3Zone::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_MSI3Zone::UpdateLEDs()
|
||||
void RGBController_MSI3Zone::DeviceUpdateLEDs()
|
||||
{
|
||||
msi->SetLEDs(colors);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ void RGBController_MSIMysticLight::SetupZones()
|
||||
new_zone.leds_min = controller->GetZoneMinLedCount(zd.value);
|
||||
new_zone.leds_max = controller->GetZoneMaxLedCount(zd.value);
|
||||
new_zone.leds_count = controller->GetZoneLedCount(zd.value);
|
||||
new_zone.matrix_map = NULL;
|
||||
zones.push_back(new_zone);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
@@ -105,7 +106,7 @@ void RGBController_MSIMysticLight::SetCustomMode()
|
||||
active_mode = 0;
|
||||
}
|
||||
|
||||
void RGBController_MSIMysticLight::UpdateLEDs()
|
||||
void RGBController_MSIMysticLight::DeviceUpdateLEDs()
|
||||
{
|
||||
for(size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ void RGBController_MSIRGB::SetupZones()
|
||||
msi_zone.leds_min = 1;
|
||||
msi_zone.leds_max = 1;
|
||||
msi_zone.leds_count = 1;
|
||||
msi_zone.matrix_map = NULL;
|
||||
zones.push_back(msi_zone);
|
||||
|
||||
led msi_led;
|
||||
@@ -53,7 +54,7 @@ void RGBController_MSIRGB::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
|
||||
}
|
||||
|
||||
void RGBController_MSIRGB::UpdateLEDs()
|
||||
void RGBController_MSIRGB::DeviceUpdateLEDs()
|
||||
{
|
||||
RGBColor color = colors[0];
|
||||
unsigned char red = RGBGetRValue(color);
|
||||
@@ -65,12 +66,12 @@ void RGBController_MSIRGB::UpdateLEDs()
|
||||
|
||||
void RGBController_MSIRGB::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_MSIRGB::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_MSIRGB::SetCustomMode()
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -199,6 +199,7 @@ void RGBController_NZXTKraken::SetupZones()
|
||||
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 ring_zone;
|
||||
@@ -207,6 +208,7 @@ void RGBController_NZXTKraken::SetupZones()
|
||||
ring_zone.leds_min = 8;
|
||||
ring_zone.leds_max = 8;
|
||||
ring_zone.leds_count = 8;
|
||||
ring_zone.matrix_map = NULL;
|
||||
zones.push_back(ring_zone);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
@@ -299,7 +301,7 @@ void RGBController_NZXTKraken::UpdateChannel(NZXTKrakenChannel_t channel, int zo
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_NZXTKraken::UpdateLEDs()
|
||||
void RGBController_NZXTKraken::DeviceUpdateLEDs()
|
||||
{
|
||||
if(logo_modes.find(modes[active_mode].value) == logo_modes.end())
|
||||
{
|
||||
@@ -344,5 +346,5 @@ void RGBController_NZXTKraken::SetCustomMode()
|
||||
|
||||
void RGBController_NZXTKraken::UpdateMode()
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBController_Network.cpp |
|
||||
| |
|
||||
| Generic RGB Interface Network Class |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 4/11/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "RGBController_Network.h"
|
||||
|
||||
RGBController_Network::RGBController_Network(NetworkClient * client_ptr, unsigned int dev_idx_val)
|
||||
{
|
||||
client = client_ptr;
|
||||
dev_idx = dev_idx_val;
|
||||
}
|
||||
|
||||
void RGBController_Network::SetupZones()
|
||||
{
|
||||
//Don't send anything, this function should only process on host
|
||||
}
|
||||
|
||||
void RGBController_Network::ResizeZone(int zone, int new_size)
|
||||
{
|
||||
client->SendRequest_RGBController_ResizeZone(dev_idx, zone, new_size);
|
||||
}
|
||||
|
||||
void RGBController_Network::DeviceUpdateLEDs()
|
||||
{
|
||||
unsigned char * data = GetColorDescription();
|
||||
unsigned int size;
|
||||
|
||||
memcpy(&size, &data[0], sizeof(unsigned int));
|
||||
|
||||
client->SendRequest_RGBController_UpdateLEDs(dev_idx, data, size);
|
||||
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
void RGBController_Network::UpdateZoneLEDs(int zone)
|
||||
{
|
||||
unsigned char * data = GetZoneColorDescription(zone);
|
||||
unsigned int size;
|
||||
|
||||
memcpy(&size, &data[0], sizeof(unsigned int));
|
||||
|
||||
client->SendRequest_RGBController_UpdateZoneLEDs(dev_idx, data, size);
|
||||
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
void RGBController_Network::UpdateSingleLED(int led)
|
||||
{
|
||||
unsigned char * data = GetSingleLEDColorDescription(led);
|
||||
|
||||
client->SendRequest_RGBController_UpdateSingleLED(dev_idx, data, sizeof(int) + sizeof(RGBColor));
|
||||
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
void RGBController_Network::SetCustomMode()
|
||||
{
|
||||
client->SendRequest_RGBController_SetCustomMode(dev_idx);
|
||||
}
|
||||
|
||||
void RGBController_Network::UpdateMode()
|
||||
{
|
||||
unsigned char * data = GetModeDescription(active_mode);
|
||||
unsigned int size;
|
||||
|
||||
memcpy(&size, &data[0], sizeof(unsigned int));
|
||||
|
||||
client->SendRequest_RGBController_UpdateMode(dev_idx, data, size);
|
||||
|
||||
delete[] data;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBController_Network.h |
|
||||
| |
|
||||
| Generic RGB Interface Network Class |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 4/11/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "NetworkClient.h"
|
||||
|
||||
class RGBController_Network : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_Network(NetworkClient * client_ptr, unsigned int dev_idx_val);
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void SetCustomMode();
|
||||
void UpdateMode();
|
||||
|
||||
private:
|
||||
NetworkClient * client;
|
||||
unsigned int dev_idx;
|
||||
};
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <fstream>
|
||||
#include <unistd.h>
|
||||
|
||||
void RGBController_OpenRazer::UpdateLEDs()
|
||||
void RGBController_OpenRazer::DeviceUpdateLEDs()
|
||||
{
|
||||
switch(matrix_type)
|
||||
{
|
||||
@@ -93,12 +93,12 @@ void RGBController_OpenRazer::UpdateLEDs()
|
||||
|
||||
void RGBController_OpenRazer::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_OpenRazer::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_OpenRazer::SetupMatrixDevice(unsigned int rows, unsigned int cols)
|
||||
@@ -383,6 +383,29 @@ void RGBController_OpenRazer::SetupZones()
|
||||
new_zone.leds_min = new_zone.leds_count;
|
||||
new_zone.leds_max = new_zone.leds_count;
|
||||
|
||||
if(new_zone.type == ZONE_TYPE_MATRIX)
|
||||
{
|
||||
matrix_map_type * new_map = new matrix_map_type;
|
||||
new_zone.matrix_map = new_map;
|
||||
|
||||
new_map->height = device_list[device_index]->zones[zone_id]->rows;
|
||||
new_map->width = device_list[device_index]->zones[zone_id]->cols;
|
||||
|
||||
new_map->map = new unsigned int[new_map->height * new_map->width];
|
||||
|
||||
for(int y = 0; y < new_map->height; y++)
|
||||
{
|
||||
for(int x = 0; x < new_map->width; x++)
|
||||
{
|
||||
new_map->map[(y * new_map->width) + x] = (y * new_map->width) + x;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
new_zone.matrix_map = NULL;
|
||||
}
|
||||
|
||||
zones.push_back(new_zone);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/hid.h>
|
||||
|
||||
void RGBController_OpenRazer::UpdateLEDs()
|
||||
void RGBController_OpenRazer::DeviceUpdateLEDs()
|
||||
{
|
||||
switch(matrix_type)
|
||||
{
|
||||
@@ -93,12 +93,12 @@ void RGBController_OpenRazer::UpdateLEDs()
|
||||
|
||||
void RGBController_OpenRazer::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_OpenRazer::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_OpenRazer::SetupMatrixDevice(device_fn_type* razer_functions, unsigned int rows, unsigned int cols)
|
||||
@@ -332,6 +332,29 @@ void RGBController_OpenRazer::SetupZones()
|
||||
new_zone.leds_min = new_zone.leds_count;
|
||||
new_zone.leds_max = new_zone.leds_count;
|
||||
|
||||
if(new_zone.type == ZONE_TYPE_MATRIX)
|
||||
{
|
||||
matrix_map_type * new_map = new matrix_map_type;
|
||||
new_zone.matrix_map = new_map;
|
||||
|
||||
new_map->height = device_list[device_index]->zones[zone_id]->rows;
|
||||
new_map->width = device_list[device_index]->zones[zone_id]->cols;
|
||||
|
||||
new_map->map = new unsigned int[new_map->height * new_map->width];
|
||||
|
||||
for(int y = 0; y < new_map->height; y++)
|
||||
{
|
||||
for(int x = 0; x < new_map->width; x++)
|
||||
{
|
||||
new_map->map[(y * new_map->width) + x] = (y * new_map->width) + x;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
new_zone.matrix_map = NULL;
|
||||
}
|
||||
|
||||
zones.push_back(new_zone);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -114,6 +114,7 @@ void RGBController_PatriotViper::SetupZones()
|
||||
new_zone->leds_min = 5;
|
||||
new_zone->leds_max = 5;
|
||||
new_zone->leds_count = 5;
|
||||
new_zone->matrix_map = NULL;
|
||||
zones.push_back(*new_zone);
|
||||
}
|
||||
|
||||
@@ -139,7 +140,7 @@ void RGBController_PatriotViper::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_PatriotViper::UpdateLEDs()
|
||||
void RGBController_PatriotViper::DeviceUpdateLEDs()
|
||||
{
|
||||
if(viper->direct == true)
|
||||
{
|
||||
@@ -167,7 +168,7 @@ void RGBController_PatriotViper::UpdateLEDs()
|
||||
|
||||
void RGBController_PatriotViper::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_PatriotViper::UpdateSingleLED(int led)
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -197,9 +197,11 @@ void RGBController_Polychrome::SetupZones()
|
||||
| Set zone name to channel name |
|
||||
\*---------------------------------------------------------*/
|
||||
new_zone->name = polychrome_zone_names[i];
|
||||
new_zone->type = ZONE_TYPE_SINGLE;
|
||||
new_zone->leds_min = 1;
|
||||
new_zone->leds_max = 1;
|
||||
new_zone->leds_count = 1;
|
||||
new_zone->matrix_map = NULL;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Push new zone to zones vector |
|
||||
@@ -235,7 +237,7 @@ void RGBController_Polychrome::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_Polychrome::UpdateLEDs()
|
||||
void RGBController_Polychrome::DeviceUpdateLEDs()
|
||||
{
|
||||
for (std::size_t led = 0; led < colors.size(); led++)
|
||||
{
|
||||
@@ -249,12 +251,12 @@ void RGBController_Polychrome::UpdateLEDs()
|
||||
|
||||
void RGBController_Polychrome::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_Polychrome::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_Polychrome::SetCustomMode()
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -9,11 +9,27 @@
|
||||
|
||||
#include "RGBController_PoseidonZRGB.h"
|
||||
|
||||
//0xFFFFFFFF indicates an unused entry in matrix
|
||||
#define NA 0xFFFFFFFF
|
||||
|
||||
static unsigned int matrix_map[6][23] =
|
||||
{ { 0, NA, 8, 15, 22, 29, NA, 37, 44, 51, 58, NA, 65, 73, 81, 88, 94, 100, 102, NA, NA, NA, NA },
|
||||
{ 1, 9, 16, 23, 30, 38, 45, 52, 59, 66, 74, NA, 82, 89, 103, NA, 7, 21, 36, 50, 64, 80, 93 },
|
||||
{ 2, NA, 10, 17, 24, 31, NA, 39, 46, 53, 60, 67, 75, 83, 90, 95, 14, 28, 43, 57, 72, 87, 86 },
|
||||
{ 3, NA, 11, 18, 25, 32, NA, 40, 47, 54, 61, 68, 76, 84, 96, NA, NA, NA, NA, 35, 99, 63, NA },
|
||||
{ 4, NA, 26, 33, 41, 48, NA, 55, NA, 62, 69, 77, 85, 91, 101, NA, NA, 27, NA, 42, 49, 71, 98 },
|
||||
{ 5, 12, 19, NA, NA, NA, NA, 34, NA, NA, NA, NA, 70, 78, 92, 97, 6, 13, 20, 56, NA, 79, NA } };
|
||||
|
||||
static const char* zone_names[] =
|
||||
{
|
||||
"Keyboard"
|
||||
};
|
||||
|
||||
static zone_type zone_types[] =
|
||||
{
|
||||
ZONE_TYPE_MATRIX,
|
||||
};
|
||||
|
||||
static const unsigned int zone_sizes[] =
|
||||
{
|
||||
104
|
||||
@@ -191,10 +207,15 @@ void RGBController_PoseidonZRGB::SetupZones()
|
||||
for(unsigned int zone_idx = 0; zone_idx < 1; zone_idx++)
|
||||
{
|
||||
zone new_zone;
|
||||
new_zone.name = zone_names[zone_idx];
|
||||
new_zone.leds_min = zone_sizes[zone_idx];
|
||||
new_zone.leds_max = zone_sizes[zone_idx];
|
||||
new_zone.leds_count = zone_sizes[zone_idx];
|
||||
new_zone.name = zone_names[zone_idx];
|
||||
new_zone.type = zone_types[zone_idx];
|
||||
new_zone.leds_min = zone_sizes[zone_idx];
|
||||
new_zone.leds_max = zone_sizes[zone_idx];
|
||||
new_zone.leds_count = zone_sizes[zone_idx];
|
||||
new_zone.matrix_map = new matrix_map_type;
|
||||
new_zone.matrix_map->height = 6;
|
||||
new_zone.matrix_map->width = 23;
|
||||
new_zone.matrix_map->map = (unsigned int *)&matrix_map;
|
||||
zones.push_back(new_zone);
|
||||
|
||||
total_led_count += zone_sizes[zone_idx];
|
||||
@@ -217,7 +238,7 @@ void RGBController_PoseidonZRGB::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_PoseidonZRGB::UpdateLEDs()
|
||||
void RGBController_PoseidonZRGB::DeviceUpdateLEDs()
|
||||
{
|
||||
if(active_mode == 0)
|
||||
{
|
||||
@@ -231,12 +252,12 @@ void RGBController_PoseidonZRGB::UpdateLEDs()
|
||||
|
||||
void RGBController_PoseidonZRGB::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_PoseidonZRGB::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_PoseidonZRGB::SetCustomMode()
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -75,6 +75,7 @@ void RGBController_RGBFusion::SetupZones()
|
||||
new_zone->leds_min = 1;
|
||||
new_zone->leds_max = 1;
|
||||
new_zone->leds_count = 1;
|
||||
new_zone->matrix_map = NULL;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Push new zone to zones vector |
|
||||
@@ -107,7 +108,7 @@ void RGBController_RGBFusion::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_RGBFusion::UpdateLEDs()
|
||||
void RGBController_RGBFusion::DeviceUpdateLEDs()
|
||||
{
|
||||
for (std::size_t led = 0; led < colors.size(); led++)
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBController_RGBFusion2SMBus.cpp |
|
||||
| |
|
||||
| Generic RGB Interface for OpenRGB |
|
||||
| Gigabyte RGB Fusion 2 SMBUS Driver |
|
||||
| |
|
||||
| Matt Harper (5/5/2020) |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController_RGBFusion2SMBus.h"
|
||||
|
||||
/* TODO - Validate all of these
|
||||
* CPU
|
||||
* ???
|
||||
* Mobo logo - Verified
|
||||
* Case rear
|
||||
* Case
|
||||
* ???
|
||||
* ???
|
||||
* ARGB header 1
|
||||
* ARGB header 2
|
||||
*
|
||||
* Do ??? actually map to anything? Are they even supported?
|
||||
* If not, what is an elegant way to display but not wreck existing logic?
|
||||
*/
|
||||
static const char* rgb_fusion_zone_names[] =
|
||||
{
|
||||
"CPU",
|
||||
"???",
|
||||
"Motherboard Logo",
|
||||
"Case Rear",
|
||||
"Case",
|
||||
"???",
|
||||
"???",
|
||||
"ARGB Header 1",
|
||||
"ARGB Header 2",
|
||||
"???"
|
||||
};
|
||||
|
||||
RGBController_RGBFusion2SMBus::RGBController_RGBFusion2SMBus(RGBFusion2SMBusController* rgb_fusion_ptr)
|
||||
{
|
||||
rgb_fusion = rgb_fusion_ptr;
|
||||
|
||||
name = "RGB Fusion 2 SMBus";
|
||||
description = "RGB Fusion 2 SMBus";
|
||||
location = rgb_fusion->GetDeviceLocation();
|
||||
|
||||
type = DEVICE_TYPE_MOTHERBOARD;
|
||||
|
||||
mode Static;
|
||||
Static.name = "Static";
|
||||
Static.value = RGB_FUSION_2_MODE_STATIC;
|
||||
Static.flags = MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
Static.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Static);
|
||||
|
||||
mode Pulse;
|
||||
Pulse.name = "Pulse";
|
||||
Pulse.value = RGB_FUSION_2_MODE_PULSE;
|
||||
Pulse.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
Pulse.speed_min = RGB_FUSION_2_SPEED_SLOW;
|
||||
Pulse.speed_max = RGB_FUSION_2_SPEED_FAST;
|
||||
Pulse.speed = RGB_FUSION_2_SPEED_NORMAL;
|
||||
Pulse.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Pulse);
|
||||
|
||||
mode Flashing;
|
||||
Flashing.name = "Flashing";
|
||||
Flashing.value = RGB_FUSION_2_MODE_FLASHING;
|
||||
Flashing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
Flashing.speed_min = 0x01;
|
||||
Flashing.speed_max = 0x04;
|
||||
Flashing.speed = 0x02;
|
||||
Flashing.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Flashing);
|
||||
|
||||
mode ColorCycle;
|
||||
ColorCycle.name = "Color Cycle";
|
||||
ColorCycle.value = RGB_FUSION_2_MODE_COLOR_CYCLE;
|
||||
ColorCycle.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
ColorCycle.speed_min = RGB_FUSION_2_SPEED_SLOW;
|
||||
ColorCycle.speed_max = RGB_FUSION_2_SPEED_FAST;
|
||||
ColorCycle.speed = RGB_FUSION_2_SPEED_NORMAL;
|
||||
ColorCycle.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(ColorCycle);
|
||||
|
||||
SetupZones();
|
||||
|
||||
// Initialize active mode
|
||||
// TODO - broken. Need to complete GetDeviceMode
|
||||
active_mode = GetDeviceMode();
|
||||
}
|
||||
|
||||
void RGBController_RGBFusion2SMBus::SetupZones()
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Search through all LEDs and create zones for each channel |
|
||||
| type |
|
||||
\*---------------------------------------------------------*/
|
||||
for(unsigned int zone_idx = 0; zone_idx < rgb_fusion->GetLEDCount(); zone_idx++)
|
||||
{
|
||||
zone* new_zone = new zone();
|
||||
|
||||
// Set zone name to channel name
|
||||
new_zone->name = rgb_fusion_zone_names[zone_idx];
|
||||
new_zone->leds_min = 1;
|
||||
new_zone->leds_max = 1;
|
||||
new_zone->leds_count = 1;
|
||||
|
||||
// Push new zone to zones vector
|
||||
zones.push_back(*new_zone);
|
||||
}
|
||||
|
||||
for(unsigned int led_idx = 0; led_idx < zones.size(); led_idx++)
|
||||
{
|
||||
led* new_led = new led();
|
||||
|
||||
// Set LED name to channel name
|
||||
new_led->name = rgb_fusion_zone_names[led_idx];
|
||||
|
||||
// Push new LED to LEDs vector
|
||||
leds.push_back(*new_led);
|
||||
}
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_RGBFusion2SMBus::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_RGBFusion2SMBus::DeviceUpdateLEDs()
|
||||
{
|
||||
for (std::size_t led = 0; led < colors.size(); led++)
|
||||
{
|
||||
RGBColor color = colors[led];
|
||||
unsigned char red = RGBGetRValue(color);
|
||||
unsigned char grn = RGBGetGValue(color);
|
||||
unsigned char blu = RGBGetBValue(color);
|
||||
|
||||
int mode = modes[active_mode].value;
|
||||
unsigned int speed = modes[active_mode].speed;
|
||||
|
||||
rgb_fusion->SetLEDEffect(led, mode, speed, red, grn, blu);
|
||||
}
|
||||
|
||||
rgb_fusion->Apply();
|
||||
}
|
||||
|
||||
void RGBController_RGBFusion2SMBus::UpdateZoneLEDs(int zone)
|
||||
{
|
||||
RGBColor color = colors[zone];
|
||||
unsigned char red = RGBGetRValue(color);
|
||||
unsigned char grn = RGBGetGValue(color);
|
||||
unsigned char blu = RGBGetBValue(color);
|
||||
|
||||
int mode = modes[active_mode].value;
|
||||
unsigned int speed = modes[active_mode].speed;
|
||||
|
||||
rgb_fusion->SetLEDEffect(zone, mode, speed, red, grn, blu);
|
||||
rgb_fusion->Apply();
|
||||
}
|
||||
|
||||
void RGBController_RGBFusion2SMBus::UpdateSingleLED(int led)
|
||||
{
|
||||
UpdateZoneLEDs(led);
|
||||
}
|
||||
|
||||
// TODO - Research if possible to read device state
|
||||
int RGBController_RGBFusion2SMBus::GetDeviceMode()
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
void RGBController_RGBFusion2SMBus::SetCustomMode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RGBController_RGBFusion2SMBus::UpdateMode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
|
||||
/*-----------------------------------------*\
|
||||
| RGBController_RGBFusion2SMBus.h |
|
||||
| |
|
||||
| Generic RGB Interface for OpenRGB |
|
||||
| Gigabyte RGB Fusion 2 SMBUS Driver |
|
||||
| |
|
||||
| Matt Harper (5/5/2020) |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "RGBFusion2SMBusController.h"
|
||||
|
||||
class RGBController_RGBFusion2SMBus : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_RGBFusion2SMBus(RGBFusion2SMBusController* rgb_fusion_ptr);
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void SetCustomMode();
|
||||
void UpdateMode();
|
||||
|
||||
private:
|
||||
RGBFusion2SMBusController* rgb_fusion;
|
||||
|
||||
int GetDeviceMode();
|
||||
};
|
||||
@@ -193,7 +193,8 @@ void RGBController_RGBFusion2USB::SetupZones()
|
||||
{
|
||||
zones[zone_idx].name = led_zones[zone_idx];
|
||||
zones[zone_idx].type = ZONE_TYPE_LINEAR;
|
||||
|
||||
zones[zone_idx].matrix_map = NULL;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Zone index 0 is motherboard LEDs and has fixed size |
|
||||
\*---------------------------------------------------------*/
|
||||
@@ -261,7 +262,7 @@ void RGBController_RGBFusion2USB::SetCustomMode()
|
||||
active_mode = 0;
|
||||
}
|
||||
|
||||
void RGBController_RGBFusion2USB::UpdateLEDs()
|
||||
void RGBController_RGBFusion2USB::DeviceUpdateLEDs()
|
||||
{
|
||||
for(size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
|
||||
{
|
||||
@@ -456,5 +457,5 @@ void RGBController_RGBFusion2USB::UpdateSingleLED(int led)
|
||||
|
||||
void RGBController_RGBFusion2USB::UpdateMode()
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ void RGBController_RGBFusionGPU::SetupZones()
|
||||
new_zone->leds_min = 1;
|
||||
new_zone->leds_max = 1;
|
||||
new_zone->leds_count = 1;
|
||||
new_zone->matrix_map = NULL;
|
||||
|
||||
new_led->name = "GPU LED";
|
||||
|
||||
@@ -105,7 +106,7 @@ void RGBController_RGBFusionGPU::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_RGBFusionGPU::UpdateLEDs()
|
||||
void RGBController_RGBFusionGPU::DeviceUpdateLEDs()
|
||||
{
|
||||
RGBColor color = colors[0];
|
||||
unsigned char red = RGBGetRValue(color);
|
||||
@@ -117,12 +118,12 @@ void RGBController_RGBFusionGPU::UpdateLEDs()
|
||||
|
||||
void RGBController_RGBFusionGPU::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_RGBFusionGPU::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_RGBFusionGPU::SetCustomMode()
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -203,7 +203,8 @@ void RGBController_RedragonK556::SetupZones()
|
||||
new_zone.leds_min = 126;
|
||||
new_zone.leds_max = 126;
|
||||
new_zone.leds_count = 126;
|
||||
|
||||
new_zone.matrix_map = NULL;
|
||||
|
||||
zones.push_back(new_zone);
|
||||
|
||||
for(int led_idx = 0; led_idx < 126; led_idx++)
|
||||
@@ -226,7 +227,7 @@ void RGBController_RedragonK556::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_RedragonK556::UpdateLEDs()
|
||||
void RGBController_RedragonK556::DeviceUpdateLEDs()
|
||||
{
|
||||
unsigned char color_data[7*0x36];
|
||||
|
||||
@@ -246,12 +247,12 @@ void RGBController_RedragonK556::UpdateLEDs()
|
||||
|
||||
void RGBController_RedragonK556::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_RedragonK556::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_RedragonK556::SetCustomMode()
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ void RGBController_RedragonM711::SetupZones()
|
||||
m711_zone.leds_min = 1;
|
||||
m711_zone.leds_max = 1;
|
||||
m711_zone.leds_count = 1;
|
||||
m711_zone.matrix_map = NULL;
|
||||
zones.push_back(m711_zone);
|
||||
|
||||
led m711_led;
|
||||
@@ -79,7 +80,7 @@ void RGBController_RedragonM711::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_RedragonM711::UpdateLEDs()
|
||||
void RGBController_RedragonM711::DeviceUpdateLEDs()
|
||||
{
|
||||
bool random = (modes[active_mode].color_mode == MODE_COLORS_RANDOM);
|
||||
unsigned char red = RGBGetRValue(colors[0]);
|
||||
@@ -100,12 +101,12 @@ void RGBController_RedragonM711::UpdateLEDs()
|
||||
|
||||
void RGBController_RedragonM711::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_RedragonM711::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_RedragonM711::SetCustomMode()
|
||||
@@ -115,5 +116,5 @@ void RGBController_RedragonM711::SetCustomMode()
|
||||
|
||||
void RGBController_RedragonM711::UpdateMode()
|
||||
{
|
||||
UpdateLEDs();
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -18,6 +18,29 @@ RGBController_ThermaltakeRiing::RGBController_ThermaltakeRiing(ThermaltakeRiingC
|
||||
type = DEVICE_TYPE_COOLER;
|
||||
description = "Thermaltake Riing Device";
|
||||
|
||||
mode Direct;
|
||||
Direct.name = "Direct";
|
||||
Direct.value = THERMALTAKE_MODE_PER_LED;
|
||||
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
Direct.speed_min = 0;
|
||||
Direct.speed_max = 0;
|
||||
Direct.speed = 0;
|
||||
Direct.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Direct);
|
||||
|
||||
mode Static;
|
||||
Static.name = "Static";
|
||||
Static.value = THERMALTAKE_MODE_FULL;
|
||||
Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
|
||||
Static.colors_min = 1;
|
||||
Static.colors_max = 1;
|
||||
Static.speed_min = 0;
|
||||
Static.speed_max = 0;
|
||||
Static.speed = 0;
|
||||
Static.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
Static.colors.resize(1);
|
||||
modes.push_back(Static);
|
||||
|
||||
mode Flow;
|
||||
Flow.name = "Flow";
|
||||
Flow.value = THERMALTAKE_MODE_FLOW;
|
||||
@@ -78,29 +101,6 @@ RGBController_ThermaltakeRiing::RGBController_ThermaltakeRiing(ThermaltakeRiingC
|
||||
Wave.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Wave);
|
||||
|
||||
mode Direct;
|
||||
Direct.name = "Direct";
|
||||
Direct.value = THERMALTAKE_MODE_PER_LED;
|
||||
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
Direct.speed_min = 0;
|
||||
Direct.speed_max = 0;
|
||||
Direct.speed = 0;
|
||||
Direct.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Direct);
|
||||
|
||||
mode Static;
|
||||
Static.name = "Static";
|
||||
Static.value = THERMALTAKE_MODE_FULL;
|
||||
Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
|
||||
Static.colors_min = 1;
|
||||
Static.colors_max = 1;
|
||||
Static.speed_min = 0;
|
||||
Static.speed_max = 0;
|
||||
Static.speed = 0;
|
||||
Static.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
Static.colors.resize(1);
|
||||
modes.push_back(Static);
|
||||
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
@@ -147,6 +147,8 @@ void RGBController_ThermaltakeRiing::SetupZones()
|
||||
zones[channel_idx].leds_count = 0;
|
||||
}
|
||||
|
||||
zones[channel_idx].matrix_map = NULL;
|
||||
|
||||
for (unsigned int led_ch_idx = 0; led_ch_idx < zones[channel_idx].leds_count; led_ch_idx++)
|
||||
{
|
||||
char led_idx_string[3];
|
||||
@@ -176,7 +178,7 @@ void RGBController_ThermaltakeRiing::ResizeZone(int zone, int new_size)
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_ThermaltakeRiing::UpdateLEDs()
|
||||
void RGBController_ThermaltakeRiing::DeviceUpdateLEDs()
|
||||
{
|
||||
for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
|
||||
{
|
||||
@@ -198,7 +200,7 @@ void RGBController_ThermaltakeRiing::UpdateSingleLED(int led)
|
||||
|
||||
void RGBController_ThermaltakeRiing::SetCustomMode()
|
||||
{
|
||||
active_mode = 6;
|
||||
active_mode = 0;
|
||||
}
|
||||
|
||||
void RGBController_ThermaltakeRiing::UpdateMode()
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
@@ -422,11 +422,12 @@ bool OptionSaveProfile(std::string argument)
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool ProcessOptions(int argc, char *argv[], Options *options)
|
||||
int ProcessOptions(int argc, char *argv[], Options *options)
|
||||
{
|
||||
int arg_index = 1;
|
||||
int current_device = -1;
|
||||
int current_zone = -1;
|
||||
unsigned int ret_flags = 0;
|
||||
int arg_index = 1;
|
||||
int current_device = -1;
|
||||
int current_zone = -1;
|
||||
|
||||
options->hasDevice = false;
|
||||
|
||||
@@ -444,10 +445,26 @@ bool ProcessOptions(int argc, char *argv[], Options *options)
|
||||
arg_index++;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| --gui |
|
||||
\*---------------------------------------------------------*/
|
||||
if(option == "--gui")
|
||||
{
|
||||
ret_flags |= 2;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| --i2c-tools / --yolo |
|
||||
\*---------------------------------------------------------*/
|
||||
else if(option == "--i2c-tools" || option == "--yolo")
|
||||
{
|
||||
ret_flags |= 4;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| -h / --help |
|
||||
\*---------------------------------------------------------*/
|
||||
if(option == "--help" || option == "-h")
|
||||
else if(option == "--help" || option == "-h")
|
||||
{
|
||||
OptionHelp();
|
||||
exit(0);
|
||||
@@ -478,7 +495,7 @@ bool ProcessOptions(int argc, char *argv[], Options *options)
|
||||
{
|
||||
if(!OptionDevice(¤t_device, argument, options))
|
||||
{
|
||||
return false;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,7 +506,7 @@ bool ProcessOptions(int argc, char *argv[], Options *options)
|
||||
{
|
||||
if(!OptionZone(¤t_device, ¤t_zone, argument, options))
|
||||
{
|
||||
return false;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -500,7 +517,7 @@ bool ProcessOptions(int argc, char *argv[], Options *options)
|
||||
{
|
||||
if(!OptionColor(¤t_device, ¤t_zone, argument, options))
|
||||
{
|
||||
return false;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -511,7 +528,7 @@ bool ProcessOptions(int argc, char *argv[], Options *options)
|
||||
{
|
||||
if(!OptionMode(¤t_device, argument, options))
|
||||
{
|
||||
return false;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -522,7 +539,7 @@ bool ProcessOptions(int argc, char *argv[], Options *options)
|
||||
{
|
||||
if(!OptionSize(¤t_device, ¤t_zone, argument, options))
|
||||
{
|
||||
return false;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -549,7 +566,7 @@ bool ProcessOptions(int argc, char *argv[], Options *options)
|
||||
else
|
||||
{
|
||||
std::cout << "Error: Invalid option: " + option << std::endl;
|
||||
return false;
|
||||
return 1;
|
||||
}
|
||||
|
||||
arg_index++;
|
||||
@@ -566,16 +583,14 @@ bool ProcessOptions(int argc, char *argv[], Options *options)
|
||||
if(!options->devices[option_idx].hasOption)
|
||||
{
|
||||
std::cout << "Error: Device " + std::to_string(option_idx) + " specified, but neither mode nor color given" << std::endl;
|
||||
return false;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return options->allDeviceOptions.hasOption;
|
||||
return ret_flags;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ApplyOptions(DeviceOptions& options)
|
||||
@@ -653,7 +668,7 @@ void ApplyOptions(DeviceOptions& options)
|
||||
}
|
||||
}
|
||||
|
||||
int cli_main(int argc, char *argv[], std::vector<RGBController *> rgb_controllers_in, ProfileManager* profile_manager_in)
|
||||
unsigned int cli_main(int argc, char *argv[], std::vector<RGBController *> rgb_controllers_in, ProfileManager* profile_manager_in)
|
||||
{
|
||||
rgb_controllers = rgb_controllers_in;
|
||||
profile_manager = profile_manager_in;
|
||||
@@ -662,10 +677,20 @@ int cli_main(int argc, char *argv[], std::vector<RGBController *> rgb_controller
|
||||
| Process the argument options |
|
||||
\*---------------------------------------------------------*/
|
||||
Options options;
|
||||
if (!ProcessOptions(argc, argv, &options))
|
||||
unsigned int ret_flags = ProcessOptions(argc, argv, &options);
|
||||
switch(ret_flags)
|
||||
{
|
||||
OptionHelp();
|
||||
return -1;
|
||||
case 0:
|
||||
break;
|
||||
|
||||
case 1:
|
||||
OptionHelp();
|
||||
exit(-1);
|
||||
break;
|
||||
|
||||
default:
|
||||
return ret_flags;
|
||||
break;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
@@ -704,5 +729,7 @@ int cli_main(int argc, char *argv[], std::vector<RGBController *> rgb_controller
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+74
-11
@@ -9,15 +9,31 @@
|
||||
#include "i2c_smbus.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
|
||||
static void Sleep(unsigned int milliseconds)
|
||||
{
|
||||
usleep(1000 * milliseconds);
|
||||
}
|
||||
#endif
|
||||
|
||||
i2c_smbus_interface::i2c_smbus_interface()
|
||||
{
|
||||
i2c_smbus_thread = new std::thread(&i2c_smbus_interface::i2c_smbus_thread_function, this);
|
||||
}
|
||||
|
||||
s32 i2c_smbus_interface::i2c_smbus_write_quick(u8 addr, u8 value)
|
||||
{
|
||||
return i2c_smbus_xfer(addr, value, 0, I2C_SMBUS_QUICK, NULL);
|
||||
return i2c_smbus_xfer_call(addr, value, 0, I2C_SMBUS_QUICK, NULL);
|
||||
}
|
||||
|
||||
s32 i2c_smbus_interface::i2c_smbus_read_byte(u8 addr)
|
||||
{
|
||||
i2c_smbus_data data;
|
||||
if (i2c_smbus_xfer(addr, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &data))
|
||||
if (i2c_smbus_xfer_call(addr, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &data))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -29,13 +45,13 @@ s32 i2c_smbus_interface::i2c_smbus_read_byte(u8 addr)
|
||||
|
||||
s32 i2c_smbus_interface::i2c_smbus_write_byte(u8 addr, u8 value)
|
||||
{
|
||||
return i2c_smbus_xfer(addr, I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
|
||||
return i2c_smbus_xfer_call(addr, I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
|
||||
}
|
||||
|
||||
s32 i2c_smbus_interface::i2c_smbus_read_byte_data(u8 addr, u8 command)
|
||||
{
|
||||
i2c_smbus_data data;
|
||||
if (i2c_smbus_xfer(addr, I2C_SMBUS_READ, command, I2C_SMBUS_BYTE_DATA, &data))
|
||||
if (i2c_smbus_xfer_call(addr, I2C_SMBUS_READ, command, I2C_SMBUS_BYTE_DATA, &data))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -49,13 +65,13 @@ s32 i2c_smbus_interface::i2c_smbus_write_byte_data(u8 addr, u8 command, u8 value
|
||||
{
|
||||
i2c_smbus_data data;
|
||||
data.byte = value;
|
||||
return i2c_smbus_xfer(addr, I2C_SMBUS_WRITE, command, I2C_SMBUS_BYTE_DATA, &data);
|
||||
return i2c_smbus_xfer_call(addr, I2C_SMBUS_WRITE, command, I2C_SMBUS_BYTE_DATA, &data);
|
||||
}
|
||||
|
||||
s32 i2c_smbus_interface::i2c_smbus_read_word_data(u8 addr, u8 command)
|
||||
{
|
||||
i2c_smbus_data data;
|
||||
if (i2c_smbus_xfer(addr, I2C_SMBUS_READ, command, I2C_SMBUS_WORD_DATA, &data))
|
||||
if (i2c_smbus_xfer_call(addr, I2C_SMBUS_READ, command, I2C_SMBUS_WORD_DATA, &data))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -69,13 +85,13 @@ s32 i2c_smbus_interface::i2c_smbus_write_word_data(u8 addr, u8 command, u16 valu
|
||||
{
|
||||
i2c_smbus_data data;
|
||||
data.word = value;
|
||||
return i2c_smbus_xfer(addr, I2C_SMBUS_WRITE, command, I2C_SMBUS_WORD_DATA, &data);
|
||||
return i2c_smbus_xfer_call(addr, I2C_SMBUS_WRITE, command, I2C_SMBUS_WORD_DATA, &data);
|
||||
}
|
||||
|
||||
s32 i2c_smbus_interface::i2c_smbus_read_block_data(u8 addr, u8 command, u8 *values)
|
||||
{
|
||||
i2c_smbus_data data;
|
||||
if (i2c_smbus_xfer(addr, I2C_SMBUS_READ, command, I2C_SMBUS_BLOCK_DATA, &data))
|
||||
if (i2c_smbus_xfer_call(addr, I2C_SMBUS_READ, command, I2C_SMBUS_BLOCK_DATA, &data))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -95,7 +111,7 @@ s32 i2c_smbus_interface::i2c_smbus_write_block_data(u8 addr, u8 command, u8 leng
|
||||
}
|
||||
data.block[0] = length;
|
||||
memcpy(&data.block[1], values, length);
|
||||
return i2c_smbus_xfer(addr, I2C_SMBUS_WRITE, command, I2C_SMBUS_BLOCK_DATA, &data);
|
||||
return i2c_smbus_xfer_call(addr, I2C_SMBUS_WRITE, command, I2C_SMBUS_BLOCK_DATA, &data);
|
||||
}
|
||||
|
||||
s32 i2c_smbus_interface::i2c_smbus_read_i2c_block_data(u8 addr, u8 command, u8 length, u8 *values)
|
||||
@@ -106,7 +122,7 @@ s32 i2c_smbus_interface::i2c_smbus_read_i2c_block_data(u8 addr, u8 command, u8 l
|
||||
length = I2C_SMBUS_BLOCK_MAX;
|
||||
}
|
||||
data.block[0] = length;
|
||||
if (i2c_smbus_xfer(addr, I2C_SMBUS_READ, command, I2C_SMBUS_I2C_BLOCK_DATA, &data))
|
||||
if (i2c_smbus_xfer_call(addr, I2C_SMBUS_READ, command, I2C_SMBUS_I2C_BLOCK_DATA, &data))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -126,5 +142,52 @@ s32 i2c_smbus_interface::i2c_smbus_write_i2c_block_data(u8 addr, u8 command, u8
|
||||
}
|
||||
data.block[0] = length;
|
||||
memcpy(&data.block[1], values, length);
|
||||
return i2c_smbus_xfer(addr, I2C_SMBUS_WRITE, command, I2C_SMBUS_I2C_BLOCK_DATA, &data);
|
||||
return i2c_smbus_xfer_call(addr, I2C_SMBUS_WRITE, command, I2C_SMBUS_I2C_BLOCK_DATA, &data);
|
||||
}
|
||||
|
||||
s32 i2c_smbus_interface::i2c_smbus_xfer_call(u8 addr, char read_write, u8 command, int size, i2c_smbus_data* data)
|
||||
{
|
||||
s32 ret_val = 0;
|
||||
|
||||
i2c_smbus_xfer_mutex.lock();
|
||||
|
||||
i2c_addr = addr;
|
||||
i2c_read_write = read_write;
|
||||
i2c_command = command;
|
||||
i2c_size = size;
|
||||
i2c_data = data;
|
||||
|
||||
std::unique_lock<std::mutex> start_lock(i2c_smbus_start_mutex);
|
||||
i2c_smbus_start = true;
|
||||
i2c_smbus_start_cv.notify_all();
|
||||
start_lock.unlock();
|
||||
|
||||
std::unique_lock<std::mutex> done_lock(i2c_smbus_done_mutex);
|
||||
|
||||
i2c_smbus_done_cv.wait(done_lock, [this]{ return i2c_smbus_done.load(); });
|
||||
i2c_smbus_done = false;
|
||||
|
||||
ret_val = i2c_ret;
|
||||
|
||||
i2c_smbus_xfer_mutex.unlock();
|
||||
|
||||
return(i2c_ret);
|
||||
}
|
||||
|
||||
void i2c_smbus_interface::i2c_smbus_thread_function()
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
std::unique_lock<std::mutex> start_lock(i2c_smbus_start_mutex);
|
||||
|
||||
i2c_smbus_start_cv.wait(start_lock, [this]{ return i2c_smbus_start.load(); });
|
||||
i2c_smbus_start = false;
|
||||
|
||||
i2c_ret = i2c_smbus_xfer(i2c_addr, i2c_read_write, i2c_command, i2c_size, i2c_data);
|
||||
|
||||
std::unique_lock<std::mutex> done_lock(i2c_smbus_done_mutex);
|
||||
i2c_smbus_done = true;
|
||||
i2c_smbus_done_cv.notify_all();
|
||||
done_lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,11 @@
|
||||
#ifndef I2C_SMBUS_H
|
||||
#define I2C_SMBUS_H
|
||||
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
@@ -54,8 +59,11 @@ class i2c_smbus_interface
|
||||
public:
|
||||
char device_name[512];
|
||||
|
||||
i2c_smbus_interface();
|
||||
virtual ~i2c_smbus_interface() = default;
|
||||
|
||||
void i2c_smbus_thread_function();
|
||||
|
||||
//Functions derived from i2c-core.c
|
||||
s32 i2c_smbus_write_quick(u8 addr, u8 value);
|
||||
s32 i2c_smbus_read_byte(u8 addr);
|
||||
@@ -69,8 +77,30 @@ public:
|
||||
s32 i2c_smbus_read_i2c_block_data(u8 addr, u8 command, u8 length, u8 *values);
|
||||
s32 i2c_smbus_write_i2c_block_data(u8 addr, u8 command, u8 length, const u8 *values);
|
||||
|
||||
s32 i2c_smbus_xfer_call(u8 addr, char read_write, u8 command, int size, i2c_smbus_data* data);
|
||||
|
||||
//Virtual function to be implemented by the driver
|
||||
virtual s32 i2c_smbus_xfer(u8 addr, char read_write, u8 command, int size, i2c_smbus_data* data) = 0;
|
||||
|
||||
private:
|
||||
std::thread * i2c_smbus_thread;
|
||||
|
||||
std::atomic<bool> i2c_smbus_start;
|
||||
std::condition_variable i2c_smbus_start_cv;
|
||||
std::mutex i2c_smbus_start_mutex;
|
||||
|
||||
std::atomic<bool> i2c_smbus_done;
|
||||
std::condition_variable i2c_smbus_done_cv;
|
||||
std::mutex i2c_smbus_done_mutex;
|
||||
|
||||
std::mutex i2c_smbus_xfer_mutex;
|
||||
|
||||
u8 i2c_addr;
|
||||
char i2c_read_write;
|
||||
u16 i2c_command;
|
||||
int i2c_size;
|
||||
i2c_smbus_data* i2c_data;
|
||||
s32 i2c_ret;
|
||||
};
|
||||
|
||||
#endif /* I2C_SMBUS_H */
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user