Ubuntu – Problem with brightness Sony Vaio NVIDIA graphics

11.10brightnessnvidiashortcuts

Recently I have installed Ubuntu 11.10 on my laptop (Sony Vaio VPCF22MOE). My graphics card is NVIDIA GeForce GT 540M.

After ubuntu installation I installed NVIDIA Driver Version which is 295.33. I uninstalled Nouveau using:

sudo apt-get --purge remove xserver-xorg-video-nouveau

I noticed a few things: my brightness Fn keys are not working (Fn+F5 / Fn+f6). Also in compiz 3D is not working. The brightness is set up to maximum.

I have tried almost everything. I have followed other threads and edited in million different ways xorg.conf. Xbacklight command in terminal doesn't work either. Does anybody have any idea how to configure it in order to make it to work?


Best Answer

Im personally using Vaio VPCCW21FX (Nvidia Graphic) and Ubuntu Studio 11.10 .. I tried many solutions and nothing could resolve my problem with LCD brightness! Finally wrote these two perl files to manually set brightness/Contrast and Gamma functions inside Nvidia driver config file.

This will be helpfull only if you are able to change brightness within Nvidia X Server Settings

Step 1: create this file and name it "Brightness-Up.pl" (you can use any text editing tool like : gedit,nano,vi,etc.. copy & paste)

    ### Code by forgottenrip@yahoo.com ###
    my $find1 = "0/RedBrightness=";my $find2 = "0/RedGamma=";
open FILE, "<Nvidia-Settings.cfg";
my @lines = <FILE>;
for (@lines) {
    if ($_ =~ /$find1/) { chomp $_;$value= substr($_,16,5); }
    if ($_ =~ /$find2/) { chomp $_;$value2= substr($_,11,5);}     
}
my @Lines;
if ( $value > 0.0) { $value = $value - 0.30 };  
if ( $value2 > 1.1) { $value2 = $value2 - 0.08 };  
$last_value = $value + 0.30;
$Lines[0] ="0/RedBrightness=".$last_value;
$Lines[1] ="0/GreenBrightness=".$last_value;;
$Lines[2] ="0/BlueBrightness=".$last_value;;
$last_value = $value + 0.30;
$Lines[3] ="0/RedContrast=".$last_value;;
$Lines[4] ="0/GreenContrast=".$last_value;;
$Lines[5] ="0/BlueContrast=".$last_value;;
$last_value = $value2 + 0.08;
$Lines[6] ="0/RedGamma=".$last_value;;
$Lines[7] ="0/GreenGamma=".$last_value;;
$Lines[8] ="0/BlueGamma=".$last_value;;

$filename = "Nvidia-Settings.cfg";
open fh2,'>',$filename or die ("can't open '$filename': $! \n");
foreach ( @Lines )
{ chomp;print "$_\n";print fh2 "$_\n"; };
close fh2; 
`nvidia-settings -l --config=Nvidia-Settings.cfg`;

Step 2: then make another file, name it "Brightness-Down.pl" and fill with this code:

    ### Code by forgottenrip@yahoo.com ###
    my $find1 = "0/RedBrightness=";my $find2 = "0/RedGamma=";
open FILE, "<Nvidia-Settings.cfg";
my @lines = <FILE>;
for (@lines) {
    if ($_ =~ /$find1/) {chomp $_;$value= substr($_,16,5);}
    if ($_ =~ /$find2/) {chomp $_;$value2= substr($_,11,5);}     
}
my @Lines;
if ( $value < -0.80) { $value = $value + 0.30 };  
if ( $value2 < 0.8) { $value2 = $value2 + 0.08 };  
$last_value = $value - 0.30;
$Lines[0] ="0/RedBrightness=".$last_value;
$Lines[1] ="0/GreenBrightness=".$last_value;;
$Lines[2] ="0/BlueBrightness=".$last_value;;
$last_value = $value - 0.30;
$Lines[3] ="0/RedContrast=".$last_value;;
$Lines[4] ="0/GreenContrast=".$last_value;;
$Lines[5] ="0/BlueContrast=".$last_value;;
$last_value = $value2 - 0.08;
$Lines[6] ="0/RedGamma=".$last_value;;
$Lines[7] ="0/GreenGamma=".$last_value;;
$Lines[8] ="0/BlueGamma=".$last_value;;

$filename = "Nvidia-Settings.cfg";
open fh2,'>',$filename or die ("can't open '$filename': $! \n");
foreach ( @Lines )
{ chomp;print "$_\n";print fh2 "$_\n"; };
close fh2; 
`nvidia-settings -l --config=Nvidia-Settings.cfg`;

Step 3: You need to create another file which contains Nvidia Settings.. name it "Nvidia-Settings.cfg" its important that you write name exactly same. fill with:

0/RedBrightness=0.1
0/GreenBrightness=0.1
0/BlueBrightness=0.1
0/RedContrast=0.1
0/GreenContrast=0.1
0/BlueContrast=0.1
0/RedGamma=1.14
0/GreenGamma=1.14
0/BlueGamma=1.14

Thats it! now place these files in unique folder.. you have to bind your Function Keys to these two perl file.you can use Compiz>commands to do that. Run below command to install the compizconfig-settings-manager

sudo apt-get install compizconfig-settings-manager

or even you can run seperately with these two commands in shell (terminal):

user$ perl Brightness/Brightness-Up.pl
user$ perl Brightness/Brightness-Down.pl

where Brightness is folder I put those files in it.