commit 9a248ae02783160a7d78adc151d065f3276055c1
parent ab74543a5e74287d11500dfbd7483dc88069e2b3
Author: Lucas Gabriel Vuotto <lgv@nanashi.co>
Date: Sat, 14 Oct 2017 14:04:10 -0300
Add screen brightness sensor
Signed-off-by: Lucas Gabriel Vuotto <lgv@nanashi.co>
Diffstat:
4 files changed, 48 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,9 +1,9 @@
VERSION = 0.5
PREFIX = /usr/local
SRC = spoon.c batt.c wifi.c cpu.c temp.c date.c load.c file.c key.c\
- netspeed.c strlcpy.c strlcat.c stub.c mix.c xkblayout.c mpd.c
+ netspeed.c strlcpy.c strlcat.c stub.c mix.c xkblayout.c mpd.c brightness.c
OBJ = spoon.o batt.o wifi.o cpu.o temp.o date.o load.o file.o key.o\
- netspeed.o strlcpy.o strlcat.o stub.o
+ netspeed.o strlcpy.o strlcat.o stub.o brightness.o
BIN = spoon
DISTFILES = $(SRC) types.h util.h config.def.h Makefile LICENSE configure
diff --git a/brightness.c b/brightness.c
@@ -0,0 +1,38 @@
+#include <err.h>
+#include <stdio.h>
+
+#ifdef __OpenBSD__
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <time.h>
+#include <unistd.h>
+#include <dev/wscons/wsconsio.h>
+
+int
+brightnessread(void *arg, char *buf, size_t len)
+{
+ struct wsdisplay_param dpyp;
+ int fd;
+
+ if ((fd = open("/dev/ttyC0", O_RDONLY)) == -1) {
+ warn("couldn't open /dev/ttyC0");
+ return -1;
+ }
+ dpyp.param = WSDISPLAYIO_PARAM_BRIGHTNESS;
+ if (ioctl(fd, WSDISPLAYIO_GETPARAM, &dpyp) == -1) {
+ warn("WSDISPLAYIO_PARAM_BRIGHTNESS ioctl");
+ return -1;
+ }
+ close(fd);
+ snprintf(buf, len, "%3d%%",
+ 100 * (dpyp.curval - dpyp.min) / (dpyp.max - dpyp.min));
+
+ return 0;
+}
+#elif __linux__
+int
+brightnessread(void *arg, char *buf, size_t len)
+{
+ return -1;
+}
+#endif
diff --git a/spoon.c b/spoon.c
@@ -21,6 +21,7 @@ int xkblayoutread(void *, char *, size_t);
int fileread(void *, char *, size_t);
int keyread(void *, char *, size_t);
int netspeedread(void *, char *, size_t);
+int brightnessread(void *, char *, size_t);
struct ent {
char *fmt;
diff --git a/stub.c b/stub.c
@@ -69,3 +69,10 @@ netspeedread(void *arg, char *buf, size_t len)
{
return -1;
}
+
+#pragma weak brightnessread
+int
+brightnessread(void *arg, char *buf, size_t len)
+{
+ return -1;
+}