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()
Metadata
Release files for gpiodmonitor 1.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gpiodmonitor-1.3.1.tar.gz | 8.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gpiodmonitor-1.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.0 kB
Release files / gpiodmonitor-1.3.1.tar.gz
| Download URL | gpiodmonitor-1.3.1.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ea34f030be177c4c155a4a059ed8c1df75a3686d4ed469778b0696d3ebaba7d7
|
|
BLAKE2b-256 checksum How to use checksums |
332cb95c6f25b7ef668480fd7f6510fde818ed35add1ec3aa4c3039ea74ca81f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.0
|
Release files / gpiodmonitor-1.3.1-py3-none-any.whl
| Download URL | gpiodmonitor-1.3.1-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8b3fa3e3d87f068d7904d57d3b15fcd66b20e9607221c0340ac71feda14b5785
|
|
BLAKE2b-256 checksum How to use checksums |
13235ed4d586b9585ca4f8a39fee9197215d4aa44f64121302ca18601e775b68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.0
|