Reorganization! Move all controllers into their own folders, move all RGBController wrappers into one folder, move i2c_smbus and serial_port dependencies into folders, and move main application/UI stuff into folders. Should help lead into creating a proper library

This commit is contained in:
Adam Honse 2019-08-22 18:43:17 -05:00
parent ef79de6c7c
commit 155ad165b1
61 changed files with 51 additions and 40 deletions

View file

@ -0,0 +1,248 @@
/*-----------------------------------------*\
| AuraController.h |
| |
| Driver for ASUS Aura RGB lighting |
| controller |
| |
| Adam Honse (CalcProgrammer1) 8/19/2018 |
\*-----------------------------------------*/
#include "AuraController.h"
#include <cstring>
AuraController::AuraController(i2c_smbus_interface* bus, aura_dev_id dev)
{
this->bus = bus;
this->dev = dev;
AuraUpdateDeviceName();
// Read the device configuration table
for (int i = 0; i < 64; i++)
{
config_table[i] = AuraRegisterRead(AURA_REG_CONFIG_TABLE + i);
}
// Read LED count from configuration table
led_count = config_table[AURA_CONFIG_LED_COUNT];
// LED-0116 - First generation motherboard controller
if (strcmp(device_name, "LED-0116") == 0)
{
direct_reg = AURA_REG_COLORS_DIRECT;
effect_reg = AURA_REG_COLORS_EFFECT;
channel_cfg = AURA_CONFIG_CHANNEL_V1;
}
// DIMM_LED-0102 - First generation DRAM controller (Trident Z RGB)
else if (strcmp(device_name, "DIMM_LED-0102") == 0)
{
direct_reg = AURA_REG_COLORS_DIRECT;
effect_reg = AURA_REG_COLORS_EFFECT;
channel_cfg = AURA_CONFIG_CHANNEL_V1;
}
// AUDA0-E6K5-0101 - Second generation DRAM controller (Geil Super Luce)
else if (strcmp(device_name, "AUDA0-E6K5-0101") == 0)
{
direct_reg = AURA_REG_COLORS_DIRECT_V2;
effect_reg = AURA_REG_COLORS_EFFECT_V2;
channel_cfg = AURA_CONFIG_CHANNEL_V2;
}
// AUMA0-E6K5-0106 - Second generation motherboard controller
else if (strcmp(device_name, "AUMA0-E6K5-0106") == 0)
{
direct_reg = AURA_REG_COLORS_DIRECT_V2;
effect_reg = AURA_REG_COLORS_EFFECT_V2;
channel_cfg = AURA_CONFIG_CHANNEL_V2;
}
// AUMA0-E6K5-0105 - Second generation motherboard controller
else if (strcmp(device_name, "AUMA0-E6K5-0105") == 0)
{
direct_reg = AURA_REG_COLORS_DIRECT_V2;
effect_reg = AURA_REG_COLORS_EFFECT_V2;
channel_cfg = AURA_CONFIG_CHANNEL_V2;
}
// AUMA0-E6K5-0104 - Second generation motherboard controller
else if (strcmp(device_name, "AUMA0-E6K5-0104") == 0)
{
direct_reg = AURA_REG_COLORS_DIRECT_V2;
effect_reg = AURA_REG_COLORS_EFFECT_V2;
channel_cfg = AURA_CONFIG_CHANNEL_V2;
}
// Assume first generation controller if string does not match
else
{
direct_reg = AURA_REG_COLORS_DIRECT;
effect_reg = AURA_REG_COLORS_EFFECT;
channel_cfg = AURA_CONFIG_CHANNEL_V1;
}
}
AuraController::~AuraController()
{
}
char * AuraController::GetDeviceName()
{
return(device_name);
}
unsigned char AuraController::GetChannel(unsigned int led)
{
return(config_table[channel_cfg + led]);
}
const char * AuraController::GetChannelName(unsigned int led)
{
switch (config_table[channel_cfg + led])
{
case (unsigned char)AURA_LED_CHANNEL_AUDIO:
return(aura_channels[0]);
break;
case (unsigned char)AURA_LED_CHANNEL_BACKPLATE:
return(aura_channels[1]);
break;
case (unsigned char)AURA_LED_CHANNEL_BACK_IO:
return(aura_channels[2]);
break;
case (unsigned char)AURA_LED_CHANNEL_CENTER:
return(aura_channels[3]);
break;
case (unsigned char)AURA_LED_CHANNEL_CENTER_START:
return(aura_channels[4]);
break;
case (unsigned char)AURA_LED_CHANNEL_DRAM:
return(aura_channels[5]);
break;
case (unsigned char)AURA_LED_CHANNEL_PCIE:
return(aura_channels[6]);
break;
case (unsigned char)AURA_LED_CHANNEL_RGB_HEADER:
return(aura_channels[7]);
break;
case (unsigned char)AURA_LED_CHANNEL_RGB_HEADER_2:
return(aura_channels[8]);
break;
case (unsigned char)AURA_LED_CHANNEL_RGB_HEADER_3:
return(aura_channels[9]);
break;
default:
return(aura_channels[10]);
break;
}
}
unsigned int AuraController::GetLEDCount()
{
return(led_count);
}
void AuraController::SetAllColorsDirect(unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char* colors = new unsigned char[led_count * 3];
for (int i = 0; i < (led_count * 3); i += 3)
{
colors[i + 0] = red;
colors[i + 1] = blue;
colors[i + 2] = green;
}
AuraRegisterWriteBlock(direct_reg, colors, led_count * 3);
delete colors;
}
void AuraController::SetAllColorsEffect(unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char* colors = new unsigned char[led_count * 3];
for (int i = 0; i < (led_count * 3); i += 3)
{
colors[i + 0] = red;
colors[i + 1] = blue;
colors[i + 2] = green;
}
AuraRegisterWriteBlock(effect_reg, colors, led_count * 3);
AuraRegisterWrite(AURA_REG_APPLY, AURA_APPLY_VAL);
delete colors;
}
void AuraController::SetDirect(unsigned char direct)
{
AuraRegisterWrite(AURA_REG_DIRECT, direct);
AuraRegisterWrite(AURA_REG_APPLY, AURA_APPLY_VAL);
}
void AuraController::SetLEDColorDirect(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char colors[3] = { red, blue, green };
AuraRegisterWriteBlock(direct_reg + ( 3 * led ), colors, 3);
}
void AuraController::SetLEDColorEffect(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char colors[3] = { red, blue, green };
AuraRegisterWriteBlock(effect_reg + (3 * led), colors, 3);
AuraRegisterWrite(AURA_REG_APPLY, AURA_APPLY_VAL);
}
void AuraController::SetMode(unsigned char mode)
{
AuraRegisterWrite(AURA_REG_MODE, mode);
AuraRegisterWrite(AURA_REG_APPLY, AURA_APPLY_VAL);
}
void AuraController::AuraUpdateDeviceName()
{
for (int i = 0; i < 16; i++)
{
device_name[i] = AuraRegisterRead(AURA_REG_DEVICE_NAME + i);
}
}
unsigned char AuraController::AuraRegisterRead(aura_register reg)
{
//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));
}
void AuraController::AuraRegisterWrite(aura_register reg, unsigned char val)
{
//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);
}
void AuraController::AuraRegisterWriteBlock(aura_register reg, unsigned char * data, unsigned char sz)
{
//Write Aura register
bus->i2c_smbus_write_word_data(dev, 0x00, ((reg << 8) & 0xFF00) | ((reg >> 8) & 0x00FF));
//Write Aura block data
bus->i2c_smbus_write_block_data(dev, 0x03, sz, data);
}

