Code cleanup round 4

This commit is contained in:
Adam Honse 2022-01-18 20:20:22 -06:00
parent c09e4c9c92
commit c07f43c8d5
20 changed files with 988 additions and 992 deletions

View file

@ -70,10 +70,7 @@ bool TestForGalaxGPUController(i2c_smbus_interface* bus, unsigned char address)
void DetectGalaxGPUControllers(std::vector<i2c_smbus_interface*> &busses)
{
GalaxGPUController* new_GalaxGPU;
RGBController_GalaxGPU* new_controller;
for (unsigned int bus = 0; bus < busses.size(); bus++)
for(unsigned int bus = 0; bus < busses.size(); bus++)
{
// Check for GALAX controller at 0x23
for(unsigned int dev_idx = 0; dev_idx < GPU_NUM_DEVICES; dev_idx++)
@ -84,12 +81,14 @@ void DetectGalaxGPUControllers(std::vector<i2c_smbus_interface*> &busses)
busses[bus]->pci_subsystem_device == device_list[dev_idx].pci_subsystem_device)
{
LOG_DEBUG(GPU_DETECT_MESSAGE, "Galax GPU", bus, device_list[dev_idx].pci_device, device_list[dev_idx].pci_subsystem_device, device_list[dev_idx].name );
if (TestForGalaxGPUController(busses[bus], 0x23))
if(TestForGalaxGPUController(busses[bus], 0x23))
{
new_GalaxGPU = new GalaxGPUController(busses[bus], 0x23);
new_controller = new RGBController_GalaxGPU(new_GalaxGPU);
new_controller->name = device_list[dev_idx].name;
ResourceManager::get()->RegisterRGBController(new_controller);
GalaxGPUController* controller = new GalaxGPUController(busses[bus], 0x23);
RGBController_GalaxGPU* rgb_controller = new RGBController_GalaxGPU(controller);
rgb_controller->name = device_list[dev_idx].name;
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
}
}

View file

@ -1,171 +1,170 @@
/*-----------------------------------------*\
| RGBController_GalaxGPU.cpp |
| |
| Driver for Galax / KFA2 RGB on GPUs |
| |
| Niels Westphal (crashniels) 12.07.2020 |
\*-----------------------------------------*/
#include "RGBController_GalaxGPU.h"
int RGBController_GalaxGPU::GetDeviceMode()
{
int modereg1 = galax_gpu->GalaxGPURegisterRead(GALAX_MODE_REGISTER_1);
int modereg2 = galax_gpu->GalaxGPURegisterRead(GALAX_MODE_REGISTER_2);
if (modereg1 == GALAX_MODE_STATIC_VALUE_1 && modereg2 == GALAX_MODE_STATIC_VALUE_2)
{
active_mode = 1;
modes[active_mode].color_mode = MODE_COLORS_PER_LED;
}
if (modereg1 == GALAX_MODE_BREATHING_VALUE_1 && modereg2 == GALAX_MODE_BREATHING_VALUE_2)
{
active_mode = 2;
modes[active_mode].color_mode = MODE_COLORS_PER_LED;
}
if (modereg1 == GALAX_MODE_RAINBOW_VALUE_1 && modereg2 == GALAX_MODE_RAINBOW_VALUE_2)
{
active_mode = 3;
modes[active_mode].color_mode = MODE_COLORS_NONE;
}
if (modereg1 == GALAX_MODE_CYCLE_BREATHING_VALUE_1 && modereg2 == GALAX_MODE_CYCLE_BREATHING_VALUE_2)
{
active_mode = 4;
modes[active_mode].color_mode = MODE_COLORS_NONE;
}
return(active_mode);
}
RGBController_GalaxGPU::RGBController_GalaxGPU(GalaxGPUController * galax_gpu_ptr)
{
galax_gpu = galax_gpu_ptr;
name = galax_gpu->GetDeviceName();
vendor = "GALAX";
type = DEVICE_TYPE_GPU;
description = "GALAX / KFA2 RTX GPU";
version = "1.0";
location = galax_gpu->GetDeviceLocation();
mode Direct;
Direct.name = "Direct";
Direct.value = 1;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Direct.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Direct);
mode Breathing;
Breathing.name = "Breathing";
Breathing.value = 2;
Breathing.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Breathing.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Breathing);
mode Rainbow;
Rainbow.name = "Rainbow";
Rainbow.value = 3;
Rainbow.flags = 0;
Rainbow.color_mode = MODE_COLORS_NONE;
modes.push_back(Rainbow);
mode Cycle_Breathing;
Cycle_Breathing.name = "Cycle Breathing";
Cycle_Breathing.value = 4;
Cycle_Breathing.flags = 0;
Cycle_Breathing.color_mode = MODE_COLORS_NONE;
modes.push_back(Cycle_Breathing);
SetupZones();
active_mode = GetDeviceMode();
}
RGBController_GalaxGPU::~RGBController_GalaxGPU()
{
delete galax_gpu;
}
void RGBController_GalaxGPU::SetupZones()
{
/*---------------------------------------------------------*\
| Set up zone |
\*---------------------------------------------------------*/
zone galax_gpu_zone;
galax_gpu_zone.name = "GPU";
galax_gpu_zone.type = ZONE_TYPE_SINGLE;
galax_gpu_zone.leds_min = 1;
galax_gpu_zone.leds_max = 1;
galax_gpu_zone.leds_count = 1;
galax_gpu_zone.matrix_map = NULL;
zones.push_back(galax_gpu_zone);
/*---------------------------------------------------------*\
| Set up LED |
\*---------------------------------------------------------*/
led galax_gpu_led;
galax_gpu_led.name = "GPU";
leds.push_back(galax_gpu_led);
SetupColors();
/*---------------------------------------------------------*\
| Initialize color |
\*---------------------------------------------------------*/
unsigned char red = galax_gpu->GetLEDRed();
unsigned char grn = galax_gpu->GetLEDGreen();
unsigned char blu = galax_gpu->GetLEDBlue();
colors[0] = ToRGBColor(red, grn, blu);
}
void RGBController_GalaxGPU::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_GalaxGPU::DeviceUpdateLEDs()
{
for(std::size_t led = 0; led < colors.size(); led++)
{
unsigned char red = RGBGetRValue(colors[led]);
unsigned char grn = RGBGetGValue(colors[led]);
unsigned char blu = RGBGetBValue(colors[led]);
if (GetMode() == 1)
{
galax_gpu->SetLEDColorsDirect(red, grn, blu);
}
else
{
galax_gpu->SetLEDColorsEffect(red, grn, blu);
}
}
}
void RGBController_GalaxGPU::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_GalaxGPU::UpdateSingleLED(int /*led*/)
{
DeviceUpdateLEDs();
}
void RGBController_GalaxGPU::SetCustomMode()
{
active_mode = 1;
}
void RGBController_GalaxGPU::DeviceUpdateMode()
{
int new_mode = modes[active_mode].value;
galax_gpu->SetMode(new_mode);
}
/*-----------------------------------------*\
| RGBController_GalaxGPU.cpp |
| |
| Driver for Galax / KFA2 RGB on GPUs |
| |
| Niels Westphal (crashniels) 12.07.2020 |
\*-----------------------------------------*/
#include "RGBController_GalaxGPU.h"
int RGBController_GalaxGPU::GetDeviceMode()
{
int modereg1 = controller->GalaxGPURegisterRead(GALAX_MODE_REGISTER_1);
int modereg2 = controller->GalaxGPURegisterRead(GALAX_MODE_REGISTER_2);
if(modereg1 == GALAX_MODE_STATIC_VALUE_1 && modereg2 == GALAX_MODE_STATIC_VALUE_2)
{
active_mode = 1;
modes[active_mode].color_mode = MODE_COLORS_PER_LED;
}
if(modereg1 == GALAX_MODE_BREATHING_VALUE_1 && modereg2 == GALAX_MODE_BREATHING_VALUE_2)
{
active_mode = 2;
modes[active_mode].color_mode = MODE_COLORS_PER_LED;
}
if(modereg1 == GALAX_MODE_RAINBOW_VALUE_1 && modereg2 == GALAX_MODE_RAINBOW_VALUE_2)
{
active_mode = 3;
modes[active_mode].color_mode = MODE_COLORS_NONE;
}
if(modereg1 == GALAX_MODE_CYCLE_BREATHING_VALUE_1 && modereg2 == GALAX_MODE_CYCLE_BREATHING_VALUE_2)
{
active_mode = 4;
modes[active_mode].color_mode = MODE_COLORS_NONE;
}
return(active_mode);
}
RGBController_GalaxGPU::RGBController_GalaxGPU(GalaxGPUController* controller_ptr)
{
controller = controller_ptr;
name = controller->GetDeviceName();
vendor = "GALAX";
type = DEVICE_TYPE_GPU;
description = "GALAX / KFA2 RTX GPU";
location = controller->GetDeviceLocation();
mode Direct;
Direct.name = "Direct";
Direct.value = 1;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Direct.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Direct);
mode Breathing;
Breathing.name = "Breathing";
Breathing.value = 2;
Breathing.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Breathing.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Breathing);
mode Rainbow;
Rainbow.name = "Rainbow";
Rainbow.value = 3;
Rainbow.flags = 0;
Rainbow.color_mode = MODE_COLORS_NONE;
modes.push_back(Rainbow);
mode Cycle_Breathing;
Cycle_Breathing.name = "Cycle Breathing";
Cycle_Breathing.value = 4;
Cycle_Breathing.flags = 0;
Cycle_Breathing.color_mode = MODE_COLORS_NONE;
modes.push_back(Cycle_Breathing);
SetupZones();
active_mode = GetDeviceMode();
}
RGBController_GalaxGPU::~RGBController_GalaxGPU()
{
delete controller;
}
void RGBController_GalaxGPU::SetupZones()
{
/*---------------------------------------------------------*\
| Set up zone |
\*---------------------------------------------------------*/
zone galax_gpu_zone;
galax_gpu_zone.name = "GPU";
galax_gpu_zone.type = ZONE_TYPE_SINGLE;
galax_gpu_zone.leds_min = 1;
galax_gpu_zone.leds_max = 1;
galax_gpu_zone.leds_count = 1;
galax_gpu_zone.matrix_map = NULL;
zones.push_back(galax_gpu_zone);
/*---------------------------------------------------------*\
| Set up LED |
\*---------------------------------------------------------*/
led galax_gpu_led;
galax_gpu_led.name = "GPU";
leds.push_back(galax_gpu_led);
SetupColors();
/*---------------------------------------------------------*\
| Initialize color |
\*---------------------------------------------------------*/
unsigned char red = controller->GetLEDRed();
unsigned char grn = controller->GetLEDGreen();
unsigned char blu = controller->GetLEDBlue();
colors[0] = ToRGBColor(red, grn, blu);
}
void RGBController_GalaxGPU::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_GalaxGPU::DeviceUpdateLEDs()
{
for(std::size_t led = 0; led < colors.size(); led++)
{
unsigned char red = RGBGetRValue(colors[led]);
unsigned char grn = RGBGetGValue(colors[led]);
unsigned char blu = RGBGetBValue(colors[led]);
if(GetMode() == 1)
{
controller->SetLEDColorsDirect(red, grn, blu);
}
else
{
controller->SetLEDColorsEffect(red, grn, blu);
}
}
}
void RGBController_GalaxGPU::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_GalaxGPU::UpdateSingleLED(int /*led*/)
{
DeviceUpdateLEDs();
}
void RGBController_GalaxGPU::SetCustomMode()
{
active_mode = 1;
}
void RGBController_GalaxGPU::DeviceUpdateMode()
{
int new_mode = modes[active_mode].value;
controller->SetMode(new_mode);
}

View file

@ -1,35 +1,35 @@
/*-----------------------------------------*\
| RGBController_GalaxGPU.h |
| |
| Driver for Galax / KFA2 RGB on GPUs |
| |
| Niels Westphal (crashniels) 12.07.2020 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "GalaxGPUController.h"
class RGBController_GalaxGPU : public RGBController
{
public:
RGBController_GalaxGPU(GalaxGPUController* galax_gpu_ptr);
~RGBController_GalaxGPU();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void SetCustomMode();
void DeviceUpdateMode();
private:
GalaxGPUController* galax_gpu;
int GetDeviceMode();
};
/*-----------------------------------------*\
| RGBController_GalaxGPU.h |
| |
| Driver for Galax / KFA2 RGB on GPUs |
| |
| Niels Westphal (crashniels) 12.07.2020 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "GalaxGPUController.h"
class RGBController_GalaxGPU : public RGBController
{
public:
RGBController_GalaxGPU(GalaxGPUController* controller_ptr);
~RGBController_GalaxGPU();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void SetCustomMode();
void DeviceUpdateMode();
private:
GalaxGPUController* controller;
int GetDeviceMode();
};