2

I have a problem with my brightness setting. When I decrease brightness to 1 and I reboot the computer, it reset to maximum brightness value. I tired to adjust it and decrease it again to 1. Why the setting doesn't save the last brightness setting for me? How can I save the current value and restore it after reboot via programming?

I also tried to add echo 0 > /sys/class/backlight/intel_backlight/brightness in /etc/rc.local file, but after rebooting, it reset to the maximum again.

My laptop model is Vaio SVF1521DCXW.

αғsнιη
  • 35,660

3 Answers3

2

I had another folder named acpi_video0 in this location /sys/class/backlight/

I added following command at the end but before exit 0 in gksu gedit /etc/rc.local file:

 echo 0 > /sys/class/backlight/intel_backlight/brightness
 echo 0 > /sys/class/backlight/acpi_video0/brightness

It worked for me. And now I want to get current brightness and save it into a file to restore it at next restart.

How to functionality last adjusted brightness load after next reboot?

Step 1: Check brightness levels

Set your brightness to maximum and check current level by below command:

 cat /sys/class/backlight/acpi_video0/max_brightness

   (my laptop max brightness is 100 :)

Now set your brightness to minimum and check current level by evoking next command:

 cat /sys/class/backlight/acpi_video0/brightness

   (my laptop min brightness level is 0 :)

Step 2: Create a file to store your current brightness:

 sudo touch /etc/init.d/prev_brightness
 sudo chmod o+w /etc/init.d/prev_brightness

Step 3: Create a script that stores your current brightness(the save_screen_brightness file) when shutting down into the file prev_brightness that you created in the previous step:

 sudo touch /etc/init.d/save_current_brightness
 sudo chmod +x /etc/init.d/save_screen_brightness

Open the save_screen_brightness file with your favorite editor app:

 gksu gedit /etc/init.d/save_screen_brightness

And put this script into it:

 #!/bin/sh
 cat /sys/class/backlight/acpi_video0/brightness > /etc/init.d/prev_brightness

Save it and go to next step ;)

Step 4: Make the script run every time we shutdown or reboot the computer:

 sudo ln -s /etc/init.d/save_current_brightness /etc/rc0.d/K99save_screen_brightness
## Shuttingdown ^^
 sudo ln -s /etc/init.d/save_current_brightness /etc/rc6.d/K99save_screen_brightness
## Rebooting ^^

Step 5: Load the value we stored when starting the computer:

Add the following line at the end and before exit 0 into your /etc/rc.local file:

 cat /etc/init.d/prev_brightness > /sys/class/backlight/acpi_video0/brightness

That's it ;)

Thanks to @Hevilath's answer and @user207402's answer and also @AiPdimi's answer

αғsнιη
  • 35,660
2

On Sony Vaio E15136CN (and most others with an AMD Graphic Card), acpi_video0 is not present. Instead, there is radeon_bl0 in /sys/class/backlight. So the statement to be added to rc.local file is

echo 60 > /sys/class/backlight/radeon_bl0/brightness

Replace 60 with whatever value is suitable to you. My brightness range is 0 to 255 (you can check your maximum brightness in /sys/class/backlight/radeon_bl0/max_brightness), so 60 suits me.

None of the answers I came across mentioned the AMD Radeon Graphic Card. So I thought I might add an answer related to it. Also, Stéphane Gourichon's answer to How do I set default display brightness? doesn't work on Sony Vaio E15136CN. So in short, these are the steps to be executed:

Step 1:

sudo nano /etc/rc.local

Step 2:

echo 60 > /sys/class/backlight/radeon_bl0/brightness

Step 3:

Restart your system.

phoenix
  • 113
1

make a file like fixMaxBrightness.sh

copy all these line to it, make it executable by chmod +x fixMaxBrightness.sh and run it by this command sudo ./fixMaxBrightness.sh restart your system.


#!/bin/bash
#this script are going to get last change screen Brightness
#and put it in /.FixBritness
#this folder is in home directory that the following line make it 
mkdir $HOME/.FixBritness
cd $HOME/.FixBritness

#make two another script that put current brightness in "currntBritness" file, 
#and it must run when system is going down
cat > getBritness.sh <<_EOF_
#!/bin/bash
cat /sys/class/backlight/acpi_video0/actual_brightness > $HOME/.FixBritness/currntBritness
exit 0
_EOF_

#to get last brightness that saved in "currntBritness" file
#and put it in system brightness file 
cat > putLastBritness.sh <<_EOF_
#!/bin/bash
cat $HOME/.FixBritness/currntBritness > /sys/class/backlight/acpi_video0/brightness
exit 0
_EOF_

# create currntBritness file and put zero to defult value
touch currntBritness
echo 0 > currntBritness

chmod 755 getBritness.sh
chmod 755 putLastBritness.sh
#put in /etc/init.d/ because these file will use in /etc/rc1 through rc6
mv getBritness.sh /etc/init.d/
mv putLastBritness.sh /etc/init.d/

#make a symbolic link to  getBritness.sh that get brightness when:
#shutting down
ln -s /etc/init.d/getBritness.sh /etc/rc0.d/S11getBritness.sh
#and restart
ln -s /etc/init.d/getBritness.sh /etc/rc6.d/S11getBritness.sh


#symlink to put last brightness when system start.
ln -s /etc/init.d/putLastBritness.sh /etc/rc1.d/S66putLastBritness.sh
ln -s /etc/init.d/putLastBritness.sh /etc/rc2.d/S66putLastBritness.sh
ln -s /etc/init.d/putLastBritness.sh /etc/rc3.d/S66putLastBritness.sh

exit 0
AiPdimi
  • 31
  • 4