diff --git a/Controllers/LinuxLEDController/LinuxLEDController.cpp b/Controllers/LinuxLEDController/LinuxLEDController.cpp new file mode 100644 index 00000000..b17ec17b --- /dev/null +++ b/Controllers/LinuxLEDController/LinuxLEDController.cpp @@ -0,0 +1,71 @@ +#include "LinuxLEDController.h" + +LinuxLEDController::LinuxLEDController() +{ + +} + +LinuxLEDController::~LinuxLEDController() +{ + +} + +std::string LinuxLEDController::GetRedPath() +{ + return(led_r_path); +} + +std::string LinuxLEDController::GetGreenPath() +{ + return(led_g_path); +} + +std::string LinuxLEDController::GetBluePath() +{ + return(led_b_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::SetRGB(unsigned char red, unsigned char grn, unsigned char blu) +{ + std::string brightness_str; + + /*-------------------------------------------------------------*\ + | 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(); +} diff --git a/Controllers/LinuxLEDController/LinuxLEDController.h b/Controllers/LinuxLEDController/LinuxLEDController.h new file mode 100644 index 00000000..53bdd7b7 --- /dev/null +++ b/Controllers/LinuxLEDController/LinuxLEDController.h @@ -0,0 +1,28 @@ + +#pragma once + +#include + +class LinuxLEDController +{ +public: + LinuxLEDController(); + ~LinuxLEDController(); + + std::string GetRedPath(); + std::string GetBluePath(); + std::string GetGreenPath(); + + void OpenRedPath(std::string red_path); + void OpenGreenPath(std::string green_path); + void OpenBluePath(std::string blue_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::ofstream led_r_brightness; + std::ofstream led_g_brightness; + std::ofstream led_b_brightness; +}; diff --git a/Controllers/LinuxLEDController/LinuxLEDControllerDetect.cpp b/Controllers/LinuxLEDController/LinuxLEDControllerDetect.cpp new file mode 100644 index 00000000..008202cd --- /dev/null +++ b/Controllers/LinuxLEDController/LinuxLEDControllerDetect.cpp @@ -0,0 +1,109 @@ +#include "Detector.h" +#include "LinuxLEDController.h" +#include "RGBController.h" +#include "RGBController_LinuxLED.h" +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifndef WIN32 +#include +#include +#else +#include +#endif + +#ifndef WIN32 +#define LPSTR char * +#define strtok_s strtok_r +#endif + + +/******************************************************************************************\ +* * +* DetectLinuxLEDControllers * +* * +* Detect devices supported by the LinuxLED driver * +* * +\******************************************************************************************/ + +void DetectLinuxLEDControllers(std::vector &rgb_controllers) +{ + std::ifstream infile; + char arg1[64]; + bool new_device = false; + std::string new_name; + + //Open settings file + infile.open("linuxled.txt"); + + LinuxLEDController* new_controller; + RGBController_LinuxLED* new_rgbcontroller; + + if (infile.good()) + { + for (std::string line; std::getline(infile, line); ) + { + if (new_device) + { + new_name = line; + new_device = false; + continue; + } + + if (line == "") + { + continue; + } + + if ((line[0] != ';') && (line[0] != '#') && (line[0] != '/')) + { + char * argument; + char * value; + + value = (char *)line.c_str(); + + argument = strtok_s(value, "=", &value); + + //Strip off new line characters if present + argument = strtok(argument, "\r\n"); + value = strtok(value, "\r\n"); + + if(argument) + { + if (strcmp(argument, "linux_led_start") == 0) + { + new_controller = new LinuxLEDController(); + new_device = true; + } + else if(strcmp(argument, "red_path") == 0) + { + new_controller->OpenRedPath(value); + } + else if(strcmp(argument, "green_path") == 0) + { + new_controller->OpenGreenPath(value); + } + else if(strcmp(argument, "blue_path") == 0) + { + new_controller->OpenBluePath(value); + } + else if(strcmp(argument, "linux_led_end") == 0) + { + new_rgbcontroller = new RGBController_LinuxLED(new_controller); + new_rgbcontroller->name = new_name; + rgb_controllers.push_back(new_rgbcontroller); + } + } + } + } + } +} /* DetectLinuxLEDControllers() */ + +REGISTER_DETECTOR("Linux LED", DetectLinuxLEDControllers); diff --git a/OpenRGB.pro b/OpenRGB.pro index 9c180e8a..504277c3 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -568,10 +568,13 @@ win32:contains(QMAKE_TARGET.arch, x86) { #-----------------------------------------------------------------------# unix:!macx { INCLUDEPATH += \ + Controllers/LinuxLEDController \ HEADERS += \ i2c_smbus/i2c_smbus_linux.h \ + Controllers/LinuxLEDController/LinuxLEDController.h \ RGBController/RGBController_Faustus.h \ + RGBController/RGBController_LinuxLED.h \ LIBS += \ -lusb-1.0 \ @@ -594,8 +597,11 @@ unix:!macx { SOURCES += \ i2c_smbus/i2c_smbus_linux.cpp \ serial_port/find_usb_serial_port_linux.cpp \ + Controllers/LinuxLEDController/LinuxLEDController.cpp \ + Controllers/LinuxLEDController/LinuxLEDControllerDetect.cpp \ RGBController/OpenRazerDetect.cpp \ RGBController/RGBController_Faustus.cpp \ + RGBController/RGBController_LinuxLED.cpp \ RGBController/RGBController_OpenRazer.cpp \ #-------------------------------------------------------------------# diff --git a/RGBController/RGBController_LinuxLED.cpp b/RGBController/RGBController_LinuxLED.cpp new file mode 100644 index 00000000..0826380e --- /dev/null +++ b/RGBController/RGBController_LinuxLED.cpp @@ -0,0 +1,86 @@ +/*-----------------------------------------*\ +| 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(); +} + +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() +{ + +} diff --git a/RGBController/RGBController_LinuxLED.h b/RGBController/RGBController_LinuxLED.h new file mode 100644 index 00000000..557f8631 --- /dev/null +++ b/RGBController/RGBController_LinuxLED.h @@ -0,0 +1,31 @@ +/*-----------------------------------------*\ +| RGBController_LinuxLED.h | +| | +| Generic RGB Interface for Linux LED | +| | +| Adam Honse (CalcProgrammer1) 9/25/2020 | +\*-----------------------------------------*/ + +#pragma once +#include "RGBController.h" +#include "LinuxLEDController.h" + +class RGBController_LinuxLED : public RGBController +{ +public: + RGBController_LinuxLED(LinuxLEDController* controller_ptr); + + void SetupZones(); + + void ResizeZone(int zone, int new_size); + + void DeviceUpdateLEDs(); + void UpdateZoneLEDs(int zone); + void UpdateSingleLED(int led); + + void SetCustomMode(); + void DeviceUpdateMode(); + +private: + LinuxLEDController* controller; +};