Ubuntu backlight control

General discussion relating to the O2 Joggler, from the default O2 setup, to alternative operating systems and applications.
bobsammers
Posts: 16
Joined: Wed Jul 03, 2013 1:14 pm

Ubuntu backlight control

Post by bobsammers »

I've been trying to set up my Joggler with an external HD as a GUI-less server, for Squeezebox Server purposes. I've used the Ubuntu Base/Server 12.04 LTS (V1.4 - 09/04/2013) image written to a 750GB external drive and it's working pretty much how I want it.

My one problem is the backlight, which (in the dark) is still visible after screen blanking. I don't want the waste of energy or the extra heat, since I can't see the Joggler where I want tot put it anyway.

I've read about two methods for manipulating the display - writing to files in the "/sys/class/backlight/openframe-bl" directory and using "xset" from the "x11-server-utils" package.

Writing to "/sys/class/backlight/openframe-bl/brightness" nets this:

Code: Select all

bob@joggler:/sys/class/backlight/openframe-bl$ sudo echo "5" > brightness
-bash: brightness: Permission denied
even though root apparently has write permission.

The xset util behaves in the following manner:

Code: Select all

bob@joggler:~$ sudo xset q
xset:  unable to open display ""
bob@joggler:~$ sudo xset -display :0.0 -q
xset:  unable to open display ":0.0"
Neither of these responses are what I was expecting. Can anyone offer any insight, or (better yet), a fix / way around this problem? I think the only thing I've done is installed Logitech Media Server and Samba (and x11-server-utils) on top of the original Ubuntu image.
ilovemyjoggler
Posts: 711
Joined: Sun May 13, 2012 4:42 pm

Re: Ubuntu backlight control

Post by ilovemyjoggler »

No idea if this works outside squeezeplay or if you've seen it...

http://www.jogglerwiki.com/forum/viewto ... ght#p10681

Am posting from my phone so can't even check if its the same code you used. Apologies if it is and also if it doesn't work.

As for the waste of energy - oh dear. I've always thought i was energy aware but i have 5 of these little suckers lighting my house like a christmas tree. I thought they were supposed to have a low power consumption.
bobsammers
Posts: 16
Joined: Wed Jul 03, 2013 1:14 pm

Re: Ubuntu backlight control

Post by bobsammers »

Thanks very much for your response, ilovemyjoggler. I hadn't seen that and it definitely helped.

I followed the patch through into the Squeezeplay installation tarball and realised I was being a bit dim! Bash command output redirection isn't elevated, even if the command itself is run with sudo, so I was trying to write to the brightness psuedo-file with normal user permissions. Squeezeplay for Joggler provides a udev rule to change permissions on the file so anyone can write to it and it's much easier now I've installed that.

I mentioned the first problem because I thought it might be relevant to xset not working. I want to be able to type xset dpms force off to switch the screen off completely (which, if I understand correctly, will properly switch off the backlight power), but adding the udev rules hasn't altered xset's apparent inability to talk to the screen hardware.

I'm sure you're correct about the power consumption - it must be pretty low (totally unsubstantiated guess: £2 - £3 worth a year). It's more the principle of the thing when it's out of sight in my server room (read: cupboard under the stairs) - it's just completely pointless having the backlight on, not to mention the fact that Joggler cooling apparently isn't great and it's a confined space. If you're using the displays, I'm not sure you deserve to worry too much!
bobsammers
Posts: 16
Joined: Wed Jul 03, 2013 1:14 pm

Re: Ubuntu backlight control

Post by bobsammers »

Just as an addendum: I should have mentioned that the Squeezeplay functionality ilovemyjoggler mentioned writes to the /sys/.../backlight psuedo-file for brightness control (which is now working on my Joggler) but uses xset to actually switch off the backlight (which is not).
Wilberforce
Posts: 134
Joined: Sun Apr 15, 2012 4:52 pm

Re: Ubuntu backlight control

Post by Wilberforce »

My hack is to start an x server. I have setup autologin on tty1 and have this in my bashrc:

Code: Select all

if [ $(tty) == "/dev/tty1" ]; then
startx /home/joggler/screenoff
fi
/home/joggler/screenoff :

Code: Select all

#!/bin/bash
echo 0 > /sys/class/backlight/openframe-bl/brightness
xset dpms 5 5 5
xset dpms force off
xset s 60 60
while true; do 
	sleep 1d
