From 9c47a3a9e79ee7e28a9794ea24c7d837a4445219 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Fri, 20 Dec 2024 22:11:28 +0800 Subject: [PATCH] Brightness (OpenBSD): add support Requires root permission. Not tested --- CMakeLists.txt | 2 +- src/detection/brightness/brightness_obsd.c | 30 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/detection/brightness/brightness_obsd.c diff --git a/CMakeLists.txt b/CMakeLists.txt index a4886e3a4..447286642 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -786,7 +786,7 @@ elseif(OpenBSD) src/detection/bluetoothradio/bluetoothradio_linux.c src/detection/board/board_nosupport.c src/detection/bootmgr/bootmgr_nosupport.c - src/detection/brightness/brightness_nosupport.c + src/detection/brightness/brightness_obsd.c src/detection/btrfs/btrfs_nosupport.c src/detection/chassis/chassis_nosupport.c src/detection/cpu/cpu_obsd.c diff --git a/src/detection/brightness/brightness_obsd.c b/src/detection/brightness/brightness_obsd.c new file mode 100644 index 000000000..ea5d7334c --- /dev/null +++ b/src/detection/brightness/brightness_obsd.c @@ -0,0 +1,30 @@ +#include "brightness.h" +#include "common/io/io.h" + +#include +#include +#include +#include + +const char* ffDetectBrightness(FF_MAYBE_UNUSED FFBrightnessOptions* options, FFlist* result) +{ + FF_AUTO_CLOSE_FD int devfd = open("/dev/ttyC0", O_RDONLY); + + if (devfd < 0) return "open(dev/ttyC0, O_RDONLY) failed"; + + struct wsdisplay_param param = { + .param = WSDISPLAYIO_PARAM_BRIGHTNESS, + }; + + if (ioctl(devfd, WSDISPLAYIO_GETPARAM, ¶m) < 0) + return "ioctl(WSDISPLAYIO_GETPARAM) failed"; + + FFBrightnessResult* brightness = (FFBrightnessResult*) ffListAdd(result); + ffStrbufInitStatic(&brightness->name, "wsdisplay"); + + brightness->max = param.max; + brightness->min = param.min; + brightness->current = param.curval; + + return NULL; +}