From 11679528b3fadb918337cc7ae75065be0da416ea Mon Sep 17 00:00:00 2001 From: Maxim Likhachev Date: Fri, 31 Jul 2020 23:53:43 +0300 Subject: [PATCH] ++xsmartlight --- README.md | 1 + xsmartlight | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100755 xsmartlight diff --git a/README.md b/README.md index f3176dd..75071c1 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ will create the symbolic link for each script in the \ directory. - [defgroups](defgroups) adds a user to default system groups. - [passgen](passgen) creates the strong passwords. - [sync-date](sync-date) sets system time according to Google. +- [xsmartlight](xsmartlight) allows to adjust ASUS smartscreen's brightness. - [use](use) shows Gentoo USE flag's description. ## Development tools diff --git a/xsmartlight b/xsmartlight new file mode 100755 index 0000000..f1495e9 --- /dev/null +++ b/xsmartlight @@ -0,0 +1,85 @@ +#!/bin/bash + +# +# Сценарий позволяет регулировать яркость экрана ASUS SmartScreen. +# +# Идея и подробности: +# https://github.com/s-light/ASUS-ZenBook-Pro-Duo-UX581GV/issues/1#issuecomment-632839056 +# +# Для работы требуется модуль ядра acpi_call +# +# Использование: +# +# + +percentage2hex() { + local decimal=$(( $1 * 255 / 100 )) + + printf "%02x" "$decimal" +} + +set_brightness() { + echo "\_SB.ATKD.WMNB 0x0 0x53564544 b32000500${1^^}000000" | tee /proc/acpi/call +} + +main_brightness() { + xbacklight | cut -d '.' -f 1 +} + +current_brightness() { + if [ -f "$BRIGHTNESS_LOG" ]; then + cat "$BRIGHTNESS_LOG" + else + echo "$DEFAULT_BRIGHTNESS" + fi +} + +adjust_brightness() { + if [ "$1" == "inc" ]; then + local adjust_to=$2 + else + local adjust_to=-$2 + fi + + local new_level=$(( "$(current_brightness)" + "$adjust_to" )) + + if [ "$new_level" -le 0 ];then + local new_level=0 + elif [ "$new_level" -gt 100 ]; then + local new_level=100 + fi + + echo "$new_level" +} + +usage() { + echo "USAGE: xsmartlight [options]" + echo " Options:" + echo " -set ?percentage? set the brightness to " + echo " -inc ?percentage? increase the brigthness to % (default is 10%)." + echo " -dec ?percentage? decrease the brigthness to % (default is 10%)." + echo " -help show this help" + echo + echo "Executing the xsmartlight command without any options" + echo "will set the brightness to default value (${DEFAULT_BRIGHTNESS}%)." +} + +INC=10 + +DEFAULT_BRIGHTNESS=70 # ~B0 + +BRIGHTNESS_LOG=/tmp/smartscreen_brightness_level + +case "$1" in + -set) NEW_LEVEL=${2:-$DEFAULT_BRIGHTNESS};; + -inc) NEW_LEVEL=$(adjust_brightness inc "${2:-$INC}");; + -dec) NEW_LEVEL=$(adjust_brightness dec "${2:-$INC}");; + -help) usage; exit;; + *) usage; exit;; +esac + +echo -n "$NEW_LEVEL" | tee "$BRIGHTNESS_LOG" +echo -n " " + +set_brightness "$(percentage2hex "$NEW_LEVEL")" +