User Tools

Site Tools

한국어

comfilepi:controlling_the_lcd_backlight:index

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
comfilepi:controlling_the_lcd_backlight:index [2023/09/14 12:57]
COMFILE Technology [Compile]
comfilepi:controlling_the_lcd_backlight:index [2023/12/06 10:00] (current)
COMFILE Technology [Controlling the LCD Backlight]
Line 1: Line 1:
 ====== Controlling the LCD Backlight ====== ====== Controlling the LCD Backlight ======
  
-The ComfilePi'​s LCD backlight is connected to GPIO 34.  The backlight can be turned on or off via the command line or via a programming language.+The ComfilePi'​s LCD backlight is connected to one of the panel PC's internal ​GPIO pins.  The backlight can be turned on or off via the command line or via a programming language.
  
  
Line 257: Line 257:
 g++ backlight_service.cpp -lX11 -lXext -lpigpiod_if2 -o backlight_service g++ backlight_service.cpp -lX11 -lXext -lpigpiod_if2 -o backlight_service
 </​code>​ </​code>​
- 
-Run ''​journalctl -t backlight_service -r''​ to view the log entries. 
  
 ==== Bash Script Implementation ==== ==== Bash Script Implementation ====
Line 266: Line 264:
 #!/bin/bash #!/bin/bash
  
-export DISPLAY=":​0.0"​ +PWM_PIN=31 
- +PIN=34
-PIN=34 ​  # CPi-A/​B/​F/​S +
-#​PIN=44 ​ # CPi-C+
  
 +# Set pins as output
 +raspi-gpio set $PWM_PIN op
 raspi-gpio set $PIN op raspi-gpio set $PIN op
 +
 +# Start with both pins HIGH.  If either of the
 +# pins go LOW, the backlight will turn off.
 +raspi-gpio set $PWM_PIN dh
 +raspi-gpio set $PIN dh
 +
 +# Get the current state
 +CURRENT_STATUS=$(xset q | grep "​Monitor is" | awk '​{print $3}')
 +LAST_STATUS=$CURRENT_STATUS
 +
 +logger -p info -t "​backlight_service"​ -s "​Monitor is $CURRENT_STATUS"​
  
 # Loop indefinitely updating backlight in sync with monitor status # Loop indefinitely updating backlight in sync with monitor status
Line 277: Line 286:
  
   # Check the current monitor status   # Check the current monitor status
-  ​current_status=$(xset q | grep "​Monitor is" | awk '​{print $3}')+  ​CURRENT_STATUS=$(xset q | grep "​Monitor is" | awk '​{print $3}')
  
-  # Control backlight pin according to the monitor status +  ​# Only turn the backlight on/off if the Monitor state has changed 
-  if [ "$current_status" = "​On"​ ]; then +  if [ "​$CURRENT_STATUS"​ != "​$LAST_STATUS"​ ]; then 
-    raspi-gpio set $PIN dh +    logger -p info -t "​backlight_service"​ -s "​Monitor is $CURRENT_STATUS"​ 
-  else + 
-    raspi-gpio set $PIN dl+    ​# Control backlight pin according to the monitor status 
 +    if [ "$CURRENT_STATUS" = "​On"​ ]; then 
 +      ​logger -p info -t "​backlight_service"​ -s "​Turning Backlight On" 
 +      ​raspi-gpio set $PIN dh 
 +    else 
 +      ​logger -p info -t "​backlight_service"​ -s "​Turning Backlight Off" 
 +      ​raspi-gpio set $PIN dl 
 +    fi 
 +    LAST_STATUS=$CURRENT_STATUS
   fi   fi
  
Line 297: Line 314:
  
 Add the line ''​@xset dpms 0 0 {timeout_in_seconds}''​ to the //​autostart//​ file to set the timeout each time the desktop loads. Add the line ''​@xset dpms 0 0 {timeout_in_seconds}''​ to the //​autostart//​ file to set the timeout each time the desktop loads.
 +
 +Run ''​journalctl -t backlight_service -r''​ to view the log entries.
  
  
comfilepi/controlling_the_lcd_backlight/index.1694663820.txt.gz · Last modified: 2023/09/14 12:57 by COMFILE Technology