diff --git a/case/backlight.py b/case/backlight.py new file mode 100644 index 0000000000000000000000000000000000000000..a4d5566468fb7bccf0ed219ab345cc1153621f00 --- /dev/null +++ b/case/backlight.py @@ -0,0 +1,50 @@ +#!/usr/bin/python + +### +### @brief Script for accessing the display's backlight +### + +import RPi.GPIO as GPIO + +# Configuration +backlight_channel = 16 + +# Function for accessing the backlight +def init(): + # Adviced by the library... + GPIO.setwarnings( False ) + + GPIO.setmode( GPIO.BCM ) + GPIO.setup( backlight_channel, GPIO.OUT ) + +def enable(): + init() + GPIO.output( backlight_channel, GPIO.HIGH ) + +def disable(): + init() + GPIO.output( backlight_channel, GPIO.LOW ) + +# If the script is executed directly... +if __name__ == '__main__': + import sys + + en = None + if len(sys.argv) == 2: + if sys.argv[1] == 'on': + en = True + elif sys.argv[1] == 'off': + en = False + + if en is None: + print( 'Usage: %s <state>' ) + print( '' ) + print( 'Parameters:' ) + print( ' state: Either "on" or "off" to enable/disable the backlight' ) + print( '' ) + sys.exit( 1 ) + + if en: + enable() + else: + disable() diff --git a/case/backlight.sh b/case/backlight.sh index 13d03cf8d2760eb845907dd753e0cb2c7cb8c680..dba275f3d93ff36dcb2496c9308cde56c491067c 100755 --- a/case/backlight.sh +++ b/case/backlight.sh @@ -5,18 +5,18 @@ export DISPLAY=:0 MONITOR_ACTIVE=false while true; do - if xset -q | grep "Monitor is On" >/dev/null 2>&1 ; then - if [ "$MONITOR_ACTIVE" != true ]; then - MONITOR_ACTIVE=true - #echo Monitor just switched on - xset led named "Scroll Lock" - fi - else - if [ "$MONITOR_ACTIVE" = true ]; then - MONITOR_ACTIVE=false - #echo Monitor just switched off - xset -led named "Scroll Lock" - fi - fi - sleep 1 + if xset -q | grep "Monitor is On" >/dev/null 2>&1 ; then + if [ "$MONITOR_ACTIVE" != true ]; then + MONITOR_ACTIVE=true + python /opt/backlight.py on + xset led named "Scroll Lock" + fi + else + if [ "$MONITOR_ACTIVE" = true ]; then + MONITOR_ACTIVE=false + python /opt/backlight.py off + xset -led named "Scroll Lock" + fi + fi + sleep 1 done