Name cleanup: adding brand names to all controllers
This commit is contained in:
parent
dde857dfb4
commit
8ffd302a57
74 changed files with 283 additions and 283 deletions
239
Controllers/NZXTHuePlusController/NZXTHuePlusController.cpp
Normal file
239
Controllers/NZXTHuePlusController/NZXTHuePlusController.cpp
Normal file
|
|
@ -0,0 +1,239 @@
|
|||
/*---------------------------------------------------------*\
|
||||
| Processing Code for NZXT Hue+ |
|
||||
| |
|
||||
| Adam Honse (calcprogrammer1@gmail.com), 12/11/2016 |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "NZXTHuePlusController.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
HuePlusController::HuePlusController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
HuePlusController::~HuePlusController()
|
||||
{
|
||||
}
|
||||
|
||||
void HuePlusController::Initialize(char* port)
|
||||
{
|
||||
strcpy(port_name, port);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
char* HuePlusController::GetLocation()
|
||||
{
|
||||
return(port_name);
|
||||
}
|
||||
|
||||
unsigned int HuePlusController::GetLEDsOnChannel(unsigned int channel)
|
||||
{
|
||||
unsigned char serial_buf[] =
|
||||
{
|
||||
0x8D, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
unsigned int ret_val = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set channel in serial packet |
|
||||
\*-----------------------------------------------------*/
|
||||
serial_buf[0x01] = channel;
|
||||
|
||||
serialport->serial_flush_rx();
|
||||
serialport->serial_write((char *)serial_buf, 2);
|
||||
serialport->serial_flush_tx();
|
||||
|
||||
std::this_thread::sleep_for(50ms);
|
||||
|
||||
int bytes_read = serialport->serial_read((char *)serial_buf, 5);
|
||||
|
||||
if(bytes_read == 5)
|
||||
{
|
||||
if(serial_buf[3] == 0x01)
|
||||
{
|
||||
ret_val = serial_buf[4] * 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_val += serial_buf[4] * 10;
|
||||
}
|
||||
}
|
||||
|
||||
return(ret_val);
|
||||
}
|
||||
|
||||
void HuePlusController::SetChannelEffect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
bool direction,
|
||||
RGBColor * colors,
|
||||
unsigned int num_colors
|
||||
)
|
||||
{
|
||||
unsigned char color_data[120];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| If mode requires no colors, send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
if(num_colors == 0)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Send mode without color data |
|
||||
\*-----------------------------------------------------*/
|
||||
SendPacket(channel, mode, direction, 0, speed, 0, NULL);
|
||||
}
|
||||
/*-----------------------------------------------------*\
|
||||
| If mode requires indexed colors, send color index |
|
||||
| packets for each mode color |
|
||||
\*-----------------------------------------------------*/
|
||||
else if(num_colors <= 8)
|
||||
{
|
||||
for(std::size_t color_idx = 0; color_idx < num_colors; color_idx++)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Fill in color data (40 entries per color) |
|
||||
\*-----------------------------------------------------*/
|
||||
for (std::size_t idx = 0; idx < 40; idx++)
|
||||
{
|
||||
int pixel_idx = idx * 3;
|
||||
RGBColor color = colors[color_idx];
|
||||
color_data[pixel_idx + 0x00] = RGBGetGValue(color);
|
||||
color_data[pixel_idx + 0x01] = RGBGetRValue(color);
|
||||
color_data[pixel_idx + 0x02] = RGBGetBValue(color);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send mode and color data |
|
||||
\*-----------------------------------------------------*/
|
||||
SendPacket(channel, mode, direction, color_idx, speed, 40, &color_data[0]);
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------*\
|
||||
| If mode requires per-LED colors, fill colors array |
|
||||
\*-----------------------------------------------------*/
|
||||
else
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Fill in color data (up to 40 colors) |
|
||||
\*-----------------------------------------------------*/
|
||||
for (std::size_t idx = 0; idx < num_colors; idx++)
|
||||
{
|
||||
int pixel_idx = idx * 3;
|
||||
RGBColor color = colors[idx];
|
||||
color_data[pixel_idx + 0x00] = RGBGetGValue(color);
|
||||
color_data[pixel_idx + 0x01] = RGBGetRValue(color);
|
||||
color_data[pixel_idx + 0x02] = RGBGetBValue(color);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send mode and color data |
|
||||
\*-----------------------------------------------------*/
|
||||
SendPacket(channel, mode, direction, 0, speed, num_colors, &color_data[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void HuePlusController::SetChannelLEDs
|
||||
(
|
||||
unsigned char channel,
|
||||
RGBColor * colors,
|
||||
unsigned int num_colors
|
||||
)
|
||||
{
|
||||
unsigned char color_data[120];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Fill in color data (up to 40 colors) |
|
||||
\*-----------------------------------------------------*/
|
||||
for (std::size_t idx = 0; idx < num_colors; idx++)
|
||||
{
|
||||
int pixel_idx = idx * 3;
|
||||
RGBColor color = colors[idx];
|
||||
color_data[pixel_idx + 0x00] = RGBGetGValue(color);
|
||||
color_data[pixel_idx + 0x01] = RGBGetRValue(color);
|
||||
color_data[pixel_idx + 0x02] = RGBGetBValue(color);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send color data |
|
||||
\*-----------------------------------------------------*/
|
||||
SendPacket(channel, HUE_PLUS_MODE_FIXED, false, 0, 0, num_colors, &color_data[0]);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------------------------------*\
|
||||
| Private packet sending functions. |
|
||||
\*-------------------------------------------------------------------------------------------------*/
|
||||
|
||||
void HuePlusController::SendPacket
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
bool direction,
|
||||
unsigned char color_idx,
|
||||
unsigned char speed,
|
||||
unsigned char color_count,
|
||||
unsigned char* color_data
|
||||
)
|
||||
{
|
||||
unsigned char serial_buf[125];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(serial_buf, 0x00, sizeof(serial_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Direct packet |
|
||||
\*-----------------------------------------------------*/
|
||||
serial_buf[0x00] = 0x4B;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set channel in serial packet |
|
||||
\*-----------------------------------------------------*/
|
||||
serial_buf[0x01] = channel + 1;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set mode in serial packet |
|
||||
\*-----------------------------------------------------*/
|
||||
serial_buf[0x02] = mode;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set options bitfield in serial packet |
|
||||
\*-----------------------------------------------------*/
|
||||
serial_buf[0x03] = 0;
|
||||
serial_buf[0x03] |= direction ? ( 1 << 4 ) : 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set color index and speed in serial packet |
|
||||
\*-----------------------------------------------------*/
|
||||
serial_buf[0x04] = ( color_idx << 5 ) | speed;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in color data bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
memcpy(&serial_buf[0x05], color_data, color_count * 3);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
serialport->serial_write((char *)serial_buf, HUE_PLUS_PACKET_SIZE);
|
||||
serialport->serial_flush_tx();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Delay to allow Hue+ device to ready for next packet |
|
||||
\*-----------------------------------------------------*/
|
||||
std::this_thread::sleep_for(20ms);
|
||||
}
|
||||
112
Controllers/NZXTHuePlusController/NZXTHuePlusController.h
Normal file
112
Controllers/NZXTHuePlusController/NZXTHuePlusController.h
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
/*---------------------------------------------------------*\
|
||||
| Definitions for NZXT Hue+ |
|
||||
| |
|
||||
| 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
|
||||
|
||||
#ifndef WIN32
|
||||
#define LPSTR char *
|
||||
#define strtok_s strtok_r
|
||||
#endif
|
||||
|
||||
#define HUE_PLUS_BAUD 256000
|
||||
#define HUE_PLUS_PACKET_SIZE 125
|
||||
|
||||
enum
|
||||
{
|
||||
HUE_PLUS_CHANNEL_BOTH = 0x00, /* Both channels */
|
||||
HUE_PLUS_CHANNEL_1 = 0x01, /* Channel 1 */
|
||||
HUE_PLUS_CHANNEL_2 = 0x02, /* Channel 2 */
|
||||
HUE_PLUS_NUM_CHANNELS = 0x02 /* Number of channels */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
HUE_PLUS_CHANNEL_1_IDX = 0x00, /* Channel 1 array index */
|
||||
HUE_PLUS_CHANNEL_2_IDX = 0x01, /* Channel 2 array index */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
HUE_PLUS_SPEED_SLOWEST = 0x00, /* Slowest speed */
|
||||
HUE_PLUS_SPEED_SLOW = 0x01, /* Slow speed */
|
||||
HUE_PLUS_SPEED_NORMAL = 0x02, /* Normal speed */
|
||||
HUE_PLUS_SPEED_FAST = 0x03, /* Fast speed */
|
||||
HUE_PLUS_SPEED_FASTEST = 0x04, /* Fastest speed */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
HUE_PLUS_MODE_FIXED = 0x00, /* Fixed colors mode */
|
||||
HUE_PLUS_MODE_FADING = 0x01, /* Fading mode */
|
||||
HUE_PLUS_MODE_SPECTRUM = 0x02, /* Spectrum cycle mode */
|
||||
HUE_PLUS_MODE_MARQUEE = 0x03, /* Marquee mode */
|
||||
HUE_PLUS_MODE_COVER_MARQUEE = 0x04, /* Cover marquee mode */
|
||||
HUE_PLUS_MODE_ALTERNATING = 0x05, /* Alternating mode */
|
||||
HUE_PLUS_MODE_PULSING = 0x06, /* Pulsing mode */
|
||||
HUE_PLUS_MODE_BREATHING = 0x07, /* Breathing mode */
|
||||
HUE_PLUS_MODE_ALERT = 0x08, /* Alert mode */
|
||||
HUE_PLUS_MODE_CANDLELIGHT = 0x09, /* Candlelight mode */
|
||||
HUE_PLUS_MODE_WINGS = 0x0C, /* Wings mode */
|
||||
HUE_PLUS_MODE_WAVE = 0x0D, /* Wave mode */
|
||||
};
|
||||
|
||||
class HuePlusController
|
||||
{
|
||||
public:
|
||||
HuePlusController();
|
||||
~HuePlusController();
|
||||
|
||||
void Initialize(char* port);
|
||||
char* GetLocation();
|
||||
unsigned int GetLEDsOnChannel(unsigned int channel);
|
||||
|
||||
void SetChannelEffect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
bool direction,
|
||||
RGBColor * colors,
|
||||
unsigned int num_colors
|
||||
);
|
||||
|
||||
void SetChannelLEDs
|
||||
(
|
||||
unsigned char channel,
|
||||
RGBColor * colors,
|
||||
unsigned int num_colors
|
||||
);
|
||||
|
||||
unsigned int channel_leds[HUE_PLUS_NUM_CHANNELS];
|
||||
|
||||
private:
|
||||
char port_name[128];
|
||||
serial_port *serialport;
|
||||
|
||||
void SendPacket
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
bool direction,
|
||||
unsigned char color_idx,
|
||||
unsigned char speed,
|
||||
unsigned char color_count,
|
||||
unsigned char* color_data
|
||||
);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
#include "Detector.h"
|
||||
#include "NZXTHuePlusController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_NZXTHuePlus.h"
|
||||
#include "find_usb_serial_port.h"
|
||||
#include <vector>
|
||||
|
||||
#define NZXT_HUE_PLUS_VID 0x04D8
|
||||
#define NZXT_HUE_PLUS_PID 0x00DF
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectNZXTHuePlusControllers *
|
||||
* *
|
||||
* Detect devices supported by the NZXTHuePlus driver *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectNZXTHuePlusControllers(std::vector<RGBController*> &rgb_controllers)
|
||||
{
|
||||
size_t i;
|
||||
HuePlusController* new_hueplus;
|
||||
RGBController_HuePlus* new_controller;
|
||||
|
||||
std::vector<std::string *> ports = find_usb_serial_port(NZXT_HUE_PLUS_VID, NZXT_HUE_PLUS_PID);
|
||||
|
||||
for (i = 0; i < ports.size(); i++)
|
||||
{
|
||||
if( *ports[i] != "" )
|
||||
{
|
||||
new_hueplus = new HuePlusController();
|
||||
new_hueplus->Initialize((char *)ports[i]->c_str());
|
||||
|
||||
new_controller = new RGBController_HuePlus(new_hueplus);
|
||||
rgb_controllers.push_back(new_controller);
|
||||
}
|
||||
}
|
||||
} /* DetectHuePlusControllers() */
|
||||
|
||||
REGISTER_DETECTOR("NZXT Hue+", DetectNZXTHuePlusControllers);
|
||||
295
Controllers/NZXTHuePlusController/RGBController_NZXTHuePlus.cpp
Normal file
295
Controllers/NZXTHuePlusController/RGBController_NZXTHuePlus.cpp
Normal file
|
|
@ -0,0 +1,295 @@
|
|||
/*-----------------------------------------*\
|
||||
| RGBController_NZXTHuePlus.cpp |
|
||||
| |
|
||||
| Generic RGB Interface for NZXT Hue+ |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 6/20/2019 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController_NZXTHuePlus.h"
|
||||
|
||||
|
||||
RGBController_HuePlus::RGBController_HuePlus(HuePlusController* hueplus_ptr)
|
||||
{
|
||||
hueplus = hueplus_ptr;
|
||||
|
||||
name = "NZXT Hue+";
|
||||
type = DEVICE_TYPE_LEDSTRIP;
|
||||
description = "NZXT Hue+ Device";
|
||||
location = hueplus->GetLocation();
|
||||
|
||||
mode Direct;
|
||||
Direct.name = "Direct";
|
||||
Direct.value = HUE_PLUS_MODE_FIXED;
|
||||
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
Direct.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Direct);
|
||||
|
||||
mode Fading;
|
||||
Fading.name = "Fading";
|
||||
Fading.value = HUE_PLUS_MODE_FADING;
|
||||
Fading.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
|
||||
Fading.speed_min = HUE_PLUS_SPEED_SLOWEST;
|
||||
Fading.speed_max = HUE_PLUS_SPEED_FASTEST;
|
||||
Fading.colors_min = 1;
|
||||
Fading.colors_max = 8;
|
||||
Fading.speed = HUE_PLUS_SPEED_NORMAL;
|
||||
Fading.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
Fading.colors.resize(2);
|
||||
modes.push_back(Fading);
|
||||
|
||||
mode SpectrumCycle;
|
||||
SpectrumCycle.name = "Spectrum Cycle";
|
||||
SpectrumCycle.value = HUE_PLUS_MODE_SPECTRUM;
|
||||
SpectrumCycle.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_DIRECTION_LR;
|
||||
SpectrumCycle.speed_min = HUE_PLUS_SPEED_SLOWEST;
|
||||
SpectrumCycle.speed_max = HUE_PLUS_SPEED_FASTEST;
|
||||
SpectrumCycle.speed = HUE_PLUS_SPEED_NORMAL;
|
||||
SpectrumCycle.direction = MODE_DIRECTION_RIGHT;
|
||||
SpectrumCycle.color_mode = MODE_COLORS_NONE;
|
||||
modes.push_back(SpectrumCycle);
|
||||
|
||||
mode Marquee;
|
||||
Marquee.name = "Marquee";
|
||||
Marquee.value = HUE_PLUS_MODE_MARQUEE;
|
||||
Marquee.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_DIRECTION_LR | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
|
||||
Marquee.speed_min = HUE_PLUS_SPEED_SLOWEST;
|
||||
Marquee.speed_max = HUE_PLUS_SPEED_FASTEST;
|
||||
Marquee.colors_min = 1;
|
||||
Marquee.colors_max = 1;
|
||||
Marquee.speed = HUE_PLUS_SPEED_NORMAL;
|
||||
Marquee.direction = MODE_DIRECTION_RIGHT;
|
||||
Marquee.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
Marquee.colors.resize(1);
|
||||
modes.push_back(Marquee);
|
||||
|
||||
mode CoverMarquee;
|
||||
CoverMarquee.name = "Cover Marquee";
|
||||
CoverMarquee.value = HUE_PLUS_MODE_COVER_MARQUEE;
|
||||
CoverMarquee.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_DIRECTION_LR | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
|
||||
CoverMarquee.speed_min = HUE_PLUS_SPEED_SLOWEST;
|
||||
CoverMarquee.speed_max = HUE_PLUS_SPEED_FASTEST;
|
||||
CoverMarquee.colors_min = 1;
|
||||
CoverMarquee.colors_max = 8;
|
||||
CoverMarquee.speed = HUE_PLUS_SPEED_NORMAL;
|
||||
CoverMarquee.direction = MODE_DIRECTION_RIGHT;
|
||||
CoverMarquee.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
CoverMarquee.colors.resize(2);
|
||||
modes.push_back(CoverMarquee);
|
||||
|
||||
mode Alternating;
|
||||
Alternating.name = "Alternating";
|
||||
Alternating.value = HUE_PLUS_MODE_ALTERNATING;
|
||||
Alternating.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_DIRECTION_LR | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
|
||||
Alternating.speed_min = HUE_PLUS_SPEED_SLOWEST;
|
||||
Alternating.speed_max = HUE_PLUS_SPEED_FASTEST;
|
||||
Alternating.colors_min = 1;
|
||||
Alternating.colors_max = 2;
|
||||
Alternating.speed = HUE_PLUS_SPEED_NORMAL;
|
||||
Alternating.direction = MODE_DIRECTION_RIGHT;
|
||||
Alternating.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
Alternating.colors.resize(2);
|
||||
modes.push_back(Alternating);
|
||||
|
||||
mode Pulsing;
|
||||
Pulsing.name = "Pulsing";
|
||||
Pulsing.value = HUE_PLUS_MODE_PULSING;
|
||||
Pulsing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
|
||||
Pulsing.speed_min = HUE_PLUS_SPEED_SLOWEST;
|
||||
Pulsing.speed_max = HUE_PLUS_SPEED_FASTEST;
|
||||
Pulsing.colors_min = 1;
|
||||
Pulsing.colors_max = 8;
|
||||
Pulsing.speed = HUE_PLUS_SPEED_NORMAL;
|
||||
Pulsing.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
Pulsing.colors.resize(2);
|
||||
modes.push_back(Pulsing);
|
||||
|
||||
mode Breathing;
|
||||
Breathing.name = "Breathing";
|
||||
Breathing.value = HUE_PLUS_MODE_BREATHING;
|
||||
Breathing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
Breathing.speed_min = HUE_PLUS_SPEED_SLOWEST;
|
||||
Breathing.speed_max = HUE_PLUS_SPEED_FASTEST;
|
||||
Breathing.colors_min = 1;
|
||||
Breathing.colors_max = 8;
|
||||
Breathing.speed = HUE_PLUS_SPEED_NORMAL;
|
||||
Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
Breathing.colors.resize(2);
|
||||
modes.push_back(Breathing);
|
||||
|
||||
mode Alert;
|
||||
Alert.name = "Alert";
|
||||
Alert.value = HUE_PLUS_MODE_ALERT;
|
||||
Alert.flags = 0;
|
||||
Alert.color_mode = MODE_COLORS_NONE;
|
||||
modes.push_back(Alert);
|
||||
|
||||
mode Candlelight;
|
||||
Candlelight.name = "Candlelight";
|
||||
Candlelight.value = HUE_PLUS_MODE_CANDLELIGHT;
|
||||
Candlelight.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
|
||||
Candlelight.colors_min = 1;
|
||||
Candlelight.colors_max = 1;
|
||||
Candlelight.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
Candlelight.colors.resize(1);
|
||||
modes.push_back(Candlelight);
|
||||
|
||||
mode Wings;
|
||||
Wings.name = "Wings";
|
||||
Wings.value = HUE_PLUS_MODE_WINGS;
|
||||
Wings.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
|
||||
Wings.speed_min = HUE_PLUS_SPEED_SLOWEST;
|
||||
Wings.speed_max = HUE_PLUS_SPEED_FASTEST;
|
||||
Wings.colors_min = 1;
|
||||
Wings.colors_max = 1;
|
||||
Wings.speed = HUE_PLUS_SPEED_NORMAL;
|
||||
Wings.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
Wings.colors.resize(1);
|
||||
modes.push_back(Wings);
|
||||
|
||||
mode Wave;
|
||||
Wave.name = "Wave";
|
||||
Wave.value = HUE_PLUS_MODE_WAVE;
|
||||
Wave.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
Wave.speed_min = HUE_PLUS_SPEED_SLOWEST;
|
||||
Wave.speed_max = HUE_PLUS_SPEED_FASTEST;
|
||||
Wave.speed = HUE_PLUS_SPEED_NORMAL;
|
||||
Wave.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Wave);
|
||||
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
void RGBController_HuePlus::SetupZones()
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Only set LED count on the first run |
|
||||
\*-------------------------------------------------*/
|
||||
bool first_run = false;
|
||||
|
||||
if(zones.size() == 0)
|
||||
{
|
||||
first_run = true;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Clear any existing color/LED configuration |
|
||||
\*-------------------------------------------------*/
|
||||
leds.clear();
|
||||
colors.clear();
|
||||
zones.resize(HUE_PLUS_NUM_CHANNELS);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Set up zones |
|
||||
\*-------------------------------------------------*/
|
||||
for(unsigned int zone_idx = 0; zone_idx < HUE_PLUS_NUM_CHANNELS; zone_idx++)
|
||||
{
|
||||
zones[zone_idx].name = "Hue+ Channel ";
|
||||
zones[zone_idx].name.append(std::to_string(zone_idx + 1));
|
||||
zones[zone_idx].type = ZONE_TYPE_LINEAR;
|
||||
zones[zone_idx].leds_min = 0;
|
||||
zones[zone_idx].leds_max = 40;
|
||||
zones[zone_idx].matrix_map = NULL;
|
||||
|
||||
if(first_run)
|
||||
{
|
||||
zones[zone_idx].leds_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Set up LEDs |
|
||||
\*-------------------------------------------------*/
|
||||
for(unsigned int zone_idx = 0; zone_idx < zones.size(); zone_idx++)
|
||||
{
|
||||
for(unsigned int led_idx = 0; led_idx < zones[zone_idx].leds_count; led_idx++)
|
||||
{
|
||||
led new_led;
|
||||
new_led.name = "Hue+ 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;
|
||||
|
||||
leds.push_back(new_led);
|
||||
}
|
||||
}
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_HuePlus::ResizeZone(int zone, int new_size)
|
||||
{
|
||||
if((size_t) zone >= zones.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(((unsigned int)new_size >= zones[zone].leds_min) && ((unsigned int)new_size <= zones[zone].leds_max))
|
||||
{
|
||||
zones[zone].leds_count = new_size;
|
||||
|
||||
SetupZones();
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_HuePlus::DeviceUpdateLEDs()
|
||||
{
|
||||
for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
|
||||
{
|
||||
hueplus->SetChannelLEDs(zone_idx, zones[zone_idx].colors, zones[zone_idx].leds_count);
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_HuePlus::UpdateZoneLEDs(int zone)
|
||||
{
|
||||
hueplus->SetChannelLEDs(zone, zones[zone].colors, zones[zone].leds_count);
|
||||
}
|
||||
|
||||
void RGBController_HuePlus::UpdateSingleLED(int led)
|
||||
{
|
||||
unsigned int zone_idx = leds[led].value;
|
||||
|
||||
hueplus->SetChannelLEDs(zone_idx, zones[zone_idx].colors, zones[zone_idx].leds_count);
|
||||
}
|
||||
|
||||
void RGBController_HuePlus::SetCustomMode()
|
||||
{
|
||||
active_mode = 0;
|
||||
}
|
||||
|
||||
void RGBController_HuePlus::DeviceUpdateMode()
|
||||
{
|
||||
if(modes[active_mode].value == HUE_PLUS_MODE_FIXED)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
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)
|
||||
{
|
||||
direction = true;
|
||||
}
|
||||
|
||||
if(modes[active_mode].colors.size() > 0)
|
||||
{
|
||||
colors = &modes[active_mode].colors[0];
|
||||
}
|
||||
|
||||
hueplus->SetChannelEffect
|
||||
(
|
||||
zone_idx,
|
||||
modes[active_mode].value,
|
||||
modes[active_mode].speed,
|
||||
direction,
|
||||
colors,
|
||||
modes[active_mode].colors.size()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*-----------------------------------------*\
|
||||
| RGBController_NZXTHuePlus.h |
|
||||
| |
|
||||
| Generic RGB Interface for NZXT Hue+ |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 6/20/2019 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
#include "RGBController.h"
|
||||
#include "serial_port.h"
|
||||
#include "NZXTHuePlusController.h"
|
||||
|
||||
class RGBController_HuePlus : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_HuePlus(HuePlusController* hueplus_ptr);
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void SetCustomMode();
|
||||
void DeviceUpdateMode();
|
||||
|
||||
private:
|
||||
HuePlusController* hueplus;
|
||||
std::vector<unsigned int> leds_channel;
|
||||
std::vector<unsigned int> zones_channel;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue