Advertisement
Guest User

lcd-backlight

a guest
Apr 10th, 2017
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.93 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. LASTPWM=/dev/shm/lcd35
  4. PWMFILE=/sys/devices/platform/pwm-ctrl/duty0
  5.  
  6. if [ -z "$1" ]; then
  7.         echo "Usage $0 on|off|<0-100>"
  8.         echo "Set the backlight of the LCD on/off or to a percent illumination"
  9.         exit;
  10. fi
  11.  
  12. if [ "$1" = "off" ]; then
  13.         #save the current value
  14.         cat $PWMFILE > $LASTPWM
  15.         echo 0 > $PWMFILE
  16.         echo "Turned off 3.5in LCD"
  17.         exit;
  18. fi
  19.  
  20. if [ "$1" = "on" ]; then
  21.         #see if the old PWM value has been saved
  22.         if [ -f "$LASTPWM" ]; then
  23.                 cat "$LASTPWM" > $PWMFILE
  24.         else
  25.                 #no previous value, turn on full brightness
  26.                 echo 1023 > $PWMFILE
  27.         fi
  28.         echo "Turned on 3.5in LCD"
  29.         exit;
  30. fi
  31.  
  32. if [ "$1" -ge 0 -a "$1" -le 100 ]; then
  33.         #set a percent of brightness
  34.         value=$[1023*$1/100]
  35.         echo $value > $PWMFILE
  36.         echo "Set backlight to $1% ($value)"
  37. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement