OpenRoadCode
Public API reference for OpenRoadCode
Loading...
Searching...
No Matches
hardware_io.buttons.rpi_gpio_push_button.RpiGpioPushButton Class Reference

Pushbutton connected to a Raspberry Pi GPIO input. More...

Inheritance diagram for hardware_io.buttons.rpi_gpio_push_button.RpiGpioPushButton:
hardware_io.buttons.push_button_if.PushButtonIf

Public Member Functions

None __init__ (self, GpioPin gpio_pin, PushButtonCallbackIf|None callback=None, *, bool active_low=True, float debounce_seconds=0.05)
 Initialize the GPIO pushbutton.
GpioPin gpio_pin (self)
 Return the GPIO pin used by this pushbutton.
None start (self)
 Configure the GPIO input and begin monitoring button events.
None stop (self)
 Stop monitoring and release the GPIO resource.
PushButtonState get_state (self)
 Return the current physical state of the pushbutton.
None set_callback (self, PushButtonCallbackIf|None callback)
 Set or clear the callback receiver.
RpiGpioPushButton __enter__ (self)
 Start monitoring when entering a context.
None __exit__ (self, *object _)
 Stop monitoring when leaving a context.

Protected Member Functions

None _handle_pressed (self)
 Forward a pressed event to the configured callback.
None _handle_released (self)
 Forward a released event to the configured callback.

Detailed Description

Pushbutton connected to a Raspberry Pi GPIO input.

The supplied GpioPin describes both the physical header position and corresponding BCM GPIO number.

In the typical active-low configuration, one switch terminal is connected to the GPIO pin and the other terminal is connected to ground. The Raspberry Pi's internal pull-up resistor is then used.

Constructor & Destructor Documentation

◆ __init__()

None hardware_io.buttons.rpi_gpio_push_button.RpiGpioPushButton.__init__ ( self,
GpioPin gpio_pin,
PushButtonCallbackIf | None callback = None,
* ,
bool active_low = True,
float debounce_seconds = 0.05 )

Initialize the GPIO pushbutton.

Args: gpio_pin: Raspberry Pi GPIO header pin description. callback: Optional receiver for pressed and released events. active_low: True when pressing the button connects GPIO to ground. debounce_seconds: Time during which repeated transitions are ignored.

Raises: ValueError: If gpio_pin does not describe a GPIO-capable pin. ValueError: If debounce_seconds is negative.

Member Function Documentation

◆ get_state()

PushButtonState hardware_io.buttons.rpi_gpio_push_button.RpiGpioPushButton.get_state ( self)

Return the current physical state of the pushbutton.

Raises: RuntimeError: If monitoring has not been started.

Reimplemented from hardware_io.buttons.push_button_if.PushButtonIf.


The documentation for this class was generated from the following file:
  • hardware_io/buttons/rpi_gpio_push_button.py