fusion_hat.user_button module

class fusion_hat.user_button.UserButton[source]

Bases: object

User button class using evdev for Linux input events

set_on_click(callback: Callable[[], None]) None[source]

Set the callback function when the user button is clicked

Parameters:

callback (Callable[[], None]) – callback function

set_on_press(callback: Callable[[], None]) None[source]

Set the callback function when the user button is pressed

Parameters:

callback (Callable[[], None]) – callback function

set_on_release(callback: Callable[[], None]) None[source]

Set the callback function when the user button is released

Parameters:

callback (Callable[[], None]) – callback function

set_on_press_released(callback: Callable[[], None]) None[source]

Set the callback function when the user button is pressed and released

Parameters:

callback (Callable[[], None]) – callback function

set_on_long_press(callback: Callable[[], None], duration: float = 2.0) None[source]

[Deprecated] Set the callback function when the user button is pressed for a long time

Parameters:

callback (Callable[[], None]) – callback function

set_on_long_press_released(callback: Callable[[], None], duration: float = 2.0) None[source]

[Deprecated] Set the callback function when the user button is pressed for a long time and released

Parameters:
  • callback (Callable[[], None]) – callback function

  • duration (float, optional) – long press duration(2.0~5.0)

_find_button_device() None[source]

Find the Fusion HAT USR button device

get_state() bool[source]

Get the state of the user button

Returns:

True if pressed, False if released

Return type:

bool

is_pressed() bool[source]

Check if the user button is pressed

Returns:

True if pressed, False if released

Return type:

bool

get_pressed_for() float[source]

Get the time the user button has been pressed for

Returns:

time in seconds

Return type:

float

_setup_event_listener() None[source]

设置事件监听器,在独立线程中处理输入事件

start() None[source]

此方法已弃用,不再需要调用

由于使用了Linux输入事件系统,按钮事件会自动被监听和处理,无需手动启动轮询循环。

stop() None[source]

关闭按钮设备连接