I am running Raspbian Jessie Lite with a custom Xfce4 Desktop Environment installed. I created a file which when run, changes the number in /sys/class/backlight/rpi_backlight/bl_power
to 0 or 1 depending on what was already in the file so that if I run the script twice it will turn the backlight off and then back on again. I am running the script as Pi user and have tried with and without sudo
.
line=$(head -n 1 "/sys/class/backlight/rpi_backlight/bl_power")
if (( $line == 1 )); then
echo 0 > "/sys/class/backlight/rpi_backlight/bl_power";
else
echo 1 > "/sys/class/backlight/rpi_backlight/bl_power";
fi
After a reboot this script works fine. However after an arbitrary number of runs it stops turning the backlight on or off. However if I cat
the bl_power
file, the number has changed...the screen is just not turning off. A reboot fixes the problem but then it starts happening again.
Any ideas why this is not working?
EDIT
I also have this line in /etc/udev/rules.d/backlight-permissions.rules
so I don't have to use sudo. Without this file and line I cannot echo to the bl_power file even with sudo.
SUBSYSTEM=="backlight",RUN+="/bin/chmod 666 /sys/class/backlight/%k/brightness /sys/class/backlight/%k/bl_power"
EDIT 2
If I create a script with the following in it:
echo 0 > "/sys/class/backlight/rpi_backlight/bl_power"
echo 1 > "/sys/class/backlight/rpi_backlight/bl_power"
Surprisingly, it works to turn it on and off and so far hasn't stopped working. This is interesting because it seems like it would leave the screen in its original state because the commands appear to cancel each other out. However, running it once turns the screen off and again turns it back on again.
EDIT 3 The above stopped working suddenly and would not work without a reboot.
EDIT 4 I ran apt-get update
and apt-get upgrade
and it still is not working so I know it is not an issue of using an old kernel.
EDIT 5 I found a solution although I still am not sure why the above doesn't work. Instead of echoing 0 or 1 to the bl_power file I echo 0 or 255 to the brightness file which does the same thing. This has worked for over 4 hours now. It might be a hardware problem like the comment below this question.
/sys/class/backlight/rpi_backlight/
) to see what other fields are there. Some of them (e.g "max_brightness", which is standard for laptops and other backlit screens) will be read only, and indicate a range. This box (intel_backlight
) it's up to 4648. "1" would be pretty dark. Of course this doesn't explain all the silly behaviour.