Code cleanup round 6

This commit is contained in:
Adam Honse 2022-01-19 23:08:09 -06:00
parent f11f242ded
commit f1ed2abe53
46 changed files with 2616 additions and 2584 deletions

View file

@ -1,77 +1,76 @@
#include "Detector.h"
#include "LinuxLEDController.h"
#include "RGBController.h"
#include "RGBController_LinuxLED.h"
#include "SettingsManager.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string>
/******************************************************************************************\
* *
* DetectLinuxLEDControllers *
* *
* Detect devices supported by the LinuxLED driver *
* *
\******************************************************************************************/
void DetectLinuxLEDControllers(std::vector<RGBController*> &rgb_controllers)
{
LinuxLEDController* new_controller;
RGBController_LinuxLED* new_rgbcontroller;
json linux_led_settings;
/*-------------------------------------------------*\
| Get Linux LED settings from settings manager |
\*-------------------------------------------------*/
linux_led_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("LinuxLEDDevices");
/*-------------------------------------------------*\
| If the LinuxLED settings contains devices, process|
\*-------------------------------------------------*/
if(linux_led_settings.contains("devices"))
{
for(unsigned int device_idx = 0; device_idx < linux_led_settings["devices"].size(); device_idx++)
{
std::string name;
std::string red_path;
std::string green_path;
std::string blue_path;
if(linux_led_settings["devices"][device_idx].contains("name"))
{
name = linux_led_settings["devices"][device_idx]["name"];
}
if(linux_led_settings["devices"][device_idx].contains("red_path"))
{
red_path = linux_led_settings["devices"][device_idx]["red_path"];
}
if(linux_led_settings["devices"][device_idx].contains("green_path"))
{
green_path = linux_led_settings["devices"][device_idx]["green_path"];
}
if(linux_led_settings["devices"][device_idx].contains("blue_path"))
{
blue_path = linux_led_settings["devices"][device_idx]["blue_path"];
}
new_controller = new LinuxLEDController();
new_controller->OpenRedPath(red_path);
new_controller->OpenGreenPath(green_path);
new_controller->OpenBluePath(blue_path);
new_rgbcontroller = new RGBController_LinuxLED(new_controller);
new_rgbcontroller->name = name;
rgb_controllers.push_back(new_rgbcontroller);
}
}
} /* DetectLinuxLEDControllers() */
REGISTER_DETECTOR("Linux LED", DetectLinuxLEDControllers);
#include "Detector.h"
#include "LinuxLEDController.h"
#include "RGBController.h"
#include "RGBController_LinuxLED.h"
#include "SettingsManager.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string>
/******************************************************************************************\
* *
* DetectLinuxLEDControllers *
* *
* Detect devices supported by the LinuxLED driver *
* *
\******************************************************************************************/
void DetectLinuxLEDControllers(std::vector<RGBController*> &rgb_controllers)
{
json linux_led_settings;
/*-------------------------------------------------*\
| Get Linux LED settings from settings manager |
\*-------------------------------------------------*/
linux_led_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("LinuxLEDDevices");
/*-------------------------------------------------*\
| If the LinuxLED settings contains devices, process|
\*-------------------------------------------------*/
if(linux_led_settings.contains("devices"))
{
for(unsigned int device_idx = 0; device_idx < linux_led_settings["devices"].size(); device_idx++)
{
std::string name;
std::string red_path;
std::string green_path;
std::string blue_path;
if(linux_led_settings["devices"][device_idx].contains("name"))
{
name = linux_led_settings["devices"][device_idx]["name"];
}
if(linux_led_settings["devices"][device_idx].contains("red_path"))
{
red_path = linux_led_settings["devices"][device_idx]["red_path"];
}
if(linux_led_settings["devices"][device_idx].contains("green_path"))
{
green_path = linux_led_settings["devices"][device_idx]["green_path"];
}
if(linux_led_settings["devices"][device_idx].contains("blue_path"))
{
blue_path = linux_led_settings["devices"][device_idx]["blue_path"];
}
LinuxLEDController* controller = new LinuxLEDController();
controller->OpenRedPath(red_path);
controller->OpenGreenPath(green_path);
controller->OpenBluePath(blue_path);
RGBController_LinuxLED* rgb_controller = new RGBController_LinuxLED(controller);
rgb_controller->name = name;
rgb_controllers.push_back(rgb_controller);
}
}
} /* DetectLinuxLEDControllers() */
REGISTER_DETECTOR("Linux LED", DetectLinuxLEDControllers);

View file

@ -1,91 +1,91 @@
/*-----------------------------------------*\
| RGBController_LinuxLED.cpp |
| |
| Generic RGB Interface for Linux LED |
| |
| Adam Honse (CalcProgrammer1) 9/25/2020 |
\*-----------------------------------------*/
#include "RGBController_LinuxLED.h"
RGBController_LinuxLED::RGBController_LinuxLED(LinuxLEDController* controller_ptr)
{
controller = controller_ptr;
name = "Linux LED";
type = DEVICE_TYPE_LEDSTRIP;
description = "Linux Sysfs LED Device";
location = "R: " + controller->GetRedPath() + "\r\n" +
"G: " + controller->GetGreenPath() + "\r\n" +
"B: " + controller->GetBluePath();
mode Direct;
Direct.name = "Direct";
Direct.value = 0;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Direct.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Direct);
SetupZones();
}
RGBController_LinuxLED::~RGBController_LinuxLED()
{
delete controller;
}
void RGBController_LinuxLED::SetupZones()
{
zone led_zone;
led_zone.name = "RGB Light";
led_zone.type = ZONE_TYPE_SINGLE;
led_zone.leds_min = 1;
led_zone.leds_max = 1;
led_zone.leds_count = 1;
led_zone.matrix_map = NULL;
zones.push_back(led_zone);
led new_led;
new_led.name = "RGB Light";
leds.push_back(new_led);
SetupColors();
}
void RGBController_LinuxLED::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_LinuxLED::DeviceUpdateLEDs()
{
unsigned char red = RGBGetRValue(colors[0]);
unsigned char grn = RGBGetGValue(colors[0]);
unsigned char blu = RGBGetBValue(colors[0]);
controller->SetRGB(red, grn, blu);
}
void RGBController_LinuxLED::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_LinuxLED::UpdateSingleLED(int /*led*/)
{
DeviceUpdateLEDs();
}
void RGBController_LinuxLED::SetCustomMode()
{
}
void RGBController_LinuxLED::DeviceUpdateMode()
{
}
/*-----------------------------------------*\
| RGBController_LinuxLED.cpp |
| |
| Generic RGB Interface for Linux LED |
| |
| Adam Honse (CalcProgrammer1) 9/25/2020 |
\*-----------------------------------------*/
#include "RGBController_LinuxLED.h"
RGBController_LinuxLED::RGBController_LinuxLED(LinuxLEDController* controller_ptr)
{
controller = controller_ptr;
name = "Linux LED";
type = DEVICE_TYPE_LEDSTRIP;
description = "Linux Sysfs LED Device";
location = "R: " + controller->GetRedPath() + "\r\n" +
"G: " + controller->GetGreenPath() + "\r\n" +
"B: " + controller->GetBluePath();
mode Direct;
Direct.name = "Direct";
Direct.value = 0;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Direct.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Direct);
SetupZones();
}
RGBController_LinuxLED::~RGBController_LinuxLED()
{
delete controller;
}
void RGBController_LinuxLED::SetupZones()
{
zone led_zone;
led_zone.name = "RGB Light";
led_zone.type = ZONE_TYPE_SINGLE;
led_zone.leds_min = 1;
led_zone.leds_max = 1;
led_zone.leds_count = 1;
led_zone.matrix_map = NULL;
zones.push_back(led_zone);
led new_led;
new_led.name = "RGB Light";
leds.push_back(new_led);
SetupColors();
}
void RGBController_LinuxLED::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_LinuxLED::DeviceUpdateLEDs()
{
unsigned char red = RGBGetRValue(colors[0]);
unsigned char grn = RGBGetGValue(colors[0]);
unsigned char blu = RGBGetBValue(colors[0]);
controller->SetRGB(red, grn, blu);
}
void RGBController_LinuxLED::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_LinuxLED::UpdateSingleLED(int /*led*/)
{
DeviceUpdateLEDs();
}
void RGBController_LinuxLED::SetCustomMode()
{
}
void RGBController_LinuxLED::DeviceUpdateMode()
{
}