I've coded a little Python program that calls Linus Groh's module (he does all the good stuff like error trapping).
It requires three files as given below,
1) The python program, called brightness.py
Code: Select all
# brightness.py Version 0.1
# Copyright (C) 2019 Roy Leith
# This program is distributed under the terms of the GNU General Public License V3
import rpi_backlight as bl
from Tkinter import *
def maxbl ():
maxb = bl.get_max_brightness()
return maxb
def statusquo ():
value = bl.get_actual_brightness()
return value / ratio
def setb (val):
bl.set_brightness (int(int(val) * ratio))
master = Tk()
master.title('Brightness')
master.option_add('*font', ('verdana', 10, 'bold'))
maxv = maxbl ()
ratio = float(maxv) / 100
maxvalue = int(maxv / ratio)
Rvalue = statusquo()
brivar = IntVar()
brivar.set(Rvalue)
brightness = Scale(master, from_=maxvalue, to=10, orient=VERTICAL, length=200, width=10,
tickinterval=20, variable=brivar, command= setb,)
brightness.grid(row=0, column=0, sticky='NE')
mainloop()
2) The desktop file brightness.desktop, so that it can appear as an application icon,
Code: Select all
[Desktop Entry]
Name=Brightness
Comment=Brightness Control
TryExec=python
Exec=python /home/pi/Programs/Brightness/brightness.py
Icon=/usr/share/icons/Adwaita/96x96/status/display-brightness-symbolic.symbolic.png
Terminal=false
Type=Application
Categories=GTK;Utility
3) Readme.txt to tell you how to use the files.
Code: Select all
How to add Brightness to your Raspberry Pi Official 7" touch display.
You will need to install two Python modules.
The first is Linus Groh's rpi-backlight module released under the MIT License.
pip install rpi_backlight
Second is tkinter,
sudo apt-get install python3-tk
You will need to give your user permission to use the system files.
sudo leafpad /etc/udev/rules.d/backlight-permissions.rules
Insert the line::
SUBSYSTEM=="backlight",RUN+="/bin/chmod 666 /sys/class/backlight/%k/brightness /sys/class/backlight/%k/bl_power"
Place the files, brightness.py, brightness.desktop and this
Readme.txt file in a folder called,
/home/pi/Programs/Brightness
If you have changed your user name, then replace the name 'pi'
in the above path and in the brightness.desktop file.
Please note that the file brightness.desktop will appear as the file
Brightness, with a 'sun' icon.
Run the File Manager with root permissions,
sudo pcmanfm
and copy the file brightness.desktop to the folder,
/usr/share/raspi-ui-overrides/applications
When you open the Applications Menu you will find the Brightness icon
in the 'Accessories' catagory. Add it to the Panel by adding an
'Application Launcher' Panel Item and editing it to use Brightness.
Copy the code for each of the above files into Leafpad and save all three in /home/pi/Programs/Brightness using the filenames indicated, above. It is important that the files are in the correct subdirectory. If you have changed your user name, then replace the name 'pi' with your user name in the above path and in the brightness.desktop file.
Then read the Readme.txt file for instructions for adding the program to the Applications Launcher and to the panel..