From 7b8f1db9a5e0114a6f5cbcdd95c10fba12dc2ace Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 7 Apr 2024 00:47:39 +0300 Subject: [PATCH] tweaks + docs... Signed-off-by: Alex A. Naanou --- Makefile | 14 ++++++----- README.md | 36 +++++++++++++++++++++++++++- thinkpad-keyboard-brightness.service | 6 +++-- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index eb46bc3..62dc9c1 100644 --- a/Makefile +++ b/Makefile @@ -1,25 +1,27 @@ -SBIN_DIR := /usr/sbin/ +NAME := thinkpad-keyboard-brightness + SERVICE_DIR := /etc/systemd/system/ -SCRIPT := thinkpad-keyboard-brightness -TIMER := $(SCRIPT).timer -UNIT := $(SCRIPT).service +TIMER := $(NAME).timer +UNIT := $(NAME).service .PHONY:install -install: $(TIMER) $(UNIT) $(SCRIPT) - cp -f $(UNIT) $(TIMER) $(SERVICE_DIR) +install: $(TIMER) $(UNIT) + cp -f $? $(SERVICE_DIR) systemctl daemon-reload systemctl enable ${UNIT} systemctl enable ${TIMER} systemctl start ${TIMER} + systemctl start ${UNIT} .PHONY:disable disable: $(TIMER) $(UNIT) systemctl stop ${TIMER} + systemctl stop ${UNIT} systemctl disable ${TIMER} systemctl disable ${UNIT} diff --git a/README.md b/README.md index d7177a9..035c847 100644 --- a/README.md +++ b/README.md @@ -1 +1,35 @@ -# thinkpad-keyboard-brightness \ No newline at end of file +# Thinkpad keyboard backlight brightness + +This service will set the keyboard backlight brightness based on ambient +light levels. + + +## Install + +```bash +$ sudo make install +``` + + +## Configure + +```bash +$ sudo systemctl edit thinkpad-keyboard-brightness.service +``` + +Variables that can change depending on device +``` +[Service] +Environment=SENSOR=/sys/bus/iio/devices/iio:device2/in_illuminance_raw +Environment=TRIGGER=/sys/class/leds/tpacpi::kbd_backlight/brightness +Environment=THRESHOLD=1500 +Environment=VALUE=1 +``` + + +## Uninstall + +```bash +$ sudo make uninstall +``` + diff --git a/thinkpad-keyboard-brightness.service b/thinkpad-keyboard-brightness.service index 5bebff6..4cd66ce 100644 --- a/thinkpad-keyboard-brightness.service +++ b/thinkpad-keyboard-brightness.service @@ -4,8 +4,10 @@ Description="Turn keyboard backlight on/off based on light sensor" [Service] Type=exec Environment=SENSOR=/sys/bus/iio/devices/iio:device2/in_illuminance_raw -WorkingDirectory=/sys/class/leds/tpacpi::kbd_backlight/ -ExecStart=bash -c "(( $(cat ${SENSOR}) < 1500 )) && echo 1 > brightness || echo 0 > brightness" +Environment=TRIGGER=/sys/class/leds/tpacpi::kbd_backlight/brightness +Environment=THRESHOLD=1500 +Environment=VALUE=1 +ExecStart=bash -c "(( $(cat ${SENSOR}) < ${THRESHOLD} )) && echo ${VALUE} > ${TRIGGER} || echo 0 > ${TRIGGER}" [Install] WantedBy=multi-user.target