diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7890c5f --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ + +SERVICE_DIR := /etc/systemd/system/ + +TIMER := thinkpad-keyboard-brightness.timer +UNIT := thinkpad-keyboard-brightness.service + + + +.PHONY:install +install: $(TIMER) $(UNIT) + cp -f $? $(SERVICE_DIR) + systemctl daemon-reload + systemctl enamble ${UNIT} + systemctl enamble ${TIMER} + systemctl start ${TIMER} + diff --git a/thinkpad-keyboard-brightness.service b/thinkpad-keyboard-brightness.service new file mode 100644 index 0000000..06b1875 --- /dev/null +++ b/thinkpad-keyboard-brightness.service @@ -0,0 +1,12 @@ +[Unit] +Description="Turn keyboard backlight on/off bases 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" + +[Install] +WantedBy=multi-user.target diff --git a/thinkpad-keyboard-brightness.timer b/thinkpad-keyboard-brightness.timer new file mode 100644 index 0000000..ce76d7e --- /dev/null +++ b/thinkpad-keyboard-brightness.timer @@ -0,0 +1,11 @@ +[Unit] +Description="Turn keyboard backlight on/off bases on light sensor (timer)" + +[Timer] +AccuracySec=1s +OnUnitActiveSec=3s +Unit=thinkpad-keyboard-brightness.service + +[Install] +WantedBy=multi-user.target +