Display brightness control

2009-07-27 05:23
I've added a display brightness control menu to dmenu on my Dingoo, which makes it possible to easily adjust the display backlight brightness. The brightness setting will be saved to disk and automatically loaded on boot. Here is what I've done to accomplish this.

First I have created two shell scripts. One for saving the new brightness setting (brightness.save) and another for actually adjusting the brightness (brightness.set). Both files need to be in the local/sbin directory.

brightness.save (56 bytes)
brightness.set (138 bytes)

Then I have added a new submenu to my dmenu.cfg with menu entries for various brightness settings (10 %, 25 %, 33 %, 50 %, 66 %, 75 %, 100 %). I have used a light bulb image as the menu icon. It needs to be in the res directory inside the dmenu folder.
Menu Brightness
{
	Icon = "res/brightness.png"
	Name = "Display Brightness"

MenuItem Brightness100 { Icon = "res/brightness.png" Name = "100 %" Executable = "./brightness.save 100" WorkDir = "/usr/local/sbin" }

MenuItem Brightness75 { Icon = "res/brightness.png" Name = "75 %" Executable = "./brightness.save 75" WorkDir = "/usr/local/sbin" }

MenuItem Brightness66 { Icon = "res/brightness.png" Name = "66 %" Executable = "./brightness.save 66" WorkDir = "/usr/local/sbin" }

MenuItem Brightness50 { Icon = "res/brightness.png" Name = "50 %" Executable = "./brightness.save 50" WorkDir = "/usr/local/sbin" }

MenuItem Brightness33 { Icon = "res/brightness.png" Name = "33 %" Executable = "./brightness.save 33" WorkDir = "/usr/local/sbin" }

MenuItem Brightness25 { Icon = "res/brightness.png" Name = "25 %" Executable = "./brightness.save 25" WorkDir = "/usr/local/sbin" }

MenuItem Brightness10 { Icon = "res/brightness.png" Name = "10 %" Executable = "./brightness.save 10" WorkDir = "/usr/local/sbin" } }


Finally, I've inserted an additional line into the local/sbin/main script to load the brightness setting on boot.

/usr/local/sbin/brightness.set


This line needs to be inserted before running dmenu.

That's it.

UPDATE: As you can read in the comments below, there was a bug in the scripts, which caused the screen to turn all black when using it for the first time. I've modified and updated the brightness.set script such, that it sets the brightness only when there has been a value stored before.
Share:
 
ironic (web) says:
2009-08-04 20:35:00
It Works !!
Nice nice nice…
Thanx guy
alfsoft (web) says:
2009-08-08 10:07:00
Thank you for these useful scripts! Worked nice. One thing I’ve noticed: on the first boot with these files the brightness was set to zero :) So I had to browse dmenu by memory and set another brightness value menu parameter.
wejp (web) says:
2009-08-11 11:36:00
Oh, yes you are right. That happens because the config file where the brightness value is stored does not exist yet (obviously ;) .
Although you don’t need a workaround anymore, others can avoid that behaviour by creating a file called lcd_brightness.conf in the local/home directory with just one line containing the value 100 for maximum brightness.
alfsoft (web) says:
2009-08-11 12:33:00
I advise you to add link to the default lcd_brightness.conf next to .save and .set :)
Or to extend brightness.set with the line that checks the existence of the .conf file. And if it doesn’t, then to ‘cat’ it and to add the ’100′ text into it. Do not know exactly the bash script command for this, sorry.
wejp (web) says:
2009-08-19 13:09:00
I’ve already updated the script, so it first checks for the existance of the lcd_brightness.conf file and only if it exists the brightness is updated. :)
(You can use the if condition in shell scripts with -e to check if a file exists.)
punkysfan (web) says:
2009-08-19 13:20:00
heres the same bulb with diffirent shades

s811.photobucket.com/albums/zz39/punkysfan/
lord bla (web) says:
2009-08-19 16:28:00
great!

Leave a comment

Name
E-Mail
Website
Homepage
Comment