gpio

package
v0.0.0-...-9eb3501 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2020 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package gpio contains an interface and implementation for controlling GPIO pins via the sysfs interface.

This packages does not contain any vendor specific implementations of GPIO pins, however the Pin struct in this package can be embedded in another struct which implements vendor specific functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Direction

type Direction string

Direction is the direction of the dataflow.

const (
	// InDirection means a value can be read from the pin.
	InDirection Direction = "in"
	// OutDirection means a value can written to the pin.
	OutDirection Direction = "out"
)

type Edge

type Edge string

Edge describes on what edge a function should be called.

const (
	// RisingEdge is triggered when the values goes from low to high.
	RisingEdge Edge = "rising"
	// FallingEdge is triggered when the values goes from high to low.
	FallingEdge Edge = "falling"
	// BothEdge is triggered when the values goes from high to low or from low to high.
	BothEdge Edge = "both"
	// NoneEdge never triggers.
	NoneEdge Edge = "none"
)

type EdgeEvent

type EdgeEvent func(pin *Pin)

EdgeEvent is a type of function that can be used as a vcallback to watcher

type GPIO

type GPIO interface {
	Value() (int, error)
	SetHigh() error
	SetLow() error

	Direction() (Direction, error)
	SetDirection(d Direction) error

	Edge() (Edge, error)
	SetEdge(edge Edge, f EdgeEvent) error

	ActiveLow() (bool, error)
	SetActiveLow(invert bool) error

	Export() error
	Unexport() error
}

GPIO is an interface for GPIO pins.

type Pin

type Pin struct {
	KernelID int
	// contains filtered or unexported fields
}

Pin is an implementation of the GPIO interface. It can be embedded in vendor specific implentations.

func NewPin

func NewPin(kernelID int, pinBase string, w Watcher) *Pin

NewPin creates an instance of Pin. The kernelID is the ID used to expose the pin. The filename is the name of the folder that contains files such as value and edge. This folder gets created when the in is exported and is often named gpio<kernelID>.

func (*Pin) ActiveLow

func (p *Pin) ActiveLow() (bool, error)

ActiveLow returns true if the the pin is inverted, i.e. it is true when the value is low

func (*Pin) Direction

func (p *Pin) Direction() (Direction, error)

Direction returns the curent direction of the pin.

func (*Pin) Edge

func (p *Pin) Edge() (Edge, error)

Edge returns the current edge of the pin.

func (*Pin) Export

func (p *Pin) Export() error

Export exports the pin, if it wasn't exported already.

func (*Pin) SetActiveLow

func (p *Pin) SetActiveLow(invert bool) error

SetActiveLow inverts the pins value, i.e. it is true when the value is low.

func (*Pin) SetDirection

func (p *Pin) SetDirection(d Direction) error

SetDirection configures the pin as an input or output.

func (*Pin) SetEdge

func (p *Pin) SetEdge(e Edge, f EdgeEvent) error

SetEdge sets an edge and sets up event handing for given edge. An edge can only be set on a pin with the 'in' direction.

func (*Pin) SetHigh

func (p *Pin) SetHigh() error

SetHigh writes a 1 to the Pin. It also sets the pins direction to output.

func (*Pin) SetLow

func (p *Pin) SetLow() error

SetLow writes a 0 to the Pin

func (*Pin) Unexport

func (p *Pin) Unexport() error

Unexport unexports the pin.

func (*Pin) Value

func (p *Pin) Value() (int, error)

Value returns the value of the pin. The pin must be in the 'in' direction.

type Watcher

type Watcher interface {
	Watch() error
	StopWatch()
	AddEvent(fpnt int, callback func()) error
	AddFile(file *os.File)
	Close() error
}

Watcher watches files for events and executes a callback when an event occurs.

func NewWatcher

func NewWatcher() (Watcher, error)

NewWatcher Creates a new Watcher.

Directories

Path Synopsis
acme
g25
Package g25 contains GPIO drivers for the Acme Systems Aria G25 The Aria G25 contains up to 60 GPIO pins.
Package g25 contains GPIO drivers for the Acme Systems Aria G25 The Aria G25 contains up to 60 GPIO pins.

Jump to

Keyboard shortcuts

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