done
I put the sleep in to stop people using tty1. If anyone has a better solution, I will be happy to know!
bobsammers
Posts: 16
Joined: Wed Jul 03, 2013 1:14 pm

Re: Ubuntu backlight control

Post by bobsammers »

Ah... so you're saying that xset won't work because it needs an X server running? That does makes sense, but I thought I'd seen something that suggested the tools could work standalone. Obviously I misunderstood. I love the irony of installing and running X to power off the screen!

Presumably, were the script allowed to complete, the X server would shut down again. I'm not really following the problem with that (indeed, it sounds better than leaving it running): what happens if X stops again after the xset commands are successfully executed? What happens if someone reuses tty1?
User avatar
BuZz
Site Admin
Posts: 1460
Joined: Fri Mar 04, 2011 1:15 am

Re: Ubuntu backlight control

Post by BuZz »

[edit] sorry realised this was worked out earlier in the thread.
bobsammers wrote: Writing to "/sys/class/backlight/openframe-bl/brightness" nets this:

Code: Select all

bob@joggler:/sys/class/backlight/openframe-bl$ sudo echo "5" > brightness
-bash: brightness: Permission denied
even though root apparently has write permission.
you are not writing it as root though. the redirect is done by the shell, not by sudo.

see
http://notfaq.wordpress.com/2007/09/26/ ... t-as-sudo/
and
http://askubuntu.com/questions/20578/su ... ect-output
User avatar
Leonardo
Posts: 146
Joined: Tue Dec 25, 2012 10:51 pm

Re: Ubuntu backlight control

Post by Leonardo »

I confirm, sorry for replying so late, if you want to do a real test with echo, become root for example with:
sudo -s

then run the echo 5 > brightness

if it works you can create a script/wrapper you can call with sudo.
Cheers, Leo
bobsammers
Posts: 16
Joined: Wed Jul 03, 2013 1:14 pm

Re: Ubuntu backlight control

Post by bobsammers »

Leonardo wrote:I confirm, sorry for replying so late, if you want to do a real test with echo, become root for example with:
sudo -s

then run the echo 5 > brightness

if it works you can create a script/wrapper you can call with sudo.
Cheers, Leo
Thanks for your help Leonardo and BuZz.

As you may have gathered, I did work out what I was doing wrong and I can now change the brightness by writing to this pseudo-file (I changed permissions on the file, but sudo su / sudo -s did work). Unfortunately, this won't let me completely switch off the backlight, which is what I really want to do.

Can anyone confirm whether or not the only straightforward way of sending DPMS commands ("force off", is what I'm after) to the screen is by starting and maintaining an X server? It seems like a hammer to smash a nut, but Googling turns up nothing else.
User avatar
Leonardo
Posts: 146
Joined: Tue Dec 25, 2012 10:51 pm

Re: Ubuntu backlight control

Post by Leonardo »

Hi Bobsammers, try these two commands:

xset dpms force standby
or
xset dpms force off

both of them should turn off the display
if you work from ssh, don't forget to "export display" with this command:

export DISPLAY=localhost:0.0

this allows you to execut x programs from a ssh console, else you could get an error like: xset: unable to open display ""

HTH, Leo
bobsammers
Posts: 16
Joined: Wed Jul 03, 2013 1:14 pm

Re: Ubuntu backlight control

Post by bobsammers »

Thanks very much for your continued assistance, Leonardo.

As I understand it, xset only works with an X11 server running. I don't have X installed and (presumably becuase of this) your method isn't working for me (I get unable to open display "localhost:0.0").

I realise it does provide a possible solution, but I was hoping not to have to constantly run an X server just to switch off the display. It seems to me that whatever X does to send DPMS instructions to the screen, it should be possible to duplicate that without the X bit. I just don't know how (but I'm still hoping to find out)!
Juggler
Posts: 249
Joined: Thu Apr 21, 2011 2:34 am

Re: Ubuntu backlight control

Post by Juggler »

This is something I've wanted to do for sometime, but haven't really looked into it - so thanks for bringing this up Bob !

I've been running BuZz's great Ubuntu minimal distro for some time on a few Jogglers, and despite what I thought initially they have been rock solid. I'm actually amazed there has not been some problems, even with flaky hubs and flash drives, they still keep on working... So thanks for doing some great work on the distros for the Joggler BuZz !

I wrote a script to control the brightness, which is below :

#!/bin/bash
echo "$1" > /sys/class/backlight/openframe-bl/brightness

Have this as an executable file, say called bright, and invoke with $ sudo ./bright 10
for 10/32 brightness. Range is from 0 to 32, by default in Ubuntu base.

I was quite pleased with this as it is the first UNIX (like) script I've written since doing some work on an IMP and Perkin Elmer in the 80's.

For some time I thought that some of the other pseudo-files in same directory may affect the backlight. These being :

-r--r--r-- 1 root root 4096 Jul 9 01:09 actual_brightness
-rw-r--r-- 1 root root 4096 Jul 9 01:09 bl_power
-rw-r--r-- 1 root root 4096 Jul 9 01:09 brightness
lrwxrwxrwx 1 root root 0 Jul 9 01:09 device -> ../../../openframe-bl
-r--r--r-- 1 root root 4096 Jul 9 01:09 max_brightness
drwxr-xr-x 2 root root 0 Jul 9 01:09 power
lrwxrwxrwx 1 root root 0 Jan 1 2005 subsystem -> ../../../../../class/backlight
-r--r--r-- 1 root root 4096 Jul 9 01:09 type
-rw-r--r-- 1 root root 4096 Jan 1 2005 uevent

it was bl_power I thought.

Anyway, doing the same thing to bl_power as done to brightness, did nothing, as far as I can tell. I'm interested to know what this is for.

Next I thought about putting a physical switch on there some how. Don't know exactly how this could be done, but may work. May also introduce more problems and be a lot more involved than I'm prepared to tinker with.

Like you Bob, I don't want to have an X server running. I'd like to keep things as light as possible.

So, given what has been discussed above, I thought there may be a way to capture the DPMS output from the xset command. First, I had to find out what DPMS was :

https://en.wikipedia.org/wiki/VESA_Disp ... _Signaling

explained a bit.

Then a search for a ubuntu dpms commands turned up the following possibilities :

http://askubuntu.com/questions/62858/tu ... mmand-line

Seems we may have a solution with the vbetool :

http://linux.die.net/man/1/vbetool
http://www.codon.org.uk/~mjg59/vbetool/

It appears that this tool depends on libx86. I'm guessing that it does not require an X server to be running, but just uses some of the code in libx86.

Of course, there's only one way to find out - try it out. Trouble is, if you turn the screen off and it won't turn back on, your left in the dark, so to speak. Wonder, if something could be done from a remote ssh session, then, I presume, that wouldn't be effected, but you could see the result of using vbetool, with whatever parameters used.

HTH

PS

Some other links of interest I came across are :

https://wiki.ubuntu.com/FrameBuffer
https://wiki.ubuntu.com/X/Troubleshooting/BlankScreen
http://systembash.com/content/how-to-tu ... in-ubuntu/

Just wondering if it could be possible to get the backlight off using the framebuffer, fbset command ?

Just looking through the last link, one user states :

Yebo29
sudo vbetool dpms off did the trick for me!
Juggler
Posts: 249
Joined: Thu Apr 21, 2011 2:34 am

Re: Ubuntu backlight control

Post by Juggler »

Just installed vbetool and it installs the xlib86-1 library as well :

root@joggler:~# apt-get -s install vbetool
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libx86-1
The following NEW packages will be installed:
libx86-1 vbetool
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Inst libx86-1 (1.1+ds1-7ubuntu1 Ubuntu:12.04/precise [i386])
Inst vbetool (1.1-2ubuntu1 Ubuntu:12.04/precise [i386])
Conf libx86-1 (1.1+ds1-7ubuntu1 Ubuntu:12.04/precise [i386])
Conf vbetool (1.1-2ubuntu1 Ubuntu:12.04/precise [i386])
root@joggler:~# apt-get install vbetool
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libx86-1
The following NEW packages will be installed:
libx86-1 vbetool
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 19.8 kB of archives.
After this operation, 110 kB of additional disk space will be used.
Do you want to continue [Y/n]? y

Tried using it from an ssh session and :

root@joggler:~# vbetool dpms off
Error: something went wrong performing real mode interrupt

I get this error for every command I try :

root@joggler:~# vbetool vbemode get
Error: something went wrong performing real mode interrupt
root@joggler:~# vbetool vbefp getbrightness
Error: something went wrong performing real mode interrupt
root@joggler:~# vbetool dpms on
Error: something went wrong performing real mode interrupt

So, I'm guessing it has something to do with the using it an ssh session.

