Browse Source

++xsmartlight

master
Maxim Likhachev 5 years ago
parent
commit
11679528b3
  1. 1
      README.md
  2. 85
      xsmartlight

1
README.md

@ -74,6 +74,7 @@ will create the symbolic link for each script in the \<path> directory. @@ -74,6 +74,7 @@ will create the symbolic link for each script in the \<path> 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

85
xsmartlight

@ -0,0 +1,85 @@ @@ -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 <percentage>"
echo " -inc ?percentage? increase the brigthness to <persentage>% (default is 10%)."
echo " -dec ?percentage? decrease the brigthness to <persentage>% (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")"
Loading…
Cancel
Save