Compare commits
48
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f8fe1d29fb | ||
|
|
42a9a9314d | ||
|
|
41d9a66c1c | ||
|
|
2437379506 | ||
|
|
f95e210260 | ||
|
|
a5d37819d2 | ||
|
|
80917314df | ||
|
|
3d25fa9451 | ||
|
|
5c4e2ee00a | ||
|
|
13b27fd966 | ||
|
|
a41a22d5d6 | ||
|
|
56572beba9 | ||
|
|
bbf98b2f72 | ||
|
|
0bba8539e4 | ||
|
|
4e00aac741 | ||
|
|
f3b20da6a3 | ||
|
|
7ae3ce651d | ||
|
|
2307566dac | ||
|
|
6101d9d43e | ||
|
|
c2541d9585 | ||
|
|
89cc9fc912 | ||
|
|
24a7940787 | ||
|
|
2aa33821dd | ||
|
|
82232b4aef | ||
|
|
de13ca2cff | ||
|
|
c45cf2466a | ||
|
|
f01aa31c3b | ||
|
|
c9f7fe8f3f | ||
|
|
e7483e22a9 | ||
|
|
438fc49127 | ||
|
|
f62851dbab | ||
|
|
5e3ad426e9 | ||
|
|
3622913291 | ||
|
|
dd0edb3f84 | ||
|
|
e1737fb971 | ||
|
|
56df7d65b3 | ||
|
|
4eb926f8ef | ||
|
|
8fc98a035b | ||
|
|
5567db88f8 | ||
|
|
b96d160ce2 | ||
|
|
f44c6365c0 | ||
|
|
94277e7d04 | ||
|
|
1d4393b5c4 | ||
|
|
fa015dd558 | ||
|
|
5c7359fa60 | ||
|
|
4dbe14febe | ||
|
|
c8346e1f7c | ||
|
|
095b9ce635 |
@@ -0,0 +1,429 @@
|
||||
/*-----------------------------------------*\
|
||||
| NetworkClient.cpp |
|
||||
| |
|
||||
| Client code for OpenRGB SDK |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 5/9/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "NetworkClient.h"
|
||||
#include "RGBController_Network.h"
|
||||
#include <cstring>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
|
||||
static void Sleep(unsigned int milliseconds)
|
||||
{
|
||||
usleep(1000 * milliseconds);
|
||||
}
|
||||
#endif
|
||||
|
||||
NetworkClient::NetworkClient(std::vector<RGBController *>& control) : controllers(control)
|
||||
{
|
||||
strcpy(port_ip, "127.0.0.1");
|
||||
port_num = 1337;
|
||||
server_connected = false;
|
||||
server_controller_count = 0;
|
||||
}
|
||||
|
||||
unsigned short NetworkClient::GetPort()
|
||||
{
|
||||
return port_num;
|
||||
}
|
||||
|
||||
bool NetworkClient::GetOnline()
|
||||
{
|
||||
return server_connected;
|
||||
}
|
||||
|
||||
void NetworkClient::SetIP(const char *new_ip)
|
||||
{
|
||||
if(server_connected == false)
|
||||
{
|
||||
strcpy(port_ip, new_ip);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::SetName(const char *new_name)
|
||||
{
|
||||
client_name = new_name;
|
||||
|
||||
if(server_connected == true)
|
||||
{
|
||||
SendData_ClientString();
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::SetPort(unsigned short new_port)
|
||||
{
|
||||
if(server_connected == false)
|
||||
{
|
||||
port_num = new_port;
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::StartClient()
|
||||
{
|
||||
unsigned int requested_controllers;
|
||||
|
||||
//Start a TCP server and launch threads
|
||||
char port_str[6];
|
||||
snprintf(port_str, 6, "%d", port_num);
|
||||
|
||||
port.tcp_client(port_ip, port_str);
|
||||
|
||||
requested_controllers = 0;
|
||||
|
||||
//Start the connection thread
|
||||
ConnectionThread = new std::thread(&NetworkClient::ConnectionThreadFunction, this);
|
||||
|
||||
//Start the listener thread
|
||||
ListenThread = new std::thread(&NetworkClient::ListenThreadFunction, this);
|
||||
|
||||
//Wait for server to connect
|
||||
while(!server_connected)
|
||||
{
|
||||
Sleep(100);
|
||||
}
|
||||
|
||||
//Once server is connected, send client string
|
||||
SendData_ClientString();
|
||||
|
||||
//Request number of controllers
|
||||
SendRequest_ControllerCount();
|
||||
|
||||
//Wait for server controller count
|
||||
while(server_controller_count == 0)
|
||||
{
|
||||
Sleep(100);
|
||||
}
|
||||
|
||||
printf("Client: Received controller count from server: %d\r\n", server_controller_count);
|
||||
|
||||
//Once count is received, request controllers
|
||||
while(requested_controllers < server_controller_count)
|
||||
{
|
||||
printf("Client: Requesting controller %d\r\n", requested_controllers);
|
||||
|
||||
SendRequest_ControllerData(requested_controllers);
|
||||
|
||||
//Wait until controller is received
|
||||
while(server_controllers.size() == requested_controllers)
|
||||
{
|
||||
Sleep(100);
|
||||
}
|
||||
|
||||
requested_controllers++;
|
||||
}
|
||||
|
||||
//All controllers received, add them to master list
|
||||
printf("Client: All controllers received, adding them to master list\r\n");
|
||||
for(std::size_t controller_idx = 0; controller_idx < server_controllers.size(); controller_idx++)
|
||||
{
|
||||
controllers.push_back(server_controllers[controller_idx]);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::StopClient()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NetworkClient::ConnectionThreadFunction()
|
||||
{
|
||||
//This thread manages the connection to the server
|
||||
while(1)
|
||||
{
|
||||
//Connect to server and reconnect if the connection is lost
|
||||
|
||||
//Try to connect to server
|
||||
port.tcp_client_connect();
|
||||
|
||||
printf( "Connected to server\n" );
|
||||
|
||||
server_connected = true;
|
||||
break;
|
||||
|
||||
//Wait 1 second between tries;
|
||||
Sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::ListenThreadFunction()
|
||||
{
|
||||
printf("Network client listener started\n");
|
||||
//This thread handles messages received from the server
|
||||
while(1)
|
||||
{
|
||||
NetPacketHeader header;
|
||||
char * data = NULL;
|
||||
int bytes_read = 0;
|
||||
|
||||
//Read first byte of magic
|
||||
do
|
||||
{
|
||||
bytes_read = port.tcp_listen(&header.pkt_magic[0], 1);
|
||||
} while(bytes_read == 0);
|
||||
|
||||
//Test first character of magic - 'O'
|
||||
if(header.pkt_magic[0] != 'O')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//Read second byte of magic
|
||||
do
|
||||
{
|
||||
bytes_read = port.tcp_listen(&header.pkt_magic[1], 1);
|
||||
} while(bytes_read == 0);
|
||||
|
||||
//Test second character of magic - 'R'
|
||||
if(header.pkt_magic[1] != 'R')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//Read third byte of magic
|
||||
do
|
||||
{
|
||||
bytes_read = port.tcp_listen(&header.pkt_magic[2], 1);
|
||||
} while(bytes_read == 0);
|
||||
|
||||
//Test third character of magic - 'G'
|
||||
if(header.pkt_magic[2] != 'G')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//Read fourth byte of magic
|
||||
do
|
||||
{
|
||||
bytes_read = port.tcp_listen(&header.pkt_magic[3], 1);
|
||||
} while(bytes_read == 0);
|
||||
|
||||
//Test fourth character of magic - 'B'
|
||||
if(header.pkt_magic[3] != 'B')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//If we get to this point, the magic is correct. Read the rest of the header
|
||||
bytes_read = 0;
|
||||
do
|
||||
{
|
||||
bytes_read += port.tcp_listen((char *)&header.pkt_dev_idx + bytes_read, sizeof(header) - sizeof(header.pkt_magic) - bytes_read);
|
||||
} while(bytes_read != sizeof(header) - sizeof(header.pkt_magic));
|
||||
|
||||
printf( "Client: Received header, now receiving data of size %d\r\n", header.pkt_size);
|
||||
|
||||
//Header received, now receive the data
|
||||
if(header.pkt_size > 0)
|
||||
{
|
||||
unsigned int bytes_read = 0;
|
||||
|
||||
data = new char[header.pkt_size];
|
||||
|
||||
do
|
||||
{
|
||||
bytes_read += port.tcp_listen(&data[bytes_read], header.pkt_size - bytes_read);
|
||||
} while (bytes_read < header.pkt_size);
|
||||
}
|
||||
|
||||
printf( "Client: Received header and data\r\n" );
|
||||
printf( "Client: Packet ID: %d \r\n", header.pkt_id);
|
||||
|
||||
//Entire request received, select functionality based on request ID
|
||||
switch(header.pkt_id)
|
||||
{
|
||||
case NET_PACKET_ID_REQUEST_CONTROLLER_COUNT:
|
||||
printf( "Client: NET_PACKET_ID_REQUEST_CONTROLLER_COUNT\r\n" );
|
||||
|
||||
ProcessReply_ControllerCount(header.pkt_size, data);
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_REQUEST_CONTROLLER_DATA:
|
||||
printf( "Client: NET_PACKET_ID_REQUEST_CONTROLLER_DATA\r\n");
|
||||
|
||||
ProcessReply_ControllerData(header.pkt_size, data, header.pkt_dev_idx);
|
||||
break;
|
||||
}
|
||||
|
||||
delete[] data;
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::ProcessReply_ControllerCount(unsigned int data_size, char * data)
|
||||
{
|
||||
if(data_size == sizeof(unsigned int))
|
||||
{
|
||||
memcpy(&server_controller_count, data, sizeof(unsigned int));
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::ProcessReply_ControllerData(unsigned int data_size, char * data, unsigned int dev_idx)
|
||||
{
|
||||
RGBController_Network * new_controller = new RGBController_Network(this, dev_idx);
|
||||
|
||||
new_controller->ReadDeviceDescription((unsigned char *)data);
|
||||
|
||||
printf("Received controller: %s\r\n", new_controller->name.c_str());
|
||||
|
||||
server_controllers.push_back(new_controller);
|
||||
}
|
||||
|
||||
void NetworkClient::SendData_ClientString()
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = 0;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_SET_CLIENT_NAME;
|
||||
reply_hdr.pkt_size = strlen(client_name.c_str()) + 1;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
port.tcp_client_write((char *)client_name.c_str(), reply_hdr.pkt_size);
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_ControllerCount()
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = 0;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_REQUEST_CONTROLLER_COUNT;
|
||||
reply_hdr.pkt_size = 0;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_ControllerData(unsigned int dev_idx)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_REQUEST_CONTROLLER_DATA;
|
||||
reply_hdr.pkt_size = 0;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_ResizeZone(unsigned int dev_idx, int zone, int new_size)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
int reply_data[2];
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE;
|
||||
reply_hdr.pkt_size = sizeof(reply_data);
|
||||
|
||||
reply_data[0] = zone;
|
||||
reply_data[1] = new_size;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
port.tcp_client_write((char *)&reply_data, sizeof(reply_data));
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS;
|
||||
reply_hdr.pkt_size = size;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
port.tcp_client_write((char *)data, size);
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_UpdateZoneLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS;
|
||||
reply_hdr.pkt_size = size;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
port.tcp_client_write((char *)data, size);
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_UpdateSingleLED(unsigned int dev_idx, unsigned char * data, unsigned int size)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED;
|
||||
reply_hdr.pkt_size = size;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
port.tcp_client_write((char *)data, size);
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_SetCustomMode(unsigned int dev_idx)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE;
|
||||
reply_hdr.pkt_size = 0;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_UpdateMode(unsigned int dev_idx, unsigned char * data, unsigned int size)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE;
|
||||
reply_hdr.pkt_size = size;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
port.tcp_client_write((char *)data, size);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*-----------------------------------------*\
|
||||
| NetworkClient.h |
|
||||
| |
|
||||
| Client header for OpenRGB SDK |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 5/9/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "NetworkProtocol.h"
|
||||
#include "net_port.h"
|
||||
|
||||
#include <thread>
|
||||
|
||||
#pragma once
|
||||
|
||||
class NetworkClient
|
||||
{
|
||||
public:
|
||||
NetworkClient(std::vector<RGBController *>& control);
|
||||
|
||||
const char * GetIP();
|
||||
unsigned short GetPort();
|
||||
bool GetOnline();
|
||||
|
||||
void SetIP(const char *new_ip);
|
||||
void SetName(const char *new_name);
|
||||
void SetPort(unsigned short new_port);
|
||||
|
||||
void StartClient();
|
||||
void StopClient();
|
||||
|
||||
void ConnectionThreadFunction();
|
||||
void ListenThreadFunction();
|
||||
|
||||
void ProcessReply_ControllerCount(unsigned int data_size, char * data);
|
||||
void ProcessReply_ControllerData(unsigned int data_size, char * data, unsigned int dev_idx);
|
||||
|
||||
void SendData_ClientString();
|
||||
|
||||
void SendRequest_ControllerCount();
|
||||
void SendRequest_ControllerData(unsigned int dev_idx);
|
||||
|
||||
void SendRequest_RGBController_ResizeZone(unsigned int dev_idx, int zone, int new_size);
|
||||
|
||||
void SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_UpdateZoneLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_UpdateSingleLED(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
|
||||
void SendRequest_RGBController_SetCustomMode(unsigned int dev_idx);
|
||||
|
||||
void SendRequest_RGBController_UpdateMode(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
|
||||
protected:
|
||||
std::vector<RGBController *>& controllers;
|
||||
std::vector<RGBController *> server_controllers;
|
||||
|
||||
private:
|
||||
std::string client_name;
|
||||
net_port port;
|
||||
char port_ip[20];
|
||||
unsigned short port_num;
|
||||
bool server_connected;
|
||||
unsigned int server_controller_count;
|
||||
|
||||
std::thread * ConnectionThread;
|
||||
std::thread * ListenThread;
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "NetworkProtocol.h"
|
||||
|
||||
NetPacketHeader * InitNetPacketHeader
|
||||
(
|
||||
unsigned int pkt_dev_idx,
|
||||
unsigned int pkt_id,
|
||||
unsigned int pkt_size
|
||||
)
|
||||
{
|
||||
NetPacketHeader * new_header = new NetPacketHeader;
|
||||
|
||||
new_header->pkt_magic[0] = 'O';
|
||||
new_header->pkt_magic[1] = 'R';
|
||||
new_header->pkt_magic[2] = 'G';
|
||||
new_header->pkt_magic[3] = 'B';
|
||||
|
||||
new_header->pkt_dev_idx = pkt_dev_idx;
|
||||
new_header->pkt_id = pkt_id;
|
||||
new_header->pkt_size = pkt_size;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*-----------------------------------------*\
|
||||
| NetworkProtocol.h |
|
||||
| |
|
||||
| Protocol header for OpenRGB SDK |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 5/9/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef struct NetPacketHeader
|
||||
{
|
||||
char pkt_magic[4]; /* Magic value "ORGB" identifies beginning of packet */
|
||||
unsigned int pkt_dev_idx; /* Device index */
|
||||
unsigned int pkt_id; /* Packet ID */
|
||||
unsigned int pkt_size; /* Packet size */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
/*----------------------------------------------------------------------------------------------------------*\
|
||||
| Network requests |
|
||||
\*----------------------------------------------------------------------------------------------------------*/
|
||||
NET_PACKET_ID_REQUEST_CONTROLLER_COUNT = 0, /* Request RGBController device count from server */
|
||||
NET_PACKET_ID_REQUEST_CONTROLLER_DATA = 1, /* Request RGBController data block */
|
||||
NET_PACKET_ID_SET_CLIENT_NAME = 50, /* Send client name string to server */
|
||||
|
||||
/*----------------------------------------------------------------------------------------------------------*\
|
||||
| RGBController class functions |
|
||||
\*----------------------------------------------------------------------------------------------------------*/
|
||||
NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE = 1000, /* RGBController::ResizeZone() */
|
||||
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS = 1050, /* RGBController::UpdateLEDs() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS = 1051, /* RGBController::UpdateZoneLEDs() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED = 1052, /* RGBController::UpdateSingleLED() */
|
||||
|
||||
NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE = 1100, /* RGBController::SetCustomMode() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE = 1101, /* RGBController::UpdateMode() */
|
||||
};
|
||||
@@ -0,0 +1,611 @@
|
||||
/*-----------------------------------------*\
|
||||
| NetworkServer.cpp |
|
||||
| |
|
||||
| Server code for OpenRGB SDK |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 5/9/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "NetworkServer.h"
|
||||
#include <cstring>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <sys/ioctl.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <sys/types.h>
|
||||
#include <arpa/inet.h>
|
||||
#else
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
#include <memory.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
|
||||
const char yes = 1;
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
|
||||
static void Sleep(unsigned int milliseconds)
|
||||
{
|
||||
usleep(1000 * milliseconds);
|
||||
}
|
||||
#endif
|
||||
|
||||
NetworkServer::NetworkServer(std::vector<RGBController *>& control) : controllers(control)
|
||||
{
|
||||
port_num = 1337;
|
||||
server_online = false;
|
||||
}
|
||||
|
||||
void NetworkServer::ClientInfoChanged()
|
||||
{
|
||||
ClientInfoChangeMutex.lock();
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Client info has changed, call the callbacks |
|
||||
\*-------------------------------------------------*/
|
||||
for(unsigned int callback_idx = 0; callback_idx < ClientInfoChangeCallbacks.size(); callback_idx++)
|
||||
{
|
||||
ClientInfoChangeCallbacks[callback_idx](ClientInfoChangeCallbackArgs[callback_idx]);
|
||||
}
|
||||
|
||||
ClientInfoChangeMutex.unlock();
|
||||
}
|
||||
|
||||
unsigned short NetworkServer::GetPort()
|
||||
{
|
||||
return port_num;
|
||||
}
|
||||
|
||||
bool NetworkServer::GetOnline()
|
||||
{
|
||||
return server_online;
|
||||
}
|
||||
|
||||
unsigned int NetworkServer::GetNumClients()
|
||||
{
|
||||
return ServerClients.size();
|
||||
}
|
||||
|
||||
const char * NetworkServer::GetClientString(unsigned int client_num)
|
||||
{
|
||||
if(client_num < ServerClients.size())
|
||||
{
|
||||
return ServerClients[client_num]->client_string.c_str();
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
const char * NetworkServer::GetClientIP(unsigned int client_num)
|
||||
{
|
||||
if(client_num < ServerClients.size())
|
||||
{
|
||||
return ServerClients[client_num]->client_ip;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkServer::RegisterClientInfoChangeCallback(NetServerCallback new_callback, void * new_callback_arg)
|
||||
{
|
||||
ClientInfoChangeCallbacks.push_back(new_callback);
|
||||
ClientInfoChangeCallbackArgs.push_back(new_callback_arg);
|
||||
}
|
||||
|
||||
void NetworkServer::SetPort(unsigned short new_port)
|
||||
{
|
||||
if(server_online == false)
|
||||
{
|
||||
port_num = new_port;
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkServer::StartServer()
|
||||
{
|
||||
//Start a TCP server and launch threads
|
||||
char port_str[6];
|
||||
snprintf(port_str, 6, "%d", port_num);
|
||||
|
||||
sockaddr_in myAddress;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Windows requires WSAStartup before using sockets |
|
||||
\*-------------------------------------------------*/
|
||||
#ifdef WIN32
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR)
|
||||
{
|
||||
WSACleanup();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Create the server socket |
|
||||
\*-------------------------------------------------*/
|
||||
server_sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (server_sock == INVALID_SOCKET)
|
||||
{
|
||||
WSACleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Fill in server address info with port value |
|
||||
\*-------------------------------------------------*/
|
||||
myAddress.sin_family = AF_INET;
|
||||
myAddress.sin_addr.s_addr = inet_addr("0.0.0.0");
|
||||
myAddress.sin_port = htons(atoi(port_str));
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Bind the server socket |
|
||||
\*-------------------------------------------------*/
|
||||
if (bind(server_sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR)
|
||||
{
|
||||
WSACleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Set socket options - no delay |
|
||||
\*-------------------------------------------------*/
|
||||
setsockopt(server_sock, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
|
||||
|
||||
server_online = true;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Start the connection thread |
|
||||
\*-------------------------------------------------*/
|
||||
ConnectionThread = new std::thread(&NetworkServer::ConnectionThreadFunction, this);
|
||||
}
|
||||
|
||||
void NetworkServer::StopServer()
|
||||
{
|
||||
server_online = false;
|
||||
|
||||
for(unsigned int client_idx = 0; client_idx < ServerClients.size(); client_idx++)
|
||||
{
|
||||
shutdown(ServerClients[client_idx]->client_sock, SD_RECEIVE);
|
||||
closesocket(ServerClients[client_idx]->client_sock);
|
||||
ServerClients[client_idx]->client_listen_thread->join();
|
||||
}
|
||||
|
||||
shutdown(server_sock, SD_RECEIVE);
|
||||
closesocket(server_sock);
|
||||
|
||||
ConnectionThread->join();
|
||||
|
||||
for(unsigned int client_idx = 0; client_idx < ServerClients.size(); client_idx++)
|
||||
{
|
||||
delete[] ServerClients[client_idx];
|
||||
}
|
||||
|
||||
ServerClients.clear();
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Client info has changed, call the callbacks |
|
||||
\*-------------------------------------------------*/
|
||||
ClientInfoChanged();
|
||||
}
|
||||
|
||||
void NetworkServer::ConnectionThreadFunction()
|
||||
{
|
||||
//This thread handles client connections
|
||||
|
||||
printf("Network connection thread started\n");
|
||||
while(server_online == true)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Create new socket for client connection |
|
||||
\*-------------------------------------------------*/
|
||||
NetworkClientInfo * client_info = new NetworkClientInfo();
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Listen for incoming client connection on the |
|
||||
| server socket. This call blocks until a |
|
||||
| connection is established |
|
||||
\*-------------------------------------------------*/
|
||||
if(listen(server_sock, 10) < 0)
|
||||
{
|
||||
printf("Connection thread closed\r\n");
|
||||
server_online = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Accept the client connection |
|
||||
\*-------------------------------------------------*/
|
||||
struct sockaddr_in client_addr;
|
||||
socklen_t client_addr_len = sizeof(client_addr);
|
||||
client_info->client_sock = accept_select(server_sock, (struct sockaddr *)&client_addr, &client_addr_len);
|
||||
|
||||
if(client_info->client_sock < 0)
|
||||
{
|
||||
printf("Connection thread closed\r\n");
|
||||
server_online = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Get the new client socket and store it in the |
|
||||
| clients vector |
|
||||
\*-------------------------------------------------*/
|
||||
u_long arg = 0;
|
||||
ioctlsocket(client_info->client_sock, FIONBIO, &arg);
|
||||
setsockopt(client_info->client_sock, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
|
||||
|
||||
inet_ntop(AF_INET, &client_addr.sin_addr, client_info->client_ip, INET_ADDRSTRLEN);
|
||||
|
||||
client_info->client_string = "Client";
|
||||
|
||||
//Start a listener thread for the new client socket
|
||||
client_info->client_listen_thread = new std::thread(&NetworkServer::ListenThreadFunction, this, client_info);
|
||||
|
||||
ServerClients.push_back(client_info);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Client info has changed, call the callbacks |
|
||||
\*-------------------------------------------------*/
|
||||
ClientInfoChanged();
|
||||
}
|
||||
|
||||
printf("Connection thread closed\r\n");
|
||||
server_online = false;
|
||||
}
|
||||
|
||||
int NetworkServer::accept_select(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
|
||||
{
|
||||
fd_set set;
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 5;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
while(1)
|
||||
{
|
||||
FD_ZERO(&set); /* clear the set */
|
||||
FD_SET(sockfd, &set); /* add our file descriptor to the set */
|
||||
|
||||
int rv = select(sockfd + 1, &set, NULL, NULL, &timeout);
|
||||
|
||||
if(rv == SOCKET_ERROR || server_online == false)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if(rv == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// socket has something to read
|
||||
return(accept(sockfd, addr, addrlen));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int NetworkServer::recv_select(SOCKET s, char *buf, int len, int flags)
|
||||
{
|
||||
fd_set set;
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 5;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
while(1)
|
||||
{
|
||||
FD_ZERO(&set); /* clear the set */
|
||||
FD_SET(s, &set); /* add our file descriptor to the set */
|
||||
|
||||
int rv = select(s + 1, &set, NULL, NULL, &timeout);
|
||||
|
||||
if(rv == SOCKET_ERROR || server_online == false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if(rv == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// socket has something to read
|
||||
return(recv(s, buf, len, flags));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
|
||||
{
|
||||
SOCKET client_sock = client_info->client_sock;
|
||||
|
||||
printf("Network server started\n");
|
||||
//This thread handles messages received from clients
|
||||
while(server_online == true)
|
||||
{
|
||||
NetPacketHeader header;
|
||||
int bytes_read = 0;
|
||||
char * data = NULL;
|
||||
|
||||
//Read first byte of magic
|
||||
bytes_read = recv_select(client_sock, &header.pkt_magic[0], 1, 0);
|
||||
|
||||
if(bytes_read == 0)
|
||||
{
|
||||
goto listen_done;
|
||||
}
|
||||
|
||||
//Test first character of magic - 'O'
|
||||
if(header.pkt_magic[0] != 'O')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//Read second byte of magic
|
||||
bytes_read = recv_select(client_sock, &header.pkt_magic[1], 1, 0);
|
||||
|
||||
if(bytes_read == 0)
|
||||
{
|
||||
goto listen_done;
|
||||
}
|
||||
|
||||
//Test second character of magic - 'R'
|
||||
if(header.pkt_magic[1] != 'R')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//Read third byte of magic
|
||||
bytes_read = recv_select(client_sock, &header.pkt_magic[2], 1, 0);
|
||||
|
||||
if(bytes_read == 0)
|
||||
{
|
||||
goto listen_done;
|
||||
}
|
||||
|
||||
//Test third character of magic - 'G'
|
||||
if(header.pkt_magic[2] != 'G')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//Read fourth byte of magic
|
||||
bytes_read = recv_select(client_sock, &header.pkt_magic[3], 1, 0);
|
||||
|
||||
if(bytes_read == 0)
|
||||
{
|
||||
goto listen_done;
|
||||
}
|
||||
|
||||
//Test fourth character of magic - 'B'
|
||||
if(header.pkt_magic[3] != 'B')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//If we get to this point, the magic is correct. Read the rest of the header
|
||||
bytes_read = 0;
|
||||
do
|
||||
{
|
||||
int tmp_bytes_read = 0;
|
||||
|
||||
tmp_bytes_read = recv_select(client_sock, (char *)&header.pkt_dev_idx + bytes_read, sizeof(header) - sizeof(header.pkt_magic) - bytes_read, 0);
|
||||
|
||||
bytes_read += tmp_bytes_read;
|
||||
|
||||
if(tmp_bytes_read == 0)
|
||||
{
|
||||
goto listen_done;
|
||||
}
|
||||
|
||||
} while(bytes_read != sizeof(header) - sizeof(header.pkt_magic));
|
||||
|
||||
//printf( "Server: Received header, now receiving data of size %d\r\n", header.pkt_size);
|
||||
|
||||
//Header received, now receive the data
|
||||
if(header.pkt_size > 0)
|
||||
{
|
||||
bytes_read = 0;
|
||||
|
||||
data = new char[header.pkt_size];
|
||||
|
||||
do
|
||||
{
|
||||
int tmp_bytes_read = 0;
|
||||
|
||||
tmp_bytes_read = recv_select(client_sock, &data[bytes_read], header.pkt_size - bytes_read, 0);
|
||||
|
||||
if(tmp_bytes_read == 0)
|
||||
{
|
||||
goto listen_done;
|
||||
}
|
||||
bytes_read += tmp_bytes_read;
|
||||
|
||||
} while (bytes_read < header.pkt_size);
|
||||
}
|
||||
|
||||
//printf( "Server: Received header and data\r\n" );
|
||||
//printf( "Server: Packet ID: %d \r\n", header.pkt_id);
|
||||
|
||||
//Entire request received, select functionality based on request ID
|
||||
switch(header.pkt_id)
|
||||
{
|
||||
case NET_PACKET_ID_REQUEST_CONTROLLER_COUNT:
|
||||
//printf( "NET_PACKET_ID_REQUEST_CONTROLLER_COUNT\r\n" );
|
||||
SendReply_ControllerCount(client_sock);
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_REQUEST_CONTROLLER_DATA:
|
||||
//printf( "NET_PACKET_ID_REQUEST_CONTROLLER_DATA\r\n" );
|
||||
SendReply_ControllerData(client_sock, header.pkt_dev_idx);
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_SET_CLIENT_NAME:
|
||||
printf( "NET_PACKET_ID_SET_CLIENT_NAME\r\n" );
|
||||
ProcessRequest_ClientString(client_sock, header.pkt_size, data);
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE:
|
||||
//printf( "NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE\r\n" );
|
||||
|
||||
if((header.pkt_dev_idx < controllers.size()) && (header.pkt_size == (2 * sizeof(int))))
|
||||
{
|
||||
int zone;
|
||||
int new_size;
|
||||
|
||||
memcpy(&zone, data, sizeof(int));
|
||||
memcpy(&new_size, data + sizeof(int), sizeof(int));
|
||||
|
||||
controllers[header.pkt_dev_idx]->ResizeZone(zone, new_size);
|
||||
}
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS:
|
||||
//printf( "NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS\r\n" );
|
||||
|
||||
if(header.pkt_dev_idx < controllers.size())
|
||||
{
|
||||
controllers[header.pkt_dev_idx]->SetColorDescription((unsigned char *)data);
|
||||
controllers[header.pkt_dev_idx]->UpdateLEDs();
|
||||
}
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS:
|
||||
//printf( "NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS\r\n" );
|
||||
|
||||
if(header.pkt_dev_idx < controllers.size())
|
||||
{
|
||||
int zone;
|
||||
|
||||
memcpy(&zone, &data[sizeof(unsigned int)], sizeof(int));
|
||||
|
||||
controllers[header.pkt_dev_idx]->SetZoneColorDescription((unsigned char *)data);
|
||||
controllers[header.pkt_dev_idx]->UpdateZoneLEDs(zone);
|
||||
}
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED:
|
||||
//printf( "NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED\r\n" );
|
||||
|
||||
if(header.pkt_dev_idx < controllers.size())
|
||||
{
|
||||
int led;
|
||||
|
||||
memcpy(&led, data, sizeof(int));
|
||||
|
||||
controllers[header.pkt_dev_idx]->SetSingleLEDColorDescription((unsigned char *)data);
|
||||
controllers[header.pkt_dev_idx]->UpdateSingleLED(led);
|
||||
}
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE:
|
||||
//printf( "NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE\r\n" );
|
||||
|
||||
if(header.pkt_dev_idx < controllers.size())
|
||||
{
|
||||
controllers[header.pkt_dev_idx]->SetCustomMode();
|
||||
}
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE:
|
||||
//printf( "NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE\r\n" );
|
||||
|
||||
if(header.pkt_dev_idx < controllers.size())
|
||||
{
|
||||
controllers[header.pkt_dev_idx]->SetModeDescription((unsigned char *)data);
|
||||
controllers[header.pkt_dev_idx]->UpdateMode();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
listen_done:
|
||||
printf("Server connection closed\r\n");
|
||||
shutdown(client_info->client_sock, SD_RECEIVE);
|
||||
closesocket(client_info->client_sock);
|
||||
|
||||
for(unsigned int this_idx = 0; this_idx < ServerClients.size(); this_idx++)
|
||||
{
|
||||
if(ServerClients[this_idx] == client_info)
|
||||
{
|
||||
ServerClients.erase(ServerClients.begin() + this_idx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Client info has changed, call the callbacks |
|
||||
\*-------------------------------------------------*/
|
||||
ClientInfoChanged();
|
||||
}
|
||||
|
||||
void NetworkServer::ProcessRequest_ClientString(SOCKET client_sock, unsigned int data_size, char * data)
|
||||
{
|
||||
for(unsigned int this_idx = 0; this_idx < ServerClients.size(); this_idx++)
|
||||
{
|
||||
if(ServerClients[this_idx]->client_sock == client_sock)
|
||||
{
|
||||
ServerClients[this_idx]->client_string = data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Client info has changed, call the callbacks |
|
||||
\*-------------------------------------------------*/
|
||||
ClientInfoChanged();
|
||||
}
|
||||
|
||||
void NetworkServer::SendReply_ControllerCount(SOCKET client_sock)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
unsigned int reply_data;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = 0;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_REQUEST_CONTROLLER_COUNT;
|
||||
reply_hdr.pkt_size = sizeof(unsigned int);
|
||||
|
||||
reply_data = controllers.size();
|
||||
|
||||
send(client_sock, (const char *)&reply_hdr, sizeof(NetPacketHeader), 0);
|
||||
send(client_sock, (const char *)&reply_data, sizeof(unsigned int), 0);
|
||||
}
|
||||
|
||||
void NetworkServer::SendReply_ControllerData(SOCKET client_sock, unsigned int dev_idx)
|
||||
{
|
||||
if(dev_idx < controllers.size())
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
unsigned char *reply_data = controllers[dev_idx]->GetDeviceDescription();
|
||||
unsigned int reply_size;
|
||||
|
||||
memcpy(&reply_size, reply_data, sizeof(reply_size));
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_REQUEST_CONTROLLER_DATA;
|
||||
reply_hdr.pkt_size = reply_size;
|
||||
|
||||
send(client_sock, (const char *)&reply_hdr, sizeof(NetPacketHeader), 0);
|
||||
send(client_sock, (const char *)reply_data, reply_size, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*-----------------------------------------*\
|
||||
| NetworkServer.h |
|
||||
| |
|
||||
| Server header for OpenRGB SDK |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 5/9/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "NetworkProtocol.h"
|
||||
#include "net_port.h"
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef void (*NetServerCallback)(void *);
|
||||
|
||||
struct NetworkClientInfo
|
||||
{
|
||||
SOCKET client_sock;
|
||||
std::thread * client_listen_thread;
|
||||
std::string client_string;
|
||||
char client_ip[INET_ADDRSTRLEN];
|
||||
};
|
||||
|
||||
class NetworkServer
|
||||
{
|
||||
public:
|
||||
NetworkServer(std::vector<RGBController *>& control);
|
||||
|
||||
unsigned short GetPort();
|
||||
bool GetOnline();
|
||||
unsigned int GetNumClients();
|
||||
const char * GetClientString(unsigned int client_num);
|
||||
const char * GetClientIP(unsigned int client_num);
|
||||
|
||||
void ClientInfoChanged();
|
||||
void RegisterClientInfoChangeCallback(NetServerCallback, void * new_callback_arg);
|
||||
|
||||
void SetPort(unsigned short new_port);
|
||||
|
||||
void StartServer();
|
||||
void StopServer();
|
||||
|
||||
void ConnectionThreadFunction();
|
||||
void ListenThreadFunction(NetworkClientInfo * client_sock);
|
||||
|
||||
void ProcessRequest_ClientString(SOCKET client_sock, unsigned int data_size, char * data);
|
||||
|
||||
void SendReply_ControllerCount(SOCKET client_sock);
|
||||
void SendReply_ControllerData(SOCKET client_sock, unsigned int dev_idx);
|
||||
|
||||
protected:
|
||||
unsigned short port_num;
|
||||
bool server_online;
|
||||
|
||||
std::vector<RGBController *>& controllers;
|
||||
|
||||
std::vector<NetworkClientInfo *> ServerClients;
|
||||
std::thread * ConnectionThread;
|
||||
|
||||
std::mutex ClientInfoChangeMutex;
|
||||
std::vector<NetServerCallback> ClientInfoChangeCallbacks;
|
||||
std::vector<void *> ClientInfoChangeCallbackArgs;
|
||||
|
||||
private:
|
||||
#ifdef WIN32
|
||||
WSADATA wsa;
|
||||
#endif
|
||||
|
||||
SOCKET server_sock;
|
||||
|
||||
int accept_select(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
int recv_select(SOCKET s, char *buf, int len, int flags);
|
||||
};
|
||||
+2
-4
@@ -256,9 +256,6 @@ void DetectI2CBusses()
|
||||
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);
|
||||
}
|
||||
|
||||
+18
-8
@@ -68,6 +68,8 @@ SOURCES += \
|
||||
main.cpp \
|
||||
cli.cpp \
|
||||
OpenRGB.cpp \
|
||||
NetworkClient.cpp \
|
||||
NetworkServer.cpp \
|
||||
ProfileManager.cpp \
|
||||
qt/OpenRGBDeviceInfoPage.cpp \
|
||||
qt/OpenRGBDevicePage.cpp \
|
||||
@@ -77,6 +79,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 \
|
||||
@@ -163,6 +166,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 \
|
||||
@@ -176,6 +180,9 @@ SOURCES += \
|
||||
|
||||
HEADERS += \
|
||||
dependencies/ColorWheel/ColorWheel.h \
|
||||
NetworkClient.h \
|
||||
NetworkProtocol.h \
|
||||
NetworkServer.h \
|
||||
ProfileManager.h \
|
||||
qt/OpenRGBDeviceInfoPage.h \
|
||||
qt/OpenRGBDevicePage.h \
|
||||
@@ -185,6 +192,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 \
|
||||
@@ -241,6 +249,7 @@ 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 \
|
||||
@@ -255,14 +264,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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -157,6 +157,8 @@ void RGBController_AuraAddressable::SetupZones()
|
||||
|
||||
leds.push_back(new_led);
|
||||
}
|
||||
|
||||
zones[channel_idx].matrix_map = NULL;
|
||||
}
|
||||
|
||||
SetupColors();
|
||||
@@ -172,7 +174,7 @@ void RGBController_AuraAddressable::ResizeZone(int zone, int new_size)
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_AuraAddressable::UpdateLEDs()
|
||||
void RGBController_AuraAddressable::DeviceUpdateLEDs()
|
||||
{
|
||||
for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
|
||||
{
|
||||
|
||||
@@ -23,7 +23,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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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++)
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void UpdateLEDs();
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
|
||||
+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 */
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
#include "NetworkServer.h"
|
||||
#include "OpenRGB.h"
|
||||
#include "ProfileManager.h"
|
||||
#include "RGBController.h"
|
||||
@@ -44,10 +45,12 @@ int main(int argc, char* argv[])
|
||||
return cli_main(argc, argv, rgb_controllers, &profile_manager);
|
||||
}
|
||||
|
||||
NetworkServer server(rgb_controllers);
|
||||
|
||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QApplication a(argc, argv);
|
||||
|
||||
Ui::OpenRGBDialog2 dlg(busses, rgb_controllers, profile_manager);
|
||||
Ui::OpenRGBDialog2 dlg(busses, rgb_controllers, &profile_manager, &server);
|
||||
dlg.show();
|
||||
|
||||
return a.exec();
|
||||
|
||||
+43
-66
@@ -155,6 +155,11 @@ bool net_port::tcp_client_connect()
|
||||
tv.tv_sec = 4;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Set socket options - no delay |
|
||||
\*-------------------------------------------------*/
|
||||
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
|
||||
|
||||
if (select(sock + 1, NULL, &fdset, NULL, &tv) == 1)
|
||||
{
|
||||
char so_error;
|
||||
@@ -187,6 +192,9 @@ bool net_port::tcp_server(const char * port)
|
||||
{
|
||||
sockaddr_in myAddress;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Windows requires WSAStartup before using sockets |
|
||||
\*-------------------------------------------------*/
|
||||
#ifdef WIN32
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR)
|
||||
{
|
||||
@@ -195,6 +203,9 @@ bool net_port::tcp_server(const char * port)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Create the server socket |
|
||||
\*-------------------------------------------------*/
|
||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sock == INVALID_SOCKET)
|
||||
{
|
||||
@@ -202,32 +213,61 @@ bool net_port::tcp_server(const char * port)
|
||||
return false;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Fill in server address info with port value |
|
||||
\*-------------------------------------------------*/
|
||||
port = strtok((char *)port, "\r");
|
||||
|
||||
myAddress.sin_family = AF_INET;
|
||||
myAddress.sin_addr.s_addr = inet_addr("0.0.0.0");
|
||||
myAddress.sin_port = htons(atoi(port));
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Bind the server socket |
|
||||
\*-------------------------------------------------*/
|
||||
if (bind(sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR)
|
||||
{
|
||||
WSACleanup();
|
||||
return false;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Set socket options - no delay |
|
||||
\*-------------------------------------------------*/
|
||||
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void net_port::tcp_server_listen()
|
||||
SOCKET * net_port::tcp_server_listen()
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Create new socket for client connection |
|
||||
\*-------------------------------------------------*/
|
||||
SOCKET * client = new SOCKET();
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Listen for incoming client connection on the |
|
||||
| server socket. This call blocks until a |
|
||||
| connection is established |
|
||||
\*-------------------------------------------------*/
|
||||
listen(sock, 10);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Accept the client connection |
|
||||
\*-------------------------------------------------*/
|
||||
*client = accept(sock, NULL, NULL);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Get the new client socket and store it in the |
|
||||
| clients vector |
|
||||
\*-------------------------------------------------*/
|
||||
u_long arg = 0;
|
||||
ioctlsocket(*client, FIONBIO, &arg);
|
||||
setsockopt(*client, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
|
||||
clients.push_back(client);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
void net_port::tcp_close()
|
||||
@@ -236,72 +276,9 @@ void net_port::tcp_close()
|
||||
connected = false;
|
||||
}
|
||||
|
||||
int net_port::tcp_listen(char * recv_data, int /*length*/)
|
||||
int net_port::tcp_listen(char * recv_data, int length)
|
||||
{
|
||||
int ret = 0;
|
||||
int len = 0;
|
||||
int tot = 0;
|
||||
timeval waitd;
|
||||
|
||||
fd_set readfd;
|
||||
|
||||
FD_ZERO(&readfd);
|
||||
FD_SET(sock, &readfd);
|
||||
|
||||
if (connected)
|
||||
{
|
||||
while(ret != sizeof(len))
|
||||
{
|
||||
waitd.tv_sec = 10;
|
||||
waitd.tv_usec = 0;
|
||||
|
||||
if (select(sock + 1, &readfd, NULL, NULL, &waitd))
|
||||
{
|
||||
ret = recv(sock, (char *)&len, sizeof(len), 0);
|
||||
|
||||
if (ret == -1 || ret == 0)
|
||||
{
|
||||
closesocket(sock);
|
||||
connected = false;
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
closesocket(sock);
|
||||
connected = false;
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
while(tot != len)
|
||||
{
|
||||
waitd.tv_sec = 10;
|
||||
waitd.tv_usec = 0;
|
||||
|
||||
if (select(sock + 1, &readfd, NULL, NULL, &waitd))
|
||||
{
|
||||
ret = recv(sock, recv_data + ret, len - ret, 0);
|
||||
|
||||
if (ret == -1 || ret == 0)
|
||||
{
|
||||
closesocket(sock);
|
||||
connected = false;
|
||||
return(0);
|
||||
}
|
||||
|
||||
tot += ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
closesocket(sock);
|
||||
connected = false;
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return(ret);
|
||||
return(recv(sock, recv_data, length, 0));
|
||||
}
|
||||
|
||||
int net_port::tcp_client_write(char * buffer, int length)
|
||||
|
||||
+5
-2
@@ -33,6 +33,7 @@
|
||||
#define WSACleanup()
|
||||
#define INVALID_SOCKET -1
|
||||
#define SOCKET_ERROR -1
|
||||
#define SD_RECEIVE SHUT_RD
|
||||
#endif
|
||||
|
||||
//Network Port Class
|
||||
@@ -54,8 +55,10 @@ public:
|
||||
bool tcp_client_connect();
|
||||
|
||||
//Function to open a server
|
||||
bool tcp_server(const char * port);
|
||||
void tcp_server_listen();
|
||||
bool tcp_server(const char * port);
|
||||
std::size_t tcp_server_num_clients();
|
||||
SOCKET * tcp_server_get_client(std::size_t client_idx);
|
||||
SOCKET * tcp_server_listen();
|
||||
|
||||
int udp_listen(char * recv_data, int length);
|
||||
int tcp_listen(char * recv_data, int length);
|
||||
|
||||
+106
-77
@@ -1,6 +1,7 @@
|
||||
#include "OpenRGBDialog2.h"
|
||||
#include "OpenRGBDevicePage.h"
|
||||
#include "OpenRGBDeviceInfoPage.h"
|
||||
#include "OpenRGBServerInfoPage.h"
|
||||
#include "OpenRGBSoftwareInfoPage.h"
|
||||
#include "OpenRGBSystemInfoPage.h"
|
||||
#include "OpenRGBProfileSaveDialog.h"
|
||||
@@ -10,7 +11,7 @@
|
||||
|
||||
using namespace Ui;
|
||||
|
||||
OpenRGBDialog2::OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vector<RGBController *>& control, ProfileManager& manager, QWidget *parent) : QMainWindow(parent), busses(bus), controllers(control), profile_manager(manager), ui(new OpenRGBDialog2Ui)
|
||||
OpenRGBDialog2::OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vector<RGBController *>& control, ProfileManager* manager, NetworkServer* server, QWidget *parent) : QMainWindow(parent), busses(bus), controllers(control), profile_manager(manager), network_server(server), ui(new OpenRGBDialog2Ui)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
@@ -202,7 +203,7 @@ OpenRGBDialog2::OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vec
|
||||
/*-----------------------------------------------------*\
|
||||
| Show the I2C Tools page only if enabled |
|
||||
\*-----------------------------------------------------*/
|
||||
if(false) //TODO: SMBus Tools enable flag
|
||||
if(true) //TODO: SMBus Tools enable flag
|
||||
{
|
||||
OpenRGBSystemInfoPage *SMBusToolsPage = new OpenRGBSystemInfoPage(bus);
|
||||
ui->InformationTabBar->addTab(SMBusToolsPage, "");
|
||||
@@ -234,7 +235,7 @@ OpenRGBDialog2::OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vec
|
||||
SoftwareTabLabel->setIndent(20);
|
||||
SoftwareTabLabel->setGeometry(0, 0, 200, 20);
|
||||
|
||||
if(false) //TODO: SMBus Tools enable flag
|
||||
if(true) //TODO: SMBus Tools enable flag
|
||||
{
|
||||
InformationTabBar->setTabButton(control.size() + 1, QTabBar::LeftSide, SoftwareTabLabel);
|
||||
}
|
||||
@@ -242,6 +243,16 @@ OpenRGBDialog2::OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vec
|
||||
{
|
||||
InformationTabBar->setTabButton(control.size(), QTabBar::LeftSide, SoftwareTabLabel);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add server information tab if there is a server |
|
||||
\*-----------------------------------------------------*/
|
||||
if(network_server != NULL)
|
||||
{
|
||||
OpenRGBServerInfoPage *ServerInfoPage = new OpenRGBServerInfoPage(network_server);
|
||||
|
||||
ui->MainTabBar->addTab(ServerInfoPage, "SDK Server");
|
||||
}
|
||||
}
|
||||
|
||||
OpenRGBDialog2::~OpenRGBDialog2()
|
||||
@@ -256,26 +267,29 @@ void OpenRGBDialog2::show()
|
||||
|
||||
void OpenRGBDialog2::RefreshProfileList()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Clear profile combo box and tray icon menu |
|
||||
\*-----------------------------------------------------*/
|
||||
ui->ProfileBox->clear();
|
||||
profileMenu->clear();
|
||||
|
||||
for(std::size_t profile_index = 0; profile_index < profile_manager.profile_list.size(); profile_index++)
|
||||
if(profile_manager != NULL)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Fill in profile combo box |
|
||||
| Clear profile combo box and tray icon menu |
|
||||
\*-----------------------------------------------------*/
|
||||
ui->ProfileBox->addItem(profile_manager.profile_list[profile_index].c_str());
|
||||
ui->ProfileBox->clear();
|
||||
profileMenu->clear();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Fill in profile tray icon menu |
|
||||
\*-----------------------------------------------------*/
|
||||
QAction* actionProfileSelected = new QAction(profile_manager.profile_list[profile_index].c_str(), this);
|
||||
actionProfileSelected->setObjectName(profile_manager.profile_list[profile_index].c_str());
|
||||
connect(actionProfileSelected, SIGNAL(triggered()), this, SLOT(on_ProfileSelected()));
|
||||
profileMenu->addAction(actionProfileSelected);
|
||||
for(std::size_t profile_index = 0; profile_index < profile_manager->profile_list.size(); profile_index++)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Fill in profile combo box |
|
||||
\*-----------------------------------------------------*/
|
||||
ui->ProfileBox->addItem(profile_manager->profile_list[profile_index].c_str());
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Fill in profile tray icon menu |
|
||||
\*-----------------------------------------------------*/
|
||||
QAction* actionProfileSelected = new QAction(profile_manager->profile_list[profile_index].c_str(), this);
|
||||
actionProfileSelected->setObjectName(profile_manager->profile_list[profile_index].c_str());
|
||||
connect(actionProfileSelected, SIGNAL(triggered()), this, SLOT(on_ProfileSelected()));
|
||||
profileMenu->addAction(actionProfileSelected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,10 +350,13 @@ void OpenRGBDialog2::on_SetAllDevices(unsigned char red, unsigned char green, un
|
||||
|
||||
void OpenRGBDialog2::on_SaveSizeProfile()
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Save the profile |
|
||||
\*---------------------------------------------------------*/
|
||||
profile_manager.SaveProfile("sizes.ors");
|
||||
if(profile_manager != NULL)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Save the profile |
|
||||
\*---------------------------------------------------------*/
|
||||
profile_manager->SaveProfile("sizes.ors");
|
||||
}
|
||||
}
|
||||
|
||||
void OpenRGBDialog2::on_ShowHide()
|
||||
@@ -356,19 +373,22 @@ void OpenRGBDialog2::on_ShowHide()
|
||||
|
||||
void Ui::OpenRGBDialog2::on_ProfileSelected()
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Get the profile filename from the selected object |
|
||||
\*---------------------------------------------------------*/
|
||||
std::string profile_name = QObject::sender()->objectName().toStdString();
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Load the profile |
|
||||
\*---------------------------------------------------------*/
|
||||
if(profile_manager.LoadProfile(profile_name))
|
||||
if(profile_manager != NULL)
|
||||
{
|
||||
for(int device = 0; device < ui->DevicesTabBar->count(); device++)
|
||||
/*---------------------------------------------------------*\
|
||||
| Get the profile filename from the selected object |
|
||||
\*---------------------------------------------------------*/
|
||||
std::string profile_name = QObject::sender()->objectName().toStdString();
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Load the profile |
|
||||
\*---------------------------------------------------------*/
|
||||
if(profile_manager->LoadProfile(profile_name))
|
||||
{
|
||||
qobject_cast<OpenRGBDevicePage *>(ui->DevicesTabBar->widget(device))->UpdateDevice();
|
||||
for(int device = 0; device < ui->DevicesTabBar->count(); device++)
|
||||
{
|
||||
qobject_cast<OpenRGBDevicePage *>(ui->DevicesTabBar->widget(device))->UpdateDevice();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -377,64 +397,73 @@ void Ui::OpenRGBDialog2::on_ButtonSaveProfile_clicked()
|
||||
{
|
||||
OpenRGBProfileSaveDialog dialog;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Open Profile Name Dialog |
|
||||
\*---------------------------------------------------------*/
|
||||
std::string profile_name = dialog.show();
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Extension .orp - OpenRgb Profile |
|
||||
\*---------------------------------------------------------*/
|
||||
std::string filename = profile_name + ".orp";
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Save the profile |
|
||||
\*---------------------------------------------------------*/
|
||||
if(profile_manager.SaveProfile(filename))
|
||||
if(profile_manager != NULL)
|
||||
{
|
||||
RefreshProfileList();
|
||||
/*---------------------------------------------------------*\
|
||||
| Open Profile Name Dialog |
|
||||
\*---------------------------------------------------------*/
|
||||
std::string profile_name = dialog.show();
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Extension .orp - OpenRgb Profile |
|
||||
\*---------------------------------------------------------*/
|
||||
std::string filename = profile_name + ".orp";
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Save the profile |
|
||||
\*---------------------------------------------------------*/
|
||||
if(profile_manager->SaveProfile(filename))
|
||||
{
|
||||
RefreshProfileList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Ui::OpenRGBDialog2::on_ButtonLoadProfile_clicked()
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Get the profile filename from the profiles list |
|
||||
\*---------------------------------------------------------*/
|
||||
std::string profile_name = ui->ProfileBox->currentText().toStdString();
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Load the profile |
|
||||
\*---------------------------------------------------------*/
|
||||
if(profile_manager.LoadProfile(profile_name))
|
||||
if(profile_manager != NULL)
|
||||
{
|
||||
for(int device = 0; device < ui->DevicesTabBar->count(); device++)
|
||||
/*---------------------------------------------------------*\
|
||||
| Get the profile filename from the profiles list |
|
||||
\*---------------------------------------------------------*/
|
||||
std::string profile_name = ui->ProfileBox->currentText().toStdString();
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Load the profile |
|
||||
\*---------------------------------------------------------*/
|
||||
if(profile_manager->LoadProfile(profile_name))
|
||||
{
|
||||
qobject_cast<OpenRGBDevicePage *>(ui->DevicesTabBar->widget(device))->UpdateDevice();
|
||||
for(int device = 0; device < ui->DevicesTabBar->count(); device++)
|
||||
{
|
||||
qobject_cast<OpenRGBDevicePage *>(ui->DevicesTabBar->widget(device))->UpdateDevice();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Ui::OpenRGBDialog2::on_ButtonDeleteProfile_clicked()
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Get the profile filename from the profiles list |
|
||||
\*---------------------------------------------------------*/
|
||||
std::string profile_name = ui->ProfileBox->currentText().toStdString();
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Confirm we want to delete the profile |
|
||||
\*---------------------------------------------------------*/
|
||||
QMessageBox::StandardButton reply;
|
||||
reply = QMessageBox::question(this, "Delete Profile", "Do you really want to delete this profile?", QMessageBox::Yes|QMessageBox::No);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Load the profile |
|
||||
\*---------------------------------------------------------*/
|
||||
if(reply == QMessageBox::Yes)
|
||||
if(profile_manager != NULL)
|
||||
{
|
||||
profile_manager.DeleteProfile(profile_name);
|
||||
/*---------------------------------------------------------*\
|
||||
| Get the profile filename from the profiles list |
|
||||
\*---------------------------------------------------------*/
|
||||
std::string profile_name = ui->ProfileBox->currentText().toStdString();
|
||||
|
||||
RefreshProfileList();
|
||||
/*---------------------------------------------------------*\
|
||||
| Confirm we want to delete the profile |
|
||||
\*---------------------------------------------------------*/
|
||||
QMessageBox::StandardButton reply;
|
||||
reply = QMessageBox::question(this, "Delete Profile", "Do you really want to delete this profile?", QMessageBox::Yes|QMessageBox::No);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Load the profile |
|
||||
\*---------------------------------------------------------*/
|
||||
if(reply == QMessageBox::Yes)
|
||||
{
|
||||
profile_manager->DeleteProfile(profile_name);
|
||||
|
||||
RefreshProfileList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -7,6 +7,7 @@
|
||||
#include "i2c_smbus.h"
|
||||
#include "RGBController.h"
|
||||
#include "ProfileManager.h"
|
||||
#include "NetworkServer.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QTimer>
|
||||
@@ -23,7 +24,7 @@ class Ui::OpenRGBDialog2 : public QMainWindow
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vector<RGBController *>& control, ProfileManager& manager, QWidget *parent = 0);
|
||||
explicit OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vector<RGBController *>& control, ProfileManager* manager, NetworkServer* server, QWidget *parent = 0);
|
||||
~OpenRGBDialog2();
|
||||
|
||||
void show();
|
||||
@@ -32,7 +33,8 @@ public:
|
||||
protected:
|
||||
std::vector<i2c_smbus_interface *>& busses;
|
||||
std::vector<RGBController *>& controllers;
|
||||
ProfileManager& profile_manager;
|
||||
ProfileManager* profile_manager;
|
||||
NetworkServer* network_server;
|
||||
|
||||
private:
|
||||
Ui::OpenRGBDialog2Ui *ui;
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
#include "OpenRGBServerInfoPage.h"
|
||||
|
||||
using namespace Ui;
|
||||
|
||||
static void UpdateInfoCallback(void * this_ptr)
|
||||
{
|
||||
OpenRGBServerInfoPage * this_obj = (OpenRGBServerInfoPage *)this_ptr;
|
||||
|
||||
QMetaObject::invokeMethod(this_obj, "UpdateInfo", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
OpenRGBServerInfoPage::OpenRGBServerInfoPage(NetworkServer * server, QWidget *parent) :
|
||||
QFrame(parent),
|
||||
ui(new Ui::OpenRGBServerInfoPageUi)
|
||||
{
|
||||
network_server = server;
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
UpdateInfo();
|
||||
|
||||
network_server->RegisterClientInfoChangeCallback(UpdateInfoCallback, this);
|
||||
}
|
||||
|
||||
OpenRGBServerInfoPage::~OpenRGBServerInfoPage()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void OpenRGBServerInfoPage::UpdateInfo()
|
||||
{
|
||||
ui->ServerPortValue->setText(std::to_string(network_server->GetPort()).c_str());
|
||||
|
||||
if(network_server->GetOnline())
|
||||
{
|
||||
ui->ServerStatusValue->setText("Online");
|
||||
ui->ServerStartButton->setEnabled(false);
|
||||
ui->ServerStopButton->setEnabled(true);
|
||||
ui->ServerPortValue->setEnabled(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->ServerStatusValue->setText("Offline");
|
||||
ui->ServerStartButton->setEnabled(true);
|
||||
ui->ServerStopButton->setEnabled(false);
|
||||
ui->ServerPortValue->setEnabled(true);
|
||||
}
|
||||
|
||||
ui->ServerClientTree->clear();
|
||||
ui->ServerClientTree->setColumnCount(2);
|
||||
ui->ServerClientTree->setHeaderLabels(QStringList() << "Client IP" << "Client Name");
|
||||
for(unsigned int client_idx = 0; client_idx < network_server->GetNumClients(); client_idx++)
|
||||
{
|
||||
QTreeWidgetItem * new_item = new QTreeWidgetItem();
|
||||
|
||||
new_item->setText(0, network_server->GetClientIP(client_idx));
|
||||
new_item->setText(1, network_server->GetClientString(client_idx));
|
||||
|
||||
ui->ServerClientTree->addTopLevelItem(new_item);
|
||||
}
|
||||
}
|
||||
|
||||
void Ui::OpenRGBServerInfoPage::on_ServerStartButton_clicked()
|
||||
{
|
||||
if(network_server->GetOnline() == false)
|
||||
{
|
||||
network_server->SetPort(ui->ServerPortValue->text().toInt());
|
||||
network_server->StartServer();
|
||||
|
||||
UpdateInfo();
|
||||
}
|
||||
}
|
||||
|
||||
void Ui::OpenRGBServerInfoPage::on_ServerStopButton_clicked()
|
||||
{
|
||||
if(network_server->GetOnline() == true)
|
||||
{
|
||||
network_server->StopServer();
|
||||
|
||||
UpdateInfo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef OPENRGBSERVERINFOPAGE_H
|
||||
#define OPENRGBSERVERINFOPAGE_H
|
||||
|
||||
#include <QFrame>
|
||||
#include "RGBController.h"
|
||||
#include "ui_OpenRGBServerInfoPage.h"
|
||||
#include "NetworkServer.h"
|
||||
|
||||
namespace Ui {
|
||||
class OpenRGBServerInfoPage;
|
||||
}
|
||||
|
||||
class Ui::OpenRGBServerInfoPage : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OpenRGBServerInfoPage(NetworkServer * server, QWidget *parent = nullptr);
|
||||
~OpenRGBServerInfoPage();
|
||||
|
||||
public slots:
|
||||
void UpdateInfo();
|
||||
|
||||
private slots:
|
||||
void on_ServerStartButton_clicked();
|
||||
void on_ServerStopButton_clicked();
|
||||
|
||||
private:
|
||||
Ui::OpenRGBServerInfoPageUi *ui;
|
||||
|
||||
NetworkServer* network_server;
|
||||
};
|
||||
|
||||
#endif // OPENRGBSERVERINFOPAGE_H
|
||||
@@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>OpenRGBServerInfoPageUi</class>
|
||||
<widget class="QFrame" name="OpenRGBServerInfoPageUi">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>664</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Frame</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="3">
|
||||
<widget class="QPushButton" name="ServerStopButton">
|
||||
<property name="text">
|
||||
<string>Stop Server</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="ServerPortLabel">
|
||||
<property name="text">
|
||||
<string>Server Port:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QPushButton" name="ServerStartButton">
|
||||
<property name="text">
|
||||
<string>Start Server</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="4">
|
||||
<widget class="QTreeWidget" name="ServerClientTree">
|
||||
<property name="columnCount">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="ServerStatusLabel">
|
||||
<property name="text">
|
||||
<string>Server Status:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="ServerStatusValue">
|
||||
<property name="text">
|
||||
<string>Offline</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="ServerPortValue">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="ServerClientsLabel">
|
||||
<property name="text">
|
||||
<string>Connected Clients:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user