25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 

136 satır
2.9 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} =~ ^[0-9]{1,${#MAX}}$ && ! ${1} > ${MAX} ]]; then
  28. LEVEL=${1}
  29. elif [[ ${1} == "up" && ${CURRLEVEL} < ${MAX} ]]; then
  30. [[ $((CURRLEVEL+STEP)) > ${MAX} ]] && \
  31. LEVEL=${MAX} || LEVEL=$((CURRLEVEL+STEP))
  32. else [[ ${1} == "down" && ${CURRLEVEL} > 0 ]]
  33. [[ $((CURRLEVEL-STEP)) < 0 ]] && \
  34. LEVEL=0 || LEVEL=$((CURRLEVEL-STEP))
  35. fi
  36. echo ${LEVEL} > ${INTERFACE}
  37. CHKLEVEL=$(cat ${INTERFACE})
  38. notify-send -t 500 "Display backlight level changed" \
  39. "${CURRLEVEL} -> ${CHKLEVEL}"
  40. }
  41. kbd() {
  42. # Changes keyboard backlight to a given level or steps up/down.
  43. # param:[0-3] set backlight level to NUM
  44. # param:up step backlight up
  45. # param:down step backlight down
  46. INTERFACE="/sys/class/leds/asus::kbd_backlight/brightness"
  47. MAX=$(cat /sys/class/leds/asus::kbd_backlight/max_brightness)
  48. CURRLEVEL=$(cat ${INTERFACE})
  49. [[ ${1} =~ ^[0-${MAX}]$ ]] && \
  50. LEVEL=${1}
  51. [[ ${1} == "up" && ${CURRLEVEL} < ${MAX} ]] && \
  52. LEVEL=$((CURRLEVEL+1))
  53. [[ ${1} == "down" && ${CURRLEVEL} > 0 ]] && \
  54. LEVEL=$((CURRLEVEL-1))
  55. echo ${LEVEL} > ${INTERFACE}
  56. CHKLEVEL=$(cat ${INTERFACE})
  57. notify-send -t 500 "Keyboard backlight level changed" \
  58. "${CURRLEVEL} -> ${CHKLEVEL}"
  59. }
  60. fan() {
  61. # Changes fan mode to a given mode or rotates through modes.
  62. # 0 = Normal/Balanced
  63. # 1 = Boost
  64. # 2 = Silent.
  65. # param:[0-2] Set fan mode to given mode
  66. # param:NONE Rotate through modes Balanced -> Boost -> Silent
  67. MODELIST=("Balanced" "Boost" "Silent")
  68. INTERFACE="/sys/devices/platform/asus-nb-wmi/throttle_thermal_policy"
  69. CURRMODE=$(cat ${INTERFACE})
  70. if [[ ${1} =~ ^[0-2]$ ]]; then
  71. MODE=${1}
  72. else
  73. if [[ ${CURRMODE} == 2 ]]; then
  74. MODE=0
  75. else
  76. let MODE=$((CURRMODE+1))
  77. fi
  78. fi
  79. echo ${MODE} > ${INTERFACE}
  80. CHKMODE=$(cat ${INTERFACE})
  81. notify-send "Fan mode changed" \
  82. "${MODELIST[${CURRMODE}]} -> ${MODELIST[${CHKMODE}]}"
  83. }
  84. usage() {
  85. echo "Usage: $0 [-d LEVEL|up|down] [-k LEVEL|up|down] [-f MODE] [-F] [-h]"
  86. }
  87. while getopts "d:k:f:Fh" ARG; do
  88. case "${ARG}" in
  89. d)
  90. disp ${OPTARG}
  91. ;;
  92. k)
  93. kbd ${OPTARG}
  94. ;;
  95. F)
  96. fan ${OPTARG}
  97. ;;
  98. f)
  99. fan ${OPTARG}
  100. ;;
  101. h)
  102. usage
  103. exit 0
  104. ;;
  105. *)
  106. usage
  107. exit 1
  108. ;;
  109. esac
  110. done
  111. exit 0