You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

140 lines
3.0 KiB

  1. #!/usr/bin/env bash
  2. set -x
  3. # g14control.sh
  4. #
  5. # version: 1.0
  6. # date: 2021-08-01
  7. # author: hmk
  8. # description: A hardware interface script for ASUS ROG Zephyrus G14 laptops.
  9. # Primary purpose is to give a minimal wrapper for hardware control in
  10. # minimal desktop environments or without any desktop environment a all.
  11. #
  12. # Tested on:
  13. # - GA401IH-BM013T (2020)
  14. #
  15. #
  16. # TODO:
  17. # - POSIX compliancy (currently uses non-POSIX-complient bash extensions)
  18. # - is amdgpu_bl0 the only dsiplay backlight interface? What happens when dGPU
  19. # is active?
  20. #
  21. disp() {
  22. # Changes display backlight to a given level or steps up/down
  23. INTERFACE="/sys/class/backlight/amdgpu_bl0/brightness"
  24. MAX=$(cat /sys/class/backlight/amdgpu_bl0/max_brightness)
  25. STEP=$((MAX/10))
  26. CURRLEVEL=$(cat ${INTERFACE})
  27. if [[ ${1} == "up" ]]; then
  28. [[ $((CURRLEVEL+STEP)) > ${MAX} ]] && \
  29. LEVEL=${MAX} || \
  30. [[ ${CURRLEVEL} < ${MAX} ]] && \
  31. LEVEL=$((CURRLEVEL+STEP))
  32. elif [[ ${1} == "down" ]]; then
  33. [[ $((CURRLEVEL-STEP)) < 0 ]] && \
  34. LEVEL=0 ||
  35. [[ ${CURRLEVEL} > 0 ]] && \
  36. LEVEL=$((CURRLEVEL-STEP))
  37. elif [[ ${1} =~ ^[0-9]{1,${#MAX}}$ && ! ${1} > ${MAX} ]]; then
  38. LEVEL=${1}
  39. fi
  40. echo ${LEVEL} > ${INTERFACE}
  41. CHKLEVEL=$(cat ${INTERFACE})
  42. notify-send -t 500 "Display backlight level changed" \
  43. "${CURRLEVEL} -> ${CHKLEVEL}"
  44. }
  45. kbd() {
  46. # Changes keyboard backlight to a given level or steps up/down.
  47. # param:[0-3] set backlight level to NUM
  48. # param:up step backlight up
  49. # param:down step backlight down
  50. INTERFACE="/sys/class/leds/asus::kbd_backlight/brightness"
  51. MAX=$(cat /sys/class/leds/asus::kbd_backlight/max_brightness)
  52. CURRLEVEL=$(cat ${INTERFACE})
  53. [[ ${1} =~ ^[0-${MAX}]$ ]] && \
  54. LEVEL=${1}
  55. [[ ${1} == "up" && ${CURRLEVEL} < ${MAX} ]] && \
  56. LEVEL=$((CURRLEVEL+1))
  57. [[ ${1} == "down" && ${CURRLEVEL} > 0 ]] && \
  58. LEVEL=$((CURRLEVEL-1))
  59. echo ${LEVEL} > ${INTERFACE}
  60. CHKLEVEL=$(cat ${INTERFACE})
  61. notify-send -t 500 "Keyboard backlight level changed" \
  62. "${CURRLEVEL} -> ${CHKLEVEL}"
  63. }
  64. fan() {
  65. # Changes fan mode to a given mode or rotates through modes.
  66. # 0 = Normal/Balanced
  67. # 1 = Boost
  68. # 2 = Silent.
  69. # param:[0-2] Set fan mode to given mode
  70. # param:NONE Rotate through modes Balanced -> Boost -> Silent
  71. MODELIST=("Balanced" "Boost" "Silent")
  72. INTERFACE="/sys/devices/platform/asus-nb-wmi/throttle_thermal_policy"
  73. CURRMODE=$(cat ${INTERFACE})
  74. if [[ ${1} =~ ^[0-2]$ ]]; then
  75. MODE=${1}
  76. else
  77. if [[ ${CURRMODE} == 2 ]]; then
  78. MODE=0
  79. else
  80. let MODE=$((CURRMODE+1))
  81. fi
  82. fi
  83. echo ${MODE} > ${INTERFACE}
  84. CHKMODE=$(cat ${INTERFACE})
  85. notify-send "Fan mode changed" \
  86. "${MODELIST[${CURRMODE}]} -> ${MODELIST[${CHKMODE}]}"
  87. }
  88. usage() {
  89. echo "Usage: $0 [-d LEVEL|up|down] [-k LEVEL|up|down] [-f MODE] [-F] [-h]"
  90. }
  91. while getopts "d:k:f:Fh" ARG; do
  92. case "${ARG}" in
  93. d)
  94. disp ${OPTARG}
  95. ;;
  96. k)
  97. kbd ${OPTARG}
  98. ;;
  99. F)
  100. fan ${OPTARG}
  101. ;;
  102. f)
  103. fan ${OPTARG}
  104. ;;
  105. h)
  106. usage
  107. exit 0
  108. ;;
  109. *)
  110. usage
  111. exit 1
  112. ;;
  113. esac
  114. done
  115. exit 0