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.
 
 

138 lines
2.9 KiB

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