Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 

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