diff --git a/Controllers/CorsairNodeProController/CorsairNodeProController.cpp b/Controllers/CorsairNodeProController/CorsairNodeProController.cpp new file mode 100644 index 00000000..6c130aa8 --- /dev/null +++ b/Controllers/CorsairNodeProController/CorsairNodeProController.cpp @@ -0,0 +1,258 @@ +/*---------------------------------------------------------*\ +| Processing Code for Corsair Lighting Node Pro | +| | +| Adam Honse (calcprogrammer1@gmail.com), 1/12/2020 | +\*---------------------------------------------------------*/ + +#include "CorsairNodeProController.h" + +#include +#include +#include + +CorsairNodeProController::CorsairNodeProController(libusb_device_handle* dev_handle) +{ + dev = dev_handle; + channel_leds[0] = 60; + channel_leds[1] = 60; +} + +CorsairNodeProController::~CorsairNodeProController() +{ +} + +void CorsairNodeProController::SetChannelLEDs(unsigned int channel, std::vector colors) +{ + unsigned char usb_start[] = + { + 0x38, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 + }; + + unsigned char usb_data[] = + { + 0x32, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 + }; + + unsigned char usb_apply[] = + { + 0x33, 0xFF, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 + }; + int actual; + + /*-----------------------------------------------------*\ + | Set channel in USB packets | + \*-----------------------------------------------------*/ + usb_data[0x01] = channel; + usb_start[0x01] = channel; + + /*-----------------------------------------------------*\ + | Send start packet | + \*-----------------------------------------------------*/ + libusb_interrupt_transfer(dev, 0x01, usb_start, 64, &actual, 0); + + /*-----------------------------------------------------*\ + | Send red channel packet 1 | + \*-----------------------------------------------------*/ + std::size_t pkt_max = 50; + + if(pkt_max > colors.size()) + { + pkt_max = colors.size(); + } + + usb_data[0x02] = 0; + usb_data[0x03] = pkt_max; + usb_data[0x04] = 0x00; //red + + for (std::size_t idx = 0; idx < pkt_max; idx++) + { + RGBColor color = colors[idx]; + usb_data[idx + 5] = RGBGetRValue(color); + } + + libusb_interrupt_transfer(dev, 0x01, usb_data, 64, &actual, 0); + + /*-----------------------------------------------------*\ + | Send red channel packet 2 if necessary | + \*-----------------------------------------------------*/ + for(int idx = 4; idx < 64; idx++) + { + usb_data[idx] = 0; + } + + pkt_max = 0; + + if (colors.size() > 50) + { + pkt_max = colors.size() - 50; + } + + if(pkt_max > 0) + { + usb_data[0x02] = 50; + usb_data[0x03] = pkt_max; + usb_data[0x04] = 0x00; //red + + for (std::size_t idx = 0; idx < pkt_max; idx++) + { + RGBColor color = colors[idx + 50]; + usb_data[idx + 5] = RGBGetRValue(color); + } + + libusb_interrupt_transfer(dev, 0x01, usb_data, 64, &actual, 0); + } + + /*-----------------------------------------------------*\ + | Send green channel packet 1 | + \*-----------------------------------------------------*/ + pkt_max = 50; + + if(pkt_max > colors.size()) + { + pkt_max = colors.size(); + } + + usb_data[0x02] = 0; + usb_data[0x03] = pkt_max; + usb_data[0x04] = 0x01; //green + + for (std::size_t idx = 0; idx < pkt_max; idx++) + { + RGBColor color = colors[idx]; + usb_data[idx + 5] = RGBGetGValue(color); + } + + libusb_interrupt_transfer(dev, 0x01, usb_data, 64, &actual, 0); + + /*-----------------------------------------------------*\ + | Send green channel packet 2 if necessary | + \*-----------------------------------------------------*/ + for(int idx = 4; idx < 64; idx++) + { + usb_data[idx] = 0; + } + + pkt_max = 0; + + if (colors.size() > 50) + { + pkt_max = colors.size() - 50; + } + + if(pkt_max > 0) + { + usb_data[0x02] = 50; + usb_data[0x03] = pkt_max; + usb_data[0x04] = 0x01; //green + + for (std::size_t idx = 0; idx < pkt_max; idx++) + { + RGBColor color = colors[idx + 50]; + usb_data[idx + 5] = RGBGetGValue(color); + } + + libusb_interrupt_transfer(dev, 0x01, usb_data, 64, &actual, 0); + } + + /*-----------------------------------------------------*\ + | Send blue channel packet 1 | + \*-----------------------------------------------------*/ + pkt_max = 50; + + if(pkt_max > colors.size()) + { + pkt_max = colors.size(); + } + + usb_data[0x02] = 0; + usb_data[0x03] = pkt_max; + usb_data[0x04] = 0x02; //blue + + for (std::size_t idx = 0; idx < pkt_max; idx++) + { + RGBColor color = colors[idx]; + usb_data[idx + 5] = RGBGetBValue(color); + } + + libusb_interrupt_transfer(dev, 0x01, usb_data, 64, &actual, 0); + + /*-----------------------------------------------------*\ + | Send blue channel packet 2 if necessary | + \*-----------------------------------------------------*/ + for(int idx = 4; idx < 64; idx++) + { + usb_data[idx] = 0; + } + + pkt_max = 0; + + if (colors.size() > 50) + { + pkt_max = colors.size() - 50; + } + + if(pkt_max > 0) + { + usb_data[0x02] = 50; + usb_data[0x03] = pkt_max; + usb_data[0x04] = 0x02; //blue + + for (std::size_t idx = 0; idx < pkt_max; idx++) + { + RGBColor color = colors[idx + 50]; + usb_data[idx + 5] = RGBGetBValue(color); + } + + libusb_interrupt_transfer(dev, 0x01, usb_data, 64, &actual, 0); + } + + /*-----------------------------------------------------*\ + | Send apply packet | + \*-----------------------------------------------------*/ + libusb_interrupt_transfer(dev, 0x01, usb_apply, 64, &actual, 0); +} diff --git a/Controllers/CorsairNodeProController/CorsairNodeProController.h b/Controllers/CorsairNodeProController/CorsairNodeProController.h new file mode 100644 index 00000000..53e8f08a --- /dev/null +++ b/Controllers/CorsairNodeProController/CorsairNodeProController.h @@ -0,0 +1,35 @@ +/*---------------------------------------------------------*\ +| Definitions for Corsair Lighting Node Pro | +| | +| Adam Honse (calcprogrammer1@gmail.com), 1/12/2020 | +\*---------------------------------------------------------*/ + +#include "RGBController.h" +#include +#include + +#pragma once + +enum +{ + CORSAIR_NODE_PRO_CHANNEL_1 = 0x00, /* Channel 1 */ + CORSAIR_NODE_PRO_CHANNEL_2 = 0x01, /* Channel 2 */ + CORSAIR_NODE_PRO_NUM_CHANNELS = 0x02 /* Number of channels */ +}; + +class CorsairNodeProController +{ +public: + CorsairNodeProController(libusb_device_handle* dev_handle); + ~CorsairNodeProController(); + + char* GetLEDString(); + unsigned int GetStripsOnChannel(unsigned int channel); + void SetChannelEffect(unsigned int channel, unsigned int mode, std::vector colors); + void SetChannelLEDs(unsigned int channel, std::vector colors); + + unsigned int channel_leds[CORSAIR_NODE_PRO_NUM_CHANNELS]; + +private: + libusb_device_handle* dev; +}; diff --git a/Controllers/CorsairNodeProController/CorsairNodeProControllerDetect.cpp b/Controllers/CorsairNodeProController/CorsairNodeProControllerDetect.cpp new file mode 100644 index 00000000..d566086e --- /dev/null +++ b/Controllers/CorsairNodeProController/CorsairNodeProControllerDetect.cpp @@ -0,0 +1,37 @@ +#include "CorsairNodeProController.h" +#include "RGBController.h" +#include "RGBController_CorsairNodePro.h" +#include +#include + +#define CORSAIR_LIGHTING_NODE_PRO_VID 0x1B1C +#define CORSAIR_LIGHTING_NODE_PRO_PID 0x0C0B + +/******************************************************************************************\ +* * +* DetectCorsairNodeProControllers * +* * +* Detect devices supported by the Corsair Lighting Node Pro driver * +* * * +\******************************************************************************************/ + +void DetectCorsairNodeProControllers(std::vector &rgb_controllers) +{ + libusb_context * ctx; + libusb_init(&ctx); + + //Look for Corsair Lighting Node Pro + libusb_device_handle * dev = libusb_open_device_with_vid_pid(ctx, CORSAIR_LIGHTING_NODE_PRO_VID, CORSAIR_LIGHTING_NODE_PRO_PID); + + if( dev ) + { + libusb_detach_kernel_driver(dev, 0); + libusb_claim_interface(dev, 0); + + CorsairNodeProController* controller = new CorsairNodeProController(dev); + + RGBController_CorsairNodePro* rgb_controller = new RGBController_CorsairNodePro(controller); + + rgb_controllers.push_back(rgb_controller); + } +} /* DetectCorsairNodeProControllers() */ diff --git a/OpenRGB.cpp b/OpenRGB.cpp index 282a3c94..ed185df6 100644 --- a/OpenRGB.cpp +++ b/OpenRGB.cpp @@ -334,6 +334,7 @@ void DetectAMDWraithPrismControllers(std::vector& rgb_controller void DetectAorusGPUControllers(std::vector &rgb_controllers); void DetectMSI3ZoneControllers(std::vector& rgb_controllers); void DetectPoseidonZRGBControllers(std::vector& rgb_controllers); +void DetectCorsairNodeProControllers(std::vector &rgb_controllers); /******************************************************************************************\ * * @@ -362,7 +363,8 @@ void DetectRGBControllers(void) DetectAMDWraithPrismControllers(rgb_controllers); DetectMSI3ZoneControllers(rgb_controllers); DetectPoseidonZRGBControllers(rgb_controllers); - + DetectCorsairNodeProControllers(rgb_controllers); + DetectE131Controllers(rgb_controllers); /*-------------------------------------*\ diff --git a/OpenRGB.pro b/OpenRGB.pro index bd584882..9faf8e80 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -14,6 +14,7 @@ INCLUDEPATH += \ Controllers/AMDWraithPrismController/ \ Controllers/AuraController/ \ Controllers/CorsairController/ \ + Controllers/CorsairNodeProController/ \ Controllers/CorsairProController/ \ Controllers/Hue2Controller/ \ Controllers/HuePlusController/ \ @@ -47,6 +48,8 @@ SOURCES += \ Controllers/AuraController/AuraControllerDetect.cpp \ Controllers/CorsairController/CorsairController.cpp \ Controllers/CorsairController/CorsairControllerDetect.cpp \ + Controllers/CorsairNodeProController/CorsairNodeProController.cpp \ + Controllers/CorsairNodeProController/CorsairNodeProControllerDetect.cpp \ Controllers/CorsairProController/CorsairProController.cpp \ Controllers/CorsairProController/CorsairProControllerDetect.cpp \ Controllers/Hue2Controller/Hue2Controller.cpp \ @@ -72,6 +75,7 @@ SOURCES += \ RGBController/RGBController_AMDWraithPrism.cpp \ RGBController/RGBController_Aura.cpp \ RGBController/RGBController_Corsair.cpp \ + RGBController/RGBController_CorsairNodePro.cpp \ RGBController/RGBController_CorsairPro.cpp \ RGBController/RGBController_Hue2.cpp \ RGBController/RGBController_HuePlus.cpp \ @@ -98,6 +102,7 @@ HEADERS += \ Controllers/AMDWraithPrismController/AMDWraithPrismController.h \ Controllers/AuraController/AuraController.h \ Controllers/CorsairController/CorsairController.h \ + Controllers/CorsairNodeProController/CorsairNodeProController.h \ Controllers/CorsairProController/CorsairProController.h \ Controllers/Hue2Controller/Hue2Controller.h \ Controllers/HuePlusController/HuePlusController.h \ @@ -112,6 +117,7 @@ HEADERS += \ RGBController/RGBController_AMDWraithPrism.h \ RGBController/RGBController_Aura.h \ RGBController/RGBController_Corsair.h \ + RGBController/RGBController_CorsairNodePro.h \ RGBController/RGBController_CorsairPro.h \ RGBController/RGBController_E131.h \ RGBController/RGBController_Hue2.h \ diff --git a/RGBController/RGBController_CorsairNodePro.cpp b/RGBController/RGBController_CorsairNodePro.cpp new file mode 100644 index 00000000..395198bd --- /dev/null +++ b/RGBController/RGBController_CorsairNodePro.cpp @@ -0,0 +1,155 @@ +/*-----------------------------------------*\ +| RGBController_CorsairNodePro.cpp | +| | +| Generic RGB Interface for Corsair | +| Lighting Node Pro | +| | +| Adam Honse (CalcProgrammer1) 1/12/2020 | +\*-----------------------------------------*/ + +#include "RGBController_CorsairNodePro.h" + + +RGBController_CorsairNodePro::RGBController_CorsairNodePro(CorsairNodeProController* corsair_ptr) +{ + corsair = corsair_ptr; + + name = "Corsair Lighting Node Pro"; + + type = DEVICE_TYPE_LEDSTRIP; + + mode led_mode; + led_mode.name = "Custom"; + modes.push_back(led_mode); + + /*-------------------------------------------------*\ + | Set size of colors array | + \*-------------------------------------------------*/ + unsigned int led_count = 0; + for (unsigned int channel_idx = 0; channel_idx < CORSAIR_NODE_PRO_NUM_CHANNELS; channel_idx++) + { + led_count += corsair->channel_leds[channel_idx]; + } + colors.resize(led_count); + + /*-------------------------------------------------*\ + | Set zones and leds | + \*-------------------------------------------------*/ + unsigned int led_idx = 0; + for (unsigned int channel_idx = 0; channel_idx < CORSAIR_NODE_PRO_NUM_CHANNELS; channel_idx++) + { + if(corsair->channel_leds[channel_idx] > 0) + { + zone* new_zone = new zone; + + char ch_idx_string[2]; + sprintf(ch_idx_string, "%d", channel_idx + 1); + + new_zone->name = "Corsair Channel "; + new_zone->name.append(ch_idx_string); + new_zone->type = ZONE_TYPE_LINEAR; + + std::vector *new_zone_map = new std::vector(); + + for (unsigned int led_ch_idx = 0; led_ch_idx < corsair->channel_leds[channel_idx]; led_ch_idx++) + { + char led_idx_string[3]; + sprintf(led_idx_string, "%d", led_ch_idx + 1); + + led new_led; + new_led.name = "Corsair Channel "; + new_led.name.append(ch_idx_string); + new_led.name.append(", LED "); + new_led.name.append(led_idx_string); + + leds.push_back(new_led); + leds_channel.push_back(channel_idx); + + new_zone_map->push_back(led_idx); + led_idx++; + } + + new_zone->map.push_back(*new_zone_map); + zones.push_back(*new_zone); + zones_channel.push_back(channel_idx); + } + } +} + +int RGBController_CorsairNodePro::GetMode() +{ + return 0; +} + +void RGBController_CorsairNodePro::SetMode(int /*mode*/) +{ + +} + +void RGBController_CorsairNodePro::SetCustomMode() +{ + +} + +void RGBController_CorsairNodePro::UpdateLEDs() +{ + for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++) + { + unsigned int channel = zones_channel[zone_idx]; + + std::vector channel_colors; + + for(std::size_t color = 0; color < colors.size(); color++) + { + if(leds_channel[color] == channel) + { + channel_colors.push_back(colors[color]); + } + } + + if(channel_colors.size() > 0) + { + corsair->SetChannelLEDs(channel, channel_colors); + } + } +} + +void RGBController_CorsairNodePro::UpdateZoneLEDs(int zone) +{ + unsigned int channel = zones_channel[zone]; + + std::vector channel_colors; + + for(std::size_t color = 0; color < colors.size(); color++) + { + if(leds_channel[color] == channel) + { + channel_colors.push_back(colors[color]); + } + } + + if(channel_colors.size() > 0) + { + corsair->SetChannelLEDs(channel, channel_colors); + } +} + +void RGBController_CorsairNodePro::UpdateSingleLED(int led) +{ + unsigned int channel = leds_channel[led]; + + std::vector channel_colors; + + for(std::size_t color = 0; color < colors.size(); color++) + { + if(leds_channel[color] == channel) + { + channel_colors.push_back(colors[color]); + } + } + + if(channel_colors.size() > 0) + { + corsair->SetChannelLEDs(channel, channel_colors); + } +} diff --git a/RGBController/RGBController_CorsairNodePro.h b/RGBController/RGBController_CorsairNodePro.h new file mode 100644 index 00000000..db27acf7 --- /dev/null +++ b/RGBController/RGBController_CorsairNodePro.h @@ -0,0 +1,30 @@ +/*-----------------------------------------*\ +| RGBController_CorsairNodePro.h | +| | +| Generic RGB Interface for Corsair | +| Lighting Node Pro | +| | +| Adam Honse (CalcProgrammer1) 1/12/2020 | +\*-----------------------------------------*/ + +#pragma once +#include "RGBController.h" +#include "serial_port.h" +#include "CorsairNodeProController.h" + +class RGBController_CorsairNodePro : public RGBController +{ +public: + RGBController_CorsairNodePro(CorsairNodeProController* corsair_ptr); + int GetMode(); + void SetMode(int mode); + void SetCustomMode(); + void UpdateLEDs(); + void UpdateZoneLEDs(int zone); + void UpdateSingleLED(int led); + +private: + CorsairNodeProController* corsair; + std::vector leds_channel; + std::vector zones_channel; +};