|
|
@@ -0,0 +1,127 @@ |
|
|
|
#!/usr/bin/env bash |
|
|
|
|
|
|
|
# g14control.sh |
|
|
|
# |
|
|
|
# version: 1.0 |
|
|
|
# date: 2021-08-01 |
|
|
|
# author: hmk |
|
|
|
# description: A hardware interface script for ASUS ROG Zephyrus G14 laptops. |
|
|
|
# Primary purpose is to give a minimal wrapper for hardware control in |
|
|
|
# minimal desktop environments or without any desktop environment a all. |
|
|
|
# |
|
|
|
# Tested on: |
|
|
|
# - GA401IH-BM013T (2020) |
|
|
|
# |
|
|
|
# |
|
|
|
# TODO: |
|
|
|
# - POSIX compliancy (currently uses non-POSIX-complient bash extensions) |
|
|
|
# - is amdgpu_bl0 the only dsiplay backlight interface? What happens when dGPU |
|
|
|
# is active? |
|
|
|
# |
|
|
|
|
|
|
|
disp() { |
|
|
|
# Changes display backlight to a given level or steps up/down |
|
|
|
|
|
|
|
INTERFACE="/sys/class/backlight/amdgpu_bl0/brightness" |
|
|
|
MAX=$(cat /sys/class/backlight/amdgpu_bl0/max_brightness) |
|
|
|
STEP=$((MAX/10)) |
|
|
|
CURRLEVEL=$(cat ${INTERFACE}) |
|
|
|
|
|
|
|
[[ ${1} =~ ^[0-9]{1,${#MAX}}$ && ! ${1} > ${MAX} ]] && \ |
|
|
|
LEVEL=${1} |
|
|
|
[[ ${1} == "up" && ${CURRLEVEL} < ${MAX} ]] && \ |
|
|
|
LEVEL=$((CURRLEVEL+STEP)) |
|
|
|
[[ ${1} == "down" && ${CURRLEVEL} > 0 ]] && \ |
|
|
|
LEVEL=$((CURRLEVEL-STEP)) |
|
|
|
|
|
|
|
echo ${LEVEL} |
|
|
|
echo ${LEVEL} > ${INTERFACE} |
|
|
|
|
|
|
|
CHKLEVEL=$(cat ${INTERFACE}) |
|
|
|
|
|
|
|
notify-send "Display backlight level changed" \ |
|
|
|
"${CURRLEVEL} -> ${CHKLEVEL}" |
|
|
|
} |
|
|
|
|
|
|
|
kbd() { |
|
|
|
# Changes keyboard backlight to a given level or steps up/down. |
|
|
|
# param:[0-3] set backlight level to NUM |
|
|
|
# param:up step backlight up |
|
|
|
# param:down step backlight down |
|
|
|
|
|
|
|
INTERFACE="/sys/class/leds/asus::kbd_backlight/brightness" |
|
|
|
MAX=$(cat /sys/class/leds/asus::kbd_backlight/max_brightness) |
|
|
|
CURRLEVEL=$(cat ${INTERFACE}) |
|
|
|
|
|
|
|
[[ ${1} =~ ^[0-${MAX}]$ ]] && \ |
|
|
|
LEVEL=${1} |
|
|
|
[[ ${1} == "up" && ${CURRLEVEL} < ${MAX} ]] && \ |
|
|
|
LEVEL=$((CURRLEVEL+1)) |
|
|
|
[[ ${1} == "down" && ${CURRLEVEL} > 0 ]] && \ |
|
|
|
LEVEL=$((CURRLEVEL-1)) |
|
|
|
|
|
|
|
echo ${LEVEL} > ${INTERFACE} |
|
|
|
|
|
|
|
CHKLEVEL=$(cat ${INTERFACE}) |
|
|
|
|
|
|
|
notify-send "Keyboard backlight level changed" \ |
|
|
|
"${CURRLEVEL} -> ${CHKLEVEL}" |
|
|
|
} |
|
|
|
|
|
|
|
fan() { |
|
|
|
# Changes fan mode to a given mode or rotates through modes. |
|
|
|
# 0 = Normal/Balanced |
|
|
|
# 1 = Boost |
|
|
|
# 2 = Silent. |
|
|
|
# param:[0-2] Set fan mode to given mode |
|
|
|
# param:NONE Rotate through modes Balanced -> Boost -> Silent |
|
|
|
|
|
|
|
MODELIST=("Balanced" "Boost" "Silent") |
|
|
|
INTERFACE="/sys/devices/platform/asus-nb-wmi/throttle_thermal_policy" |
|
|
|
CURRMODE=$(cat ${INTERFACE}) |
|
|
|
|
|
|
|
if [[ ${1} =~ ^[0-2]$ ]]; then |
|
|
|
MODE=${1} |
|
|
|
else |
|
|
|
if [[ ${CURRMODE} == 2 ]]; then |
|
|
|
MODE=0 |
|
|
|
else |
|
|
|
let MODE=$((CURRMODE+1)) |
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
echo ${MODE} > ${INTERFACE} |
|
|
|
|
|
|
|
CHKMODE=$(cat ${INTERFACE}) |
|
|
|
|
|
|
|
notify-send "Fan mode changed" \ |
|
|
|
"${MODELIST[${CURRMODE}]} -> ${MODELIST[${CHKMODE}]}" |
|
|
|
} |
|
|
|
|
|
|
|
usage() { |
|
|
|
echo "Usage: $0 [-d LEVEL|up|down] [-k LEVEL|up|down] [-f [MODE]] [-h]" |
|
|
|
} |
|
|
|
|
|
|
|
while getopts "d:k:f:h" ARG; do |
|
|
|
case "${ARG}" in |
|
|
|
d) |
|
|
|
disp ${OPTARG} |
|
|
|
;; |
|
|
|
k) |
|
|
|
kbd ${OPTARG} |
|
|
|
;; |
|
|
|
f) |
|
|
|
fan ${OPTARG} |
|
|
|
;; |
|
|
|
h) |
|
|
|
usage |
|
|
|
exit 0 |
|
|
|
;; |
|
|
|
*) |
|
|
|
usage |
|
|
|
exit 1 |
|
|
|
;; |
|
|
|
esac |
|
|
|
done |
|
|
|
|
|
|
|
exit 0 |