Skip to content

gpio

LED, buzzer, and button control.

omgrab.gpio.gpio

GPIO control module for Raspberry Pi 5 LED, buzzer, and button management.

This module uses a separate process for GPIO control to avoid GIL contention with video encoding and other CPU-intensive operations in the main process.

LEDState

Bases: Enum

LED state patterns.

GPIOController()

Controller for GPIO components: LEDs, buzzer, and push button.

This controller delegates all GPIO operations to a separate process, ensuring smooth LED blinking even during heavy CPU load from video encoding or other operations that would normally cause GIL contention.

Initialize GPIO controller with a separate process.

cleanup()

Cleanup GPIO resources.

set_led_states(red, green)

Set both LED states.

Parameters:

Name Type Description Default
red LEDState

Desired state for red LED.

required
green LEDState

Desired state for green LED.

required

set_buzzer(state)

Set buzzer state.

Parameters:

Name Type Description Default
state bool

True for ON, False for OFF.

required

set_buzzer_volume(volume)

Set buzzer volume via PWM duty cycle.

Parameters:

Name Type Description Default
volume float

Volume level from 0.0 (silent) to 1.0 (full).

required

set_buzzer_tone(freq)

Set buzzer tone frequency.

Parameters:

Name Type Description Default
freq float

Tone frequency in Hz (clamped to 20-20000).

required

read_button()

Read the state of the push button.

Returns:

Type Description
bool

True if button is pressed, False otherwise.

buzzer_beep(duration=0.1, count=1)

Sound the buzzer for specified duration and count.

Parameters:

Name Type Description Default
duration float

Duration of each beep in seconds.

0.1
count int

Number of beeps.

1