From 2099abb126b6d32fe2566d6cf2e72b6579a4753a Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Sat, 7 Mar 2020 18:01:00 -0600 Subject: [PATCH] Update Patriot Viper RGB controller to new RGBController API --- OpenRGB.cpp | 2 +- OpenRGB.pro | 8 +- RGBController/RGBController_PatriotViper.cpp | 159 ++++++++++--------- RGBController/RGBController_PatriotViper.h | 5 + 4 files changed, 91 insertions(+), 83 deletions(-) diff --git a/OpenRGB.cpp b/OpenRGB.cpp index e77d62ab6..4936e1c61 100644 --- a/OpenRGB.cpp +++ b/OpenRGB.cpp @@ -320,7 +320,7 @@ void DetectRGBControllers(void) DetectCorsairProControllers(busses, rgb_controllers); DetectCrucialControllers(busses, rgb_controllers); DetectHyperXControllers(busses, rgb_controllers); - //DetectPatriotViperControllers(busses, rgb_controllers); + DetectPatriotViperControllers(busses, rgb_controllers); DetectPolychromeControllers(busses, rgb_controllers); DetectRGBFusionGPUControllers(busses, rgb_controllers); diff --git a/OpenRGB.pro b/OpenRGB.pro index ea92a73c4..a4209e362 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -44,7 +44,7 @@ INCLUDEPATH += \ Controllers/LEDStripController/ \ Controllers/MSI3ZoneController/ \ Controllers/MSIRGBController/ \ -# Controllers/PatriotViperController/ \ + Controllers/PatriotViperController/ \ Controllers/PolychromeController/ \ Controllers/PoseidonZRGBController/ \ Controllers/RGBFusionController/ \ @@ -105,8 +105,8 @@ SOURCES += \ Controllers/MSI3ZoneController/MSI3ZoneControllerDetect.cpp \ Controllers/MSIRGBController/MSIRGBController.cpp \ Controllers/MSIRGBController/MSIRGBControllerDetect.cpp \ -# Controllers/PatriotViperController/PatriotViperController.cpp \ -# Controllers/PatriotViperController/PatriotViperControllerDetect.cpp \ + Controllers/PatriotViperController/PatriotViperController.cpp \ + Controllers/PatriotViperController/PatriotViperControllerDetect.cpp \ Controllers/PolychromeController/PolychromeController.cpp \ Controllers/PolychromeController/PolychromeControllerDetect.cpp \ Controllers/PoseidonZRGBController/PoseidonZRGBController.cpp \ @@ -138,7 +138,7 @@ SOURCES += \ RGBController/RGBController_LEDStrip.cpp \ RGBController/RGBController_MSI3Zone.cpp \ RGBController/RGBController_MSIRGB.cpp \ -# RGBController/RGBController_PatriotViper.cpp \ + RGBController/RGBController_PatriotViper.cpp \ RGBController/RGBController_Polychrome.cpp \ RGBController/RGBController_PoseidonZRGB.cpp \ RGBController/RGBController_RGBFusion.cpp \ diff --git a/RGBController/RGBController_PatriotViper.cpp b/RGBController/RGBController_PatriotViper.cpp index 48f4a069e..f9d93fd15 100644 --- a/RGBController/RGBController_PatriotViper.cpp +++ b/RGBController/RGBController_PatriotViper.cpp @@ -9,54 +9,6 @@ #include "RGBController_PatriotViper.h" -void RGBController_PatriotViper::UpdateLEDs() -{ - if(viper->direct == true) - { - for(int led = 0; led < 5; led++) - { - RGBColor color = colors[led]; - unsigned char red = RGBGetRValue(color); - unsigned char grn = RGBGetGValue(color); - unsigned char blu = RGBGetBValue(color); - viper->SetLEDColor(led, red, grn, blu); - } - } - else - { - for(int led = 0; led < 5; led++) - { - RGBColor color = colors[led]; - unsigned char red = RGBGetRValue(color); - unsigned char grn = RGBGetGValue(color); - unsigned char blu = RGBGetBValue(color); - viper->SetLEDEffectColor(led, red, grn, blu); - } - } -} - -void RGBController_PatriotViper::UpdateZoneLEDs(int zone) -{ - UpdateLEDs(); -} - -void RGBController_PatriotViper::UpdateSingleLED(int led) -{ - RGBColor color = colors[led]; - unsigned char red = RGBGetRValue(color); - unsigned char grn = RGBGetGValue(color); - unsigned char blu = RGBGetBValue(color); - - if(viper->direct == true) - { - viper->SetLEDColor(led, red, grn, blu); - } - else - { - viper->SetLEDEffectColor(led, red, grn, blu); - } -} - RGBController_PatriotViper::RGBController_PatriotViper(PatriotViperController* viper_ptr) { viper = viper_ptr; @@ -146,42 +98,93 @@ RGBController_PatriotViper::RGBController_PatriotViper(PatriotViperController* v Aurora.speed = VIPER_SPEED_DEFAULT; modes.push_back(Aurora); - colors.resize(viper->GetLEDCount()); + SetupZones(); +} - unsigned int led_idx = 0; +void RGBController_PatriotViper::SetupZones() +{ + /*---------------------------------------------------------*\ + | Set up zones | + \*---------------------------------------------------------*/ for(unsigned int slot = 0; slot < viper->GetSlotCount(); slot++) { zone* new_zone = new zone; - - char slot_idx_str[3]; - sprintf(slot_idx_str, "%d", slot); - new_zone->name = "Patriot Viper RGB Slot "; - new_zone->name.append(slot_idx_str); - - new_zone->type = ZONE_TYPE_LINEAR; - - std::vector *new_zone_map = new std::vector(); - - for(int led_slot_idx = 0; led_slot_idx < 5; led_slot_idx++) - { - led* new_led = new led(); - - char led_idx_str[3]; - sprintf(led_idx_str, "%d", led_slot_idx); - new_led->name = "Patriot Viper RGB Slot "; - new_led->name.append(slot_idx_str); - new_led->name.append(", LED "); - new_led->name.append(led_idx_str); - - leds.push_back(*new_led); - - new_zone_map->push_back(led_idx); - led_idx++; - } - - new_zone->map.push_back(*new_zone_map); + new_zone->name = "Patriot Viper RGB"; + new_zone->type = ZONE_TYPE_LINEAR; + new_zone->leds_min = 5; + new_zone->leds_max = 5; + new_zone->leds_count = 5; zones.push_back(*new_zone); } + + /*---------------------------------------------------------*\ + | Set up LEDs | + \*---------------------------------------------------------*/ + for(int led_idx = 0; led_idx < zones[0].leds_count; led_idx++) + { + led* new_led = new led(); + + new_led->name = "Patriot Viper RGB LED "; + new_led->name.append(std::to_string(led_idx + 1)); + leds.push_back(*new_led); + } + + SetupColors(); +} + +void RGBController_PatriotViper::ResizeZone(int /*zone*/, int /*new_size*/) +{ + /*---------------------------------------------------------*\ + | This device does not support resizing zones | + \*---------------------------------------------------------*/ +} + +void RGBController_PatriotViper::UpdateLEDs() +{ + if(viper->direct == true) + { + for(int led = 0; led < 5; led++) + { + RGBColor color = colors[led]; + unsigned char red = RGBGetRValue(color); + unsigned char grn = RGBGetGValue(color); + unsigned char blu = RGBGetBValue(color); + viper->SetLEDColor(led, red, grn, blu); + } + } + else + { + for(int led = 0; led < 5; led++) + { + RGBColor color = colors[led]; + unsigned char red = RGBGetRValue(color); + unsigned char grn = RGBGetGValue(color); + unsigned char blu = RGBGetBValue(color); + viper->SetLEDEffectColor(led, red, grn, blu); + } + } +} + +void RGBController_PatriotViper::UpdateZoneLEDs(int zone) +{ + UpdateLEDs(); +} + +void RGBController_PatriotViper::UpdateSingleLED(int led) +{ + RGBColor color = colors[led]; + unsigned char red = RGBGetRValue(color); + unsigned char grn = RGBGetGValue(color); + unsigned char blu = RGBGetBValue(color); + + if(viper->direct == true) + { + viper->SetLEDColor(led, red, grn, blu); + } + else + { + viper->SetLEDEffectColor(led, red, grn, blu); + } } void RGBController_PatriotViper::SetCustomMode() diff --git a/RGBController/RGBController_PatriotViper.h b/RGBController/RGBController_PatriotViper.h index 737b47a0c..1fe2877f8 100644 --- a/RGBController/RGBController_PatriotViper.h +++ b/RGBController/RGBController_PatriotViper.h @@ -16,6 +16,11 @@ class RGBController_PatriotViper : public RGBController { public: RGBController_PatriotViper(PatriotViperController* viper_ptr); + + void SetupZones(); + + void ResizeZone(int zone, int new_size); + void UpdateLEDs(); void UpdateZoneLEDs(int zone); void UpdateSingleLED(int led);