View file

@ -0,0 +1,123 @@
/*-----------------------------------------*\
| AuraController.h |
| |
| Definitions and types for ASUS Aura RGB |
| lighting controller |
| |
| Adam Honse (CalcProgrammer1) 8/19/2018 |
\*-----------------------------------------*/
#include "i2c_smbus.h"
#pragma once
typedef unsigned char aura_dev_id;
typedef unsigned short aura_register;
#define AURA_APPLY_VAL 0x01 /* Value for Apply Changes Register */
enum
{
AURA_REG_DEVICE_NAME = 0x1000, /* Device String 16 bytes */
AURA_REG_CONFIG_TABLE = 0x1C00, /* Start of LED configuration bytes */
AURA_REG_COLORS_DIRECT = 0x8000, /* Colors for Direct Mode 15 bytes */
AURA_REG_COLORS_EFFECT = 0x8010, /* Colors for Internal Effects 15 bytes */
AURA_REG_DIRECT = 0x8020, /* "Direct Access" Selection Register */
AURA_REG_MODE = 0x8021, /* AURA Mode Selection Register */
AURA_REG_APPLY = 0x80A0, /* AURA Apply Changes Register */
AURA_REG_SLOT_INDEX = 0x80F8, /* AURA Slot Index Register (RAM only) */
AURA_REG_I2C_ADDRESS = 0x80F9, /* AURA I2C Address Register (RAM only) */
AURA_REG_COLORS_DIRECT_V2 = 0x8100, /* Direct Colors (v2) 30 bytes */
AURA_REG_COLORS_EFFECT_V2 = 0x8160, /* Internal Colors (v2) 30 bytes */
};
enum
{
AURA_MODE_OFF = 0, /* OFF mode */
AURA_MODE_STATIC = 1, /* Static color mode */
AURA_MODE_BREATHING = 2, /* Breathing effect mode */
AURA_MODE_FLASHING = 3, /* Flashing effect mode */
AURA_MODE_SPECTRUM_CYCLE = 4, /* Spectrum Cycle mode */
AURA_MODE_RAINBOW = 5, /* Rainbow effect mode */
AURA_MODE_SPECTRUM_CYCLE_BREATHING = 6, /* Rainbow Breathing effect mode */
AURA_MODE_CHASE_FADE = 7, /* Chase with Fade effect mode */
AURA_MODE_SPECTRUM_CYCLE_CHASE_FADE = 8, /* Chase with Fade, Rainbow effect mode */
AURA_MODE_CHASE = 9, /* Chase effect mode */
AURA_MODE_SPECTRUM_CYCLE_CHASE = 10, /* Chase with Rainbow effect mode */
AURA_MODE_SPECTRUM_CYCLE_WAVE = 11, /* Wave effect mode */
AURA_MODE_CHASE_RAINBOW_PULSE = 12, /* Chase with Rainbow Pulse effect mode*/
AURA_MODE_RANDOM_FLICKER = 13, /* Random flicker effect mode */
AURA_NUMBER_MODES /* Number of Aura modes */
};
enum
{
AURA_LED_CHANNEL_DRAM_2 = 0x05, /* DRAM LED channel */
AURA_LED_CHANNEL_CENTER_START = 0x82, /* Center zone first LED channel */
AURA_LED_CHANNEL_CENTER = 0x83, /* Center zone LED channel */
AURA_LED_CHANNEL_AUDIO = 0x84, /* Audio zone LED channel */
AURA_LED_CHANNEL_BACK_IO = 0x85, /* Back I/O zone LED channel */
AURA_LED_CHANNEL_RGB_HEADER = 0x86, /* RGB Header LED channel */
AURA_LED_CHANNEL_RGB_HEADER_2 = 0x87, /* RGB Header 2 LED channel */
AURA_LED_CHANNEL_BACKPLATE = 0x88, /* Backplate zone LED channel */
AURA_LED_CHANNEL_DRAM = 0x8A, /* DRAM LED channel */
AURA_LED_CHANNEL_PCIE = 0x8B, /* PCIe zone LED channel */
AURA_LED_CHANNEL_RGB_HEADER_3 = 0x91, /* RGB Header 3 LED channel */
};
static const char* aura_channels[] = /* Aura channel strings */
{
"Audio",
"Backplate",
"Back I/O",
"Center",
"Center",
"DRAM",
"PCIe",
"RGB Header",
"RGB Header 2",
"RGB Header",
"Unknown",
};
enum
{
AURA_CONFIG_LED_COUNT = 0x02, /* LED Count configuration offset */
AURA_CONFIG_CHANNEL_V1 = 0x13, /* LED Channel configuration offset */
AURA_CONFIG_CHANNEL_V2 = 0x1B, /* LED Channel V2 configuration offset */
};
class AuraController
{
public:
AuraController(i2c_smbus_interface* bus, aura_dev_id dev);
~AuraController();
char* GetDeviceName();
unsigned char GetChannel(unsigned int led);
const char* GetChannelName(unsigned int led);
unsigned int GetLEDCount();
void SetAllColorsDirect(unsigned char red, unsigned char green, unsigned char blue);
void SetAllColorsEffect(unsigned char red, unsigned char green, unsigned char blue);
void SetDirect(unsigned char direct);
void SetLEDColorDirect(unsigned int led, unsigned char red, unsigned char green, unsigned char blue);
void SetLEDColorEffect(unsigned int led, unsigned char red, unsigned char green, unsigned char blue);
void SetMode(unsigned char mode);
void AuraUpdateDeviceName();
unsigned char AuraRegisterRead(aura_register reg);
void AuraRegisterWrite(aura_register reg, unsigned char val);
void AuraRegisterWriteBlock(aura_register reg, unsigned char * data, unsigned char sz);
private:
char device_name[16];
unsigned char config_table[64];
unsigned int led_count;
aura_register direct_reg;
aura_register effect_reg;
unsigned char channel_cfg;
i2c_smbus_interface * bus;
aura_dev_id dev;
};

