# rpi-backlight
> A Python module for controlling power and brightness of the official Raspberry Pi 7" touch display.
[![PyPI](https://img.shields.io/pypi/v/rpi-backlight)](https://pypi.org/project/rpi-backlight/)
![Python Version](https://img.shields.io/pypi/pyversions/rpi-backlight)
[![Downloads](https://pepy.tech/badge/rpi-backlight)](https://pepy.tech/project/rpi-backlight)
[![Documentation](https://img.shields.io/badge/docs-latest-blue)](https://rpi-backlight.readthedocs.io/en/latest/)
[![License](https://img.shields.io/github/license/linusg/rpi-backlight?color=d63e97)](https://github.com/linusg/rpi-backlight/blob/main/LICENSE)
[![Black](https://img.shields.io/badge/code%20style-black-000000)](https://github.com/ambv/black)
[![Build](https://github.com/linusg/rpi-backlight/workflows/Build/badge.svg)](https://github.com/linusg/rpi-backlight/actions?query=workflow%3ABuild)
[![Read the Docs](https://img.shields.io/readthedocs/rpi-backlight)](https://rpi-backlight.readthedocs.io/en/latest/)
[![Issues](https://img.shields.io/github/issues/linusg/rpi-backlight)](https://github.com/linusg/rpi-backlight/issues)
![Example](https://raw.githubusercontent.com/linusg/rpi-backlight/main/docs/_static/example.gif)
**Note:** _This GIF was created using the old v1 API, so please don't use it as API reference 🙂_
## Features
- Set the display brightness **smoothly** or **abrupt**
- Set the display power on or off
- Get the current brightness
- Get the display power state (on/off)
- Command line interface
- Graphical user interface
## Requirements
- A **Raspberry Pi or ASUS Tinker Board** including a correctly assembled **7" touch display v1.1 or higher**
(look on the display's circuit board to see its version), or a [**Surface RT**](https://openrt.gitbook.io/open-surfacert/surface-rt/linux/root-filesystem/distros/raspberry-pi-os) running a Linux-based OS
- Python 3.6+
- Optional: Raspberry Pi: ``pygobject`` for the GUI, already installed on a recent Raspbian
- Optional: Tinker Board: ``gir1.2-gtk-3.0`` for the GUI install
## Installation
Install from PyPI:
```console
$ pip3 install rpi-backlight
```
**Note:** Create this udev rule to update permissions, otherwise you'll have to run
Python code, the GUI and CLI as root when _changing_ the power or brightness:
```console
$ echo 'SUBSYSTEM=="backlight",RUN+="/bin/chmod 666 /sys/class/backlight/%k/brightness /sys/class/backlight/%k/bl_power"' | sudo tee -a /etc/udev/rules.d/backlight-permissions.rules
```
### Emulator
For testing without a physical display (e.g. on your main Linux/macOS/Windows machine)
you can use [`linusg/rpi-backlight-emulator`](https://github.com/linusg/rpi-backlight-emulator).
## Usage
### API
Example in a Python shell:
```python
>>> from rpi_backlight import Backlight
>>>
>>> backlight = Backlight()
>>> backlight.brightness
100
>>> backlight.brightness = 50
>>> backlight.brightness
50
>>>
>>> with backlight.fade(duration=1):
... backlight.brightness = 0
...
>>> backlight.fade_duration = 0.5
>>> # subsequent `backlight.brightness = x` will fade 500ms
>>>
>>> backlight.power
True
>>> backlight.power = False
>>> backlight.power
False
>>>
```
For more details see [docs](https://rpi-backlight.readthedocs.io/en/latest/api.html).
### CLI
Open a terminal and run `rpi-backlight`.
```console
$ rpi-backlight -b 100
$ rpi-backlight --set-brightness 20 --duration 1.5
$ rpi-backlight --get-brightness
20
$ rpi-backlight --get-power
on
$ rpi-backlight -p off
$ rpi-backlight --get-power
off
$ rpi-backlight --set-power off :emulator:
$ rpi-backlight -p toggle
$ rpi-backlight -p toggle -d 1.5
$
```
For all available options see [docs](https://rpi-backlight.readthedocs.io/en/latest/usage.html#command-line-interface).
### GUI
Open a terminal and run `rpi-backlight-gui`.
![Graphical User Interface](https://raw.githubusercontent.com/linusg/rpi-backlight/main/docs/_static/gui.png)
![Graphical User Interface (2)](https://raw.githubusercontent.com/linusg/rpi-backlight/main/docs/_static/gui2.png)
### Adding a shortcut to the LXDE panel
![Panel result](https://raw.githubusercontent.com/linusg/rpi-backlight/main/docs/_static/panel_result.png)
See [docs](https://rpi-backlight.readthedocs.io/en/latest/usage.html#adding-a-shortcut-to-the-lxde-panel).
## Tests
Tests use `pytest`, install with `pip3 install pytest`.
Now, run from the repository root directory:
```console
$ python3 -m pytest
```
## Contributing
Please free to open an issue for bug reports and to discuss new features - pull requests for new features or bug fixes are welcome as well!
## License
The source code and all other files in this repository are licensed under the MIT
license, so you can easily use it in your own projects. See [`LICENSE`](LICENSE) for
more information.
Raw data
{
"_id": null,
"home_page": "https://github.com/linusg/rpi-backlight",
"name": "rpi-backlight",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "raspberry pi,display,touchscreen,brightness,backlight",
"author": "Linus Groh",
"author_email": "mail@linusgroh.de",
"download_url": "https://files.pythonhosted.org/packages/fb/77/7593fea7fc165c4b710ea6177c9c946398f57ff4803a9218c00f545523a5/rpi-backlight-2.6.0.tar.gz",
"platform": null,
"description": "# rpi-backlight\n\n> A Python module for controlling power and brightness of the official Raspberry Pi 7\" touch display.\n\n[![PyPI](https://img.shields.io/pypi/v/rpi-backlight)](https://pypi.org/project/rpi-backlight/)\n![Python Version](https://img.shields.io/pypi/pyversions/rpi-backlight)\n[![Downloads](https://pepy.tech/badge/rpi-backlight)](https://pepy.tech/project/rpi-backlight)\n[![Documentation](https://img.shields.io/badge/docs-latest-blue)](https://rpi-backlight.readthedocs.io/en/latest/)\n[![License](https://img.shields.io/github/license/linusg/rpi-backlight?color=d63e97)](https://github.com/linusg/rpi-backlight/blob/main/LICENSE)\n[![Black](https://img.shields.io/badge/code%20style-black-000000)](https://github.com/ambv/black)\n[![Build](https://github.com/linusg/rpi-backlight/workflows/Build/badge.svg)](https://github.com/linusg/rpi-backlight/actions?query=workflow%3ABuild)\n[![Read the Docs](https://img.shields.io/readthedocs/rpi-backlight)](https://rpi-backlight.readthedocs.io/en/latest/)\n[![Issues](https://img.shields.io/github/issues/linusg/rpi-backlight)](https://github.com/linusg/rpi-backlight/issues)\n\n![Example](https://raw.githubusercontent.com/linusg/rpi-backlight/main/docs/_static/example.gif)\n\n**Note:** _This GIF was created using the old v1 API, so please don't use it as API reference \ud83d\ude42_\n\n## Features\n\n- Set the display brightness **smoothly** or **abrupt**\n- Set the display power on or off\n- Get the current brightness\n- Get the display power state (on/off)\n- Command line interface\n- Graphical user interface\n\n## Requirements\n\n- A **Raspberry Pi or ASUS Tinker Board** including a correctly assembled **7\" touch display v1.1 or higher**\n (look on the display's circuit board to see its version), or a [**Surface RT**](https://openrt.gitbook.io/open-surfacert/surface-rt/linux/root-filesystem/distros/raspberry-pi-os) running a Linux-based OS\n- Python 3.6+\n- Optional: Raspberry Pi: ``pygobject`` for the GUI, already installed on a recent Raspbian\n- Optional: Tinker Board: ``gir1.2-gtk-3.0`` for the GUI install\n\n## Installation\n\nInstall from PyPI:\n\n```console\n$ pip3 install rpi-backlight\n```\n\n**Note:** Create this udev rule to update permissions, otherwise you'll have to run\nPython code, the GUI and CLI as root when _changing_ the power or brightness:\n\n```console\n$ echo 'SUBSYSTEM==\"backlight\",RUN+=\"/bin/chmod 666 /sys/class/backlight/%k/brightness /sys/class/backlight/%k/bl_power\"' | sudo tee -a /etc/udev/rules.d/backlight-permissions.rules\n```\n\n### Emulator\n\nFor testing without a physical display (e.g. on your main Linux/macOS/Windows machine)\nyou can use [`linusg/rpi-backlight-emulator`](https://github.com/linusg/rpi-backlight-emulator).\n\n## Usage\n\n### API\n\nExample in a Python shell:\n\n```python\n>>> from rpi_backlight import Backlight\n>>>\n>>> backlight = Backlight()\n>>> backlight.brightness\n100\n>>> backlight.brightness = 50\n>>> backlight.brightness\n50\n>>>\n>>> with backlight.fade(duration=1):\n... backlight.brightness = 0\n...\n>>> backlight.fade_duration = 0.5\n>>> # subsequent `backlight.brightness = x` will fade 500ms\n>>>\n>>> backlight.power\nTrue\n>>> backlight.power = False\n>>> backlight.power\nFalse\n>>>\n```\n\nFor more details see [docs](https://rpi-backlight.readthedocs.io/en/latest/api.html).\n\n### CLI\n\nOpen a terminal and run `rpi-backlight`.\n\n```console\n$ rpi-backlight -b 100\n$ rpi-backlight --set-brightness 20 --duration 1.5\n$ rpi-backlight --get-brightness\n20\n$ rpi-backlight --get-power\non\n$ rpi-backlight -p off\n$ rpi-backlight --get-power\noff\n$ rpi-backlight --set-power off :emulator:\n$ rpi-backlight -p toggle\n$ rpi-backlight -p toggle -d 1.5\n$\n```\n\nFor all available options see [docs](https://rpi-backlight.readthedocs.io/en/latest/usage.html#command-line-interface).\n\n### GUI\n\nOpen a terminal and run `rpi-backlight-gui`.\n\n![Graphical User Interface](https://raw.githubusercontent.com/linusg/rpi-backlight/main/docs/_static/gui.png)\n![Graphical User Interface (2)](https://raw.githubusercontent.com/linusg/rpi-backlight/main/docs/_static/gui2.png)\n\n### Adding a shortcut to the LXDE panel\n\n![Panel result](https://raw.githubusercontent.com/linusg/rpi-backlight/main/docs/_static/panel_result.png)\n\nSee [docs](https://rpi-backlight.readthedocs.io/en/latest/usage.html#adding-a-shortcut-to-the-lxde-panel).\n\n## Tests\n\nTests use `pytest`, install with `pip3 install pytest`.\n\nNow, run from the repository root directory:\n\n```console\n$ python3 -m pytest\n```\n\n## Contributing\n\nPlease free to open an issue for bug reports and to discuss new features - pull requests for new features or bug fixes are welcome as well!\n\n## License\n\nThe source code and all other files in this repository are licensed under the MIT\nlicense, so you can easily use it in your own projects. See [`LICENSE`](LICENSE) for\nmore information.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python module for controlling power and brightness of the official Raspberry Pi 7\" touch display.",
"version": "2.6.0",
"split_keywords": [
"raspberry pi",
"display",
"touchscreen",
"brightness",
"backlight"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "e799e8bfa7804321c97c39b4d8c18127",
"sha256": "c5fe0a7b85dbe95adf3114983a63841d09e359b7c3a8d38b4a4f2e81d09d73fd"
},
"downloads": -1,
"filename": "rpi_backlight-2.6.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e799e8bfa7804321c97c39b4d8c18127",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 10091,
"upload_time": "2022-12-29T15:38:03",
"upload_time_iso_8601": "2022-12-29T15:38:03.148239Z",
"url": "https://files.pythonhosted.org/packages/3f/85/cdc0ee00d04c54f5fad00746ea90a4d125b0e2fea483a2d20bc2d4da49a2/rpi_backlight-2.6.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "9aab969e38fd0df1bec99ff7d0b5fc8d",
"sha256": "4b57871020e3067026fcd1f00a0f67265e269af18b7ef53f7725580c3d08e219"
},
"downloads": -1,
"filename": "rpi-backlight-2.6.0.tar.gz",
"has_sig": false,
"md5_digest": "9aab969e38fd0df1bec99ff7d0b5fc8d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 10509,
"upload_time": "2022-12-29T15:38:04",
"upload_time_iso_8601": "2022-12-29T15:38:04.968144Z",
"url": "https://files.pythonhosted.org/packages/fb/77/7593fea7fc165c4b710ea6177c9c946398f57ff4803a9218c00f545523a5/rpi-backlight-2.6.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-29 15:38:04",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "linusg",
"github_project": "rpi-backlight",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "rpi-backlight"
}