Skip to content
Snippets Groups Projects
Commit 580129ba authored by Tim Rheinfels's avatar Tim Rheinfels
Browse files

+ Implemented backlight control

parent b1581e28
No related branches found
No related tags found
No related merge requests found
#!/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()
...@@ -8,13 +8,13 @@ while true; do ...@@ -8,13 +8,13 @@ while true; do
if xset -q | grep "Monitor is On" >/dev/null 2>&1 ; then if xset -q | grep "Monitor is On" >/dev/null 2>&1 ; then
if [ "$MONITOR_ACTIVE" != true ]; then if [ "$MONITOR_ACTIVE" != true ]; then
MONITOR_ACTIVE=true MONITOR_ACTIVE=true
#echo Monitor just switched on python /opt/backlight.py on
xset led named "Scroll Lock" xset led named "Scroll Lock"
fi fi
else else
if [ "$MONITOR_ACTIVE" = true ]; then if [ "$MONITOR_ACTIVE" = true ]; then
MONITOR_ACTIVE=false MONITOR_ACTIVE=false
#echo Monitor just switched off python /opt/backlight.py off
xset -led named "Scroll Lock" xset -led named "Scroll Lock"
fi fi
fi fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment