Clean up unused channel field in NZXTHue1Controller, as it only supports one channel

This commit is contained in:
Adam Honse
2023-05-01 20:22:19 -05:00
parent 9d97c8ca74
commit 0ce0dd91ec
5 changed files with 79 additions and 128 deletions

View File

@@ -7,13 +7,11 @@
#include "NZXTHue1Controller.h"
#include <cstring>
NZXTHue1Controller::NZXTHue1Controller(hid_device* dev_handle, unsigned int rgb_channels, unsigned int fan_channels, const char* path)
NZXTHue1Controller::NZXTHue1Controller(hid_device* dev_handle, unsigned int /*fan_channels*/, const char* path)
{
dev = dev_handle;
location = path;
num_rgb_channels = rgb_channels;
Initialize();
}
@@ -53,14 +51,8 @@ unsigned int NZXTHue1Controller::GetAccessoryType()
return(accessory_type);
}
unsigned int NZXTHue1Controller::GetNumRGBChannels()
{
return(num_rgb_channels);
}
void NZXTHue1Controller::SetChannelEffect
void NZXTHue1Controller::SetEffect
(
unsigned char channel,
unsigned char mode,
unsigned char speed,
bool direction,
@@ -78,7 +70,7 @@ void NZXTHue1Controller::SetChannelEffect
/*-----------------------------------------------------*\
| Send mode without color data |
\*-----------------------------------------------------*/
SendPacket(channel, mode, direction, 0, speed, 0, NULL);
SendPacket(mode, direction, 0, speed, 0, NULL);
}
/*-----------------------------------------------------*\
| If mode requires indexed colors, send color index |
@@ -103,7 +95,7 @@ void NZXTHue1Controller::SetChannelEffect
/*-----------------------------------------------------*\
| Send mode and color data |
\*-----------------------------------------------------*/
SendPacket(channel, mode, direction, color_idx, speed, 40, &color_data[0]);
SendPacket(mode, direction, color_idx, speed, 40, &color_data[0]);
}
}
/*-----------------------------------------------------*\
@@ -126,13 +118,12 @@ void NZXTHue1Controller::SetChannelEffect
/*-----------------------------------------------------*\
| Send mode and color data |
\*-----------------------------------------------------*/
SendPacket(channel, mode, direction, 0, speed, num_colors, &color_data[0]);
SendPacket(mode, direction, 0, speed, num_colors, &color_data[0]);
}
}
void NZXTHue1Controller::SetChannelLEDs
void NZXTHue1Controller::SetLEDs
(
unsigned char channel,
RGBColor * colors,
unsigned int num_colors
)
@@ -154,7 +145,7 @@ void NZXTHue1Controller::SetChannelLEDs
/*-----------------------------------------------------*\
| Send color data |
\*-----------------------------------------------------*/
SendPacket(channel, HUE_1_MODE_FIXED, false, 0, 0, num_colors, &color_data[0]);
SendPacket(HUE_1_MODE_FIXED, false, 0, 0, num_colors, &color_data[0]);
}
/*-------------------------------------------------------------------------------------------------*\
@@ -218,17 +209,16 @@ void NZXTHue1Controller::Initialize()
if(accessory_type == HUE_1_ACCESSORY_STRIP)
{
channel_leds[HUE_1_CHANNEL_1_IDX] = dev_count * 10;
num_leds = dev_count * 10;
}
else
{
channel_leds[HUE_1_CHANNEL_1_IDX] = dev_count * 8;
num_leds = dev_count * 8;
}
}
void NZXTHue1Controller::SendPacket
(
unsigned char channel,
unsigned char mode,
bool direction,
unsigned char color_idx,

View File

@@ -9,17 +9,6 @@
#pragma once
enum
{
HUE_1_CHANNEL_1 = 0x01, /* Channel 1 */
HUE_1_NUM_CHANNELS = 0x01 /* Number of channels */
};
enum
{
HUE_1_CHANNEL_1_IDX = 0x00, /* Channel 1 array index */
};
enum
{
HUE_1_ACCESSORY_STRIP = 0x00, /* NZXT Hue+ LED Strip (10 LEDs)*/
@@ -54,7 +43,7 @@ enum
class NZXTHue1Controller
{
public:
NZXTHue1Controller(hid_device* dev_handle, unsigned int rgb_channels, unsigned int fan_channels, const char* path);
NZXTHue1Controller(hid_device* dev_handle, unsigned int fan_channels, const char* path);
~NZXTHue1Controller();
std::string GetFirmwareVersion();
@@ -62,11 +51,9 @@ public:
std::string GetSerialString();
unsigned int GetAccessoryType();
unsigned int GetNumRGBChannels();
void SetChannelEffect
void SetEffect
(
unsigned char channel,
unsigned char mode,
unsigned char speed,
bool direction,
@@ -74,28 +61,25 @@ public:
unsigned int num_colors
);
void SetChannelLEDs
void SetLEDs
(
unsigned char channel,
RGBColor * colors,
unsigned int num_colors
);
unsigned int channel_leds[HUE_1_NUM_CHANNELS];
unsigned int num_leds;
private:
hid_device* dev;
char firmware_version[16];
std::string location;
unsigned int num_rgb_channels;
unsigned int accessory_type;
void Initialize();
void SendPacket
(
unsigned char channel,
unsigned char mode,
bool direction,
unsigned char color_idx,

View File

@@ -24,7 +24,7 @@ void DetectNZXTHue1Controllers(hid_device_info* info, const std::string& name)
if(dev)
{
NZXTHue1Controller* controller = new NZXTHue1Controller(dev, 1, 3, info->path);
NZXTHue1Controller* controller = new NZXTHue1Controller(dev, 3, info->path);
RGBController_NZXTHue1* rgb_controller = new RGBController_NZXTHue1(controller);
rgb_controller->name = name;

View File

@@ -181,77 +181,65 @@ RGBController_NZXTHue1::~RGBController_NZXTHue1()
void RGBController_NZXTHue1::SetupZones()
{
/*-------------------------------------------------*\
| Set up zones |
| Set up zone |
\*-------------------------------------------------*/
for(unsigned int zone_idx = 0; zone_idx < controller->GetNumRGBChannels(); zone_idx++)
{
zone* new_zone = new zone;
zone* new_zone = new zone;
new_zone->name = "Hue 1 Channel ";
new_zone->name.append(std::to_string(zone_idx + 1));
new_zone->type = ZONE_TYPE_LINEAR;
new_zone->leds_min = 0;
new_zone->leds_max = 40;
new_zone->leds_count = controller->channel_leds[zone_idx];
new_zone->matrix_map = NULL;
new_zone->name = "Hue 1 Channel";
new_zone->type = ZONE_TYPE_LINEAR;
new_zone->leds_min = 0;
new_zone->leds_max = 40;
new_zone->leds_count = controller->num_leds;
new_zone->matrix_map = NULL;
zones.push_back(*new_zone);
}
zones.push_back(*new_zone);
/*-------------------------------------------------*\
| Set up LEDs |
\*-------------------------------------------------*/
for(unsigned int zone_idx = 0; zone_idx < zones.size(); zone_idx++)
for(unsigned int led_idx = 0; led_idx < zones[0].leds_count; led_idx++)
{
for(unsigned int led_idx = 0; led_idx < zones[zone_idx].leds_count; led_idx++)
{
led new_led;
new_led.name = "Hue 1 Channel ";
new_led.name.append(std::to_string(zone_idx + 1));
new_led.name.append(", LED ");
new_led.name.append(std::to_string(led_idx + 1));
new_led.value = zone_idx;
led new_led;
new_led.name = "Hue 1 Channel";
new_led.name.append(", LED ");
new_led.name.append(std::to_string(led_idx + 1));
leds.push_back(new_led);
}
leds.push_back(new_led);
}
/*-------------------------------------------------*\
| Set up Segments |
\*-------------------------------------------------*/
for(unsigned int zone_idx = 0; zone_idx < zones.size(); zone_idx++)
unsigned int num_segments = 0;
unsigned int segment_size = 0;
std::string segment_name = "";
switch(controller->GetAccessoryType())
{
unsigned int num_segments = 0;
unsigned int segment_size = 0;
std::string segment_name = "";
case HUE_1_ACCESSORY_STRIP:
segment_size = 10;
num_segments = zones[0].leds_count / segment_size;
segment_name = "Hue+ Strip";
break;
switch(controller->GetAccessoryType())
case HUE_1_ACCESSORY_FAN:
segment_size = 8;
num_segments = zones[0].leds_count / segment_size;
segment_name = "Aer RGB Fan";
break;
}
if(segment_name != "")
{
for(unsigned int segment_idx = 0; segment_idx < num_segments; segment_idx++)
{
case HUE_1_ACCESSORY_STRIP:
segment_size = 10;
num_segments = zones[zone_idx].leds_count / segment_size;
segment_name = "Hue+ Strip";
break;
segment new_segment;
new_segment.name = segment_name;
new_segment.type = ZONE_TYPE_LINEAR;
new_segment.start_idx = segment_idx * segment_size;
new_segment.leds_count = segment_size;
case HUE_1_ACCESSORY_FAN:
segment_size = 8;
num_segments = zones[zone_idx].leds_count / segment_size;
segment_name = "Aer RGB Fan";
break;
}
if(segment_name != "")
{
for(unsigned int segment_idx = 0; segment_idx < num_segments; segment_idx++)
{
segment new_segment;
new_segment.name = segment_name;
new_segment.type = ZONE_TYPE_LINEAR;
new_segment.start_idx = segment_idx * segment_size;
new_segment.leds_count = segment_size;
zones[zone_idx].segments.push_back(new_segment);
}
zones[0].segments.push_back(new_segment);
}
}
@@ -264,22 +252,17 @@ void RGBController_NZXTHue1::ResizeZone(int zone, int new_size)
void RGBController_NZXTHue1::DeviceUpdateLEDs()
{
for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
{
controller->SetChannelLEDs(zone_idx, zones[zone_idx].colors, zones[zone_idx].leds_count);
}
controller->SetLEDs(zones[0].colors, zones[0].leds_count);
}
void RGBController_NZXTHue1::UpdateZoneLEDs(int zone)
void RGBController_NZXTHue1::UpdateZoneLEDs(int /*zone*/)
{
controller->SetChannelLEDs(zone, zones[zone].colors, zones[zone].leds_count);
DeviceUpdateLEDs();
}
void RGBController_NZXTHue1::UpdateSingleLED(int led)
void RGBController_NZXTHue1::UpdateSingleLED(int /*led*/)
{
unsigned int zone_idx = leds[led].value;
controller->SetChannelLEDs(zone_idx, zones[zone_idx].colors, zones[zone_idx].leds_count);
DeviceUpdateLEDs();
}
void RGBController_NZXTHue1::DeviceUpdateMode()
@@ -290,30 +273,26 @@ void RGBController_NZXTHue1::DeviceUpdateMode()
}
else
{
for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
RGBColor* colors = NULL;
bool direction = false;
if(modes[active_mode].direction == MODE_DIRECTION_LEFT)
{
RGBColor* colors = NULL;
bool direction = false;
if(modes[active_mode].direction == MODE_DIRECTION_LEFT)
{
direction = true;
}
if(modes[active_mode].colors.size() > 0)
{
colors = &modes[active_mode].colors[0];
}
controller->SetChannelEffect
(
zone_idx,
modes[active_mode].value,
modes[active_mode].speed,
direction,
colors,
modes[active_mode].colors.size()
);
direction = true;
}
if(modes[active_mode].colors.size() > 0)
{
colors = &modes[active_mode].colors[0];
}
controller->SetEffect
(
modes[active_mode].value,
modes[active_mode].speed,
direction,
colors,
modes[active_mode].colors.size()
);
}
}

View File

@@ -27,6 +27,4 @@ public:
private:
NZXTHue1Controller* controller;
std::vector<unsigned int> leds_channel;
std::vector<unsigned int> zones_channel;
};