viam.components.input

Submodules

Package Contents

Classes

Control

Control identifies the input (specific Axis or Button) of a controller.

Controller

Controller is a logical "container" more than an actual device

Event

EventType

Represents the type of input event.

Attributes

ControlFunction

class viam.components.input.Control[source]

Control identifies the input (specific Axis or Button) of a controller.

ABSOLUTE_X = AbsoluteX
ABSOLUTE_Y = AbsoluteY
ABSOLUTE_Z = AbsoluteZ
ABSOLUTE_RX = AbsoluteRX
ABSOLUTE_RY = AbsoluteRY
ABSOLUTE_RZ = AbsoluteRZ
ABSOLUTE_HAT0_X = AbsoluteHat0X
ABSOLUTE_HAT0_Y = AbsoluteHat0Y
BUTTON_SOUTH = ButtonSouth
BUTTON_EAST = ButtonEast
BUTTON_WEST = ButtonWest
BUTTON_NORTH = ButtonNorth
BUTTON_LT = ButtonLT
BUTTON_RT = ButtonRT
BUTTON_LT2 = ButtonLT2
BUTTON_RT2 = ButtonRT2
BUTTON_L_THUMB = ButtonLThumb
BUTTON_R_THUMB = ButtonRThumb
BUTTON_SELECT = ButtonSelect
BUTTON_START = ButtonStart
BUTTON_MENU = ButtonMenu
BUTTON_RECORD = ButtonRecord
BUTTON_E_STOP = ButtonEStop
ABSOLUTE_PEDAL_ACCELERATOR = AbsolutePedalAccelerator
ABSOLUTE_PEDAL_BRAKE = AbsolutePedalBrake
ABSOLUTE_PEDAL_CLUTCH = AbsolutePedalClutch
viam.components.input.ControlFunction
class viam.components.input.Controller(name: str)[source]

Controller is a logical “container” more than an actual device Could be a single gamepad, or a collection of digitalInterrupts and analogReaders, a keyboard, etc.

SUBTYPE :Final
abstract async get_controls(*, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) List[Control][source]

Returns a list of Controls provided by the Controller

Returns

List of controls provided by the Controller

Return type

List[Control]

abstract async get_events(*, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) Dict[Control, Event][source]

Returns the most recent Event for each input (which should be the current state)

Returns

The most recent event for each input

Return type

Dict[Control, Event]

abstract register_control_callback(control: Control, triggers: List[EventType], function: Optional[ControlFunction], *, extra: Optional[Dict[str, Any]] = None, **kwargs)[source]

Register a function that will fire on given EventTypes for a given Control

Parameters
  • control (Control) – The control to register the function for

  • triggers (List[EventType]) – The events that will trigger the function

  • function (ControlFunction) – The function to run on specific triggers

async trigger_event(event: Event, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs)[source]

Directly send an Event (such as a button press) from external code

Parameters

event (Event) – The event to trigger

class viam.components.input.Event[source]
property proto
time :float

seconds since epoch

event :EventType
control :Control
value :float

0 or 1 for buttons, -1.0 to +1.0 for axes

classmethod from_proto(proto: viam.proto.component.inputcontroller.Event) typing_extensions.Self[source]
class viam.components.input.EventType[source]

Represents the type of input event.

ALL_EVENTS = AllEvents

Callbacks registered for this event will be called in ADDITION to other registered event callbacks.

CONNECT = Connect

Sent at controller initialization, and on reconnects.

DISCONNECT = Disconnect

If unplugged, or wireless/network times out.

BUTTON_PRESS = ButtonPress

Typical key press.

BUTTON_RELEASE = ButtonRelease

Key release.

BUTTON_HOLD = ButtonHold

Key is held down. This wil likely be a repeated event.

BUTTON_CHANGE = ButtonChange

Both up and down for convenience during registration, not typically emitted.

POSITION_CHANGE_ABSOLUTE = PositionChangeAbs

Absolute position is reported via Value, a la joysticks.

POSITION_CHANGE_RELATIVE = PositionChangeRel

Relative position is reported via Value, a la mice, or simulating axes with up/down buttons.