Skip to main content

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)
    # set the interval in milliseconds after which `on_active` is fired
    # repetitively while the signal on the pin is active
    # set to 0 to turn off repetitive firing of `on_active`
    monitor.set_active_pulses_interval(gpio_pin, 300)
    # 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


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.2.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

gpiodmonitor-1.2.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file gpiodmonitor-1.2.0.tar.gz.

File metadata

  • Download URL: gpiodmonitor-1.2.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for gpiodmonitor-1.2.0.tar.gz
Algorithm Hash digest
SHA256 14d339d2ea5d121b58935ddcefd18d003378b86e90fadbe3d6bcbcacc3d7db6c
MD5 a4de88c9ae6ae9effc44dcd39c79e690
BLAKE2b-256 0ffc58a93f8bc47e6494f456b136634ad1a4be107e84a433ee02b6edd04cc7d2

See more details on using hashes here.

File details

Details for the file gpiodmonitor-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gpiodmonitor-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3697d16dd5892feb51679711273e8351302be25ecb1adfc12e9b4a5442131c4c
MD5 6aa53a23d54c17d5582ddaace2bd77ba
BLAKE2b-256 4cd59258ee24f1f0558f7b309f56fd73c54fd1f1b3453260207af63e363bf81e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page