gpio

package
v0.36.0-rc0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package gpio implements a gpio/adc based input.Controller.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGPIOController

func NewGPIOController(
	ctx context.Context,
	deps resource.Dependencies,
	conf resource.Config,
	logger logging.Logger,
) (input.Controller, error)

NewGPIOController returns a new input.Controller.

Types

type AxisConfig

type AxisConfig struct {
	Control       input.Control `json:"control"`
	Min           int           `json:"min"`
	Max           int           `json:"max"`
	Bidirectional bool          `json:"bidirectional"`
	Deadzone      int           `json:"deadzone"`
	MinChange     int           `json:"min_change"`
	PollHz        float64       `json:"poll_hz"`
	Invert        bool          `json:"invert"`
}

AxisConfig is a subconfig for axes.

type ButtonConfig

type ButtonConfig struct {
	Control    input.Control `json:"control"`
	Invert     bool          `json:"invert"`
	DebounceMs int           `json:"debounce_msec"` // set to -1 to disable, default=5
}

ButtonConfig is a subconfig for buttons.

type Config

type Config struct {
	Board   string                   `json:"board"`
	Buttons map[string]*ButtonConfig `json:"buttons"`
	Axes    map[string]*AxisConfig   `json:"axes"`
}

Config is the overall config.

func (*Config) Validate added in v0.1.6

func (conf *Config) Validate(path string) ([]string, error)

Validate ensures all parts of the config are valid.

type Controller

type Controller struct {
	resource.Named
	resource.AlwaysRebuild
	// contains filtered or unexported fields
}

A Controller creates an input.Controller from DigitalInterrupts and AnalogReaders.

func (*Controller) Close

func (c *Controller) Close(ctx context.Context) error

Close terminates background worker threads.

func (*Controller) Controls

func (c *Controller) Controls(ctx context.Context, extra map[string]interface{}) ([]input.Control, error)

Controls lists the inputs.

func (*Controller) Events

func (c *Controller) Events(ctx context.Context, extra map[string]interface{}) (map[input.Control]input.Event, error)

Events returns the last input.Event (the current state) of each control.

func (*Controller) RegisterControlCallback

func (c *Controller) RegisterControlCallback(
	ctx context.Context,
	control input.Control,
	triggers []input.EventType,
	ctrlFunc input.ControlFunction,
	extra map[string]interface{},
) error

RegisterControlCallback registers a callback function to be executed on the specified trigger Event.

Jump to

Keyboard shortcuts

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