mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 13:46:36 +00:00
Support brightness control on Linux fbdev
This commit is contained in:
parent
f36dd66a05
commit
a7d900ed7b
@ -25,6 +25,7 @@
|
|||||||
#include "display/fbdev.h"
|
#include "display/fbdev.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
// extern monitor_t monitor;
|
// extern monitor_t monitor;
|
||||||
@ -153,7 +154,31 @@ void PosixDevice::update_backlight()
|
|||||||
#if USE_MONITOR
|
#if USE_MONITOR
|
||||||
monitor_backlight(level);
|
monitor_backlight(level);
|
||||||
#elif USE_FBDEV
|
#elif USE_FBDEV
|
||||||
// set display backlight, if possible
|
// set display backlight, if possible
|
||||||
|
if(backlight_device != "") {
|
||||||
|
if(backlight_max == 0) {
|
||||||
|
std::ifstream f;
|
||||||
|
f.open("/sys/class/backlight/" + backlight_device + "/max_brightness");
|
||||||
|
if(!f.fail()) {
|
||||||
|
f >> backlight_max;
|
||||||
|
f.close();
|
||||||
|
} else {
|
||||||
|
perror("Max brightness read failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int brightness = map(level, 0, 255, 0, backlight_max);
|
||||||
|
LOG_VERBOSE(0, "Setting brightness to %d/255 (%d)", level, brightness);
|
||||||
|
|
||||||
|
std::ofstream f;
|
||||||
|
f.open("/sys/class/backlight/" + backlight_device + "/brightness");
|
||||||
|
if(!f.fail()) {
|
||||||
|
f << brightness;
|
||||||
|
f.close();
|
||||||
|
} else {
|
||||||
|
perror("Brightness write failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +56,10 @@ class PosixDevice : public BaseDevice {
|
|||||||
|
|
||||||
bool is_system_pin(uint8_t pin) override;
|
bool is_system_pin(uint8_t pin) override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::string backlight_device;
|
||||||
|
int backlight_max = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string _hostname;
|
std::string _hostname;
|
||||||
std::string _core_version;
|
std::string _core_version;
|
||||||
|
@ -119,6 +119,10 @@ void usage(const char* progName, const char* version)
|
|||||||
<< " (default: 'AppData\\hasp\\hasp')" << std::endl
|
<< " (default: 'AppData\\hasp\\hasp')" << std::endl
|
||||||
#elif defined(POSIX)
|
#elif defined(POSIX)
|
||||||
<< " (default: '~/.local/share/hasp/hasp')" << std::endl
|
<< " (default: '~/.local/share/hasp/hasp')" << std::endl
|
||||||
|
#endif
|
||||||
|
#if USE_FBDEV && defined(POSIX)
|
||||||
|
<< " -b | --backlight Backlight device name (in /sys/class/backlight/)" << std::endl
|
||||||
|
<< " -B | --bl-max Backlight brightness limit (default: max_brightness)" << std::endl
|
||||||
#endif
|
#endif
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@ -138,6 +142,25 @@ int main(int argc, char* argv[])
|
|||||||
for(int arg = 1; arg < argc; arg++) {
|
for(int arg = 1; arg < argc; arg++) {
|
||||||
if(strncmp(argv[arg], "--help", 6) == 0 || strncmp(argv[arg], "-h", 2) == 0) {
|
if(strncmp(argv[arg], "--help", 6) == 0 || strncmp(argv[arg], "-h", 2) == 0) {
|
||||||
showhelp = true;
|
showhelp = true;
|
||||||
|
#if USE_FBDEV && defined(POSIX)
|
||||||
|
} else if(strncmp(argv[arg], "--backlight", 11) == 0 || strncmp(argv[arg], "-b", 2) == 0) {
|
||||||
|
if(arg + 1 < argc) {
|
||||||
|
haspDevice.backlight_device = argv[arg + 1];
|
||||||
|
arg++;
|
||||||
|
} else {
|
||||||
|
std::cout << "Missing device name" << std::endl;
|
||||||
|
showhelp = true;
|
||||||
|
}
|
||||||
|
} else if(strncmp(argv[arg], "--bl-max", 9) == 0 || strncmp(argv[arg], "-B", 2) == 0) {
|
||||||
|
if(arg + 1 < argc) {
|
||||||
|
int bl_max = atoi(argv[arg + 1]);
|
||||||
|
if(bl_max > 0) haspDevice.backlight_max = bl_max;
|
||||||
|
arg++;
|
||||||
|
} else {
|
||||||
|
std::cout << "Missing backlight level" << std::endl;
|
||||||
|
showhelp = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
} else if(strncmp(argv[arg], "--width", 7) == 0 || strncmp(argv[arg], "-W", 2) == 0) {
|
} else if(strncmp(argv[arg], "--width", 7) == 0 || strncmp(argv[arg], "-W", 2) == 0) {
|
||||||
if(arg + 1 < argc) {
|
if(arg + 1 < argc) {
|
||||||
int w = atoi(argv[arg + 1]);
|
int w = atoi(argv[arg + 1]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user