From 70d99430a2f2d3d9d855957d7ae611e58e2bd886 Mon Sep 17 00:00:00 2001 From: haemka Date: Sun, 1 Aug 2021 13:20:56 +0200 Subject: [PATCH] initial version of g14control.sh, fanmode integrated --- fanmode.sh | 24 ---------- g14control.sh | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 24 deletions(-) delete mode 100755 fanmode.sh create mode 100755 g14control.sh diff --git a/fanmode.sh b/fanmode.sh deleted file mode 100755 index 46c7f7f..0000000 --- a/fanmode.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash - -# 0 = Normal/Balanced -# 1 = Boost -# 2 = Silent. - -MODELIST=("Balanced" "Boost" "Silent") -INTERFACE="/sys/devices/platform/asus-nb-wmi/throttle_thermal_policy" -CURRENT_MODE=$(cat ${INTERFACE}) -MODE=${CURRENT_MODE} - -if [[ ! ${1} ]]; then - [[ ${MODE} == 2 ]] && MODE=0 || let MODE+=1 -else - MODE=${1} -fi - -echo ${MODE} > ${INTERFACE} - -CHECK_MODE=$(cat ${INTERFACE}) - -notify-send "Fan mode changed" "${MODELIST[${CURRENT_MODE}]} -> ${MODELIST[${CHECK_MODE}]}" - - diff --git a/g14control.sh b/g14control.sh new file mode 100755 index 0000000..4a33b70 --- /dev/null +++ b/g14control.sh @@ -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