Publish LumaOps source
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| LinuxLEDControllerDetect_Linux.cpp |
|
||||
| |
|
||||
| Detector for Linux sysfs LEDs |
|
||||
| |
|
||||
| Adam Honse (calcprogrammer1@gmail.com) 25 Sep 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <string>
|
||||
#include "Detector.h"
|
||||
#include "RGBController_LinuxLED_Linux.h"
|
||||
#include "SettingsManager.h"
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectLinuxLEDControllers *
|
||||
* *
|
||||
* Detect devices supported by the LinuxLED driver *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectLinuxLEDControllers()
|
||||
{
|
||||
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;
|
||||
std::string rgb_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"];
|
||||
}
|
||||
|
||||
if(linux_led_settings["devices"][device_idx].contains("rgb_path"))
|
||||
{
|
||||
rgb_path = linux_led_settings["devices"][device_idx]["rgb_path"];
|
||||
}
|
||||
|
||||
LinuxLEDController* controller = new LinuxLEDController(name);
|
||||
controller->OpenRedPath(red_path);
|
||||
controller->OpenGreenPath(green_path);
|
||||
controller->OpenBluePath(blue_path);
|
||||
controller->OpenRgbPath(rgb_path);
|
||||
|
||||
RGBController_LinuxLED* rgb_controller = new RGBController_LinuxLED(controller);
|
||||
|
||||
ResourceManager::get()->RegisterRGBController(rgb_controller);
|
||||
}
|
||||
}
|
||||
|
||||
} /* DetectLinuxLEDControllers() */
|
||||
|
||||
REGISTER_DETECTOR("Linux LED", DetectLinuxLEDControllers);
|
||||
@@ -0,0 +1,119 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| LinuxLEDController_Linux.cpp |
|
||||
| |
|
||||
| Driver for Linux sysfs LEDs |
|
||||
| |
|
||||
| Adam Honse (calcprogrammer1@gmail.com) 25 Sep 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "LinuxLEDController_Linux.h"
|
||||
|
||||
LinuxLEDController::LinuxLEDController(std::string dev_name)
|
||||
{
|
||||
name = dev_name;
|
||||
}
|
||||
|
||||
LinuxLEDController::~LinuxLEDController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string LinuxLEDController::GetName()
|
||||
{
|
||||
return(name);
|
||||
}
|
||||
|
||||
std::string LinuxLEDController::GetRedPath()
|
||||
{
|
||||
return(led_r_path);
|
||||
}
|
||||
|
||||
std::string LinuxLEDController::GetGreenPath()
|
||||
{
|
||||
return(led_g_path);
|
||||
}
|
||||
|
||||
std::string LinuxLEDController::GetBluePath()
|
||||
{
|
||||
return(led_b_path);
|
||||
}
|
||||
|
||||
std::string LinuxLEDController::GetRgbPath()
|
||||
{
|
||||
return(led_rgb_path);
|
||||
}
|
||||
|
||||
void LinuxLEDController::OpenRedPath(std::string red_path)
|
||||
{
|
||||
led_r_path = red_path;
|
||||
led_r_brightness.open(led_r_path + "brightness");
|
||||
}
|
||||
|
||||
void LinuxLEDController::OpenGreenPath(std::string green_path)
|
||||
{
|
||||
led_g_path = green_path;
|
||||
led_g_brightness.open(led_g_path + "brightness");
|
||||
}
|
||||
|
||||
void LinuxLEDController::OpenBluePath(std::string blue_path)
|
||||
{
|
||||
led_b_path = blue_path;
|
||||
led_b_brightness.open(led_b_path + "brightness");
|
||||
}
|
||||
|
||||
void LinuxLEDController::OpenRgbPath(std::string rgb_path)
|
||||
{
|
||||
led_rgb_path = rgb_path;
|
||||
led_rgb_brightness.open(led_rgb_path + "brightness");
|
||||
led_rgb_color.open(led_rgb_path + "multi_intensity");
|
||||
}
|
||||
|
||||
void LinuxLEDController::SetRGB(unsigned char red, unsigned char grn, unsigned char blu)
|
||||
{
|
||||
std::string brightness_str;
|
||||
|
||||
if(led_rgb_path.empty())
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| My phone LED that I tested this on shuts down if |
|
||||
| you set zero |
|
||||
\*-------------------------------------------------*/
|
||||
if(red == 0) red = 1;
|
||||
if(grn == 0) grn = 1;
|
||||
if(blu == 0) blu = 1;
|
||||
|
||||
brightness_str = std::to_string((unsigned int)red);
|
||||
|
||||
led_r_brightness.write(brightness_str.c_str(), brightness_str.length());
|
||||
led_r_brightness.flush();
|
||||
|
||||
brightness_str = std::to_string((unsigned int)grn);
|
||||
|
||||
led_g_brightness.write(brightness_str.c_str(), brightness_str.length());
|
||||
led_g_brightness.flush();
|
||||
|
||||
brightness_str = std::to_string((unsigned int)blu);
|
||||
|
||||
led_b_brightness.write(brightness_str.c_str(), brightness_str.length());
|
||||
led_b_brightness.flush();
|
||||
}
|
||||
else
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| For the led_classdev_mc brightness just applies a |
|
||||
| coefficient to the multi_intensity. Set brightness|
|
||||
| to maximum and use the RGB values directly |
|
||||
| instead. |
|
||||
\*-------------------------------------------------*/
|
||||
brightness_str = std::to_string((unsigned int)255);
|
||||
led_rgb_brightness.write(brightness_str.c_str(), brightness_str.length());
|
||||
led_rgb_brightness.flush();
|
||||
|
||||
brightness_str = std::to_string((unsigned int)red) + " " + std::to_string((unsigned int)grn) + " " + std::to_string((unsigned int)blu);
|
||||
led_rgb_color.write(brightness_str.c_str(), brightness_str.length());
|
||||
led_rgb_color.flush();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| LinuxLEDController_Linux.h |
|
||||
| |
|
||||
| Driver for Linux sysfs LEDs |
|
||||
| |
|
||||
| Adam Honse (calcprogrammer1@gmail.com) 25 Sep 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
|
||||
class LinuxLEDController
|
||||
{
|
||||
public:
|
||||
LinuxLEDController(std::string dev_name);
|
||||
~LinuxLEDController();
|
||||
|
||||
std::string GetName();
|
||||
|
||||
std::string GetRedPath();
|
||||
std::string GetBluePath();
|
||||
std::string GetGreenPath();
|
||||
std::string GetRgbPath();
|
||||
|
||||
void OpenRedPath(std::string red_path);
|
||||
void OpenGreenPath(std::string green_path);
|
||||
void OpenBluePath(std::string blue_path);
|
||||
void OpenRgbPath(std::string rgb_path);
|
||||
|
||||
void SetRGB(unsigned char red, unsigned char grn, unsigned char blu);
|
||||
|
||||
private:
|
||||
std::string led_r_path;
|
||||
std::string led_g_path;
|
||||
std::string led_b_path;
|
||||
std::string led_rgb_path;
|
||||
std::ofstream led_r_brightness;
|
||||
std::ofstream led_g_brightness;
|
||||
std::ofstream led_b_brightness;
|
||||
std::ofstream led_rgb_brightness;
|
||||
std::ofstream led_rgb_color;
|
||||
std::string name;
|
||||
};
|
||||
@@ -0,0 +1,107 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_LinuxLED.cpp |
|
||||
| |
|
||||
| RGBController for Linux sysfs LEDs |
|
||||
| |
|
||||
| Adam Honse (calcprogrammer1@gmail.com) 25 Sep 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "RGBController_LinuxLED_Linux.h"
|
||||
|
||||
/**------------------------------------------------------------------*\
|
||||
@name Dummy
|
||||
@category LEDStrip
|
||||
@type File Stream
|
||||
@save :x:
|
||||
@direct :white_check_mark:
|
||||
@effects :x:
|
||||
@detectors DetectLinuxLEDControllers
|
||||
@comment
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
RGBController_LinuxLED::RGBController_LinuxLED(LinuxLEDController* controller_ptr)
|
||||
{
|
||||
controller = controller_ptr;
|
||||
|
||||
name = controller->GetName();
|
||||
type = DEVICE_TYPE_LEDSTRIP;
|
||||
description = "Linux Sysfs LED Device";
|
||||
|
||||
if(controller->GetRgbPath().empty())
|
||||
{
|
||||
location = "R: " + controller->GetRedPath() + "\r\n" +
|
||||
"G: " + controller->GetGreenPath() + "\r\n" +
|
||||
"B: " + controller->GetBluePath();
|
||||
}
|
||||
else
|
||||
{
|
||||
location = controller->GetRgbPath();
|
||||
}
|
||||
|
||||
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::DeviceUpdateMode()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_LinuxLED.h |
|
||||
| |
|
||||
| RGBController for Linux sysfs LEDs |
|
||||
| |
|
||||
| Adam Honse (calcprogrammer1@gmail.com) 25 Sep 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "LinuxLEDController_Linux.h"
|
||||
|
||||
class RGBController_LinuxLED : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_LinuxLED(LinuxLEDController* controller_ptr);
|
||||
~RGBController_LinuxLED();
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void DeviceUpdateMode();
|
||||
|
||||
private:
|
||||
LinuxLEDController* controller;
|
||||
};
|
||||
Reference in New Issue
Block a user