From 57060577bf6cde7316a700ac7cc713e94e452d8a Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Sun, 22 Sep 2024 19:37:18 -0500 Subject: [PATCH] Update file header comments and minor code cleanup --- .../AirgooLustrousCommanderController.cpp | 35 ++-- .../AirgooLustrousCommanderController.h | 29 ++-- ...irgooLustrousCommanderControllerDetect.cpp | 34 ++-- .../RGBController_AirgooLustrousCommander.cpp | 152 +++++++++--------- .../RGBController_AirgooLustrousCommander.h | 25 +-- 5 files changed, 138 insertions(+), 137 deletions(-) diff --git a/Controllers/AirgooLustrousCommanderController/AirgooLustrousCommanderController.cpp b/Controllers/AirgooLustrousCommanderController/AirgooLustrousCommanderController.cpp index 2367e6e66..bc3e604be 100644 --- a/Controllers/AirgooLustrousCommanderController/AirgooLustrousCommanderController.cpp +++ b/Controllers/AirgooLustrousCommanderController/AirgooLustrousCommanderController.cpp @@ -1,18 +1,18 @@ /*---------------------------------------------------------*\ -| AirgooLustrousCommanderController.cpp | +| AirgooLustrousCommanderController.cpp | | | -| Processing Code for Airgoo Lustrous Commander | -| Based on code by: | -| Jeff P (@jeffp1), 2020/02/07 | +| Driver for Airgoo Lustrous Commander | | | -| Zacahry G. | +| Zacahry Guinn 07 Feb 2022 | +| | +| This file is part of the OpenRGB project | +| SPDX-License-Identifier: GPL-2.0-only | \*---------------------------------------------------------*/ -#include "AirgooLustrousCommanderController.h" - #include #include #include +#include "AirgooLustrousCommanderController.h" using namespace std::chrono_literals; @@ -20,14 +20,11 @@ AirgooLustrousCommanderController::AirgooLustrousCommanderController(hid_device* { dev = dev_handle; location = path; - controller_ready = 0; /*-----------------------------------------------------*\ | Initialize controller | \*-----------------------------------------------------*/ InitController(); - - } AirgooLustrousCommanderController::~AirgooLustrousCommanderController() @@ -41,9 +38,9 @@ AirgooLustrousCommanderController::~AirgooLustrousCommanderController() void AirgooLustrousCommanderController::InitController() { unsigned char usb_buf[AIRGOO_LUSTROUS_COMMANDER_PACKET_SIZE]; - + /*-----------------------------------------------------*\ - | Initialize Controller | + | Send initialization packet | \*-----------------------------------------------------*/ memset(usb_buf, 0x00, sizeof(usb_buf)); @@ -56,7 +53,7 @@ void AirgooLustrousCommanderController::InitController() //expecting the device to return AA 55 01 hid_read(dev, usb_buf, AIRGOO_LUSTROUS_COMMANDER_PACKET_SIZE); - + usb_buf[0x00] = 0x00; usb_buf[0x01] = 0x03; usb_buf[0x02] = 0x55; @@ -67,9 +64,6 @@ void AirgooLustrousCommanderController::InitController() hid_write(dev, usb_buf, AIRGOO_LUSTROUS_COMMANDER_PACKET_SIZE); //device will send aa 55 00 back and it seems that we should be ready to send commands at this point - - controller_ready = 1; - } std::string AirgooLustrousCommanderController::GetLocationString() @@ -82,20 +76,21 @@ void AirgooLustrousCommanderController::SetMode(unsigned char mode) active_mode = mode; } - -void AirgooLustrousCommanderController::UpdateDevice( +void AirgooLustrousCommanderController::UpdateDevice + ( unsigned char mode, unsigned char red, unsigned char grn, unsigned char blu, - unsigned char speed) + unsigned char speed + ) { unsigned char usb_buf[65]; memset(usb_buf, 0x00, sizeof(usb_buf)); /*-----------------------------------------------------*\ - | Set up message packet with leading 00 | + | Set up message packet with leading 00 | \*-----------------------------------------------------*/ usb_buf[0x00] = 0x00; diff --git a/Controllers/AirgooLustrousCommanderController/AirgooLustrousCommanderController.h b/Controllers/AirgooLustrousCommanderController/AirgooLustrousCommanderController.h index 3e3c7acb2..1ec9d8d2c 100644 --- a/Controllers/AirgooLustrousCommanderController/AirgooLustrousCommanderController.h +++ b/Controllers/AirgooLustrousCommanderController/AirgooLustrousCommanderController.h @@ -1,23 +1,24 @@ /*---------------------------------------------------------*\ -| AirgooLustrousCommanderController.h | +| AirgooLustrousCommanderController.h | | | -| Definitions for Airgoo Lustrous Commander | -| Based on code by: | -| Jeff P (@jeffp1), 2020/02/07 | +| Driver for Airgoo Lustrous Commander | | | -| Zachary G | +| Zacahry Guinn 07 Feb 2022 | +| | +| This file is part of the OpenRGB project | +| SPDX-License-Identifier: GPL-2.0-only | \*---------------------------------------------------------*/ -#include "RGBController.h" -#include -#include -#include - #pragma once -#define AIRGOO_LUSTROUS_COMMANDER_PACKET_SIZE 65 -#define AIRGOO_LUSTROUS_COMMANDER_NUM_RGB_CHANNELS 2 -#define AIRGOO_LUSTROUS_COMMANDER_NUM_FAN_CHANNELS 4 +#include +#include +#include +#include "RGBController.h" + +#define AIRGOO_LUSTROUS_COMMANDER_PACKET_SIZE 65 +#define AIRGOO_LUSTROUS_COMMANDER_NUM_RGB_CHANNELS 2 +#define AIRGOO_LUSTROUS_COMMANDER_NUM_FAN_CHANNELS 4 class AirgooLustrousCommanderController { @@ -38,11 +39,9 @@ public: unsigned char speed ); - private: hid_device* dev; unsigned char active_mode; - std::atomic controller_ready; std::string location; void InitController(); diff --git a/Controllers/AirgooLustrousCommanderController/AirgooLustrousCommanderControllerDetect.cpp b/Controllers/AirgooLustrousCommanderController/AirgooLustrousCommanderControllerDetect.cpp index 6127e4f53..2491b1ef4 100644 --- a/Controllers/AirgooLustrousCommanderController/AirgooLustrousCommanderControllerDetect.cpp +++ b/Controllers/AirgooLustrousCommanderController/AirgooLustrousCommanderControllerDetect.cpp @@ -1,19 +1,30 @@ +/*---------------------------------------------------------*\ +| AirgooLustrousCommanderControllerDetect.cpp | +| | +| Detector for Airgoo Lustrous Commander | +| | +| Zacahry Guinn 07 Feb 2022 | +| | +| This file is part of the OpenRGB project | +| SPDX-License-Identifier: GPL-2.0-only | +\*---------------------------------------------------------*/ + +#include +#include #include "Detector.h" #include "AirgooLustrousCommanderController.h" #include "RGBController.h" #include "RGBController_AirgooLustrousCommander.h" -#include -#include -/*-----------------------------------------------------*\ -| Airgoo vendor ID | -\*-----------------------------------------------------*/ -#define AIRGOO_VID 0x1A86 +/*---------------------------------------------------------*\ +| Airgoo vendor ID | +\*---------------------------------------------------------*/ +#define AIRGOO_VID 0x1A86 -/*-----------------------------------------------------*\ -| Lustrous Commander product IDs | -\*-----------------------------------------------------*/ -#define AIRGOO_LUSTROUS_COMMANDER_PID 0xE6E0 +/*---------------------------------------------------------*\ +| Lustrous Commander product IDs | +\*---------------------------------------------------------*/ +#define AIRGOO_LUSTROUS_COMMANDER_PID 0xE6E0 /******************************************************************************************\ * * @@ -31,8 +42,7 @@ void DetectAirgooLustrousCommanderHIDControllers(hid_device_info* info, const st { AirgooLustrousCommanderController* controller = new AirgooLustrousCommanderController(dev, info->path); RGBController_AirgooLustrousCommander* rgb_controller = new RGBController_AirgooLustrousCommander(controller); - - rgb_controller->name = name; + rgb_controller->name = name; ResourceManager::get()->RegisterRGBController(rgb_controller); } diff --git a/Controllers/AirgooLustrousCommanderController/RGBController_AirgooLustrousCommander.cpp b/Controllers/AirgooLustrousCommanderController/RGBController_AirgooLustrousCommander.cpp index a9d4f67b4..b0aeecd4e 100644 --- a/Controllers/AirgooLustrousCommanderController/RGBController_AirgooLustrousCommander.cpp +++ b/Controllers/AirgooLustrousCommanderController/RGBController_AirgooLustrousCommander.cpp @@ -1,12 +1,13 @@ -/*-----------------------------------------*\ -| RGBController_AirgooLustrousCommander.cpp| -| | -| Generic RGB Interface for Airgoo | -| Based on code by: | -| Jeff P (@jeffp1), 2020/02/07 | -| | -| Zachary G | -\*-----------------------------------------*/ +/*---------------------------------------------------------*\ +| RGBController_AirgooLustrousCommander.cpp | +| | +| RGBController for Airgoo Lustrous Commander | +| | +| Zacahry Guinn 07 Feb 2022 | +| | +| This file is part of the OpenRGB project | +| SPDX-License-Identifier: GPL-2.0-only | +\*---------------------------------------------------------*/ #include "RGBController_AirgooLustrousCommander.h" @@ -19,74 +20,6 @@ RGBController_AirgooLustrousCommander::RGBController_AirgooLustrousCommander(Air type = DEVICE_TYPE_LEDSTRIP; location = controller->GetLocationString(); - SetupZones(); - SetupModes(); -} - -RGBController_AirgooLustrousCommander::~RGBController_AirgooLustrousCommander() -{ - delete controller; -} - -void RGBController_AirgooLustrousCommander::SetupZones() -{ - std::atomic first_run; - first_run = 0; - - if(zones.size() == 0) - { - first_run = 1; - } - - zones.resize(3); - - for(unsigned int i = 1; i < (AIRGOO_LUSTROUS_COMMANDER_NUM_RGB_CHANNELS + 1); i++) - { - zones[i].name = "RGB Port " + std::to_string(i); - zones[i].type = ZONE_TYPE_LINEAR; - zones[i].leds_min = 1; - zones[i].leds_max = 34; - - if(first_run) - { - zones[i].leds_count = 1; - } - } - - leds.clear(); - colors.clear(); - - for(unsigned int zone_idx = 0; zone_idx < zones.size(); zone_idx++) - { - for (unsigned int led_idx = 0; led_idx < zones[zone_idx].leds_count; led_idx++) - { - led new_led; - new_led.name = zones[zone_idx].name + " LED " + std::to_string(led_idx+1); - - leds.push_back(new_led); - } - } - - SetupColors(); -} - -void RGBController_AirgooLustrousCommander::ResizeZone(int zone, int new_size) -{ - if((size_t) zone >= zones.size()) - { - return; - } - - if(((unsigned int)new_size >= zones[zone].leds_min) && ((unsigned int)new_size <= zones[zone].leds_max)) - { - zones[zone].leds_count = new_size; - - SetupZones(); - } -} - -void RGBController_AirgooLustrousCommander::SetupModes() -{ mode Off; Off.name = "Off"; Off.value = 0; @@ -171,6 +104,69 @@ void RGBController_AirgooLustrousCommander::SetupModes() // ColorMeteor.color_mode = MODE_COLORS_MODE_SPECIFIC; // modes.push_back(ColorMeteor); + SetupZones(); +} + +RGBController_AirgooLustrousCommander::~RGBController_AirgooLustrousCommander() +{ + delete controller; +} + +void RGBController_AirgooLustrousCommander::SetupZones() +{ + std::atomic first_run; + first_run = 0; + + if(zones.size() == 0) + { + first_run = 1; + } + + zones.resize(3); + + for(unsigned int i = 1; i < (AIRGOO_LUSTROUS_COMMANDER_NUM_RGB_CHANNELS + 1); i++) + { + zones[i].name = "RGB Port " + std::to_string(i); + zones[i].type = ZONE_TYPE_LINEAR; + zones[i].leds_min = 0; + zones[i].leds_max = 34; + + if(first_run) + { + zones[i].leds_count = 0; + } + } + + leds.clear(); + colors.clear(); + + for(unsigned int zone_idx = 0; zone_idx < zones.size(); zone_idx++) + { + for (unsigned int led_idx = 0; led_idx < zones[zone_idx].leds_count; led_idx++) + { + led new_led; + new_led.name = zones[zone_idx].name + " LED " + std::to_string(led_idx+1); + + leds.push_back(new_led); + } + } + + SetupColors(); +} + +void RGBController_AirgooLustrousCommander::ResizeZone(int zone, int new_size) +{ + if((size_t) zone >= zones.size()) + { + return; + } + + if(((unsigned int)new_size >= zones[zone].leds_min) && ((unsigned int)new_size <= zones[zone].leds_max)) + { + zones[zone].leds_count = new_size; + + SetupZones(); + } } void RGBController_AirgooLustrousCommander::DeviceUpdateLEDs() @@ -205,4 +201,4 @@ void RGBController_AirgooLustrousCommander::DeviceUpdateMode() blu = RGBGetBValue(modes[active_mode].colors[0]); } controller->UpdateDevice(modes[active_mode].value, red, grn, blu, modes[active_mode].speed); -} \ No newline at end of file +} diff --git a/Controllers/AirgooLustrousCommanderController/RGBController_AirgooLustrousCommander.h b/Controllers/AirgooLustrousCommanderController/RGBController_AirgooLustrousCommander.h index c3e2e2bcf..230ef2368 100644 --- a/Controllers/AirgooLustrousCommanderController/RGBController_AirgooLustrousCommander.h +++ b/Controllers/AirgooLustrousCommanderController/RGBController_AirgooLustrousCommander.h @@ -1,15 +1,16 @@ -/*-----------------------------------------*\ -| RGBController_AirgooLustrousCommander.h | -| | -| Generic RGB Interface for Airgoo | -| Lustrous Commander | -| Based on code by: | -| Jeff P (@jeffp1), 2020/02/07 | -| | -| Zachary G | -\*-----------------------------------------*/ +/*---------------------------------------------------------*\ +| RGBController_AirgooLustrousCommander.cpp | +| | +| RGBController for Airgoo Lustrous Commander | +| | +| Zacahry Guinn 07 Feb 2022 | +| | +| This file is part of the OpenRGB project | +| SPDX-License-Identifier: GPL-2.0-only | +\*---------------------------------------------------------*/ #pragma once + #include "RGBController.h" #include "AirgooLustrousCommanderController.h" @@ -21,8 +22,8 @@ public: void SetupZones(); void ResizeZone(int zone, int new_size); + void DeviceUpdateLEDs(); - void SetupModes(); void UpdateZoneLEDs(int zone); void UpdateSingleLED(int led); @@ -30,6 +31,6 @@ public: void DeviceUpdateMode(); private: - AirgooLustrousCommanderController* controller; + AirgooLustrousCommanderController* controller; std::vector fanleds{0}; };