From f1fd3e0191707da6e2e1372279ccfb42537ad93a Mon Sep 17 00:00:00 2001 From: silas Date: Fri, 20 Nov 2020 17:51:59 -0600 Subject: [PATCH] Add an ARGB debug device Commits squashed and adjusted for code style by Adam Honse --- .../DebugController/DebugControllerDetect.cpp | 51 ++++++++++++++++++- .../DebugController/RGBController_Debug.cpp | 48 +++++++++++++++++ .../DebugController/RGBController_Debug.h | 15 ++++++ OpenRGB.pro | 2 + 4 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 Controllers/DebugController/RGBController_Debug.cpp create mode 100644 Controllers/DebugController/RGBController_Debug.h diff --git a/Controllers/DebugController/DebugControllerDetect.cpp b/Controllers/DebugController/DebugControllerDetect.cpp index 5caf74ff..23fca424 100644 --- a/Controllers/DebugController/DebugControllerDetect.cpp +++ b/Controllers/DebugController/DebugControllerDetect.cpp @@ -1,5 +1,6 @@ #include "Detector.h" #include "RGBController.h" +#include "RGBController_Debug.h" #include "RGBController_Dummy.h" #include "SettingsManager.h" #include @@ -161,7 +162,7 @@ static const char *led_names[] = * * * DetectDebugControllers * * * -* Add dummy controllers based on debug.txt * +* Add dummy controllers based on the Setting_DebugDevices key in the settings json * * * \******************************************************************************************/ @@ -487,6 +488,54 @@ void DetectDebugControllers(std::vector &rgb_controllers) \*---------------------------------------------------------*/ rgb_controllers.push_back(dummy_keyboard); } + else if(type == "argb") + { + /*---------------------------------------------------------*\ + | Create a dummy ARGB | + \*---------------------------------------------------------*/ + RGBController_Debug* dummy_argb = new RGBController_Debug(); + + dummy_argb->name = "Debug ARGB"; + dummy_argb->type = DEVICE_TYPE_LEDSTRIP; + dummy_argb->description = "Debug ARGB Device"; + dummy_argb->location = "Debug ARGB Location"; + dummy_argb->version = "Debug ARGB Version"; + dummy_argb->serial = "Debug ARGB Serial"; + + /*---------------------------------------------------------*\ + | Create a direct mode for the dummy ARGB | + \*---------------------------------------------------------*/ + mode dummy_argb_direct_mode; + + dummy_argb_direct_mode.name = "Direct"; + dummy_argb_direct_mode.value = 0; + dummy_argb_direct_mode.flags = MODE_FLAG_HAS_PER_LED_COLOR; + dummy_argb_direct_mode.color_mode = MODE_COLORS_PER_LED; + + dummy_argb->modes.push_back(dummy_argb_direct_mode); + + /*---------------------------------------------------------*\ + | Create a linear zone for the dummy ARGB | + \*---------------------------------------------------------*/ + zone dummy_argb_linear_zone; + + dummy_argb_linear_zone.name = "Resizable zone"; + dummy_argb_linear_zone.type = ZONE_TYPE_LINEAR; + dummy_argb_linear_zone.leds_min = 1; + dummy_argb_linear_zone.leds_max = 100; + dummy_argb_linear_zone.leds_count = 0; + dummy_argb_linear_zone.matrix_map = NULL; + + dummy_argb->zones.push_back(dummy_argb_linear_zone); + + dummy_argb->SetupColors(); + dummy_argb->ResizeZone(0, 60); + + /*---------------------------------------------------------*\ + | Push the dummy ARGB onto the controller list | + \*---------------------------------------------------------*/ + rgb_controllers.push_back(dummy_argb); + } } } diff --git a/Controllers/DebugController/RGBController_Debug.cpp b/Controllers/DebugController/RGBController_Debug.cpp new file mode 100644 index 00000000..c70a3de0 --- /dev/null +++ b/Controllers/DebugController/RGBController_Debug.cpp @@ -0,0 +1,48 @@ +#include "RGBController_Debug.h" + +#include + +RGBController_Debug::RGBController_Debug() +{ + +} + +void RGBController_Debug::ResizeZone(int index, int new_size) +{ + //Make sure that it isn't out of bounds (negative numbers) + if(new_size < int(zones[index].leds_min)) + { + new_size = zones[index].leds_min; + } + + // Same thing as the above line except for over 100 + if(new_size > int(zones[index].leds_max)) + { + new_size = zones[index].leds_max; + } + + // Store the previous amount of LEDs + int old_size = zones[index].leds_count; + + // Set the LED count in the zone to the new ammount + zones[index].leds_count = new_size; + + // Set the new ammount of LEDs for to the new size + size_t old_leds_size = leds.size(); + + // Add the new ammount of LEDs to the old ammount + size_t new_leds_size = leds.size() - old_size + new_size; + + leds.resize(std::max(old_leds_size, new_leds_size)); + + memmove(&leds[zones[index].start_idx] + old_leds_size, &leds[zones[index].start_idx] + new_leds_size, (old_leds_size - zones[index].start_idx - old_size) * sizeof(led)); + + leds.resize(new_leds_size); + + for(int i = 0; i < new_size; ++i) + { + leds[zones[index].start_idx + i].name = "Linear LED " + std::to_string(i); + } + + SetupColors(); +} diff --git a/Controllers/DebugController/RGBController_Debug.h b/Controllers/DebugController/RGBController_Debug.h new file mode 100644 index 00000000..2f6c2c78 --- /dev/null +++ b/Controllers/DebugController/RGBController_Debug.h @@ -0,0 +1,15 @@ +#ifndef RGBCONTROLLER_DEBUG_H +#define RGBCONTROLLER_DEBUG_H + +#include "RGBController_Dummy.h" + +// A variation of Dummy controller that allows the zones to be resized + +class RGBController_Debug : public RGBController_Dummy +{ +public: + RGBController_Debug(); + void ResizeZone(int zone, int newSize) override; +}; + +#endif // RGBCONTROLLER_DEBUG_H diff --git a/OpenRGB.pro b/OpenRGB.pro index 0a3549d1..1ced5f09 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -171,6 +171,7 @@ HEADERS += Controllers/CrucialController/RGBController_Crucial.h \ Controllers/DuckyKeyboardController/DuckyKeyboardController.h \ Controllers/DuckyKeyboardController/RGBController_DuckyKeyboard.h \ + Controllers/DebugController/RGBController_Debug.h \ Controllers/E131Controller/RGBController_E131.h \ Controllers/EKController/EKController.h \ Controllers/EKController/RGBController_EKController.h \ @@ -358,6 +359,7 @@ SOURCES += Controllers/DuckyKeyboardController/DuckyKeyboardController.cpp \ Controllers/DuckyKeyboardController/DuckyKeyboardControllerDetect.cpp \ Controllers/DuckyKeyboardController/RGBController_DuckyKeyboard.cpp \ + Controllers/DebugController/RGBController_Debug.cpp \ Controllers/E131Controller/E131ControllerDetect.cpp \ Controllers/E131Controller/RGBController_E131.cpp \ Controllers/EKController/EKControllerDetect.cpp \