Compare commits

..
Author SHA1 Message Date
Adam Honse 42df4c5026 Make i2c thread safe 2020-01-07 23:59:52 -06:00
43 changed files with 197 additions and 1429 deletions
@@ -244,30 +244,45 @@ void AuraController::AuraUpdateDeviceName()
unsigned char AuraController::AuraRegisterRead(aura_register reg)
{
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
//Write Aura register
bus->i2c_smbus_write_word_data(dev, 0x00, ((reg << 8) & 0xFF00) | ((reg >> 8) & 0x00FF));
//Read Aura value
return(bus->i2c_smbus_read_byte_data(dev, 0x81));
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
void AuraController::AuraRegisterWrite(aura_register reg, unsigned char val)
{
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
//Write Aura register
bus->i2c_smbus_write_word_data(dev, 0x00, ((reg << 8) & 0xFF00) | ((reg >> 8) & 0x00FF));
//Write Aura value
bus->i2c_smbus_write_byte_data(dev, 0x01, val);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
void AuraController::AuraRegisterWriteBlock(aura_register reg, unsigned char * data, unsigned char sz)
{
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
//Write Aura register
bus->i2c_smbus_write_word_data(dev, 0x00, ((reg << 8) & 0xFF00) | ((reg >> 8) & 0x00FF));
//Write Aura block data
bus->i2c_smbus_write_block_data(dev, 0x03, sz, data);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
@@ -46,14 +46,26 @@ unsigned int CorsairController::GetLEDCount()
void CorsairController::SetLEDColor(unsigned char red, unsigned char green, unsigned char blue)
{
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_FADE_TIME, 0x00);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_RED_VAL, red);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_GREEN_VAL, green);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_BLUE_VAL, blue);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_MODE, CORSAIR_VENGEANCE_RGB_MODE_SINGLE);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
void CorsairController::SetMode(unsigned char /*mode*/)
{
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_MODE, CORSAIR_VENGEANCE_RGB_MODE_SINGLE);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
@@ -1,141 +0,0 @@
/*-----------------------------------------*\
| CorsairKbdV1Controller.cpp |
| |
| Driver for first-generation Corsair Kxx |
| RGB keyboard lighting controller |
| |
| Adam Honse (CalcProgrammer1) 1/9/2020 |
\*-----------------------------------------*/
#include "CorsairKbdV1Controller.h"
static void send_usb_msg(hid_device* dev, char * data_pkt)
{
char usb_pkt[65];
usb_pkt[0] = 0x00;
for(int i = 1; i < 65; i++)
{
usb_pkt[i] = data_pkt[i-1];
}
int bytes = hid_send_feature_report(dev, (unsigned char *)usb_pkt, 65);
bytes++;
}
CorsairKbdV1Controller::CorsairKbdV1Controller(hid_device* dev_handle)
{
dev = dev_handle;
char data_pkt[64] = { 0 };
data_pkt[0] = 0x07;
data_pkt[1] = 0x05;
data_pkt[2] = 0x02;
data_pkt[3] = 0x00;
data_pkt[4] = 0x03;
send_usb_msg(dev, data_pkt);
}
CorsairKbdV1Controller::~CorsairKbdV1Controller()
{
}
char* CorsairKbdV1Controller::GetDeviceName()
{
return device_name;
}
void CorsairKbdV1Controller::SetLEDs(std::vector<RGBColor> colors)
{
char data_pkt[5][64] = { 0 };
char red_val[144];
char grn_val[144];
char blu_val[144];
for(int color_idx = 0; color_idx < colors.size(); color_idx++)
{
RGBColor color = colors[color_idx];
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
if( red > 7 ) red = 7;
if( grn > 7 ) grn = 7;
if( blu > 7 ) blu = 7;
red = 7 - red;
grn = 7 - grn;
blu = 7 - blu;
red_val[color_idx] = red;
grn_val[color_idx] = grn;
blu_val[color_idx] = blu;
}
// Perform USB control message to keyboard
//
// Request Type: 0x21
// Request: 0x09
// Value 0x0300
// Index: 0x03
// Size: 64
data_pkt[0][0] = 0x7F;
data_pkt[0][1] = 0x01;
data_pkt[0][2] = 0x3C;
data_pkt[1][0] = 0x7F;
data_pkt[1][1] = 0x02;
data_pkt[1][2] = 0x3C;
data_pkt[2][0] = 0x7F;
data_pkt[2][1] = 0x03;
data_pkt[2][2] = 0x3C;
data_pkt[3][0] = 0x7F;
data_pkt[3][1] = 0x04;
data_pkt[3][2] = 0x24;
data_pkt[4][0] = 0x07;
data_pkt[4][1] = 0x27;
data_pkt[4][2] = 0x00;
data_pkt[4][2] = 0x00;
data_pkt[4][4] = 0xD8; //Number of payload bytes
for(int i = 0; i < 60; i++)
{
data_pkt[0][i+4] = red_val[i*2+1] << 4 | red_val[i*2];
}
for(int i = 0; i < 12; i++)
{
data_pkt[1][i+4] = red_val[i*2+121] << 4 | red_val[i*2+120];
}
for(int i = 0; i < 48; i++)
{
data_pkt[1][i+16] = grn_val[i*2+1] << 4 | grn_val[i*2];
}
for(int i = 0; i < 24; i++)
{
data_pkt[2][i+4] = grn_val[i*2+97] << 4 | grn_val[i*2+96];
}
for(int i = 0; i < 36; i++)
{
data_pkt[2][i+28] = blu_val[i*2+1] << 4 | blu_val[i*2];
}
for(int i = 0; i < 36; i++)
{
data_pkt[3][i+4] = blu_val[i*2+73] << 4 | blu_val[i*2+72];
}
send_usb_msg(dev, data_pkt[0]);
send_usb_msg(dev, data_pkt[1]);
send_usb_msg(dev, data_pkt[2]);
send_usb_msg(dev, data_pkt[3]);
send_usb_msg(dev, data_pkt[4]);
}
@@ -1,31 +0,0 @@
/*-----------------------------------------*\
| CorsairKbdV1Controller.h |
| |
| Definitions and types for first-gene |
| Corsair Kxx keyboard lighting controller |
| |
| Adam Honse (CalcProgrammer1) 1/9/2020 |
\*-----------------------------------------*/
#include "RGBController.h"
#include <string>
#include <hidapi/hidapi.h>
#pragma once
class CorsairKbdV1Controller
{
public:
CorsairKbdV1Controller(hid_device* dev_handle);
~CorsairKbdV1Controller();
char* GetDeviceName();
void SetLEDsDirect(std::vector<RGBColor> colors);
void SetLEDs(std::vector<RGBColor> colors);
private:
char device_name[32];
hid_device* dev;
};
@@ -1,52 +0,0 @@
#include "CorsairKbdV1Controller.h"
#include "RGBController.h"
#include "RGBController_CorsairKbdV1.h"
#include <vector>
#include <hidapi/hidapi.h>
#define CORSAIR_RGB_KEYBOARD_VID 0x1B1C
#define CORSAIR_RGB_KEYBOARD_K70_PID 0x1B13
#define CORSAIR_RGB_KEYBOARD_K95_PID 0x1B11
/******************************************************************************************\
* *
* DetectCorsairKbdV1Controllers *
* *
* Tests the USB address to see if a Corsair RGB Keyboard controller exists there. *
* *
\******************************************************************************************/
void DetectCorsairKbdV1Controllers(std::vector<RGBController*>& rgb_controllers)
{
hid_device_info* info;
hid_device* dev;
hid_init();
info = hid_enumerate(CORSAIR_RGB_KEYBOARD_VID, CORSAIR_RGB_KEYBOARD_K70_PID);
//Look for Corsair RGB Keyboard, interface 1
while(info)
{
if((info->vendor_id == CORSAIR_RGB_KEYBOARD_VID)
&&(info->product_id == CORSAIR_RGB_KEYBOARD_K70_PID)
&&(info->interface_number == 1))
{
dev = hid_open_path(info->path);
break;
}
else
{
info = info->next;
}
}
if( dev )
{
CorsairKbdV1Controller* controller = new CorsairKbdV1Controller(dev);
RGBController_CorsairKbdV1* rgb_controller = new RGBController_CorsairKbdV1(controller);
rgb_controllers.push_back(rgb_controller);
}
}
@@ -29,8 +29,6 @@ CorsairProController::CorsairProController(i2c_smbus_interface* bus, corsair_dev
strcpy(device_name, "Corsair Vengeance Pro RGB");
led_count = CORSAIR_PRO_LED_COUNT;
effect_mode = CORSAIR_PRO_MODE_STATIC;
for (unsigned int i = 0; i < led_count; i++)
{
led_red[i] = 0;
@@ -64,11 +62,6 @@ unsigned int CorsairProController::GetLEDCount()
return(led_count);
}
unsigned char CorsairProController::GetEffect()
{
return(effect_mode);
}
void CorsairProController::SetAllColors(unsigned char red, unsigned char green, unsigned char blue)
{
for (unsigned int i = 0; i < led_count; i++)
@@ -88,6 +81,9 @@ void CorsairProController::SetLEDColor(unsigned int led, unsigned char red, unsi
void CorsairProController::ApplyColors()
{
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
bus->i2c_smbus_write_byte_data(dev, 0x26, 0x02);
Sleep(1);
bus->i2c_smbus_write_byte_data(dev, 0x21, 0x00);
@@ -102,18 +98,22 @@ void CorsairProController::ApplyColors()
}
bus->i2c_smbus_write_byte_data(dev, 0x82, 0x02);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
void CorsairProController::SetEffect(unsigned char mode)
{
effect_mode = mode;
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
bus->i2c_smbus_write_byte_data(dev, 0x26, 0x01);
Sleep(1);
bus->i2c_smbus_write_byte_data(dev, 0x21, 0x00);
Sleep(1);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, effect_mode); //Mode
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, mode); //Mode
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, CORSAIR_PRO_SPEED_MEDIUM); //Speed
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, CORSAIR_PRO_EFFECT_RANDOM_COLORS); //Custom color
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, CORSAIR_PRO_DIRECTION_UP); //Direction
@@ -136,6 +136,9 @@ void CorsairProController::SetEffect(unsigned char mode)
bus->i2c_smbus_write_byte_data(dev, 0x82, 0x01);
WaitReady();
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
void CorsairProController::SetCustom()
@@ -69,7 +69,6 @@ public:
std::string GetDeviceName();
std::string GetDeviceLocation();
unsigned int GetLEDCount();
unsigned char GetEffect();
void SetEffect(unsigned char mode);
void SetCustom();
@@ -81,7 +80,7 @@ public:
private:
char device_name[32];
unsigned int led_count;
unsigned char effect_mode;
unsigned char led_red[CORSAIR_PRO_LED_COUNT];
unsigned char led_green[CORSAIR_PRO_LED_COUNT];
unsigned char led_blue[CORSAIR_PRO_LED_COUNT];
@@ -60,11 +60,7 @@ unsigned int Hue2Controller::GetStripsOnChannel(unsigned int /*channel*/)
case 0x01: //Hue 1 strip
num_leds_on_channel += 10;
break;
case 0x02: //Aer 1 fan
num_leds_on_channel += 8;
break;
case 0x04: //Hue 2 strip
num_leds_on_channel += 10;
break;
@@ -37,8 +37,8 @@ void HuePlusController::Initialize(char* port_name)
serialport = new serial_port(port_name, HUE_PLUS_BAUD);
channel_leds[HUE_PLUS_CHANNEL_1_IDX] = GetLEDsOnChannel(HUE_PLUS_CHANNEL_1);
channel_leds[HUE_PLUS_CHANNEL_2_IDX] = GetLEDsOnChannel(HUE_PLUS_CHANNEL_2);
channel_leds[HUE_PLUS_CHANNEL_1_IDX] = GetStripsOnChannel(HUE_PLUS_CHANNEL_1) * 10;
channel_leds[HUE_PLUS_CHANNEL_2_IDX] = GetStripsOnChannel(HUE_PLUS_CHANNEL_2) * 10;
}
char* HuePlusController::GetLEDString()
@@ -46,7 +46,7 @@ char* HuePlusController::GetLEDString()
return(led_string);
}
unsigned int HuePlusController::GetLEDsOnChannel(unsigned int channel)
unsigned int HuePlusController::GetStripsOnChannel(unsigned int channel)
{
unsigned char serial_buf[] =
{
@@ -68,17 +68,9 @@ unsigned int HuePlusController::GetLEDsOnChannel(unsigned int channel)
int bytes_read = serialport->serial_read((char *)serial_buf, 5);
printf("%x %x %x %x %x \r\n", serial_buf[0], serial_buf[1], serial_buf[2], serial_buf[3], serial_buf[4]);
if(bytes_read == 5)
{
if(serial_buf[3] == 0x01)
{
ret_val = serial_buf[4] * 8;
}
else
{
ret_val += serial_buf[4] * 10;
}
ret_val = serial_buf[4];
}
return(ret_val);
@@ -55,7 +55,7 @@ public:
void Initialize(char* port_name);
char* GetLEDString();
unsigned int GetLEDsOnChannel(unsigned int channel);
unsigned int GetStripsOnChannel(unsigned int channel);
void SetChannelEffect(unsigned int channel, unsigned int mode, std::vector<RGBColor> colors);
void SetChannelLEDs(unsigned int channel, std::vector<RGBColor> colors);
@@ -78,6 +78,9 @@ unsigned int HyperXController::GetMode()
void HyperXController::SetEffectColor(unsigned char red, unsigned char green, unsigned char blue)
{
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_EFFECT_RED, red );
@@ -87,10 +90,16 @@ void HyperXController::SetEffectColor(unsigned char red, unsigned char green, un
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x02);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x03);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
void HyperXController::SetAllColors(unsigned char red, unsigned char green, unsigned char blue)
{
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01);
/*-----------------------------------------------------*\
@@ -124,6 +133,9 @@ void HyperXController::SetAllColors(unsigned char red, unsigned char green, unsi
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x02);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x03);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
void HyperXController::SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
@@ -163,6 +175,9 @@ void HyperXController::SetLEDColor(unsigned int led, unsigned char red, unsigned
unsigned char blue_base = base + 0x02;
unsigned char bright_base = base + 0x10;
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01);
bus->i2c_smbus_write_byte_data(dev, red_base + (3 * led), red );
@@ -172,6 +187,9 @@ void HyperXController::SetLEDColor(unsigned int led, unsigned char red, unsigned
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x02);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x03);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
@@ -183,6 +201,9 @@ void HyperXController::SetLEDColor(unsigned int slot, unsigned int led, unsigned
unsigned char blue_base = base + 0x02;
unsigned char bright_base = base + 0x10;
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01);
bus->i2c_smbus_write_byte_data(dev, red_base + (3 * led), red );
@@ -192,12 +213,18 @@ void HyperXController::SetLEDColor(unsigned int slot, unsigned int led, unsigned
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x02);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x03);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
void HyperXController::SetMode(unsigned char new_mode)
{
mode = new_mode;
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01);
switch (mode)
@@ -241,4 +268,7 @@ void HyperXController::SetMode(unsigned char new_mode)
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x02);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x03);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
@@ -1,78 +0,0 @@
/*-----------------------------------------*\
| MSI3ZoneController.cpp |
| |
| Driver for MSI/Steelseries 3-Zone |
| Keyboard lighting controller |
| |
| Adam Honse (CalcProgrammer1) 12/25/2019 |
\*-----------------------------------------*/
#include "MSI3ZoneController.h"
MSI3ZoneController::MSI3ZoneController(hid_device* dev_handle)
{
dev = dev_handle;
//strcpy(device_name, "MSI 3-Zone Keyboard");
}
MSI3ZoneController::~MSI3ZoneController()
{
}
char* MSI3ZoneController::GetDeviceName()
{
return device_name;
}
void MSI3ZoneController::SetLEDs(std::vector<RGBColor> colors)
{
//Shout out to bparker06 for reverse engineering the MSI keyboard USB protocol!
// https://github.com/bparker06/msi-keyboard/blob/master/keyboard.cpp for original implementation
unsigned char buf[8] = { 0 };
buf[0] = 1;
buf[1] = 2;
buf[2] = 64;
buf[3] = 1;
buf[4] = RGBGetRValue(colors[0]);
buf[5] = RGBGetGValue(colors[0]);
buf[6] = RGBGetBValue(colors[0]);
buf[7] = 236;
hid_send_feature_report(dev, buf, 8);
buf[3] = 2;
buf[4] = RGBGetRValue(colors[1]);
buf[5] = RGBGetGValue(colors[1]);
buf[6] = RGBGetBValue(colors[1]);
hid_send_feature_report(dev, buf, 8);
buf[3] = 3;
buf[4] = RGBGetRValue(colors[2]);
buf[5] = RGBGetGValue(colors[2]);
buf[6] = RGBGetBValue(colors[2]);
hid_send_feature_report(dev, buf, 8);
buf[3] = 4;
buf[4] = RGBGetRValue(colors[3]);
buf[5] = RGBGetGValue(colors[3]);
buf[6] = RGBGetBValue(colors[3]);
hid_send_feature_report(dev, buf, 8);
buf[3] = 5;
hid_send_feature_report(dev, buf, 8);
buf[3] = 6;
hid_send_feature_report(dev, buf, 8);
buf[3] = 7;
hid_send_feature_report(dev, buf, 8);
}
@@ -1,30 +0,0 @@
/*-----------------------------------------*\
| MSI3ZoneController.h |
| |
| Definitions and types for MSI/Steelseries|
| 3-Zone Keyboard lighting controller |
| |
| Adam Honse (CalcProgrammer1) 12/25/2019 |
\*-----------------------------------------*/
#include "RGBController.h"
#include <string>
#include <hidapi/hidapi.h>
#pragma once
class MSI3ZoneController
{
public:
MSI3ZoneController(hid_device* dev_handle);
~MSI3ZoneController();
char* GetDeviceName();
void SetLEDs(std::vector<RGBColor> colors);
private:
char device_name[32];
hid_device* dev;
};
@@ -1,36 +0,0 @@
#include "MSI3ZoneController.h"
#include "RGBController.h"
#include "RGBController_MSI3Zone.h"
#include <vector>
#include <hidapi/hidapi.h>
#define MSI_3_ZONE_KEYBOARD_VID 0x1770
#define MSI_3_ZONE_KEYBOARD_PID 0xFF00
/******************************************************************************************\
* *
* DetectMSI3ZoneControllers *
* *
* Tests the USB address to see if an MSI/SteelSeries 3-zone Keyboard controller *
* exists there. *
* *
\******************************************************************************************/
void DetectMSI3ZoneControllers(std::vector<RGBController*>& rgb_controllers)
{
hid_device* dev;
//Look for MSI/Steelseries 3-zone Keyboard
hid_init();
dev = hid_open(MSI_3_ZONE_KEYBOARD_VID, MSI_3_ZONE_KEYBOARD_PID, 0);
if( dev )
{
MSI3ZoneController* controller = new MSI3ZoneController(dev);
RGBController_MSI3Zone* rgb_controller = new RGBController_MSI3Zone(controller);
rgb_controllers.push_back(rgb_controller);
}
}
@@ -76,6 +76,9 @@ unsigned int PatriotViperController::GetMode()
void PatriotViperController::SetEffectColor(unsigned char red, unsigned char green, unsigned char blue)
{
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
ViperRegisterWrite(VIPER_REG_START, 0xFF, 0xFF, 0xFF);
ViperRegisterWrite(VIPER_REG_STATIC, 0x04, 0x00, 0x00);
@@ -88,10 +91,16 @@ void PatriotViperController::SetEffectColor(unsigned char red, unsigned char gre
ViperRegisterWrite(VIPER_REG_MODE, mode, 0x00, 0x0C);
ViperRegisterWrite(VIPER_REG_MODE, 0xAA, 0x00, 0x00);
ViperRegisterWrite(VIPER_REG_MODE, 0xFA, 0x00, 0x00);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
void PatriotViperController::SetAllColors(unsigned char red, unsigned char green, unsigned char blue)
{
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
ViperRegisterWrite(VIPER_REG_START, 0xFF, 0xFF, 0xFF);
ViperRegisterWrite(VIPER_REG_STATIC, 0x04, 0x00, 0x00);
@@ -102,20 +111,32 @@ void PatriotViperController::SetAllColors(unsigned char red, unsigned char green
ViperRegisterWrite(VIPER_REG_LED4_DIRECT_COLOR, red, blue, green);
ViperRegisterWrite(VIPER_REG_APPLY, 0x01, 0x00, 0x00);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
void PatriotViperController::SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
ViperRegisterWrite(VIPER_REG_START, 0xFF, 0xFF, 0xFF);
ViperRegisterWrite(VIPER_REG_STATIC, 0x04, 0x00, 0x00);
ViperRegisterWrite(VIPER_REG_LED0_DIRECT_COLOR + led, red, blue, green);
ViperRegisterWrite(VIPER_REG_APPLY, 0x01, 0x00, 0x00);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
void PatriotViperController::SetLEDEffectColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
ViperRegisterWrite(VIPER_REG_START, 0xFF, 0xFF, 0xFF);
ViperRegisterWrite(VIPER_REG_STATIC, 0x04, 0x00, 0x00);
@@ -124,20 +145,32 @@ void PatriotViperController::SetLEDEffectColor(unsigned int led, unsigned char r
ViperRegisterWrite(VIPER_REG_MODE, mode, 0x00, 0x0C);
ViperRegisterWrite(VIPER_REG_MODE, 0xAA, 0x00, 0x00);
ViperRegisterWrite(VIPER_REG_MODE, 0xFA, 0x00, 0x00);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
void PatriotViperController::SetLEDColor(unsigned int slot, unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
ViperRegisterWrite(VIPER_REG_START, 0xFF, 0xFF, 0xFF);
ViperRegisterWrite(VIPER_REG_STATIC, 0x04, 0x00, 0x00);
ViperRegisterWrite(VIPER_REG_LED0_DIRECT_COLOR + led, red, blue, green);
ViperRegisterWrite(VIPER_REG_APPLY, 0x01, 0x00, 0x00);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
void PatriotViperController::SetLEDEffectColor(unsigned int slot, unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
ViperRegisterWrite(VIPER_REG_START, 0xFF, 0xFF, 0xFF);
ViperRegisterWrite(VIPER_REG_STATIC, 0x04, 0x00, 0x00);
@@ -146,6 +179,9 @@ void PatriotViperController::SetLEDEffectColor(unsigned int slot, unsigned int l
ViperRegisterWrite(VIPER_REG_MODE, mode, 0x00, 0x0C);
ViperRegisterWrite(VIPER_REG_MODE, 0xAA, 0x00, 0x00);
ViperRegisterWrite(VIPER_REG_MODE, 0xFA, 0x00, 0x00);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
void PatriotViperController::SetMode(unsigned char new_mode)
@@ -153,19 +189,32 @@ void PatriotViperController::SetMode(unsigned char new_mode)
direct = false;
mode = new_mode;
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
ViperRegisterWrite(VIPER_REG_START, 0xFF, 0xFF, 0xFF);
ViperRegisterWrite(VIPER_REG_STATIC, 0x04, 0x00, 0x00);
ViperRegisterWrite(VIPER_REG_MODE, new_mode, 0x00, 0x0C);
ViperRegisterWrite(VIPER_REG_MODE, 0xAA, 0x00, 0x00);
ViperRegisterWrite(VIPER_REG_MODE, 0xFA, 0x00, 0x00);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
void PatriotViperController::SetDirect()
{
direct = true;
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
ViperRegisterWrite(VIPER_REG_START, 0xFF, 0xFF, 0xFF);
ViperRegisterWrite(VIPER_REG_STATIC, 0x04, 0x00, 0x00);
ViperRegisterWrite(VIPER_REG_APPLY, 0x01, 0x00, 0x00);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
void PatriotViperController::ViperRegisterWrite(viper_register reg, unsigned char val0, unsigned char val1, unsigned char val2)
@@ -1,173 +0,0 @@
/*-----------------------------------------*\
| PoseidonZRGBController.cpp |
| |
| Driver for Thermaltake Poseidon Z RGB |
| Keyboard lighting controller |
| |
| Adam Honse (CalcProgrammer1) 12/25/2019 |
\*-----------------------------------------*/
#include "PoseidonZRGBController.h"
#ifdef WIN32
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
static unsigned int keys[] = {8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21,
22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35,
36, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, 52, 54, 55, 56, 57, 58, 59, 60, 62, 63, 64,
65, 66, 67, 68, 70, 71, 72, 73, 74, 75, 76, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
93, 94, 95, 96, 97, 98, 99, 100, 102, 103, 104, 105,
106, 108, 109, 111, 112, 114, 115, 117, 118, 119, 120,
124, 128, 129 };
PoseidonZRGBController::PoseidonZRGBController(hid_device* dev_handle)
{
dev = dev_handle;
}
PoseidonZRGBController::~PoseidonZRGBController()
{
}
char* PoseidonZRGBController::GetDeviceName()
{
return device_name;
}
void PoseidonZRGBController::SetLEDsDirect(std::vector<RGBColor> colors)
{
unsigned char red_grn_buf[264];
unsigned char blu_buf[264];
for(int i = 0; i < 264; i++)
{
red_grn_buf[i] = 0x00;
blu_buf[i] = 0x00;
}
red_grn_buf[0] = POSEIDONZ_START;
red_grn_buf[1] = POSEIDONZ_LED_CMD;
red_grn_buf[2] = POSEIDONZ_PROFILE;
red_grn_buf[3] = POSEIDONZ_RED_GRN_CH;
red_grn_buf[4] = 0x00;
red_grn_buf[5] = 0x00;
red_grn_buf[6] = 0x00;
red_grn_buf[7] = 0x00;
blu_buf[0] = POSEIDONZ_START;
blu_buf[1] = POSEIDONZ_LED_CMD;
blu_buf[2] = POSEIDONZ_PROFILE;
blu_buf[3] = POSEIDONZ_BLU_CH;
blu_buf[4] = 0x00;
blu_buf[5] = 0x00;
blu_buf[6] = 0x00;
blu_buf[7] = 0x00;
for(int i = 0; i < 104; i++)
{
red_grn_buf[keys[i] ] = RGBGetRValue(colors[i]);
red_grn_buf[keys[i] + 128] = RGBGetGValue(colors[i]);
blu_buf[ keys[i] ] = RGBGetBValue(colors[i]);
}
hid_send_feature_report(dev, red_grn_buf, 264);
Sleep(1);
hid_send_feature_report(dev, blu_buf, 264);
}
void PoseidonZRGBController::SetLEDs(std::vector<RGBColor> colors)
{
unsigned char buf[264] = {0};
//Send Red Packet
for(int i = 0; i < 264; i++)
{
buf[i] = 0xFF;
}
buf[0] = 0x07;
buf[1] = 0x09;
buf[2] = 0x01;
buf[3] = 0x01;
for(int i = 0; i < 104; i++)
{
buf[keys[i]] = RGBGetRValue(colors[i]);
}
hid_send_feature_report(dev, buf, 264);
Sleep(10);
//Send Green Packet
for(int i = 0; i < 264; i++)
{
buf[i] = 0x00;
}
buf[0] = 0x07;
buf[1] = 0x09;
buf[2] = 0x01;
buf[3] = 0x02;
buf[8] = 0xFF;
for(int i = 0; i < 104; i++)
{
buf[keys[i]] = RGBGetGValue(colors[i]);
}
hid_send_feature_report(dev, buf, 264);
Sleep(10);
//Send Blue Packet
for(int i = 0; i < 264; i++)
{
buf[i] = 0x11;
}
buf[0] = 0x07;
buf[1] = 0x09;
buf[2] = 0x01;
buf[3] = 0x03;
for(int i = 0; i < 104; i++)
{
buf[keys[i]] = RGBGetBValue(colors[i]);
}
hid_send_feature_report(dev, buf, 264);
Sleep(10);
//Send Update Packet
for(int i = 0; i < 264; i++)
{
buf[i] = 0x00;
}
buf[0] = 0x07;
buf[1] = 0x02;
buf[2] = 0x01;
buf[8] = 0x01; //Preset to save
buf[13] = 0x04; //Brightness?
buf[16] = 0x08;
buf[22] = 0x03;
hid_send_feature_report(dev, buf, 264);
}
@@ -1,38 +0,0 @@
/*-----------------------------------------*\
| PoseidonZRGBController.h |
| |
| Definitions and types for Thermaltake |
| Poseidon Z RGB Keyboard lighting |
| controller |
| |
| Adam Honse (CalcProgrammer1) 12/25/2019 |
\*-----------------------------------------*/
#include "RGBController.h"
#include <string>
#include <hidapi/hidapi.h>
#pragma once
#define POSEIDONZ_START 0x07
#define POSEIDONZ_PROFILE 0x01
#define POSEIDONZ_LED_CMD 0x0E
#define POSEIDONZ_RED_GRN_CH 0x01
#define POSEIDONZ_BLU_CH 0x02
class PoseidonZRGBController
{
public:
PoseidonZRGBController(hid_device* dev_handle);
~PoseidonZRGBController();
char* GetDeviceName();
void SetLEDsDirect(std::vector<RGBColor> colors);
void SetLEDs(std::vector<RGBColor> colors);
private:
char device_name[32];
hid_device* dev;
};
@@ -1,36 +0,0 @@
#include "PoseidonZRGBController.h"
#include "RGBController.h"
#include "RGBController_PoseidonZRGB.h"
#include <vector>
#include <hidapi/hidapi.h>
#define TT_POSEIDON_Z_RGB_VID 0x264A
#define TT_POSEIDON_Z_RGB_PID 0x3006
/******************************************************************************************\
* *
* DetectPoseidonZRGBControllers *
* *
* Tests the USB address to see if a Thermaltake Poseidon Z RGB Keyboard controller *
* exists there. *
* *
\******************************************************************************************/
void DetectPoseidonZRGBControllers(std::vector<RGBController*>& rgb_controllers)
{
hid_device* dev;
//Look for Thermaltake Poseidon Z RGB Keyboard
hid_init();
dev = hid_open(TT_POSEIDON_Z_RGB_VID, TT_POSEIDON_Z_RGB_PID, 0);
if( dev )
{
PoseidonZRGBController* controller = new PoseidonZRGBController(dev);
RGBController_PoseidonZRGB* rgb_controller = new RGBController_PoseidonZRGB(controller);
rgb_controllers.push_back(rgb_controller);
}
}
@@ -63,6 +63,9 @@ void RGBFusionController::SetAllColors(unsigned char red, unsigned char green, u
{
unsigned char mode_ch_0;
unsigned char mode_ch_1;
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
switch_bank(1);
set_color_ch_0(red, green, blue);
@@ -74,6 +77,8 @@ void RGBFusionController::SetAllColors(unsigned char red, unsigned char green, u
set_mode_ch_0(mode_ch_0);
set_mode_ch_1(mode_ch_1);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
void RGBFusionController::SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
@@ -83,30 +88,48 @@ void RGBFusionController::SetLEDColor(unsigned int led, unsigned char red, unsig
switch (led)
{
case 0:
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
switch_bank(1);
set_color_ch_0(red, green, blue);
switch_bank(0);
mode = get_mode_ch_0();
set_mode_ch_0(mode);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
break;
case 1:
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
switch_bank(1);
set_color_ch_1(red, green, blue);
switch_bank(0);
mode = get_mode_ch_1();
set_mode_ch_1(mode);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
break;
}
}
void RGBFusionController::SetMode(unsigned char mode)
{
//Lock SMBus interface
bus->i2c_smbus_wait_and_lock();
switch_bank(0);
set_mode_ch_0(mode);
set_mode_ch_1(mode);
//Unlock SMBus interface
bus->i2c_smbus_unlock();
}
void RGBFusionController::dump()
+1 -7
View File
@@ -332,9 +332,6 @@ void DetectRazerChromaSDKControllers(std::vector<RGBController*>& rgb_controller
void DetectE131Controllers(std::vector<RGBController*> &rgb_controllers);
void DetectAMDWraithPrismControllers(std::vector<RGBController*>& rgb_controllers);
void DetectAorusGPUControllers(std::vector<RGBController*> &rgb_controllers);
void DetectMSI3ZoneControllers(std::vector<RGBController*>& rgb_controllers);
void DetectPoseidonZRGBControllers(std::vector<RGBController*>& rgb_controllers);
void DetectCorsairKbdV1Controllers(std::vector<RGBController*>& rgb_controllers);
/******************************************************************************************\
* *
@@ -361,10 +358,7 @@ void DetectRGBControllers(void)
DetectHuePlusControllers(rgb_controllers);
DetectAMDWraithPrismControllers(rgb_controllers);
DetectMSI3ZoneControllers(rgb_controllers);
DetectPoseidonZRGBControllers(rgb_controllers);
DetectCorsairKbdV1Controllers(rgb_controllers);
DetectE131Controllers(rgb_controllers);
/*-------------------------------------*\
+4 -34
View File
@@ -14,21 +14,19 @@ INCLUDEPATH += \
Controllers/AMDWraithPrismController/ \
Controllers/AuraController/ \
Controllers/CorsairController/ \
Controllers/CorsairKbdV1Controller/ \
Controllers/CorsairProController/ \
Controllers/Hue2Controller/ \
Controllers/HuePlusController/ \
Controllers/HyperXController/ \
Controllers/LEDStripController/ \
Controllers/MSI3ZoneController/ \
Controllers/PatriotViperController/ \
Controllers/PolychromeController/ \
Controllers/PoseidonZRGBController/ \
Controllers/RGBFusionController/ \
RGBController/ \
qt/
SOURCES += \
RGBController/RGBController.cpp \
dependencies/libe131/src/e131.c \
main.cpp \
OpenRGB.cpp \
@@ -47,8 +45,6 @@ SOURCES += \
Controllers/AuraController/AuraController.cpp \
Controllers/AuraController/AuraControllerDetect.cpp \
Controllers/CorsairController/CorsairController.cpp \
Controllers/CorsairKbdV1Controller/CorsairKbdV1Controller.cpp \
Controllers/CorsairKbdV1Controller/CorsairKbdV1ControllerDetect.cpp \
Controllers/CorsairController/CorsairControllerDetect.cpp \
Controllers/CorsairProController/CorsairProController.cpp \
Controllers/CorsairProController/CorsairProControllerDetect.cpp \
@@ -60,35 +56,28 @@ SOURCES += \
Controllers/HyperXController/HyperXControllerDetect.cpp \
Controllers/LEDStripController/LEDStripController.cpp \
Controllers/LEDStripController/LEDStripControllerDetect.cpp \
Controllers/MSI3ZoneController/MSI3ZoneController.cpp \
Controllers/MSI3ZoneController/MSI3ZoneControllerDetect.cpp \
Controllers/PatriotViperController/PatriotViperController.cpp \
Controllers/PatriotViperController/PatriotViperControllerDetect.cpp \
Controllers/PolychromeController/PolychromeController.cpp \
Controllers/PolychromeController/PolychromeControllerDetect.cpp \
Controllers/PoseidonZRGBController/PoseidonZRGBController.cpp \
Controllers/PoseidonZRGBController/PoseidonZRGBControllerDetect.cpp \
Controllers/RGBFusionController/RGBFusionController.cpp \
Controllers/RGBFusionController/RGBFusionControllerDetect.cpp \
RGBController/RGBController.cpp \
RGBController/E131ControllerDetect.cpp \
RGBController/RGBController_AMDWraithPrism.cpp \
RGBController/RGBController_Aura.cpp \
RGBController/RGBController_Corsair.cpp \
RGBController/RGBController_CorsairKbdV1.cpp \
RGBController/RGBController_CorsairPro.cpp \
RGBController/RGBController_Hue2.cpp \
RGBController/RGBController_HuePlus.cpp \
RGBController/RGBController_HyperX.cpp \
RGBController/RGBController_E131.cpp \
RGBController/RGBController_LEDStrip.cpp \
RGBController/RGBController_MSI3Zone.cpp \
RGBController/RGBController_PatriotViper.cpp \
RGBController/RGBController_Polychrome.cpp \
RGBController/RGBController_PoseidonZRGB.cpp \
RGBController/RGBController_RGBFusion.cpp
HEADERS += \
Controllers/RGBFusionController/RGBFusionController.h \
qt/OpenRGBDeviceInfoPage.h \
qt/OpenRGBDevicePage.h \
qt/OpenRGBDialog.h \
@@ -107,26 +96,20 @@ HEADERS += \
Controllers/HuePlusController/HuePlusController.h \
Controllers/HyperXController/HyperXController.h \
Controllers/LEDStripController/LEDStripController.h \
Controllers/MSI3ZoneController/MSI3ZoneController.h \
Controllers/PatriotViperController/PatriotViperController.h \
Controllers/PolychromeController/PolychromeController.h \
Controllers/PoseidonZRGBController/PoseidonZRGBController.h \
Controllers/RGBFusionController/RGBFusionController.h \
RGBController/RGBController.h \
RGBController/RGBController_AMDWraithPrism.h \
RGBController/RGBController_Aura.h \
RGBController/RGBController_Corsair.h \
RGBController/RGBController_CorsairKbdV1.h \
RGBController/RGBController_CorsairPro.h \
RGBController/RGBController_E131.h \
RGBController/RGBController_Hue2.h \
RGBController/RGBController_HuePlus.h \
RGBController/RGBController_HyperX.h \
RGBController/RGBController_LEDStrip.h \
RGBController/RGBController_MSI3Zone.h \
RGBController/RGBController_PatriotViper.h \
RGBController/RGBController_Polychrome.h \
RGBController/RGBController_PoseidonZRGB.h \
RGBController/RGBController_RGBFusion.h
RESOURCES += \
@@ -146,7 +129,6 @@ win32:INCLUDEPATH += \
dependencies/inpout32_1501/Win32/ \
dependencies/razer-chroma-2.9.0/inc \
dependencies/libusb-1.0.22/include \
dependencies/hidapi \
wmi/ \
win32:SOURCES += \
@@ -172,8 +154,7 @@ win32:HEADERS += \
win32:LIBS += \
-lws2_32 \
-L"$$PWD/dependencies/inpout32_1501/Win32/" -linpout32 \
-L"$$PWD/dependencies/libusb-1.0.22/MS32/dll" -llibusb-1.0 \
-L"$$PWD/dependencies/hidapi-win/x86/" -lhidapi
-L"$$PWD/dependencies/libusb-1.0.22/MS32/dll" -llibusb-1.0
win32:DEFINES -= \
UNICODE
@@ -194,18 +175,7 @@ unix:HEADERS += \
i2c_smbus/i2c_smbus_linux.h \
unix:LIBS += \
-lusb-1.0 \
packagesExist(hidapi-libusb){
unix:LIBS += -lhidapi-libusb
} else {
packagesExist(hidapi) {
unix:LIBS += -lhidapi
} else {
unix:LIBS += -lhidapi-libusb
}
}
-lusb-1.0
unix:SOURCES += \
i2c_smbus/i2c_smbus_linux.cpp \
@@ -1,58 +0,0 @@
/*-----------------------------------------*\
| RGBController_CorsairKbdV1.cpp |
| |
| Generic RGB Interface for first-gen |
| Corsair RGB keyboard |
| |
| Adam Honse (CalcProgrammer1) 1/9/2020 |
\*-----------------------------------------*/
#include "RGBController_CorsairKbdV1.h"
RGBController_CorsairKbdV1::RGBController_CorsairKbdV1(CorsairKbdV1Controller* corsair_ptr)
{
corsair = corsair_ptr;
name = "Corsair RGB Keyboard";
type = DEVICE_TYPE_KEYBOARD;
for(int i = 0; i < 144; i++)
{
colors.push_back(0x00000000);
}
}
RGBController_CorsairKbdV1::~RGBController_CorsairKbdV1()
{
}
int RGBController_CorsairKbdV1::GetMode()
{
return 0;
}
void RGBController_CorsairKbdV1::SetMode(int mode)
{
}
void RGBController_CorsairKbdV1::SetCustomMode()
{
}
void RGBController_CorsairKbdV1::UpdateLEDs()
{
corsair->SetLEDs(colors);
}
void RGBController_CorsairKbdV1::UpdateZoneLEDs(int zone)
{
corsair->SetLEDs(colors);
}
void RGBController_CorsairKbdV1::UpdateSingleLED(int led)
{
corsair->SetLEDs(colors);
}
@@ -1,28 +0,0 @@
/*-----------------------------------------*\
| RGBController_CorsairKbdV1.h |
| |
| Generic RGB Interface for first-gen |
| Corsair RGB keyboard |
| |
| Adam Honse (CalcProgrammer1) 1/9/2020 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "CorsairKbdV1Controller.h"
class RGBController_CorsairKbdV1 : public RGBController
{
public:
RGBController_CorsairKbdV1(CorsairKbdV1Controller* corsair_ptr);
~RGBController_CorsairKbdV1();
int GetMode();
void SetMode(int mode);
void SetCustomMode();
void UpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
private:
CorsairKbdV1Controller* corsair;
};
@@ -11,40 +11,6 @@
int RGBController_CorsairPro::GetMode()
{
switch (corsair->GetEffect())
{
case CORSAIR_PRO_MODE_COLOR_SHIFT:
return(0);
break;
case CORSAIR_PRO_MODE_COLOR_PULSE:
return(1);
break;
case CORSAIR_PRO_MODE_RAINBOW_WAVE:
return(2);
break;
case CORSAIR_PRO_MODE_COLOR_WAVE:
return(3);
break;
case CORSAIR_PRO_MODE_VISOR:
return(4);
break;
case CORSAIR_PRO_MODE_RAIN:
return(5);
break;
case CORSAIR_PRO_MODE_MARQUEE:
return(6);
break;
case CORSAIR_PRO_MODE_RAINBOW:
return(7);
break;
case CORSAIR_PRO_MODE_SEQUENTIAL:
return(8);
break;
case CORSAIR_PRO_MODE_STATIC:
return(9);
break;
}
return(0);
}
+1 -1
View File
@@ -92,7 +92,7 @@ void RGBController_Hue2::SetCustomMode()
void RGBController_Hue2::UpdateLEDs()
{
for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
for(std::size_t zone_idx = 0; zone_idx <= zones.size(); zone_idx++)
{
unsigned int channel = zones_channel[zone_idx];
+1 -1
View File
@@ -94,7 +94,7 @@ void RGBController_HuePlus::SetCustomMode()
void RGBController_HuePlus::UpdateLEDs()
{
for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
for(std::size_t zone_idx = 0; zone_idx <= zones.size(); zone_idx++)
{
unsigned int channel = zones_channel[zone_idx];
+2 -2
View File
@@ -122,8 +122,6 @@ RGBController_HyperX::RGBController_HyperX(HyperXController* hyperx_ptr)
modes.push_back(hyperx_modes[i]);
}
colors.resize(hyperx->GetLEDCount());
unsigned int led_idx = 0;
for(unsigned int slot = 0; slot < hyperx->GetSlotCount(); slot++)
@@ -141,6 +139,8 @@ RGBController_HyperX::RGBController_HyperX(HyperXController* hyperx_ptr)
for(int led_slot_idx = 0; led_slot_idx < 5; led_slot_idx++)
{
colors.push_back(0x00000000);
led* new_led = new led();
char led_idx_str[3];
+1 -2
View File
@@ -22,10 +22,9 @@ RGBController_LEDStrip::RGBController_LEDStrip(LEDStripController* ledstrip_ptr)
led_mode.name = "Custom";
modes.push_back(led_mode);
colors.resize(strip->num_leds);
for (int i = 0; i < strip->num_leds; i++)
{
colors.push_back(0x00000000);
led new_led;
new_led.name = "LED Strip";
leds.push_back(new_led);
-95
View File
@@ -1,95 +0,0 @@
/*-----------------------------------------*\
| RGBController_MSI3Zone.cpp |
| |
| Generic RGB Interface for MSI/Steelseries|
| 3-Zone Keyboard |
| |
| Adam Honse (CalcProgrammer1) 12/25/2019 |
\*-----------------------------------------*/
#include "RGBController_MSI3Zone.h"
RGBController_MSI3Zone::RGBController_MSI3Zone(MSI3ZoneController* msi_ptr)
{
msi = msi_ptr;
name = "MSI 3-Zone Keyboard";
type = DEVICE_TYPE_KEYBOARD;
mode led_mode;
led_mode.name = "Custom";
modes.push_back(led_mode);
led left_led;
left_led.name = "Keyboard Left";
leds.push_back(left_led);
colors.push_back(0x00000000);
led mid_led;
mid_led.name = "Keyboard Middle";
leds.push_back(mid_led);
colors.push_back(0x00000000);
led right_led;
right_led.name = "Keyboard Right";
leds.push_back(right_led);
colors.push_back(0x00000000);
zone keyboard_zone;
keyboard_zone.name = "Keyboard";
keyboard_zone.type = ZONE_TYPE_LINEAR;
std::vector<int> keyboard_zone_map;
keyboard_zone_map.push_back(0);
keyboard_zone_map.push_back(1);
keyboard_zone_map.push_back(2);
keyboard_zone.map.push_back(keyboard_zone_map);
zones.push_back(keyboard_zone);
led aux_led;
aux_led.name = "Aux";
leds.push_back(aux_led);
colors.push_back(0x00000000);
zone aux_zone;
aux_zone.name = "Aux";
aux_zone.type = ZONE_TYPE_SINGLE;
std::vector<int> aux_zone_map;
aux_zone_map.push_back(3);
aux_zone.map.push_back(aux_zone_map);
zones.push_back(aux_zone);
}
RGBController_MSI3Zone::~RGBController_MSI3Zone()
{
}
int RGBController_MSI3Zone::GetMode()
{
return 0;
}
void RGBController_MSI3Zone::SetMode(int mode)
{
}
void RGBController_MSI3Zone::SetCustomMode()
{
}
void RGBController_MSI3Zone::UpdateLEDs()
{
msi->SetLEDs(colors);
}
void RGBController_MSI3Zone::UpdateZoneLEDs(int zone)
{
msi->SetLEDs(colors);
}
void RGBController_MSI3Zone::UpdateSingleLED(int led)
{
msi->SetLEDs(colors);
}
-28
View File
@@ -1,28 +0,0 @@
/*-----------------------------------------*\
| RGBController_MSI3Zone.h |
| |
| Generic RGB Interface for MSI/Steelseries|
| 3-Zone Keyboard |
| |
| Adam Honse (CalcProgrammer1) 12/25/2019 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "MSI3ZoneController.h"
class RGBController_MSI3Zone : public RGBController
{
public:
RGBController_MSI3Zone(MSI3ZoneController* msi_ptr);
~RGBController_MSI3Zone();
int GetMode();
void SetMode(int mode);
void SetCustomMode();
void UpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
private:
MSI3ZoneController* msi;
};
+3 -2
View File
@@ -106,9 +106,8 @@ RGBController_PatriotViper::RGBController_PatriotViper(PatriotViperController* v
modes.push_back(viper_modes[i]);
}
colors.resize(viper->GetLEDCount());
unsigned int led_idx = 0;
for(unsigned int slot = 0; slot < viper->GetSlotCount(); slot++)
{
zone* new_zone = new zone;
@@ -124,6 +123,8 @@ RGBController_PatriotViper::RGBController_PatriotViper(PatriotViperController* v
for(int led_slot_idx = 0; led_slot_idx < 5; led_slot_idx++)
{
colors.push_back(0x00000000);
led* new_led = new led();
char led_idx_str[3];
+1 -2
View File
@@ -68,8 +68,6 @@ RGBController_Polychrome::RGBController_Polychrome(PolychromeController* polychr
modes.push_back(polychrome_modes[i]);
}
colors.resize(polychrome->GetLEDCount());
// Search through all LEDs and create zones for each channel type
for (unsigned int i = 0; i < polychrome->GetLEDCount(); i++)
{
@@ -90,6 +88,7 @@ RGBController_Polychrome::RGBController_Polychrome(PolychromeController* polychr
// Push new LED to LEDs vector
leds.push_back(*new_led);
colors.push_back(0x00000000);
// Push new zone to zones vector
zones.push_back(*new_zone);
@@ -1,58 +0,0 @@
/*-----------------------------------------*\
| RGBController_PoseidonZRGB.cpp |
| |
| Generic RGB Interface for Thermaltake |
| Poseidon Z RGB Keyboard |
| |
| Adam Honse (CalcProgrammer1) 12/25/2019 |
\*-----------------------------------------*/
#include "RGBController_PoseidonZRGB.h"
RGBController_PoseidonZRGB::RGBController_PoseidonZRGB(PoseidonZRGBController* poseidon_ptr)
{
poseidon = poseidon_ptr;
name = "Thermaltake Poseidon Z RGB";
type = DEVICE_TYPE_KEYBOARD;
for(int i = 0; i < 104; i++)
{
colors.push_back(0x00000000);
}
}
RGBController_PoseidonZRGB::~RGBController_PoseidonZRGB()
{
}
int RGBController_PoseidonZRGB::GetMode()
{
return 0;
}
void RGBController_PoseidonZRGB::SetMode(int mode)
{
}
void RGBController_PoseidonZRGB::SetCustomMode()
{
}
void RGBController_PoseidonZRGB::UpdateLEDs()
{
poseidon->SetLEDs(colors);
}
void RGBController_PoseidonZRGB::UpdateZoneLEDs(int zone)
{
poseidon->SetLEDs(colors);
}
void RGBController_PoseidonZRGB::UpdateSingleLED(int led)
{
poseidon->SetLEDs(colors);
}
@@ -1,28 +0,0 @@
/*-----------------------------------------*\
| RGBController_PoseidonZRGB.h |
| |
| Generic RGB Interface for Thermaltake |
| Poseidon Z RGB Keyboard |
| |
| Adam Honse (CalcProgrammer1) 12/25/2019 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "PoseidonZRGBController.h"
class RGBController_PoseidonZRGB : public RGBController
{
public:
RGBController_PoseidonZRGB(PoseidonZRGBController* poseidon_ptr);
~RGBController_PoseidonZRGB();
int GetMode();
void SetMode(int mode);
void SetCustomMode();
void UpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
private:
PoseidonZRGBController* poseidon;
};
+1 -2
View File
@@ -79,8 +79,6 @@ RGBController_RGBFusion::RGBController_RGBFusion(RGBFusionController* rgb_fusion
modes.push_back(rgb_fusion_modes[i]);
}
colors.resize(rgb_fusion->GetLEDCount());
// Search through all LEDs and create zones for each channel type
for (unsigned int i = 0; i < rgb_fusion->GetLEDCount(); i++)
{
@@ -101,6 +99,7 @@ RGBController_RGBFusion::RGBController_RGBFusion(RGBFusionController* rgb_fusion
// Push new LED to LEDs vector
leds.push_back(*new_led);
colors.push_back(0x00000000);
// Push new zone to zones vector
zones.push_back(*new_zone);
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-395
View File
@@ -1,395 +0,0 @@
/*******************************************************
HIDAPI - Multi-Platform library for
communication with HID devices.
Alan Ott
Signal 11 Software
8/22/2009
Copyright 2009, All Rights Reserved.
At the discretion of the user of this library,
this software may be licensed under the terms of the
GNU General Public License v3, a BSD-Style license, or the
original HIDAPI license as outlined in the LICENSE.txt,
LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt
files located at the root of the source distribution.
These files may also be found in the public source
code repository located at:
http://github.com/signal11/hidapi .
********************************************************/
/** @file
* @defgroup API hidapi API
*/
#ifndef HIDAPI_H__
#define HIDAPI_H__
#include <wchar.h>
#ifdef _WIN32
#define HID_API_EXPORT __declspec(dllexport)
#define HID_API_CALL
#else
#define HID_API_EXPORT /**< API export macro */
#define HID_API_CALL /**< API call macro */
#endif
#define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL /**< API export and call macro*/
#ifdef __cplusplus
extern "C" {
#endif
struct hid_device_;
typedef struct hid_device_ hid_device; /**< opaque hidapi structure */
/** hidapi info structure */
struct hid_device_info {
/** Platform-specific device path */
char *path;
/** Device Vendor ID */
unsigned short vendor_id;
/** Device Product ID */
unsigned short product_id;
/** Serial Number */
wchar_t *serial_number;
/** Device Release Number in binary-coded decimal,
also known as Device Version Number */
unsigned short release_number;
/** Manufacturer String */
wchar_t *manufacturer_string;
/** Product string */
wchar_t *product_string;
/** Usage Page for this Device/Interface
(Windows/Mac only). */
unsigned short usage_page;
/** Usage for this Device/Interface
(Windows/Mac only).*/
unsigned short usage;
/** The USB interface which this logical device
represents.
* Valid on both Linux implementations in all cases.
* Valid on the Windows implementation only if the device
contains more than one interface.
* Valid on the Mac implementation if and only if the device
is a USB HID device. */
int interface_number;
/** Pointer to the next device */
struct hid_device_info *next;
};
/** @brief Initialize the HIDAPI library.
This function initializes the HIDAPI library. Calling it is not
strictly necessary, as it will be called automatically by
hid_enumerate() and any of the hid_open_*() functions if it is
needed. This function should be called at the beginning of
execution however, if there is a chance of HIDAPI handles
being opened by different threads simultaneously.
@ingroup API
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_init(void);
/** @brief Finalize the HIDAPI library.
This function frees all of the static data associated with
HIDAPI. It should be called at the end of execution to avoid
memory leaks.
@ingroup API
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_exit(void);
/** @brief Enumerate the HID Devices.
This function returns a linked list of all the HID devices
attached to the system which match vendor_id and product_id.
If @p vendor_id is set to 0 then any vendor matches.
If @p product_id is set to 0 then any product matches.
If @p vendor_id and @p product_id are both set to 0, then
all HID devices will be returned.
@ingroup API
@param vendor_id The Vendor ID (VID) of the types of device
to open.
@param product_id The Product ID (PID) of the types of
device to open.
@returns
This function returns a pointer to a linked list of type
struct #hid_device_info, containing information about the HID devices
attached to the system, or NULL in the case of failure. Free
this linked list by calling hid_free_enumeration().
*/
struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id);
/** @brief Free an enumeration Linked List
This function frees a linked list created by hid_enumerate().
@ingroup API
@param devs Pointer to a list of struct_device returned from
hid_enumerate().
*/
void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs);
/** @brief Open a HID device using a Vendor ID (VID), Product ID
(PID) and optionally a serial number.
If @p serial_number is NULL, the first device with the
specified VID and PID is opened.
@ingroup API
@param vendor_id The Vendor ID (VID) of the device to open.
@param product_id The Product ID (PID) of the device to open.
@param serial_number The Serial Number of the device to open
(Optionally NULL).
@returns
This function returns a pointer to a #hid_device object on
success or NULL on failure.
*/
HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number);
/** @brief Open a HID device by its path name.
The path name be determined by calling hid_enumerate(), or a
platform-specific path name can be used (eg: /dev/hidraw0 on
Linux).
@ingroup API
@param path The path name of the device to open
@returns
This function returns a pointer to a #hid_device object on
success or NULL on failure.
*/
HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path);
/** @brief Write an Output report to a HID device.
The first byte of @p data[] must contain the Report ID. For
devices which only support a single report, this must be set
to 0x0. The remaining bytes contain the report data. Since
the Report ID is mandatory, calls to hid_write() will always
contain one more byte than the report contains. For example,
if a hid report is 16 bytes long, 17 bytes must be passed to
hid_write(), the Report ID (or 0x0, for devices with a
single report), followed by the report data (16 bytes). In
this example, the length passed in would be 17.
hid_write() will send the data on the first OUT endpoint, if
one exists. If it does not, it will send the data through
the Control Endpoint (Endpoint 0).
@ingroup API
@param dev A device handle returned from hid_open().
@param data The data to send, including the report number as
the first byte.
@param length The length in bytes of the data to send.
@returns
This function returns the actual number of bytes written and
-1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *data, size_t length);
/** @brief Read an Input report from a HID device with timeout.
Input reports are returned
to the host through the INTERRUPT IN endpoint. The first byte will
contain the Report number if the device uses numbered reports.
@ingroup API
@param dev A device handle returned from hid_open().
@param data A buffer to put the read data into.
@param length The number of bytes to read. For devices with
multiple reports, make sure to read an extra byte for
the report number.
@param milliseconds timeout in milliseconds or -1 for blocking wait.
@returns
This function returns the actual number of bytes read and
-1 on error. If no packet was available to be read within
the timeout period, this function returns 0.
*/
int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds);
/** @brief Read an Input report from a HID device.
Input reports are returned
to the host through the INTERRUPT IN endpoint. The first byte will
contain the Report number if the device uses numbered reports.
@ingroup API
@param dev A device handle returned from hid_open().
@param data A buffer to put the read data into.
@param length The number of bytes to read. For devices with
multiple reports, make sure to read an extra byte for
the report number.
@returns
This function returns the actual number of bytes read and
-1 on error. If no packet was available to be read and
the handle is in non-blocking mode, this function returns 0.
*/
int HID_API_EXPORT HID_API_CALL hid_read(hid_device *dev, unsigned char *data, size_t length);
/** @brief Set the device handle to be non-blocking.
In non-blocking mode calls to hid_read() will return
immediately with a value of 0 if there is no data to be
read. In blocking mode, hid_read() will wait (block) until
there is data to read before returning.
Nonblocking can be turned on and off at any time.
@ingroup API
@param dev A device handle returned from hid_open().
@param nonblock enable or not the nonblocking reads
- 1 to enable nonblocking
- 0 to disable nonblocking.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *dev, int nonblock);
/** @brief Send a Feature report to the device.
Feature reports are sent over the Control endpoint as a
Set_Report transfer. The first byte of @p data[] must
contain the Report ID. For devices which only support a
single report, this must be set to 0x0. The remaining bytes
contain the report data. Since the Report ID is mandatory,
calls to hid_send_feature_report() will always contain one
more byte than the report contains. For example, if a hid
report is 16 bytes long, 17 bytes must be passed to
hid_send_feature_report(): the Report ID (or 0x0, for
devices which do not use numbered reports), followed by the
report data (16 bytes). In this example, the length passed
in would be 17.
@ingroup API
@param dev A device handle returned from hid_open().
@param data The data to send, including the report number as
the first byte.
@param length The length in bytes of the data to send, including
the report number.
@returns
This function returns the actual number of bytes written and
-1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *dev, const unsigned char *data, size_t length);
/** @brief Get a feature report from a HID device.
Set the first byte of @p data[] to the Report ID of the
report to be read. Make sure to allow space for this
extra byte in @p data[]. Upon return, the first byte will
still contain the Report ID, and the report data will
start in data[1].
@ingroup API
@param dev A device handle returned from hid_open().
@param data A buffer to put the read data into, including
the Report ID. Set the first byte of @p data[] to the
Report ID of the report to be read, or set it to zero
if your device does not use numbered reports.
@param length The number of bytes to read, including an
extra byte for the report ID. The buffer can be longer
than the actual report.
@returns
This function returns the number of bytes read plus
one for the report ID (which is still in the first
byte), or -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *dev, unsigned char *data, size_t length);
/** @brief Close a HID device.
@ingroup API
@param dev A device handle returned from hid_open().
*/
void HID_API_EXPORT HID_API_CALL hid_close(hid_device *dev);
/** @brief Get The Manufacturer String from a HID device.
@ingroup API
@param dev A device handle returned from hid_open().
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *dev, wchar_t *string, size_t maxlen);
/** @brief Get The Product String from a HID device.
@ingroup API
@param dev A device handle returned from hid_open().
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_product_string(hid_device *dev, wchar_t *string, size_t maxlen);
/** @brief Get The Serial Number String from a HID device.
@ingroup API
@param dev A device handle returned from hid_open().
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *string, size_t maxlen);
/** @brief Get a string from a HID device, based on its string index.
@ingroup API
@param dev A device handle returned from hid_open().
@param string_index The index of the string to get.
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index, wchar_t *string, size_t maxlen);
/** @brief Get a string describing the last error which occurred.
@ingroup API
@param dev A device handle returned from hid_open().
@returns
This function returns a string containing the last error
which occurred or NULL if none has occurred.
*/
HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *dev);
#ifdef __cplusplus
}
#endif
#endif
+26
View File
@@ -9,6 +9,17 @@
#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
s32 i2c_smbus_interface::i2c_smbus_write_quick(u8 addr, u8 value)
{
return i2c_smbus_xfer(addr, value, 0, I2C_SMBUS_QUICK, NULL);
@@ -128,3 +139,18 @@ s32 i2c_smbus_interface::i2c_smbus_write_i2c_block_data(u8 addr, u8 command, u8
memcpy(&data.block[1], values, length);
return i2c_smbus_xfer(addr, I2C_SMBUS_WRITE, command, I2C_SMBUS_I2C_BLOCK_DATA, &data);
}
void i2c_smbus_interface::i2c_smbus_wait_and_lock()
{
while(lock == true)
{
Sleep(1);
}
lock = true;
}
void i2c_smbus_interface::i2c_smbus_unlock()
{
lock = false;
}
+6
View File
@@ -69,8 +69,14 @@ 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);
void i2c_smbus_wait_and_lock();
void i2c_smbus_unlock();
//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:
bool lock = false;
};
#endif /* I2C_SMBUS_H */
-6
View File
@@ -64,7 +64,6 @@ OpenRGBDevicePage::OpenRGBDevicePage(RGBController *dev, QWidget *parent) :
/*-----------------------------------------------------*\
| Fill in the combo boxes with device information |
\*-----------------------------------------------------*/
ui->ModeBox->blockSignals(true);
ui->ModeBox->clear();
for (std::size_t i = 0; i < device->modes.size(); i++)
@@ -73,9 +72,7 @@ OpenRGBDevicePage::OpenRGBDevicePage(RGBController *dev, QWidget *parent) :
}
ui->ModeBox->setCurrentIndex(device->GetMode());
ui->ModeBox->blockSignals(false);
ui->ZoneBox->blockSignals(true);
ui->ZoneBox->clear();
for (std::size_t i = 0; i < device->zones.size(); i++)
@@ -84,9 +81,7 @@ OpenRGBDevicePage::OpenRGBDevicePage(RGBController *dev, QWidget *parent) :
}
ui->ZoneBox->setCurrentIndex(0);
ui->ZoneBox->blockSignals(false);
ui->LEDBox->blockSignals(true);
ui->LEDBox->clear();
for (std::size_t i = 0; i < device->leds.size(); i++)
@@ -95,7 +90,6 @@ OpenRGBDevicePage::OpenRGBDevicePage(RGBController *dev, QWidget *parent) :
}
ui->LEDBox->setCurrentIndex(0);
ui->LEDBox->blockSignals(false);
/*-----------------------------------------------------*\
| Update color picker with color of first LED |