|
|
|
|
@ -10,115 +10,93 @@
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
#include <Windows.h>
|
|
|
|
|
#else
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
static void Sleep(unsigned int milliseconds)
|
|
|
|
|
{
|
|
|
|
|
usleep(1000 * milliseconds);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
HuePlusController::HuePlusController()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HuePlusController::~HuePlusController()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HuePlusController::Initialize(char* ledstring)
|
|
|
|
|
void HuePlusController::Initialize(char* port_name)
|
|
|
|
|
{
|
|
|
|
|
strcpy(led_string, ledstring);
|
|
|
|
|
|
|
|
|
|
LPSTR source = NULL;
|
|
|
|
|
LPSTR channels = NULL;
|
|
|
|
|
LPSTR numleds = NULL;
|
|
|
|
|
LPSTR next = NULL;
|
|
|
|
|
|
|
|
|
|
source = strtok_s(ledstring, ",", &next);
|
|
|
|
|
|
|
|
|
|
//Check for selected channel 0=both, 1= Ch.1, 2= Ch.2
|
|
|
|
|
if (strlen(next))
|
|
|
|
|
{
|
|
|
|
|
channels = strtok_s(next, ",", &next);
|
|
|
|
|
}
|
|
|
|
|
strcpy(led_string, port_name);
|
|
|
|
|
|
|
|
|
|
serialport = new serial_port(port_name, HUE_PLUS_BAUD);
|
|
|
|
|
|
|
|
|
|
switch (atoi(channels))
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
channel = 0x00;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
channel = 0x01;
|
|
|
|
|
break;
|
|
|
|
|
channel_leds[HUE_PLUS_CHANNEL_1_IDX] = GetStripsOnChannel(HUE_PLUS_CHANNEL_1) * 10;
|
|
|
|
|
channel_leds[HUE_PLUS_CHANNEL_2_IDX] = GetStripsOnChannel(HUE_PLUS_CHANNEL_2) * 10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
channel = 0x02;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
char* HuePlusController::GetLEDString()
|
|
|
|
|
{
|
|
|
|
|
return(led_string);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Check for the number of LEDs, sets the corresponding variable with the counter for the fans
|
|
|
|
|
if (strlen(next))
|
|
|
|
|
{
|
|
|
|
|
numleds = strtok_s(next, ",", &next);
|
|
|
|
|
}
|
|
|
|
|
unsigned int HuePlusController::GetStripsOnChannel(unsigned int channel)
|
|
|
|
|
{
|
|
|
|
|
unsigned int ret_val = 0;
|
|
|
|
|
|
|
|
|
|
switch (atoi(numleds) / 8)
|
|
|
|
|
if (serialport != NULL)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
fans = 0x00;
|
|
|
|
|
break;
|
|
|
|
|
unsigned char *serial_buf;
|
|
|
|
|
serial_buf = new unsigned char[5];
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
fans = 0x01;
|
|
|
|
|
break;
|
|
|
|
|
serial_buf[0] = 0x8D;
|
|
|
|
|
serial_buf[1] = channel;
|
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
fans = 0x02;
|
|
|
|
|
break;
|
|
|
|
|
serialport->serial_flush_rx();
|
|
|
|
|
serialport->serial_write((char *)serial_buf, 2);
|
|
|
|
|
serialport->serial_flush_tx();
|
|
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
fans = 0x03;
|
|
|
|
|
break;
|
|
|
|
|
Sleep(50);
|
|
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
|
fans = 0x04;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
int bytes_read = serialport->serial_read((char *)serial_buf, 5);
|
|
|
|
|
|
|
|
|
|
//Initialize with default baud rate
|
|
|
|
|
source = strtok(source, "\r");
|
|
|
|
|
strcpy(port_name, source);
|
|
|
|
|
baud_rate = 256000;
|
|
|
|
|
serialport = new serial_port(port_name, baud_rate);
|
|
|
|
|
if(bytes_read == 5)
|
|
|
|
|
{
|
|
|
|
|
ret_val = serial_buf[4];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (numleds != NULL && strlen(numleds))
|
|
|
|
|
{
|
|
|
|
|
num_leds = atoi(numleds);
|
|
|
|
|
delete[] serial_buf;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* HuePlusController::GetLEDString()
|
|
|
|
|
{
|
|
|
|
|
return(led_string);
|
|
|
|
|
return(ret_val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HuePlusController::SetLEDs(std::vector<RGBColor> colors)
|
|
|
|
|
void HuePlusController::SetChannelLEDs(unsigned int channel, std::vector<RGBColor> colors)
|
|
|
|
|
{
|
|
|
|
|
if (serialport != NULL)
|
|
|
|
|
{
|
|
|
|
|
unsigned char *serial_buf;
|
|
|
|
|
|
|
|
|
|
serial_buf = new unsigned char[hueSize]; //Size of Message always 5 XX Blocks (Mode Selection) + 3 XX for each LED (1 color)
|
|
|
|
|
//-> max of 40 LEDs per Channel (or 5 Fans a 8 LEDs) -> 125 Blocks (empty LEDs are written, too
|
|
|
|
|
serial_buf[0] = 0x4b;
|
|
|
|
|
serial_buf = new unsigned char[HUE_PLUS_PACKET_SIZE];
|
|
|
|
|
|
|
|
|
|
serial_buf[0] = 0x4B;
|
|
|
|
|
serial_buf[1] = channel;
|
|
|
|
|
serial_buf[2] = 0x0e;
|
|
|
|
|
serial_buf[3] = fans;
|
|
|
|
|
serial_buf[2] = HUE_PLUS_MODE_FIXED;
|
|
|
|
|
serial_buf[3] = 0x00;
|
|
|
|
|
serial_buf[4] = 0x00;
|
|
|
|
|
|
|
|
|
|
for (int i = 5; i < hueSize; i++)
|
|
|
|
|
for (int i = 5; i < HUE_PLUS_PACKET_SIZE; i++)
|
|
|
|
|
{
|
|
|
|
|
//clearing the buf otherwise sometimes strange things are written to the COM Port
|
|
|
|
|
serial_buf[i] = 0x00;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int idx = 0; idx < (num_leds * 3); idx += 3)
|
|
|
|
|
for (int idx = 0; idx < (colors.size() * 3); idx += 3)
|
|
|
|
|
{
|
|
|
|
|
int pixel_idx = idx / 3;
|
|
|
|
|
RGBColor color = colors[pixel_idx];
|
|
|
|
|
@ -127,7 +105,7 @@ void HuePlusController::SetLEDs(std::vector<RGBColor> colors)
|
|
|
|
|
serial_buf[idx + 7] = RGBGetBValue(color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serialport->serial_write((char *)serial_buf, hueSize);
|
|
|
|
|
serialport->serial_write((char *)serial_buf, HUE_PLUS_PACKET_SIZE);
|
|
|
|
|
serialport->serial_flush_tx();
|
|
|
|
|
|
|
|
|
|
delete[] serial_buf;
|
|
|
|
|
|