View file

@ -0,0 +1,125 @@
#include "AuraController.h"
#include "RGBController.h"
#include "RGBController_Aura.h"
#include "i2c_smbus.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
/******************************************************************************************\
* *
* TestForAuraController *
* *
* Tests the given address to see if an Aura controller exists there. First does a *
* quick write to test for a response, and if so does a simple read at 0xA0 to test *
* for incrementing values 0...F which was observed at this location during data dump *
* *
\******************************************************************************************/
bool TestForAuraController(i2c_smbus_interface* bus, unsigned char address)
{
bool pass = false;
int res = bus->i2c_smbus_write_quick(address, I2C_SMBUS_WRITE);
if (res >= 0)
{
pass = true;
for (int i = 0xA0; i < 0xB0; i++)
{
res = bus->i2c_smbus_read_byte_data(address, i);
if (res != (i - 0xA0))
{
pass = false;
}
}
}
return(pass);
} /* TestForAuraController() */
/******************************************************************************************\
* *
* DetectAuraControllers *
* *
* Detect Aura controllers on the enumerated I2C busses. Searches for Aura-enabled *
* RAM at 0x77 and tries to initialize their slot addresses, then searches for them *
* at their correct initialized addresses. Also looks for motherboard controller at *
* address 0x4E. *
* *
* bus - pointer to i2c_smbus_interface where Aura device is connected *
* dev - I2C address of Aura device *
* *
\******************************************************************************************/
void DetectAuraControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers)
{
AuraController* new_aura;
RGBController_Aura* new_controller;
for (unsigned int bus = 0; bus < busses.size(); bus++)
{
// Remap Aura-enabled RAM modules on 0x77
for (unsigned int slot = 0; slot < 8; slot++)
{
int res = busses[bus]->i2c_smbus_write_quick(0x77, I2C_SMBUS_WRITE);
if (res < 0)
{
break;
}
AuraController temp_controller(busses[bus], 0x77);
temp_controller.AuraRegisterWrite(AURA_REG_SLOT_INDEX, slot);
temp_controller.AuraRegisterWrite(AURA_REG_I2C_ADDRESS, 0xE0 + (slot << 1));
}
// Add Aura-enabled controllers at their remapped addresses
for (unsigned int slot = 0; slot < 8; slot++)
{
if (TestForAuraController(busses[bus], 0x70 + slot))
{
new_aura = new AuraController(busses[bus], 0x70 + slot);
new_controller = new RGBController_Aura(new_aura);
rgb_controllers.push_back(new_controller);
}
}
// Check for Aura controller at 0x40
if (TestForAuraController(busses[bus], 0x40))
{
new_aura = new AuraController(busses[bus], 0x40);
new_controller = new RGBController_Aura(new_aura);
rgb_controllers.push_back(new_controller);
}
// Check for Aura controller at 0x4E
if (TestForAuraController(busses[bus], 0x4E))
{
new_aura = new AuraController(busses[bus], 0x4E);
new_controller = new RGBController_Aura(new_aura);
rgb_controllers.push_back(new_controller);
}
// Check for Aura controller at 0x4F
if (TestForAuraController(busses[bus], 0x4F))
{
new_aura = new AuraController(busses[bus], 0x4F);
new_controller = new RGBController_Aura(new_aura);
rgb_controllers.push_back(new_controller);
}
// Check for Aura controller at 0x66
if (TestForAuraController(busses[bus], 0x66))
{
new_aura = new AuraController(busses[bus], 0x66);
new_controller = new RGBController_Aura(new_aura);
rgb_controllers.push_back(new_controller);
}
}
} /* DetectAuraControllers() */

View file

@ -0,0 +1,58 @@
/*-----------------------------------------*\
| CorsairController.h |
| |
| Driver for Corsair Vengeance RGB RAM |
| lighting controller |
| |
| Adam Honse (CalcProgrammer1) 3/8/2019 |
\*-----------------------------------------*/
#include "CorsairController.h"
#include <cstring>
CorsairController::CorsairController(i2c_smbus_interface* bus, corsair_dev_id dev)
{
this->bus = bus;
this->dev = dev;
strcpy(device_name, "Corsair Vengeance RGB");
led_count = 1;
}
CorsairController::~CorsairController()
{
}
char * CorsairController::GetDeviceName()
{
return(device_name);
}
unsigned int CorsairController::GetLEDCount()
{
return(led_count);
}
void CorsairController::SetAllColors(unsigned char red, unsigned char green, unsigned char blue)
{
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_FADE_TIME, 0x00);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_RED_VAL, red);
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);
}
void CorsairController::SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_FADE_TIME, 0x00);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_RED_VAL, red);
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);
}
void CorsairController::SetMode(unsigned char mode)
{
bus->i2c_smbus_write_byte_data(dev, CORSAIR_VENGEANCE_RGB_CMD_MODE, CORSAIR_VENGEANCE_RGB_MODE_SINGLE);
}

View file

@ -0,0 +1,53 @@
/*-----------------------------------------*\
| CorsairController.h |
| |
| Definitions and types for Corsair |
| Vengeance RGB RAM lighting controller |
| |
| Adam Honse (CalcProgrammer1) 3/8/2019 |
\*-----------------------------------------*/
#include "i2c_smbus.h"
#pragma once
typedef unsigned char corsair_dev_id;
typedef unsigned char corsair_cmd;
enum
{
CORSAIR_VENGEANCE_RGB_CMD_FADE_TIME = 0xA4, /* Fade Time, 0 for Static */
CORSAIR_VENGEANCE_RGB_CMD_HOLD_TIME = 0xA5, /* Hold Time */
CORSAIR_VENGEANCE_RGB_CMD_MODE = 0xA6, /* Mode Control Value */
CORSAIR_VENGEANCE_RGB_CMD_RED_VAL = 0xB0, /* Red Color Value */
CORSAIR_VENGEANCE_RGB_CMD_GREEN_VAL = 0xB1, /* Green Color Value */
CORSAIR_VENGEANCE_RGB_CMD_BLUE_VAL = 0xB2, /* Blue Color Value */
};
enum
{
CORSAIR_VENGEANCE_RGB_MODE_SINGLE = 0x00, /* Single Color Effect Mode */
CORSAIR_VENGEANCE_RGB_MODE_FADE = 0x01, /* Fade Through Colors */
CORSAIR_VENGEANCE_RGB_MODE_PULSE = 0x02, /* Pulse Through Colors */
CORSAIR_NUMBER_MODES /* Number of Corsair modes */
};
class CorsairController
{
public:
CorsairController(i2c_smbus_interface* bus, corsair_dev_id dev);
~CorsairController();
char* GetDeviceName();
unsigned int GetLEDCount();
void SetMode(unsigned char mode);
void SetAllColors(unsigned char red, unsigned char green, unsigned char blue);
void SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue);
private:
char device_name[32];
unsigned int led_count;
i2c_smbus_interface * bus;
corsair_dev_id dev;
};

View file

@ -0,0 +1,109 @@
#include "CorsairController.h"
#include "RGBController.h"
#include "RGBController_Corsair.h"
#include "i2c_smbus.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
/******************************************************************************************\
* *
* TestForCorsairController *
* *
* Tests the given address to see if a Corsair controller exists there. *
* *
\******************************************************************************************/
bool TestForCorsairController(i2c_smbus_interface* bus, unsigned char address)
{
bool pass = false;
int res = bus->i2c_smbus_write_quick(address, I2C_SMBUS_WRITE);
if (res >= 0)
{
pass = true;
for (int i = 0xA0; i < 0xB0; i++)
{
res = bus->i2c_smbus_read_byte_data(address, i);
if (res != 0xBA)
{
pass = false;
}
}
}
return(pass);
} /* TestForCorsairController() */
/******************************************************************************************\
* *
* DetectCorsairControllers *
* *
* Detect Corsair controllers on the enumerated I2C busses. *
* *
* bus - pointer to i2c_smbus_interface where Aura device is connected *
* dev - I2C address of Aura device *
* *
\******************************************************************************************/
void DetectCorsairControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers)
{
CorsairController* new_corsair;
RGBController_Corsair* new_controller;
for (unsigned int bus = 0; bus < busses.size(); bus++)
{
// Check for Corsair controller at 0x58
if (TestForCorsairController(busses[bus], 0x58))
{
new_corsair = new CorsairController(busses[bus], 0x58);
new_controller = new RGBController_Corsair(new_corsair);
rgb_controllers.push_back(new_controller);
}
// Check for Corsair controller at 0x59
if (TestForCorsairController(busses[bus], 0x59))
{
new_corsair = new CorsairController(busses[bus], 0x59);
new_controller = new RGBController_Corsair(new_corsair);
rgb_controllers.push_back(new_controller);
}
// Check for Corsair controller at 0x5A
if (TestForCorsairController(busses[bus], 0x5A))
{
new_corsair = new CorsairController(busses[bus], 0x5A);
new_controller = new RGBController_Corsair(new_corsair);
rgb_controllers.push_back(new_controller);
}
// Check for Corsair controller at 0x5B
if (TestForCorsairController(busses[bus], 0x5B))
{
new_corsair = new CorsairController(busses[bus], 0x5B);
new_controller = new RGBController_Corsair(new_corsair);
rgb_controllers.push_back(new_controller);
}
// Check for Corsair controller at 0x5C
if (TestForCorsairController(busses[bus], 0x5C))
{
new_corsair = new CorsairController(busses[bus], 0x5C);
new_controller = new RGBController_Corsair(new_corsair);
rgb_controllers.push_back(new_controller);
}
// Check for Corsair controller at 0x5D
if (TestForCorsairController(busses[bus], 0x5D))
{
new_corsair = new CorsairController(busses[bus], 0x5D);
new_controller = new RGBController_Corsair(new_corsair);
rgb_controllers.push_back(new_controller);
}
}
} /* DetectCorsairControllers() */

View file

@ -0,0 +1,137 @@
/*-----------------------------------------*\
| CorsairProController.cpp |
| |
| Definitions and types for Corsair |
| Vengeance Pro RGB RAM lighting controller|
| |
| Adam Honse (CalcProgrammer1) 6/30/2019 |
\*-----------------------------------------*/
#include "CorsairProController.h"
#include <cstring>
#ifdef WIN32
#include <Windows.h>
#else
#include <unistd.h>
void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
CorsairProController::CorsairProController(i2c_smbus_interface* bus, corsair_dev_id dev)
{
this->bus = bus;
this->dev = dev;
strcpy(device_name, "Corsair Vengeance Pro RGB");
led_count = CORSAIR_PRO_LED_COUNT;
for (int i = 0; i < led_count; i++)
{
led_red[i] = 0;
led_green[i] = 0;
led_blue[i] = 0;
}
}
CorsairProController::~CorsairProController()
{
}
char* CorsairProController::GetDeviceName()
{
return(device_name);
}
unsigned int CorsairProController::GetLEDCount()
{
return(led_count);
}
void CorsairProController::SetAllColors(unsigned char red, unsigned char green, unsigned char blue)
{
for (int i = 0; i < led_count; i++)
{
led_red[i] = red;
led_green[i] = green;
led_blue[i] = blue;
}
}
void CorsairProController::SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
led_red[led] = red;
led_green[led] = green;
led_blue[led] = blue;
}
void CorsairProController::ApplyColors()
{
bus->i2c_smbus_write_byte_data(dev, 0x26, 0x02);
Sleep(1);
bus->i2c_smbus_write_byte_data(dev, 0x21, 0x00);
Sleep(1);
for (int i = 0; i < 10; i++)
{
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, led_red[i]);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, led_green[i]);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, led_blue[i]);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0xFF);
}
bus->i2c_smbus_write_byte_data(dev, 0x82, 0x02);
}
void CorsairProController::SetEffect(unsigned char mode)
{
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, 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
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00); // Custom color 1 red
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00); // Custom color 1 green
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00); // Custom color 1 blue
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0xFF);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00); // Custom color 2 red
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00); // Custom color 2 green
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00); // Custom color 2 blue
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0xFF);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00);
bus->i2c_smbus_write_byte_data(dev, 0x82, 0x01);
WaitReady();
}
void CorsairProController::SetCustom()
{
SetEffect(CORSAIR_PRO_MODE_STATIC);
}
bool CorsairProController::WaitReady()
{
int i = 0;
while (bus->i2c_smbus_read_byte_data(dev, 0x41) != 0x00)
{
i++;
Sleep(1);
}
return false;
}

View file

@ -0,0 +1,88 @@
/*-----------------------------------------*\
| CorsairProController.h |
| |
| Definitions and types for Corsair |
| Vengeance Pro RGB RAM lighting controller|
| |
| Adam Honse (CalcProgrammer1) 6/30/2019 |
\*-----------------------------------------*/
#include "i2c_smbus.h"
#pragma once
typedef unsigned char corsair_dev_id;
#define CORSAIR_PRO_LED_COUNT ( 10 )
enum
{
CORSAIR_PRO_REG_COMMAND = 0x20, /* Command write register */
};
enum
{
CORSAIR_PRO_MODE_COLOR_SHIFT = 0x00, /* Color Shift mode */
CORSAIR_PRO_MODE_COLOR_PULSE = 0x01, /* Color Pulse mode */
CORSAIR_PRO_MODE_RAINBOW_WAVE = 0x03, /* Rainbow Wave mode */
CORSAIR_PRO_MODE_COLOR_WAVE = 0x04, /* Color Wave mode */
CORSAIR_PRO_MODE_VISOR = 0x05, /* Visor mode */
CORSAIR_PRO_MODE_RAIN = 0x06, /* Rain mode */
CORSAIR_PRO_MODE_MARQUEE = 0x07, /* Marquee mode */
CORSAIR_PRO_MODE_RAINBOW = 0x08, /* Rainbow mode */
CORSAIR_PRO_MODE_SEQUENTIAL = 0x09, /* Sequential mode */
CORSAIR_PRO_MODE_STATIC = 0x10, /* Static mode */
CORSAIR_PRO_NUMBER_MODES = 10, /* Number of Corsair Pro modes */
};
enum
{
CORSAIR_PRO_SPEED_SLOW = 0x00, /* Slow speed */
CORSAIR_PRO_SPEED_MEDIUM = 0x01, /* Medium speed */
CORSAIR_PRO_SPEED_FAST = 0x02, /* Fast speed */
};
enum
{
CORSAIR_PRO_EFFECT_RANDOM_COLORS = 0x00, /* Random colors */
CORSAIR_PRO_EFFECT_CUSTOM_COLORS = 0x01, /* Custom colors */
};
enum
{
CORSAIR_PRO_DIRECTION_UP = 0x00, /* Up direction */
CORSAIR_PRO_DIRECTION_DOWN = 0x01, /* Down direction */
CORSAIR_PRO_DIRECTION_LEFT = 0x02, /* Left direction */
CORSAIR_PRO_DIRECTION_RIGHT = 0x03, /* Right direction */
CORSAIR_PRO_DIRECTION_VERTICAL = 0x01, /* Vertical direction */
CORSAIR_PRO_DIRECTION_HORIZONTAL = 0x03, /* Horizontal direction */
};
class CorsairProController
{
public:
CorsairProController(i2c_smbus_interface* bus, corsair_dev_id dev);
~CorsairProController();
char* GetDeviceName();
unsigned int GetLEDCount();
void SetEffect(unsigned char mode);
void SetCustom();
void SetAllColors(unsigned char red, unsigned char green, unsigned char blue);
void SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue);
void ApplyColors();
bool WaitReady();
private:
char device_name[32];
unsigned int led_count;
unsigned char led_red[CORSAIR_PRO_LED_COUNT];
unsigned char led_green[CORSAIR_PRO_LED_COUNT];
unsigned char led_blue[CORSAIR_PRO_LED_COUNT];
i2c_smbus_interface* bus;
corsair_dev_id dev;
};

