input

package
v0.2.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2023 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package input contains a gRPC based input controller client.

Package input provides human input, such as buttons, switches, knobs, gamepads, joysticks, keyboards, mice, etc.

Package input contains a gRPC based input controller service server.

Index

Constants

View Source
const SubtypeName = resource.SubtypeName("input_controller")

SubtypeName is a constant that identifies the component resource subtype string input.

Variables

Subtype is a constant that identifies the component resource subtype.

Functions

func CreateStatus

func CreateStatus(ctx context.Context, resource interface{}) (*pb.Status, error)

CreateStatus creates a status from the input controller.

func DependencyTypeError

func DependencyTypeError(name string, actual interface{}) error

DependencyTypeError is used when a resource doesn't implement the expected interface.

func Named

func Named(name string) resource.Name

Named is a helper for getting the named input's typed resource name.

func NamesFromRobot

func NamesFromRobot(r robot.Robot) []string

NamesFromRobot is a helper for getting all input controller names from the given Robot.

func NewServer

NewServer constructs an input controller gRPC service server.

func NewUnimplementedInterfaceError

func NewUnimplementedInterfaceError(actual interface{}) error

NewUnimplementedInterfaceError is used when there is a failed interface check.

func WrapWithReconfigurable

func WrapWithReconfigurable(r interface{}, name resource.Name) (resource.Reconfigurable, error)

WrapWithReconfigurable wraps a Controller with a reconfigurable and locking interface.

Types

type Control

type Control string

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

const (
	// Axes.
	AbsoluteX     Control = "AbsoluteX"
	AbsoluteY     Control = "AbsoluteY"
	AbsoluteZ     Control = "AbsoluteZ"
	AbsoluteRX    Control = "AbsoluteRX"
	AbsoluteRY    Control = "AbsoluteRY"
	AbsoluteRZ    Control = "AbsoluteRZ"
	AbsoluteHat0X Control = "AbsoluteHat0X"
	AbsoluteHat0Y Control = "AbsoluteHat0Y"

	// Buttons.
	ButtonSouth  Control = "ButtonSouth"
	ButtonEast   Control = "ButtonEast"
	ButtonWest   Control = "ButtonWest"
	ButtonNorth  Control = "ButtonNorth"
	ButtonLT     Control = "ButtonLT"
	ButtonRT     Control = "ButtonRT"
	ButtonLT2    Control = "ButtonLT2"
	ButtonRT2    Control = "ButtonRT2"
	ButtonLThumb Control = "ButtonLThumb"
	ButtonRThumb Control = "ButtonRThumb"
	ButtonSelect Control = "ButtonSelect"
	ButtonStart  Control = "ButtonStart"
	ButtonMenu   Control = "ButtonMenu"
	ButtonRecord Control = "ButtonRecord"
	ButtonEStop  Control = "ButtonEStop"

	// Pedals.
	AbsolutePedalAccelerator Control = "AbsolutePedalAccelerator"
	AbsolutePedalBrake       Control = "AbsolutePedalBrake"
	AbsolutePedalClutch      Control = "AbsolutePedalClutch"
)

Controls, to be expanded as new input devices are developed.

type ControlFunction

type ControlFunction func(ctx context.Context, ev Event)

ControlFunction is a callback passed to RegisterControlCallback.

type Controller

type Controller interface {
	// Controls returns a list of Controls provided by the Controller
	Controls(ctx context.Context, extra map[string]interface{}) ([]Control, error)

	// Events returns most recent Event for each input (which should be the current state)
	Events(ctx context.Context, extra map[string]interface{}) (map[Control]Event, error)

	// RegisterCallback registers a callback that will fire on given EventTypes for a given Control.
	// The callback is called on the same goroutine as the firer and if any long operation is to occur,
	// the callback should start a goroutine.
	RegisterControlCallback(
		ctx context.Context,
		control Control,
		triggers []EventType,
		ctrlFunc ControlFunction,
		extra map[string]interface{},
	) error

	generic.Generic
}

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.

func FromDependencies

func FromDependencies(deps registry.Dependencies, name string) (Controller, error)

FromDependencies is a helper for getting the named input controller from a collection of dependencies.

func FromRobot

func FromRobot(r robot.Robot, name string) (Controller, error)

FromRobot is a helper for getting the named input controller from the given Robot.

func NewClientFromConn

func NewClientFromConn(ctx context.Context, conn rpc.ClientConn, name string, logger golog.Logger) Controller

NewClientFromConn constructs a new Client from connection passed in.

type Event

type Event struct {
	Time    time.Time
	Event   EventType
	Control Control // Key or Axis
	Value   float64 // 0 or 1 for buttons, -1.0 to +1.0 for axes
}

Event is passed to the registered ControlFunction or returned by State().

type EventType

type EventType string

EventType represents the type of input event, and is returned by LastEvent() or passed to ControlFunction callbacks.

const (
	// Callbacks registered for this event will be called in ADDITION to other registered event callbacks.
	AllEvents EventType = "AllEvents"
	// Sent at controller initialization, and on reconnects.
	Connect EventType = "Connect"
	// If unplugged, or wireless/network times out.
	Disconnect EventType = "Disconnect"
	// Typical key press.
	ButtonPress EventType = "ButtonPress"
	// Key release.
	ButtonRelease EventType = "ButtonRelease"
	// Key is held down. This will likely be a repeated event.
	ButtonHold EventType = "ButtonHold"
	// Both up and down for convenience during registration, not typically emitted.
	ButtonChange EventType = "ButtonChange"
	// Absolute position is reported via Value, a la joysticks.
	PositionChangeAbs EventType = "PositionChangeAbs"
	// Relative position is reported via Value, a la mice, or simulating axes with up/down buttons.
	PositionChangeRel EventType = "PositionChangeRel"
)

EventType list, to be expanded as new input devices are developed.

type Triggerable

type Triggerable interface {
	// TriggerEvent allows directly sending an Event (such as a button press) from external code
	TriggerEvent(ctx context.Context, event Event, extra map[string]interface{}) error
}

Triggerable is used by the WebGamepad interface to inject events.

Directories

Path Synopsis
Package fake implements a fake input controller.
Package fake implements a fake input controller.
Package gamepad implements a linux gamepad as an input controller.
Package gamepad implements a linux gamepad as an input controller.
Package gpio implements a gpio/adc based input.Controller.
Package gpio implements a gpio/adc based input.Controller.
Package mux implements a multiplexed input controller.
Package mux implements a multiplexed input controller.
Package register registers all relevant inputs
Package register registers all relevant inputs
Package webgamepad implements a web based input controller.
Package webgamepad implements a web based input controller.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL