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_pulsed_active(pin: int):
"""Dummy function."""
print(f'{pin} is still active')
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 function that will be called every 300 ms as long as the
# pin is active
monitor.register_pulsed_active(int(gpio_pin),
callback=dummy_pulsed_active,
seconds=0.3)
# register a function to be called when the button is pressed for 3
# seconds
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.3.1.tar.gz
(8.8 kB
view details)
Built Distribution
File details
Details for the file gpiodmonitor-1.3.1.tar.gz
.
File metadata
- Download URL: gpiodmonitor-1.3.1.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea34f030be177c4c155a4a059ed8c1df75a3686d4ed469778b0696d3ebaba7d7 |
|
MD5 | c7e97300cf7fa16a42567cc4404d2a07 |
|
BLAKE2b-256 | 332cb95c6f25b7ef668480fd7f6510fde818ed35add1ec3aa4c3039ea74ca81f |
File details
Details for the file gpiodmonitor-1.3.1-py3-none-any.whl
.
File metadata
- Download URL: gpiodmonitor-1.3.1-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b3fa3e3d87f068d7904d57d3b15fcd66b20e9607221c0340ac71feda14b5785 |
|
MD5 | 5a82d1fd11feb40ab384e175443468e9 |
|
BLAKE2b-256 | 13235ed4d586b9585ca4f8a39fee9197215d4aa44f64121302ca18601e775b68 |