From 2cd0b642511bfa34549f3f5a9b3f65d43e37d82e Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Sun, 9 Feb 2020 15:26:20 -0600 Subject: [PATCH] Add mode control to Thermaltake Riing controller --- .../ThermaltakeRiingController.cpp | 12 ++- .../ThermaltakeRiingController.h | 8 +- .../RGBController_ThermaltakeRiing.cpp | 93 +++++++++++++++++++ qt/OpenRGBDevicePage.cpp | 16 +++- 4 files changed, 120 insertions(+), 9 deletions(-) diff --git a/Controllers/ThermaltakeRiingController/ThermaltakeRiingController.cpp b/Controllers/ThermaltakeRiingController/ThermaltakeRiingController.cpp index dd3ea350..5b0b37f3 100644 --- a/Controllers/ThermaltakeRiingController/ThermaltakeRiingController.cpp +++ b/Controllers/ThermaltakeRiingController/ThermaltakeRiingController.cpp @@ -20,7 +20,7 @@ ThermaltakeRiingController::ThermaltakeRiingController(libusb_device_handle* dev channel_leds[0] = 9; channel_leds[1] = 9; channel_leds[2] = 9; - channel_leds[4] = 0; + channel_leds[3] = 0; channel_leds[4] = 0; } @@ -31,7 +31,7 @@ ThermaltakeRiingController::~ThermaltakeRiingController() void ThermaltakeRiingController::SetChannelLEDs(unsigned char channel, std::vector colors) { - unsigned char* color_data = new unsigned char[colors.size()]; + unsigned char* color_data = new unsigned char[3 * colors.size()]; for(int color = 0; color < colors.size(); color++) { @@ -41,11 +41,17 @@ void ThermaltakeRiingController::SetChannelLEDs(unsigned char channel, std::vect color_data[color_idx + 2] = RGBGetBValue(colors[color]); } - SendRGB(channel, THERMALTAKE_MODE_PER_LED, THERMALTAKE_SPEED_FAST, colors.size(), color_data); + SendRGB(channel, current_mode, current_speed, colors.size(), color_data); delete[] color_data; } +void ThermaltakeRiingController::SetMode(unsigned char mode, unsigned char speed) +{ + current_mode = mode; + current_speed = speed; +} + /*-------------------------------------------------------------------------------------------------*\ | Private packet sending functions. | \*-------------------------------------------------------------------------------------------------*/ diff --git a/Controllers/ThermaltakeRiingController/ThermaltakeRiingController.h b/Controllers/ThermaltakeRiingController/ThermaltakeRiingController.h index c7b62bc4..41785f5a 100644 --- a/Controllers/ThermaltakeRiingController/ThermaltakeRiingController.h +++ b/Controllers/ThermaltakeRiingController/ThermaltakeRiingController.h @@ -48,12 +48,16 @@ public: ThermaltakeRiingController(libusb_device_handle* dev_handle); ~ThermaltakeRiingController(); - void SetChannelLEDs(unsigned char channel, std::vector colors); - + void SetChannelLEDs(unsigned char channel, std::vector colors); + void SetMode(unsigned char mode, unsigned char speed); + unsigned int channel_leds[5]; private: libusb_device_handle* dev; + + unsigned char current_mode; + unsigned char current_speed; void SendInit(); diff --git a/RGBController/RGBController_ThermaltakeRiing.cpp b/RGBController/RGBController_ThermaltakeRiing.cpp index e4f5165e..7471de1e 100644 --- a/RGBController/RGBController_ThermaltakeRiing.cpp +++ b/RGBController/RGBController_ThermaltakeRiing.cpp @@ -18,6 +18,78 @@ RGBController_ThermaltakeRiing::RGBController_ThermaltakeRiing(ThermaltakeRiingC type = DEVICE_TYPE_COOLER; + mode Flow; + Flow.name = "Flow"; + Flow.value = THERMALTAKE_MODE_FLOW; + Flow.flags = MODE_FLAG_HAS_SPEED; + Flow.speed_min = THERMALTAKE_SPEED_SLOW; + Flow.speed_max = THERMALTAKE_SPEED_EXTREME; + Flow.speed = THERMALTAKE_SPEED_NORMAL; + modes.push_back(Flow); + + mode Spectrum; + Spectrum.name = "Spectrum"; + Spectrum.value = THERMALTAKE_MODE_SPECTRUM; + Spectrum.flags = MODE_FLAG_HAS_SPEED; + Spectrum.speed_min = THERMALTAKE_SPEED_SLOW; + Spectrum.speed_max = THERMALTAKE_SPEED_EXTREME; + Spectrum.speed = THERMALTAKE_SPEED_NORMAL; + modes.push_back(Spectrum); + + mode Ripple; + Ripple.name = "Ripple"; + Ripple.value = THERMALTAKE_MODE_RIPPLE; + Ripple.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_COLOR; + Ripple.speed_min = THERMALTAKE_SPEED_SLOW; + Ripple.speed_max = THERMALTAKE_SPEED_EXTREME; + Ripple.speed = THERMALTAKE_SPEED_NORMAL; + modes.push_back(Ripple); + + mode Blink; + Blink.name = "Blink"; + Blink.value = THERMALTAKE_MODE_BLINK; + Blink.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_COLOR | MODE_FLAG_PER_LED_COLOR; + Blink.speed_min = THERMALTAKE_SPEED_SLOW; + Blink.speed_max = THERMALTAKE_SPEED_EXTREME; + Blink.speed = THERMALTAKE_SPEED_NORMAL; + modes.push_back(Blink); + + mode Pulse; + Pulse.name = "Pulse"; + Pulse.value = THERMALTAKE_MODE_PULSE; + Pulse.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_COLOR | MODE_FLAG_PER_LED_COLOR; + Pulse.speed_min = THERMALTAKE_SPEED_SLOW; + Pulse.speed_max = THERMALTAKE_SPEED_EXTREME; + Pulse.speed = THERMALTAKE_SPEED_NORMAL; + modes.push_back(Pulse); + + mode Wave; + Wave.name = "Wave"; + Wave.value = THERMALTAKE_MODE_WAVE; + Wave.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_COLOR | MODE_FLAG_PER_LED_COLOR; + Wave.speed_min = THERMALTAKE_SPEED_SLOW; + Wave.speed_max = THERMALTAKE_SPEED_EXTREME; + Wave.speed = THERMALTAKE_SPEED_NORMAL; + modes.push_back(Wave); + + mode Direct; + Direct.name = "Direct"; + Direct.value = THERMALTAKE_MODE_PER_LED; + Direct.flags = MODE_FLAG_HAS_COLOR | MODE_FLAG_PER_LED_COLOR; + Direct.speed_min = 0; + Direct.speed_max = 0; + Direct.speed = 0; + modes.push_back(Direct); + + mode Static; + Static.name = "Static"; + Static.value = THERMALTAKE_MODE_FULL; + Static.flags = MODE_FLAG_HAS_COLOR; + Static.speed_min = 0; + Static.speed_max = 0; + Static.speed = 0; + modes.push_back(Static); + /*-------------------------------------------------*\ | Set size of colors array | \*-------------------------------------------------*/ @@ -137,8 +209,29 @@ void RGBController_ThermaltakeRiing::UpdateSingleLED(int led) void RGBController_ThermaltakeRiing::SetCustomMode() { + SetMode(6); } void RGBController_ThermaltakeRiing::UpdateMode() { + 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) + { + riing->SetMode(modes[active_mode].value, modes[active_mode].speed); + riing->SetChannelLEDs(channel, channel_colors); + } + } } diff --git a/qt/OpenRGBDevicePage.cpp b/qt/OpenRGBDevicePage.cpp index d63a5887..5e50bee2 100644 --- a/qt/OpenRGBDevicePage.cpp +++ b/qt/OpenRGBDevicePage.cpp @@ -348,7 +348,7 @@ void Ui::OpenRGBDevicePage::UpdateMode() | Read user interface | \*-----------------------------------------------------*/ int current_mode = ui->ModeBox->currentIndex(); - int current_speed = ui->SpeedSlider->value(); + int current_speed = 0; bool current_random = ui->RandomCheck->checkState(); int current_dir_idx = ui->DirectionBox->currentIndex(); int current_direction = 0; @@ -396,11 +396,19 @@ void Ui::OpenRGBDevicePage::UpdateMode() device->modes[current_mode].direction = current_direction; /*-----------------------------------------------------*\ - | If Speed Slider is inverted, invert value | + | If Speed Slider is enabled, read the speed value | \*-----------------------------------------------------*/ - if(InvertedSpeed) + if(ui->SpeedSlider->isEnabled()) { - current_speed = device->modes[current_mode].speed_min - current_speed + device->modes[current_mode].speed_max; + current_speed = ui->SpeedSlider->value(); + + /*-----------------------------------------------------*\ + | If Speed Slider is inverted, invert value | + \*-----------------------------------------------------*/ + if(InvertedSpeed) + { + current_speed = device->modes[current_mode].speed_min - current_speed + device->modes[current_mode].speed_max; + } } /*-----------------------------------------------------*\