Installed fbset too. But seems there is no option in there to turn the screen off :

Linux Frame Buffer Device Configuration Version 2.1 (23/06/1999)
(C) Copyright 1995-1999 by Geert Uytterhoeven

Usage: fbset [options] [mode]

Valid options:
General options:
-h, --help : display this usage information
--test : don't change, just test whether the mode is valid
-s, --show : display video mode settings
-i, --info : display all frame buffer information
-v, --verbose : verbose mode
-V, --version : print version information
-x, --xfree86 : XFree86 compatibility mode
-a, --all : change all virtual consoles on this device
Frame buffer special device nodes:
-fb <device> : processed frame buffer device
(default is /dev/fb0)
Video mode database:
-db <file> : video mode database file
(default is /etc/fb.modes)
Display geometry:
-xres <value> : horizontal resolution (in pixels)
-yres <value> : vertical resolution (in pixels)
-vxres <value> : virtual horizontal resolution (in pixels)
-vyres <value> : virtual vertical resolution (in pixels)
-depth <value> : display depth (in bits per pixel)
-nonstd <value> : select nonstandard video mode
-g, --geometry ... : set all geometry parameters at once
-match : set virtual vertical resolution by virtual resolution
Display timings:
-pixclock <value> : pixel clock (in picoseconds)
-left <value> : left margin (in pixels)
-right <value> : right margin (in pixels)
-upper <value> : upper margin (in pixel lines)
-lower <value> : lower margin (in pixel lines)
-hslen <value> : horizontal sync length (in pixels)
-vslen <value> : vertical sync length (in pixel lines)
-t, --timings ... : set all timing parameters at once
Display flags:
-accel <value> : hardware text acceleration enable (false or true)
-hsync <value> : horizontal sync polarity (low or high)
-vsync <value> : vertical sync polarity (low or high)
-csync <value> : composite sync polarity (low or high)
-gsync <value> : synch on green (false or true)
-extsync <value> : external sync enable (false or true)
-bcast <value> : broadcast enable (false or true)
-laced <value> : interlace enable (false or true)
-double <value> : doublescan enable (false or true)
-rgba <r,g,b,a> : recommended length of color entries
-grayscale <value> : grayscale enable (false or true)
Display positioning:
-move <direction> : move the visible part (left, right, up or down)
-step <value> : step increment (in pixels or pixel lines)
(default is 8 horizontal, 2 vertical)

Oh well, that's enough for now.
Wilberforce
Posts: 134
Joined: Sun Apr 15, 2012 4:52 pm

Re: Ubuntu backlight control

Post by Wilberforce »

Try adding this to you rc.local:

Code: Select all

setterm -powersave on
setterm -powerdown 1
setterm -blank 1
for a one minute timeout. setterm cannot be issued remotely.
bobsammers
Posts: 16
Joined: Wed Jul 03, 2013 1:14 pm

Re: Ubuntu backlight control

Post by bobsammers »

Juggler wrote:For some time I thought that some of the other pseudo-files in same directory may affect the backlight.
[...]
doing the same thing to bl_power as done to brightness, did nothing, as far as I can tell. I'm interested to know what this is for.
Hi Juggler, thanks for your ideas. Over the last few days I've actually been trying some of the things you've been playing with too.

I discovered there was a wiki page on backlight control. Rather contrarily (in my opinion) writing "1" to bl_power turns the backlight off, while "0" turns it back on. It works for me, but it appears to be identical to setting brightness to 0: the backlight is still visible in dim light as before.

I also tried vbetool and got the same results as you, also running it from an SSH session.
Wilberforce wrote:Try adding this to you rc.local:

Code: Select all

setterm -powersave on
setterm -powerdown 1
setterm -blank 1
for a one minute timeout. setterm cannot be issued remotely.
Thanks, Wilberforce. I thought you were incorrect to say that setterm couldn't be issued remotely. You can do this from an SSH session:

Code: Select all

setterm -clear all > /dev/tty1
and the Joggler display's login screen is cleared. Unfortunately the more interesting commands (including all supposedly valid -powersave options) do this:

Code: Select all

root@joggler:/home/bob# setterm -powersave powerdown > /dev/tty1
setterm: cannot (un)set powersave mode: Invalid argument
However, so I could claim I tried it on the actual console, I did... the -powersave commands work fine! So I did this:

Code: Select all

setterm -powersave powerdown -blank 1 -powerdown 1
and the screen blanks after a minute... but there is the same glow from it as I've had all along.

So, new questions:
  1. Is it actually possible to switch the backlight off? Do those people with X servers and the capability to use xset dpms force off actually see a completely black screen in a dark room (Wilberforce, are you able to test this)?
  2. Have I been turning off the backlight all along, and what I'm seeing is the glow of the couple of LEDs which appear to be fitted inside the case (illuminating the screen suspiciously evenly )?
bobsammers
Posts: 16
Joined: Wed Jul 03, 2013 1:14 pm

Re: Ubuntu backlight control

Post by bobsammers »

[offtopic]
Hi BuZz,

I've only belatedly realised (reading through this thread) that you are responsible for the Ubuntu images I'm using. Thank you so much for doing this, it's breathed a new lease of life into a Joggler-in-a-cupboard and meant I can keep my power-hungry Dell tower switched off most of the time but still use my squeezeboxes and have a constantly running fileserver.

And it seems to have been done very well!
[/offtopic]
bobsammers
Posts: 16
Joined: Wed Jul 03, 2013 1:14 pm

Re: Ubuntu backlight control

Post by bobsammers »

Just an update on vbetool.

After it turned out that setterm could do some things remotely, but not others, I tried vbetool at the console. I get the same results as reported earlier: every command gives "Error: something went wrong performing real mode interrupt"
Juggler
Posts: 249
Joined: Thu Apr 21, 2011 2:34 am

Re: Ubuntu backlight control

Post by Juggler »

I tried the setterm commands, Wilberforce suggested, just after midday today, and it appeared to work. But it was hard to be certain as it was quite light. Just had a look a few minutes ago and I can see that the illumination on the screen is the same as previously. However, if I have the brightness set on the highest, when the powersave/blank kicks in, the intensity of the backlight is the same/similar to that of previous, where brightness was set to 0.

So with regard to the above, and to the other conclusions Bob has, I corroborate with you.

I'm tempted to get a full xubuntu or other distro with X and see what happens when an x server is running and the relevant xset commands are issued. Is the backlight fully extinguished ?

I would like to add though, that in the 3+ months of having Jogglers running 24/7 with brightness mostly at 0, that the Jogglers and the power supplies have not become noticeably hot. Having said that, the Jogglers are under a minute load and have only to power a hub, keyboard, flash drive and camera. One observation is that the hub is quite hot and that the heat transfers into the flash drive, possibly as it has a metallic casing.

Nevertheless, as far as I am concerned, it is always better to turn something off that is not needed/being used than to just leave it.

Now, if it is possible to get the desired result with X running and using the xset command, how can we find out what is happening ? I wonder if there is some tool to capture what is sent to the screen or whatever makes it happen ? And if we need to have a look through some code; happy to do that. Actually, when I did some searches on the vbetool and the error message Bob and I have received, I came across the source code for the tool. But given the time of day, I usually do this type of stuff, I didn't go any further...
bobsammers
Posts: 16
Joined: Wed Jul 03, 2013 1:14 pm

Re: Ubuntu backlight control

Post by bobsammers »

So I've spent 1/2 an hour this morning looking at the X11 source code...

xset dpms force off calls a function in the DPMS.c module of libXext called DPMSForceLevel(). This uses a macro, GetReq() defined in xlibinit.h which appears to create a data structure containing opcodes and relevant parameters inside a buffer of some sort. And some magic happens.

The GetReq() macro seems to be very commonly used within X11 and I'd hazard a guess that it is responsible for talking to the video card or its driver. It's not clear to me exactly what this interface is or where it might be documented. It seems it's actually an internal messaging system to allow extensions and other modules to talk to the server. So the question is, where in the server is this request processed?

I've got a bit bogged down in the details now and I've run out of free time today.
User avatar
BuZz
Site Admin
Posts: 1460
Joined: Fri Mar 04, 2011 1:15 am

Re: Ubuntu backlight control

Post by BuZz »

bobsammers wrote:[offtopic]
Hi BuZz,

I've only belatedly realised (reading through this thread) that you are responsible for the Ubuntu images I'm using. Thank you so much for doing this, it's breathed a new lease of life into a Joggler-in-a-cupboard and meant I can keep my power-hungry Dell tower switched off most of the time but still use my squeezeboxes and have a constantly running fileserver.

And it seems to have been done very well!
[/offtopic]
you're welcome :) Always nice to hear people are getting use out of them.
Post Reply