Linux LED sysfs entries controller
This commit is contained in:
parent
88759aaac3
commit
533bd0c1a0
6 changed files with 331 additions and 0 deletions
71
Controllers/LinuxLEDController/LinuxLEDController.cpp
Normal file
71
Controllers/LinuxLEDController/LinuxLEDController.cpp
Normal file
|
|
@ -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();
|
||||
}
|
||||
28
Controllers/LinuxLEDController/LinuxLEDController.h
Normal file
28
Controllers/LinuxLEDController/LinuxLEDController.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
|
||||
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;
|
||||
};
|
||||
109
Controllers/LinuxLEDController/LinuxLEDControllerDetect.cpp
Normal file
109
Controllers/LinuxLEDController/LinuxLEDControllerDetect.cpp
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
#include "Detector.h"
|
||||
#include "LinuxLEDController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_LinuxLED.h"
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#else
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
#define LPSTR char *
|
||||
#define strtok_s strtok_r
|
||||
#endif
|
||||
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectLinuxLEDControllers *
|
||||
* *
|
||||
* Detect devices supported by the LinuxLED driver *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectLinuxLEDControllers(std::vector<RGBController*> &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);
|
||||
Loading…
Add table
Add a link
Reference in a new issue