From 2bd93f2964540dd85867c165670a86a7284f692a Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 7 Apr 2024 00:30:23 +0300 Subject: [PATCH] now working... Signed-off-by: Alex A. Naanou --- Makefile | 31 ++++++++++++++++++++++------ thinkpad-keyboard-brightness.service | 12 +++++------ thinkpad-keyboard-brightness.timer | 2 +- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 7890c5f..eb46bc3 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,35 @@ +SBIN_DIR := /usr/sbin/ SERVICE_DIR := /etc/systemd/system/ -TIMER := thinkpad-keyboard-brightness.timer -UNIT := thinkpad-keyboard-brightness.service +SCRIPT := thinkpad-keyboard-brightness +TIMER := $(SCRIPT).timer +UNIT := $(SCRIPT).service .PHONY:install -install: $(TIMER) $(UNIT) - cp -f $? $(SERVICE_DIR) +install: $(TIMER) $(UNIT) $(SCRIPT) + cp -f $(UNIT) $(TIMER) $(SERVICE_DIR) systemctl daemon-reload - systemctl enamble ${UNIT} - systemctl enamble ${TIMER} + systemctl enable ${UNIT} + systemctl enable ${TIMER} systemctl start ${TIMER} + +.PHONY:disable +disable: $(TIMER) $(UNIT) + systemctl stop ${TIMER} + systemctl disable ${TIMER} + systemctl disable ${UNIT} + +.PHONY:uninstall +uninstall: disable $(TIMER) $(UNIT) + rm -f \ + $(SERVICE_DIR)/$(TIMER) \ + $(SERVICE_DIR)/$(UNIT) + systemctl daemon-reload + +.PHONY:reinstall +reinstall: uninstall install + diff --git a/thinkpad-keyboard-brightness.service b/thinkpad-keyboard-brightness.service index 06b1875..5bebff6 100644 --- a/thinkpad-keyboard-brightness.service +++ b/thinkpad-keyboard-brightness.service @@ -1,12 +1,12 @@ [Unit] -Description="Turn keyboard backlight on/off bases on light sensor" +Description="Turn keyboard backlight on/off based on light sensor" [Service] -Type=oneshot -RemainAfterExit=yes -Environment="SENSOR=/sys/bus/iio/devices/iio::device2/in_illuminance_raw" -WorkingDirectory=/sys/class/leds/dell::kbd_backlight/ -ExecStart=bash -c "[[ $(cat ${SENSOR}) < 1500 ]] && echo 1 > brightness || echo 0 > brightness" +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" [Install] WantedBy=multi-user.target + diff --git a/thinkpad-keyboard-brightness.timer b/thinkpad-keyboard-brightness.timer index ce76d7e..ea43950 100644 --- a/thinkpad-keyboard-brightness.timer +++ b/thinkpad-keyboard-brightness.timer @@ -1,5 +1,5 @@ [Unit] -Description="Turn keyboard backlight on/off bases on light sensor (timer)" +Description="Turn keyboard backlight on/off based on light sensor (timer)" [Timer] AccuracySec=1s