Raspberry Pi/Quick Reference
(→xset) |
(→init.d script to control/check status) |
||
(2 intermediate revisions by one user not shown) | |||
Line 61: | Line 61: | ||
#run script to disable screensaver, screen blanking, screen exposure, standby, suspend, and energy star features. | #run script to disable screensaver, screen blanking, screen exposure, standby, suspend, and energy star features. | ||
− | /home/pi/xset.sh | + | sleep 5; export DISPLAY=:0; su - pi -c "/home/pi/xset.sh &" |
==Turn monitors on/off== | ==Turn monitors on/off== | ||
Line 123: | Line 123: | ||
Make it executable | Make it executable | ||
~$ sudo chmod +x /etc/cron.d/raspi-monitor-scheduler | ~$ sudo chmod +x /etc/cron.d/raspi-monitor-scheduler | ||
+ | |||
+ | ====init.d script to control/check status==== | ||
+ | Add the following script to init.d | ||
+ | <nowiki>pi@raspberrypi:~$ sudo nano /etc/init.d/monitor | ||
+ | |||
+ | #!/bin/sh | ||
+ | ### BEGIN INIT INFO | ||
+ | # Provides: vncviewer | ||
+ | # Required-Start: $remote_fs $syslog | ||
+ | # Required-Stop: $remote_fs $syslog | ||
+ | # Default-Start: 2 3 4 5 | ||
+ | # Default-Stop: 0 1 6 | ||
+ | # Short-Description: Turn on monitor at boot time | ||
+ | # Description: Turn on monitor at boot time. | ||
+ | ### END INIT INFO | ||
+ | |||
+ | |||
+ | monitor_status=$(tvservice -s | cut -c9-13) | ||
+ | |||
+ | case "$1" in | ||
+ | start) | ||
+ | /opt/vc/bin/tvservice --preferred | ||
+ | # Hack to enable virtual terminal nr 7 again: | ||
+ | chvt 6 | ||
+ | chvt 7 | ||
+ | ;; | ||
+ | |||
+ | stop) | ||
+ | /opt/vc/bin/tvservice --off | ||
+ | ;; | ||
+ | |||
+ | status) | ||
+ | if [ "$monitor_status" -eq "12001" ]; then | ||
+ | echo 'Monitor is on' | ||
+ | elif [ "$monitor_status" -eq "12000" ]; then | ||
+ | echo "Monitor is off" | ||
+ | else | ||
+ | echo "Usage: $0 <start|stop|status>" | ||
+ | exit 1 | ||
+ | fi | ||
+ | </nowiki> | ||
+ | =====Usage===== | ||
+ | ;Start | ||
+ | :<code><nowiki>~$ sudo service monitor start</nowiki></code> | ||
+ | :<code>Powering on HDMI with preferred settings</code> | ||
+ | ;Stop | ||
+ | :<code><nowiki>~$ sudo service monitor stop</nowiki></code> | ||
+ | :<code>Powering off HDMI</code> | ||
+ | ;Status | ||
+ | :<code><nowiki>~$ sudo service monitor status</nowiki></code> | ||
+ | :<code>Monitor is on</code> | ||
+ | :<code>Monitor is off</code> |
Latest revision as of 14:43, 17 June 2015
Contents |
[edit] xset
[edit] Overview
xset allows you to control a few things, but the most common is the monitor states. You can manipulate, enable, or disable some features like:
- dpms energy star features
- monitor standby, suspend, off, or on
- screen blanking
- screen exposing
- activate/reset screen saver
- screen saver on/off
It should be noted that while this can blank the monitor, it does not tell the monitor to turn off it's backlight.
[edit] disable screen saver/blanking
a common issue with raspberry pis used in kiosk/monitor setups is the screen blanking/screen saver kicking in. You can disable them with the following commands:
~$xset s noblank ~$xset s noexpose ~$xset s off ~$xset dpms 0 0 0
check it by doing:
~$xset -q Keyboard Control: auto repeat: on key click percent: 0 LED mask: 00000000 XKB indicators: 00: Caps Lock: off 01: Num Lock: off 02: Scroll Lock: off 03: Compose: off 04: Kana: off 05: Sleep: off 06: Suspend: off 07: Mute: off 08: Misc: off 09: Mail: off 10: Charging: off 11: Shift Lock: off 12: Group 2: off 13: Mouse Keys: off auto repeat delay: 500 repeat rate: 33 auto repeating keys: 00ffffffdffffbbf fadfffefffedffff 9fffffffffffffff fff7ffffffffffff bell percent: 0 bell pitch: 400 bell duration: 100 Pointer Control: acceleration: 20/10 threshold: 10 Screen Saver: prefer blanking: no allow exposures: no timeout: 0 cycle: 600 Colors: default colormap: 0x20 BlackPixel: 0x0 WhitePixel: 0xffff Font Path: /usr/share/fonts/X11/misc,/usr/share/fonts/X11/Type1,built-ins DPMS (Energy Star): Standby: 0 Suspend: 0 Off: 0 DPMS is Enabled Monitor is On
[edit] Script xset settings in case of reboot/poweroff
Create a script for the default pi user to launch
~$ nano /home/pi/xset.sh #!/bin/bash xset s noblank xset s noexpose xset s off xset dpms 0 0 0
Make it executable
~$ sudo chmod +x /home/pi/xset.sh
Add it to rc.local for launch on boot
~$ sudo nano /etc/rc.local #run script to disable screensaver, screen blanking, screen exposure, standby, suspend, and energy star features. sleep 5; export DISPLAY=:0; su - pi -c "/home/pi/xset.sh &"
[edit] Turn monitors on/off
You can use tvservice to turn the monitors on and off, however, turning them back on and displaying the signal is a bit tricky.
[edit] script to turn monitor on/off
#!/bin/bash -e # /usr/local/sbin/raspi-monitor # Script to enable and disable the HDMI signal of the Raspberry PI # Inspiration: http://www.raspberrypi.org/forums/viewtopic.php?t=16472&p=176258 CMD="$1" function on { /opt/vc/bin/tvservice --preferred # Hack to enable virtual terminal nr 7 again: chvt 6 chvt 7 } function off { /opt/vc/bin/tvservice --off } function must_be_root { if [ $USER != root ]; then echo "ERROR: Script must be executed as the root user" exit 1 fi } function main { must_be_root if [ "$CMD" == "on" ]; then on elif [ "$CMD" == "off" ]; then off else echo "Usage: $0 <on|off>" exit 1 fi exit 0 } main
[edit] Add to cron job
Add the following script as a cronjob file
~$ sudo nano /etc/cron.d/raspi-monitor-scheduler
# /etc/cron.d/raspi-monitor-scheduler # Enable the monitor every weekday morning at 7:00 0 7 * * 1,2,3,4,5 root /usr/local/sbin/raspi-monitor on > /dev/null 2>&1 # Disable the monitor every weekday evening at 19:30 30 19 * * 1,2,3,4,5 root /usr/local/sbin/raspi-monitor off > /dev/null 2>&1
Make it executable
~$ sudo chmod +x /etc/cron.d/raspi-monitor-scheduler
[edit] init.d script to control/check status
Add the following script to init.d
pi@raspberrypi:~$ sudo nano /etc/init.d/monitor #!/bin/sh ### BEGIN INIT INFO # Provides: vncviewer # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Turn on monitor at boot time # Description: Turn on monitor at boot time. ### END INIT INFO monitor_status=$(tvservice -s | cut -c9-13) case "$1" in start) /opt/vc/bin/tvservice --preferred # Hack to enable virtual terminal nr 7 again: chvt 6 chvt 7 ;; stop) /opt/vc/bin/tvservice --off ;; status) if [ "$monitor_status" -eq "12001" ]; then echo 'Monitor is on' elif [ "$monitor_status" -eq "12000" ]; then echo "Monitor is off" else echo "Usage: $0 <start|stop|status>" exit 1 fi
[edit] Usage
- Start
~$ sudo service monitor start
Powering on HDMI with preferred settings
- Stop
~$ sudo service monitor stop
Powering off HDMI
- Status
~$ sudo service monitor status
Monitor is on
Monitor is off