API reference

class rpi_backlight.Backlight(backlight_sysfs_path: Union[str, PathLike[str], None] = None, board_type: rpi_backlight.BoardType = <BoardType.RASPBERRY_PI: 1>)

Main class to access and control the display backlight power and brightness.

Set backlight_sysfs_path to ":emulator:" to use with rpi-backlight-emulator.

brightness

The display brightness in range 0-100.

>>> backlight = Backlight()
>>> backlight.brightness  # Display is at 50% brightness
50
>>> backlight.brightness = 100  # Set to full brightness
Getter:Return the display brightness.
Setter:Set the display brightness.
Type:float
fade(duration: float) → Generator[T_co, T_contra, V_co]

Context manager for temporarily changing the fade duration.

>>> backlight = Backlight()
>>> with backlight.fade(duration=0.5):
...     backlight.brightness = 1  # Fade to 100% brightness for 0.5s
...
>>> with backlight.fade(duration=0):
...     backlight.brightness = 0  # Set to 0% brightness without fading, use if you have set `backlight.fade_duration` > 0
fade_duration

The brightness fade duration in seconds, defaults to 0. Also see fade().

>>> backlight = Backlight()
>>> backlight.fade_duration  # Fading is disabled by default
0
>>> backlight.fade_duration = 0.5  # Set to 500ms
Getter:Return the fade duration.
Setter:Set the fade duration.
Type:float
power

Turn the display on and off.

>>> backlight = Backlight()
>>> backlight.power  # Display is on
True
>>> backlight.power = False  # Turn display off
Getter:Return whether the display is powered on or off.
Setter:Set the display power on or off.
Type:bool
class rpi_backlight.BoardType

Enum to specify a board type in the Backlight constructor.

MICROSOFT_SURFACE_RT = 4

Microsoft Surface RT

RASPBERRY_PI = 1

Raspberry Pi

TINKER_BOARD = 2

Tinker Board

TINKER_BOARD_2 = 3

Tinker Board 2

rpi_backlight.cli.main()

Start the command line interface.

rpi_backlight.gui.main()

Start the graphical user interface.

rpi_backlight.utils.detect_board_type() → Optional[BoardType]

Try to detect the board type based on the model string in /proc/device-tree/model.

class rpi_backlight.utils.FakeBacklightSysfs

Context manager to create a temporary “fake sysfs” containing all relevant files. Used for tests and emulation.

>>> with FakeBacklightSysfs() as backlight_sysfs:
...     backlight = Backlight(backlight_sysfs_path=backlight_sysfs.path)
...     # use `backlight` as usual