View file

@ -0,0 +1,127 @@
#include "CorsairProController.h"
#include "RGBController.h"
#include "RGBController_CorsairPro.h"
#include "i2c_smbus.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
/******************************************************************************************\
* *
* TestForCorsairProController *
* *
* Tests the given address to see if a Corsair Pro controller exists there. *
* *
\******************************************************************************************/
bool TestForCorsairProController(i2c_smbus_interface* bus, unsigned char address)
{
bool pass = false;
int res = bus->i2c_smbus_write_quick(address, I2C_SMBUS_WRITE);
if (res >= 0)
{
pass = true;
res = bus->i2c_smbus_read_byte_data(address, 0x24);
if (res != 0x02)
{
pass = false;
}
res = bus->i2c_smbus_read_byte_data(address, 0x25);
if (res != 0x02)
{
pass = false;
}
res = bus->i2c_smbus_read_byte_data(address, 0x43);
if (res != 0x1C)
{
pass = false;
}
res = bus->i2c_smbus_read_byte_data(address, 0x44);
if (res != 0x03)
{
pass = false;
}
}
return(pass);
} /* TestForCorsairProController() */
/******************************************************************************************\
* *
* DetectCorsairProControllers *
* *
* Detect Corsair Pro controllers on the enumerated I2C busses. *
* *
* bus - pointer to i2c_smbus_interface where Aura device is connected *
* dev - I2C address of Aura device *
* *
\******************************************************************************************/
void DetectCorsairProControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers)
{
CorsairProController* new_corsair_pro;
RGBController_CorsairPro* new_controller;
for (unsigned int bus = 0; bus < busses.size(); bus++)
{
// Check for Corsair controller at 0x58
if (TestForCorsairProController(busses[bus], 0x58))
{
new_corsair_pro = new CorsairProController(busses[bus], 0x58);
new_controller = new RGBController_CorsairPro(new_corsair_pro);
rgb_controllers.push_back(new_controller);
}
// Check for Corsair controller at 0x59
if (TestForCorsairProController(busses[bus], 0x59))
{
new_corsair_pro = new CorsairProController(busses[bus], 0x59);
new_controller = new RGBController_CorsairPro(new_corsair_pro);
rgb_controllers.push_back(new_controller);
}
// Check for Corsair controller at 0x5A
if (TestForCorsairProController(busses[bus], 0x5A))
{
new_corsair_pro = new CorsairProController(busses[bus], 0x5A);
new_controller = new RGBController_CorsairPro(new_corsair_pro);
rgb_controllers.push_back(new_controller);
}
// Check for Corsair controller at 0x5B
if (TestForCorsairProController(busses[bus], 0x5B))
{
new_corsair_pro = new CorsairProController(busses[bus], 0x5B);
new_controller = new RGBController_CorsairPro(new_corsair_pro);
rgb_controllers.push_back(new_controller);
}
// Check for Corsair controller at 0x5C
if (TestForCorsairProController(busses[bus], 0x5C))
{
new_corsair_pro = new CorsairProController(busses[bus], 0x5C);
new_controller = new RGBController_CorsairPro(new_corsair_pro);
rgb_controllers.push_back(new_controller);
}
// Check for Corsair controller at 0x5D
if (TestForCorsairProController(busses[bus], 0x5D))
{
new_corsair_pro = new CorsairProController(busses[bus], 0x5D);
new_controller = new RGBController_CorsairPro(new_corsair_pro);
rgb_controllers.push_back(new_controller);
}
}
} /* DetectCorsairProControllers() */

View file

@ -0,0 +1,102 @@
/*-----------------------------------------*\
| HyperXController.cpp |
| |
| Definitions and types for HyperX Predator|
| RGB RAM lighting controller |
| |
| Adam Honse (CalcProgrammer1) 6/29/2019 |
\*-----------------------------------------*/
#include "HyperXController.h"
#include <cstring>
HyperXController::HyperXController(i2c_smbus_interface* bus, hyperx_dev_id dev)
{
this->bus = bus;
this->dev = dev;
strcpy(device_name, "HyperX Predator RGB");
led_count = 1;
}
HyperXController::~HyperXController()
{
}
char* HyperXController::GetDeviceName()
{
return(device_name);
}
unsigned int HyperXController::GetLEDCount()
{
return(led_count);
}
void HyperXController::SetAllColors(unsigned char red, unsigned char green, unsigned char blue)
{
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_RED, red);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_GREEN, green);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_BLUE, blue);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x02);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x03);
}
void HyperXController::SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_RED, red);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_GREEN, green);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_BLUE, blue);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x02);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x03);
}
void HyperXController::SetMode(unsigned char mode)
{
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01);
switch (mode)
{
case HYPERX_MODE_STATIC:
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE2, HYPERX_MODE2_STATIC);
break;
case HYPERX_MODE_RAINBOW:
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE1, HYPERX_MODE1_RAINBOW);
break;
case HYPERX_MODE_COMET:
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE2, HYPERX_MODE2_COMET);
break;
case HYPERX_MODE_HEARTBEAT:
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE2, HYPERX_MODE2_HEARTBEAT);
break;
case HYPERX_MODE_CYCLE:
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE1, HYPERX_MODE1_CYCLE);
break;
case HYPERX_MODE_BREATHING:
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE2, HYPERX_MODE2_BREATHING);
break;
case HYPERX_MODE_BOUNCE:
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE2, HYPERX_MODE2_BOUNCE);
break;
case HYPERX_MODE_BLINK:
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE2, HYPERX_MODE2_BLINK);
break;
}
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x02);
bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x03);
}

View file

@ -0,0 +1,76 @@
/*-----------------------------------------*\
| HyperXController.h |
| |
| Definitions and types for HyperX Predator|
| RGB RAM lighting controller |
| |
| Adam Honse (CalcProgrammer1) 6/29/2019 |
\*-----------------------------------------*/
#include "i2c_smbus.h"
#pragma once
typedef unsigned char hyperx_dev_id;
typedef unsigned short hyperx_register;
enum
{
HYPERX_REG_BRIGHTNESS = 0xDD, /* Brightness control register (0-100) */
HYPERX_REG_APPLY = 0xE1, /* Apply changes register */
HYPERX_REG_MODE1 = 0xE3, /* Mode control register 1 */
HYPERX_REG_MODE2 = 0xE4, /* Mode control register 2 */
HYPERX_REG_RED = 0xEC, /* Red color register */
HYPERX_REG_GREEN = 0xED, /* Green color register */
HYPERX_REG_BLUE = 0xEE, /* Blue color register */
};
enum
{
HYPERX_MODE1_RAINBOW = 0x05, /* Mode 1 rainbow effect */
HYPERX_MODE1_CYCLE = 0x04, /* Mode 1 cycle effect */
};
enum
{
HYPERX_MODE2_BOUNCE = 0x02, /* Mode 2 bounce effect */
HYPERX_MODE2_BREATHING = 0x03, /* Mode 2 breathing effect */
HYPERX_MODE2_BLINK = 0x06, /* Mode 2 blink effect */
HYPERX_MODE2_HEARTBEAT = 0x07, /* Mode 2 heartbeat effect */
HYPERX_MODE2_COMET = 0x08, /* Mode 2 comet effect */
HYPERX_MODE2_STATIC = 0x09, /* Mode 2 static effect */
};
enum
{
HYPERX_MODE_STATIC = 0, /* Static color mode */
HYPERX_MODE_RAINBOW = 1, /* Rainbow wave mode */
HYPERX_MODE_COMET = 2, /* Comet (chase) mode */
HYPERX_MODE_HEARTBEAT = 3, /* Heartbeat (pulsing) mode */
HYPERX_MODE_CYCLE = 4, /* Spectrum cycle mode */
HYPERX_MODE_BREATHING = 5, /* Breathing mode */
HYPERX_MODE_BOUNCE = 6, /* Bounce mode */
HYPERX_MODE_BLINK = 7, /* Blinking mode */
HYPERX_NUMBER_MODES /* Number of HyperX modes */
};
class HyperXController
{
public:
HyperXController(i2c_smbus_interface* bus, hyperx_dev_id dev);
~HyperXController();
char* GetDeviceName();
unsigned int GetLEDCount();
void SetMode(unsigned char mode);
void SetAllColors(unsigned char red, unsigned char green, unsigned char blue);
void SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue);
private:
char device_name[32];
unsigned int led_count;
i2c_smbus_interface* bus;
hyperx_dev_id dev;
};

View file

@ -0,0 +1,70 @@
#include "HyperXController.h"
#include "RGBController.h"
#include "RGBController_HyperX.h"
#include "i2c_smbus.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
/******************************************************************************************\
* *
* TestForHyperXController *
* *
* Tests the given address to see if a HyperX controller exists there. *
* *
\******************************************************************************************/
bool TestForHyperXController(i2c_smbus_interface* bus, unsigned char address)
{
bool pass = false;
int res = bus->i2c_smbus_write_quick(address, I2C_SMBUS_WRITE);
if (res >= 0)
{
pass = true;
for (int i = 0xA0; i < 0xB0; i++)
{
res = bus->i2c_smbus_read_byte_data(address, i);
if (res != i)
{
pass = false;
}
}
}
return(pass);
} /* TestForHyperXController() */
/******************************************************************************************\
* *
* DetectHyperXControllers *
* *
* Detect HyperX controllers on the enumerated I2C busses. *
* *
* bus - pointer to i2c_smbus_interface where Aura device is connected *
* dev - I2C address of Aura device *
* *
\******************************************************************************************/
void DetectHyperXControllers(std::vector<i2c_smbus_interface*> &busses, std::vector<RGBController*> &rgb_controllers)
{
HyperXController* new_hyperx;
RGBController_HyperX* new_controller;
for (unsigned int bus = 0; bus < busses.size(); bus++)
{
// Check for HyperX controller at 0x27
if (TestForHyperXController(busses[bus], 0x27))
{
new_hyperx = new HyperXController(busses[bus], 0x27);
new_controller = new RGBController_HyperX(new_hyperx);
rgb_controllers.push_back(new_controller);
}
}
} /* DetectHyperXControllers() */

View file

@ -0,0 +1,128 @@
/*---------------------------------------------------------*\
| Processing Code for Generic LED Strip Interface |
| |
| Adam Honse (calcprogrammer1@gmail.com), 12/11/2016 |
\*---------------------------------------------------------*/
#include "LEDStripController.h"
#include <fstream>
#include <iostream>
#include <string>
#define LPSTR char *
#define strtok_s strtok_r
LEDStripController::LEDStripController()
{
}
LEDStripController::~LEDStripController()
{
}
void LEDStripController::Initialize(char* ledstring)
{
LPSTR numleds = NULL;
LPSTR source = NULL;
LPSTR udpport_baud = NULL;
LPSTR next = NULL;
source = strtok_s(ledstring, ",", &next);
//Check for either the UDP port or the serial baud rate
if (strlen(next))
{
udpport_baud = strtok_s(next, ",", &next);
}
//Check for the number of LEDs
if (strlen(next))
{
numleds = strtok_s(next, ",", &next);
}
//Initialize with custom baud rate
InitializeSerial(source, atoi(udpport_baud));
if (numleds != NULL && strlen(numleds))
{
num_leds = atoi(numleds);
}
}
void LEDStripController::InitializeSerial(char* portname, int baud)
{
portname = strtok(portname, "\r");
strcpy(port_name, portname);
baud_rate = baud;
serialport = new serial_port(port_name, baud_rate);
}
void LEDStripController::InitializeUDP(char * clientname, char * port)
{
strcpy(client_name, clientname);
strcpy(port_name, port);
//udpport = new net_port(client_name, port_name);
serialport = NULL;
}
void LEDStripController::InitializeEspurna(char * clientname, char * port, char * apikey)
{
strcpy(client_name, clientname);
strcpy(port_name, port);
strcpy(espurna_apikey, apikey);
//tcpport = new net_port;
serialport = NULL;
}
char* LEDStripController::GetLEDString()
{
return(led_string);
}
void LEDStripController::SetLEDs(std::vector<RGBColor> colors)
{
if (serialport != NULL )
{
unsigned char *serial_buf;
serial_buf = new unsigned char[(num_leds * 3) + 3];
serial_buf[0] = 0xAA;
for (int idx = 0; idx < (num_leds * 3); idx += 3)
{
int pixel_idx = idx / 3;
RGBColor color = colors[pixel_idx];
serial_buf[idx + 1] = RGBGetRValue(color);
serial_buf[idx + 2] = RGBGetGValue(color);
serial_buf[idx + 3] = RGBGetBValue(color);
}
unsigned short sum = 0;
for (int i = 0; i < (num_leds * 3) + 1; i++)
{
sum += serial_buf[i];
}
serial_buf[(num_leds * 3) + 1] = sum >> 8;
serial_buf[(num_leds * 3) + 2] = sum & 0x00FF;
if (serialport != NULL)
{
serialport->serial_write((char *)serial_buf, (num_leds * 3) + 3);
serialport->serial_flush_tx();
}
delete[] serial_buf;
}
else
{
//SetLEDsEspurna(pixels);
}
}

View file

@ -0,0 +1,52 @@
/*---------------------------------------------------------*\
| Definitions for Generic LED Strip Interface |
| |
| Adam Honse (calcprogrammer1@gmail.com), 12/11/2016 |
\*---------------------------------------------------------*/
#ifndef LED_STRIP_H
#define LED_STRIP_H
#include "RGBController.h"
#include "serial_port.h"
#include <vector>
#ifndef TRUE
#define TRUE true
#define FALSE false
#endif
class LEDStripController
{
public:
LEDStripController();
~LEDStripController();
void Initialize(char* ledstring);
void InitializeHuePlus(char * ledstring);
void InitializeSerial(char* portname, int baud);
void InitializeUDP(char* clientname, char* port);
void InitializeEspurna(char* clientname, char* port, char * apikey);
char* GetLEDString();
void SetLEDs(std::vector<RGBColor> colors);
int num_leds;
private:
int baud_rate;
int fans;
int channel;
const int hueSize = 125;
int * LEDStripXIndex;
int * LEDStripYIndex;
char led_string[1024];
char port_name[128];
char client_name[1024];
char espurna_apikey[128];
serial_port *serialport;
};
#endif

View file

@ -0,0 +1,87 @@
#include "LEDStripController.h"
#include "RGBController.h"
#include "RGBController_LEDStrip.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#include <fstream>
#include <iostream>
#include <string>
/******************************************************************************************\
* *
* DetectLEDStripControllers *
* *
* Detect devices supported by the LEDStrip driver *
* * *
\******************************************************************************************/
void DetectLEDStripControllers(std::vector<RGBController*> &rgb_controllers)
{
LEDStripController* new_ledstrip;
RGBController_LEDStrip* new_controller;
//Get file path in executable directory
std::ifstream infile;
char filename[2048];
char arg1[64];
snprintf(arg1, 64, "/proc/%d/exe", getpid());
readlink(arg1, filename, 1024);
strcpy(filename, std::string(filename).substr(0, std::string(filename).find_last_of("\\/")).c_str());
strcat(filename, "/settings.txt");
//Open settings file
infile.open(filename);
if (infile.good())
{
for (std::string line; std::getline(infile, line); )
{
if (line == "")
{
continue;
}
if ((line[0] != ';') && (line[0] != '#') && (line[0] != '/'))
{
char * argument;
char * value;
value = (char *)line.c_str();
argument = strtok_r(value, "=", &value);
//Strip off new line characters if present
argument = strtok(argument, "\r\n");
value = strtok(value, "\r\n");
if(argument)
{
if (strcmp(argument, "ledstrip") == 0)
{
new_ledstrip = new LEDStripController();
new_ledstrip->Initialize(value);
new_controller = new RGBController_LEDStrip(new_ledstrip);
rgb_controllers.push_back(new_controller);
}
else if (strcmp(argument, "xmas") == 0)
{
}
else if (strcmp(argument, "hueplus") == 0)
{
}
}
}
}
}
} /* DetectLEDStripControllers() */