Pushbutton connected to a Raspberry Pi GPIO input. More...
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. | |
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.
| 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.
| 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.