CROSS_COMPILE ?= arm-none-linux-gnueabi-
CC = $(CROSS_COMPILE)gcc
-CFLAGS += -Wall -O2
-LDFLAGS += -s
+CFLAGS += -Wall -Os
INSTALL ?= bin
-BIN = op_runfbapp op_gammatool op_gammatable op_test_inputs ofbset
+BIN += op_runfbapp op_gammatool op_gammatable op_test_inputs op_lidstate
+BIN += ofbset
all: $(BIN)
clean:
$(RM) *.o $(BIN)
-op_runfbapp: LDFLAGS += -lpthread -lX11
-op_test_inputs: LDFLAGS += -lpthread -lts
-op_gammatable: LDFLAGS += -lm
+op_runfbapp: LDLIBS += -lpthread -lX11
+op_test_inputs: LDLIBS += -lpthread -lts
+op_gammatable: LDLIBS += -lm
$(INSTALL):
mkdir -p $(INSTALL)
cp op_gammatool $(INSTALL)/op_gammatool_bin
cp op_gammatable $(INSTALL)/
cp op_test_inputs $(INSTALL)/op_test_inputs_bin
+ cp op_lidstate $(INSTALL)/
cp ofbset $(INSTALL)/
cp scripts/op_gammatool $(INSTALL)/
cp scripts/op_test_inputs $(INSTALL)/
vld:
$(CC) -Wall -O2 -DVALIDATION -s op_test_inputs.c -o op_test_inputs -Wl,-Bstatic -lpthread -lc -Wl,-Bdynamic -lts
+
+.PHONY: all clean install vld
--- /dev/null
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <linux/input.h>
+
+int main(int argc, char *argv[])
+{
+ unsigned int state = 0;
+ int fd = -1;
+ int id, ret;
+
+ if (argv[1] != NULL
+ && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")))
+ {
+ fprintf(stderr, "prints 1 if lid is closed, "
+ "0 if open or in unknown state "
+ "or if an error occurs\n");
+ return 0;
+ }
+
+ for (id = 0; id < 100; id++)
+ {
+ char fname[64];
+ char name[64];
+
+ snprintf(fname, sizeof(fname), "/dev/input/event%i", id);
+ fd = open(fname, O_RDONLY);
+ if (fd == -1)
+ {
+ if (errno == EACCES)
+ continue;
+ break;
+ }
+
+ name[0] = 0;
+ ioctl(fd, EVIOCGNAME(sizeof(name)), name);
+ if (!strcmp(name, "gpio-keys"))
+ break;
+
+ close(fd);
+ fd = -1;
+ }
+
+ if (fd == -1)
+ {
+ fprintf(stderr, "unable to find or access gpio-keys\n");
+ fprintf(stdout, "0\n");
+ return 1;
+ }
+
+ ret = ioctl(fd, EVIOCGSW(sizeof(state)), &state);
+ close(fd);
+ if (ret < 0)
+ {
+ perror("ioctl EVIOCGSW");
+ fprintf(stdout, "0\n");
+ return 1;
+ }
+
+ printf("%d\n", state & (1u << SW_LID) ? 1 : 0);
+
+ return 0;
+}