No project description provided
Project description
gpiodmonitor
Tiny wrapper around gpiod used to monitor and debounce button presses.
Callbacks are triggered on these events:
- on change to active signal (e.g., button pressed)
- on change to inactive signal (e.g., button released)
- after the active signal has been stable for a certain period of time (e.g., button held down)
- in regular interval while an "active" signal is recieved
Installation
You can isntall the package from pip
:
pip install gpiodmonitor
Needs libgpiod2 installed. Under Ubuntu / Debian you can install it using:
sudo apt install libgpiod2 python3-gpiod
Usage:
from gpiodmonitor import gpiodmonitor
def dummy_active(pin: int):
"""Dummy function."""
print(f'{pin} is active')
def dummy_inactive(pin: int):
"""Dummy function."""
print(f'{pin} is inactive')
def dummy_long_active(pin: int):
"""Dummy function."""
print(f'{pin} has been active for a long time')
monitor = gpiodmonitor.GPIODMonitor(chip=0)
for gpio_pin in [12,13]:
# register some functions to be called on activity on pins 12 and 13
monitor.register(int(gpio_pin),
on_active=dummy_active,
on_inactive=dummy_inactive)
# register a function to be called when the button is pressed for 3 seconds
# duration=3
monitor.register_long_active(int(gpio_pin),
callback=dummy_long_active,
seconds=3)
with monitor.open_chip():
try:
while True:
# check according to interval
time.sleep(monitor.check_interval / 1000)
monitor.tick()
except KeyboardInterrupt:
sys.exit(130)
# or use (equivalent but you don't have controll over the loop):
# chip.monitor()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
gpiodmonitor-1.1.3.tar.gz
(8.2 kB
view details)
Built Distribution
File details
Details for the file gpiodmonitor-1.1.3.tar.gz
.
File metadata
- Download URL: gpiodmonitor-1.1.3.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.12.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cfb2e4cdd517b7b72344940a5ed3c0624ead6038eb90a22086ca35d5546711f |
|
MD5 | c27d9d7a80955962a843ed2521bc0734 |
|
BLAKE2b-256 | e9bed5b81dcd5690ee1c7e5c84195ddf160d54fff6ced95f7e83d5303a14cb4d |
File details
Details for the file gpiodmonitor-1.1.3-py3-none-any.whl
.
File metadata
- Download URL: gpiodmonitor-1.1.3-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.12.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48ac2e2db2c83bfd0924d64c784b1d476d32e01bd9389072276900ac83bc8959 |
|
MD5 | 3d0da9b004fc74f16f6718386cbcd8e9 |
|
BLAKE2b-256 | f25fb6784ddaf14048889fde5d236554db0bd7de7814257a6eafd9ae296f5904 |