Aura USB: Addressable header and direct mode fixes
* Add addressable header and integrated LED count detection * Correctly use the direct mode
This commit is contained in:
parent
6a85729f10
commit
ca9c40f084
7 changed files with 179 additions and 110 deletions
|
|
@ -12,7 +12,13 @@
|
|||
|
||||
AuraAddressableController::AuraAddressableController(hid_device* dev_handle) : AuraUSBController(dev_handle)
|
||||
{
|
||||
channel_count = config_table[2];
|
||||
/*-----------------------------------------------------*\
|
||||
| Add addressable devices |
|
||||
\*-----------------------------------------------------*/
|
||||
for(int i = 0; i < config_table[0x02]; ++i)
|
||||
{
|
||||
device_info.push_back({0x01, (unsigned char)i, 0x01, AuraDeviceType::ADDRESSABLE});
|
||||
}
|
||||
}
|
||||
|
||||
AuraAddressableController::~AuraAddressableController()
|
||||
|
|
@ -112,41 +118,6 @@ void AuraAddressableController::SendEffect
|
|||
hid_write(dev, usb_buf, 65);
|
||||
}
|
||||
|
||||
void AuraAddressableController::SendDirect
|
||||
(
|
||||
unsigned char device,
|
||||
unsigned char start_led,
|
||||
unsigned char led_count,
|
||||
unsigned char* led_data
|
||||
)
|
||||
{
|
||||
unsigned char usb_buf[65];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up message packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0xEC;
|
||||
usb_buf[0x01] = AURA_ADDRESSABLE_CONTROL_MODE_DIRECT;
|
||||
usb_buf[0x02] = device;
|
||||
usb_buf[0x03] = start_led;
|
||||
usb_buf[0x04] = led_count;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in color data bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(&usb_buf[0x05], led_data, led_count * 3);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, usb_buf, 65);
|
||||
}
|
||||
|
||||
void AuraAddressableController::SendDirectApply
|
||||
(
|
||||
unsigned char channel
|
||||
|
|
@ -163,7 +134,7 @@ void AuraAddressableController::SendDirectApply
|
|||
| Set up message packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0xEC;
|
||||
usb_buf[0x01] = AURA_ADDRESSABLE_CONTROL_MODE_DIRECT;
|
||||
usb_buf[0x01] = AURA_CONTROL_MODE_DIRECT;
|
||||
usb_buf[0x02] = 0x80 | channel;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
enum
|
||||
{
|
||||
AURA_ADDRESSABLE_CONTROL_MODE_EFFECT = 0x3B, /* Effect control mode */
|
||||
AURA_ADDRESSABLE_CONTROL_MODE_DIRECT = 0x40, /* Direct control mode */
|
||||
};
|
||||
|
||||
class AuraAddressableController : public AuraUSBController
|
||||
|
|
@ -54,14 +53,6 @@ private:
|
|||
unsigned char blu
|
||||
);
|
||||
|
||||
void SendDirect
|
||||
(
|
||||
unsigned char device,
|
||||
unsigned char start_led,
|
||||
unsigned char led_count,
|
||||
unsigned char* led_data
|
||||
);
|
||||
|
||||
void SendDirectApply
|
||||
(
|
||||
unsigned char channel
|
||||
|
|
|
|||
|
|
@ -12,7 +12,18 @@
|
|||
|
||||
AuraMainboardController::AuraMainboardController(hid_device* dev_handle) : AuraUSBController(dev_handle), mode(AURA_MODE_DIRECT)
|
||||
{
|
||||
channel_count = 5;
|
||||
/*-----------------------------------------------------*\
|
||||
| Add mainboard device |
|
||||
\*-----------------------------------------------------*/
|
||||
device_info.push_back({0x00, 0x04, config_table[0x1B], AuraDeviceType::FIXED});
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add addressable devices |
|
||||
\*-----------------------------------------------------*/
|
||||
for(int i = 0; i < config_table[0x02]; ++i)
|
||||
{
|
||||
device_info.push_back({0x01, (unsigned char)i, 0x01, AuraDeviceType::ADDRESSABLE});
|
||||
}
|
||||
}
|
||||
|
||||
AuraMainboardController::~AuraMainboardController()
|
||||
|
|
@ -21,36 +32,69 @@ AuraMainboardController::~AuraMainboardController()
|
|||
|
||||
void AuraMainboardController::SetChannelLEDs(unsigned char channel, RGBColor * colors, unsigned int num_colors)
|
||||
{
|
||||
unsigned char led_data[60];
|
||||
unsigned int leds_sent = 0;
|
||||
SendEffect(device_info[channel].effect_channel, mode);
|
||||
|
||||
SendEffect(channel, mode);
|
||||
|
||||
while(leds_sent < num_colors)
|
||||
if(mode == AURA_MODE_DIRECT)
|
||||
{
|
||||
unsigned int leds_to_send = 20;
|
||||
unsigned char led_data[60];
|
||||
unsigned int leds_sent = 0;
|
||||
|
||||
if((num_colors - leds_sent) < leds_to_send)
|
||||
while(leds_sent < num_colors)
|
||||
{
|
||||
leds_to_send = num_colors - leds_sent;
|
||||
unsigned int leds_to_send = 20;
|
||||
|
||||
if((num_colors - leds_sent) < leds_to_send)
|
||||
{
|
||||
leds_to_send = num_colors - leds_sent;
|
||||
}
|
||||
|
||||
for(int led_idx = 0; led_idx < leds_to_send; led_idx++)
|
||||
{
|
||||
led_data[(led_idx * 3) + 0] = RGBGetRValue(colors[led_idx + leds_sent]);
|
||||
led_data[(led_idx * 3) + 1] = RGBGetGValue(colors[led_idx + leds_sent]);
|
||||
led_data[(led_idx * 3) + 2] = RGBGetBValue(colors[led_idx + leds_sent]);
|
||||
}
|
||||
|
||||
SendDirect
|
||||
(
|
||||
device_info[channel].direct_channel,
|
||||
leds_sent,
|
||||
leds_to_send,
|
||||
led_data,
|
||||
leds_sent + leds_to_send >= num_colors
|
||||
);
|
||||
|
||||
leds_sent += leds_to_send;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RGBColor color;
|
||||
unsigned char led_data[60];
|
||||
unsigned char start_led = 0;
|
||||
|
||||
for(std::size_t i = 0; i < channel; ++i)
|
||||
{
|
||||
start_led += device_info[i].num_leds;
|
||||
}
|
||||
|
||||
for(int led_idx = 0; led_idx < leds_to_send; led_idx++)
|
||||
color = num_colors < 1 ? ToRGBColor(0x00, 0x00, 0x00) : colors[0];
|
||||
|
||||
for(std::size_t led_idx = 0; led_idx < device_info[channel].num_leds; led_idx++)
|
||||
{
|
||||
led_data[(led_idx * 3) + 0] = RGBGetRValue(colors[led_idx + leds_sent]);
|
||||
led_data[(led_idx * 3) + 1] = RGBGetGValue(colors[led_idx + leds_sent]);
|
||||
led_data[(led_idx * 3) + 2] = RGBGetBValue(colors[led_idx + leds_sent]);
|
||||
led_data[(led_idx * 3) + 0] = RGBGetRValue(color);
|
||||
led_data[(led_idx * 3) + 1] = RGBGetGValue(color);
|
||||
led_data[(led_idx * 3) + 2] = RGBGetBValue(color);
|
||||
}
|
||||
|
||||
SendDirect
|
||||
SendColor
|
||||
(
|
||||
channel,
|
||||
leds_sent,
|
||||
leds_to_send,
|
||||
led_data
|
||||
start_led,
|
||||
device_info[channel].num_leds,
|
||||
led_data,
|
||||
device_info[channel].device_type == AuraDeviceType::FIXED
|
||||
);
|
||||
|
||||
leds_sent += leds_to_send;
|
||||
}
|
||||
|
||||
SendCommit();
|
||||
|
|
@ -66,24 +110,9 @@ void AuraMainboardController::SetMode
|
|||
)
|
||||
{
|
||||
this->mode = mode;
|
||||
unsigned char led_data[3];
|
||||
led_data[0] = red;
|
||||
led_data[1] = grn;
|
||||
led_data[2] = blu;
|
||||
RGBColor color = ToRGBColor(red, grn, blu);
|
||||
|
||||
SendEffect
|
||||
(
|
||||
channel,
|
||||
mode
|
||||
);
|
||||
SendDirect
|
||||
(
|
||||
channel,
|
||||
0,
|
||||
1,
|
||||
led_data
|
||||
);
|
||||
SendCommit();
|
||||
SetChannelLEDs(channel, &color, 1);
|
||||
}
|
||||
|
||||
void AuraMainboardController::SendEffect
|
||||
|
|
@ -94,9 +123,6 @@ void AuraMainboardController::SendEffect
|
|||
{
|
||||
unsigned char usb_buf[65];
|
||||
|
||||
if(mode == AURA_MODE_DIRECT) {
|
||||
mode = AURA_MODE_STATIC;
|
||||
}
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
|
|
@ -107,9 +133,9 @@ void AuraMainboardController::SendEffect
|
|||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0xEC;
|
||||
usb_buf[0x01] = AURA_MAINBOARD_CONTROL_MODE_EFFECT;
|
||||
usb_buf[0x02] = 0x00;
|
||||
usb_buf[0x02] = channel;
|
||||
usb_buf[0x03] = 0x00;
|
||||
usb_buf[0x04] = channel;
|
||||
usb_buf[0x04] = 0x00;
|
||||
usb_buf[0x05] = mode;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
|
|
@ -118,12 +144,13 @@ void AuraMainboardController::SendEffect
|
|||
hid_write(dev, usb_buf, 65);
|
||||
}
|
||||
|
||||
void AuraMainboardController::SendDirect
|
||||
void AuraMainboardController::SendColor
|
||||
(
|
||||
unsigned char device,
|
||||
unsigned char channel,
|
||||
unsigned char start_led,
|
||||
unsigned char led_count,
|
||||
unsigned char* led_data
|
||||
unsigned char* led_data,
|
||||
bool fixed
|
||||
)
|
||||
{
|
||||
unsigned char usb_buf[65];
|
||||
|
|
@ -137,15 +164,15 @@ void AuraMainboardController::SendDirect
|
|||
| Set up message packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0xEC;
|
||||
usb_buf[0x01] = AURA_MAINBOARD_CONTROL_MODE_DIRECT;
|
||||
usb_buf[0x02] = start_led;
|
||||
usb_buf[0x03] = 0xff;
|
||||
usb_buf[0x01] = AURA_MAINBOARD_CONTROL_MODE_EFFECT_COLOR;
|
||||
usb_buf[0x02] = channel;
|
||||
usb_buf[0x03] = fixed ? 0xFF : 0x00;
|
||||
usb_buf[0x04] = 0x00;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in color data bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(&usb_buf[0x05], led_data, led_count * 3);
|
||||
memcpy(&usb_buf[0x05 + 3 * start_led], led_data, led_count * 3);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
enum
|
||||
{
|
||||
AURA_MAINBOARD_CONTROL_MODE_EFFECT = 0x35, /* Effect control mode */
|
||||
AURA_MAINBOARD_CONTROL_MODE_DIRECT = 0x36, /* Direct control mode */
|
||||
AURA_MAINBOARD_CONTROL_MODE_COMMIT = 0x3F, /* Direct control mode */
|
||||
AURA_MAINBOARD_CONTROL_MODE_EFFECT_COLOR = 0x36, /* Effect color control mode */
|
||||
AURA_MAINBOARD_CONTROL_MODE_COMMIT = 0x3F, /* Commit mode */
|
||||
};
|
||||
|
||||
class AuraMainboardController : public AuraUSBController
|
||||
|
|
@ -53,12 +53,13 @@ private:
|
|||
unsigned char mode
|
||||
);
|
||||
|
||||
void SendDirect
|
||||
void SendColor
|
||||
(
|
||||
unsigned char device,
|
||||
unsigned char channel,
|
||||
unsigned char start_led,
|
||||
unsigned char led_count,
|
||||
unsigned char* led_data
|
||||
unsigned char* led_data,
|
||||
bool fixed
|
||||
);
|
||||
|
||||
void SendCommit();
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ AuraUSBController::~AuraUSBController()
|
|||
|
||||
unsigned int AuraUSBController::GetChannelCount()
|
||||
{
|
||||
return( channel_count );
|
||||
return(device_info.size());
|
||||
}
|
||||
|
||||
std::string AuraUSBController::GetDeviceName()
|
||||
|
|
@ -33,6 +33,11 @@ std::string AuraUSBController::GetDeviceName()
|
|||
return(device_name);
|
||||
}
|
||||
|
||||
const std::vector<AuraDeviceInfo>& AuraUSBController::GetAuraDevices() const
|
||||
{
|
||||
return(device_info);
|
||||
}
|
||||
|
||||
void AuraUSBController::GetConfigTable()
|
||||
{
|
||||
unsigned char usb_buf[65];
|
||||
|
|
@ -102,3 +107,40 @@ void AuraUSBController::GetFirmwareVersion()
|
|||
memcpy(device_name, &usb_buf[2], 16);
|
||||
}
|
||||
}
|
||||
|
||||
void AuraUSBController::SendDirect
|
||||
(
|
||||
unsigned char device,
|
||||
unsigned char start_led,
|
||||
unsigned char led_count,
|
||||
unsigned char* led_data,
|
||||
bool apply /* = false */
|
||||
)
|
||||
{
|
||||
unsigned char usb_buf[65];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up message packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0xEC;
|
||||
usb_buf[0x01] = AURA_CONTROL_MODE_DIRECT;
|
||||
usb_buf[0x02] = apply ? 0x80 : 0x00;
|
||||
usb_buf[0x02] |= device;
|
||||
usb_buf[0x03] = start_led;
|
||||
usb_buf[0x04] = led_count;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in color data bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(&usb_buf[0x05], led_data, led_count * 3);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, usb_buf, 65);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include "RGBController.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#pragma once
|
||||
|
|
@ -38,6 +39,21 @@ enum
|
|||
{
|
||||
AURA_REQUEST_FIRMWARE_VERSION = 0x82, /* Request firmware string */
|
||||
AURA_REQUEST_CONFIG_TABLE = 0xB0, /* Request configuration table */
|
||||
AURA_CONTROL_MODE_DIRECT = 0x40, /* Direct control mode */
|
||||
};
|
||||
|
||||
enum class AuraDeviceType
|
||||
{
|
||||
FIXED,
|
||||
ADDRESSABLE,
|
||||
};
|
||||
|
||||
struct AuraDeviceInfo
|
||||
{
|
||||
unsigned char effect_channel;
|
||||
unsigned char direct_channel;
|
||||
unsigned char num_leds;
|
||||
AuraDeviceType device_type;
|
||||
};
|
||||
|
||||
class AuraUSBController
|
||||
|
|
@ -50,6 +66,8 @@ public:
|
|||
|
||||
std::string GetDeviceName();
|
||||
|
||||
const std::vector<AuraDeviceInfo>& GetAuraDevices() const;
|
||||
|
||||
virtual void SetChannelLEDs
|
||||
(
|
||||
unsigned char channel,
|
||||
|
|
@ -67,13 +85,21 @@ public:
|
|||
) = 0;
|
||||
|
||||
protected:
|
||||
hid_device* dev;
|
||||
unsigned int channel_count;
|
||||
unsigned char config_table[60];
|
||||
hid_device* dev;
|
||||
unsigned char config_table[60];
|
||||
std::vector<AuraDeviceInfo> device_info;
|
||||
|
||||
void SendDirect
|
||||
(
|
||||
unsigned char device,
|
||||
unsigned char start_led,
|
||||
unsigned char led_count,
|
||||
unsigned char* led_data,
|
||||
bool apply = false
|
||||
);
|
||||
private:
|
||||
char device_name[16];
|
||||
unsigned int led_count;
|
||||
char device_name[16];
|
||||
unsigned int led_count;
|
||||
|
||||
void GetConfigTable();
|
||||
|
||||
|
|
|
|||
|
|
@ -128,6 +128,7 @@ void RGBController_AuraUSB::SetupZones()
|
|||
\*-------------------------------------------------*/
|
||||
for (unsigned int channel_idx = 0; channel_idx < zones.size(); channel_idx++)
|
||||
{
|
||||
AuraDeviceInfo device_info = aura->GetAuraDevices()[channel_idx];
|
||||
char ch_idx_string[2];
|
||||
sprintf(ch_idx_string, "%d", channel_idx + 1);
|
||||
|
||||
|
|
@ -135,13 +136,23 @@ void RGBController_AuraUSB::SetupZones()
|
|||
zones[channel_idx].name.append(ch_idx_string);
|
||||
zones[channel_idx].type = ZONE_TYPE_LINEAR;
|
||||
|
||||
zones[channel_idx].leds_min = 0;
|
||||
zones[channel_idx].leds_max = AURA_ADDRESSABLE_MAX_LEDS;
|
||||
|
||||
if(first_run)
|
||||
if(device_info.device_type == AuraDeviceType::FIXED)
|
||||
{
|
||||
zones[channel_idx].leds_count = 0;
|
||||
zones[channel_idx].leds_min = device_info.num_leds;
|
||||
zones[channel_idx].leds_max = device_info.num_leds;
|
||||
zones[channel_idx].leds_count = device_info.num_leds;
|
||||
}
|
||||
else
|
||||
{
|
||||
zones[channel_idx].leds_min = 0;
|
||||
zones[channel_idx].leds_max = AURA_ADDRESSABLE_MAX_LEDS;
|
||||
|
||||
if(first_run)
|
||||
{
|
||||
zones[channel_idx].leds_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (unsigned int led_ch_idx = 0; led_ch_idx < zones[channel_idx].leds_count; led_ch_idx++)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue