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 ¶
- type Direction
- type Edge
- type EdgeEvent
- type GPIO
- type Pin
- func (p *Pin) ActiveLow() (bool, error)
- func (p *Pin) Direction() (Direction, error)
- func (p *Pin) Edge() (Edge, error)
- func (p *Pin) Export() error
- func (p *Pin) SetActiveLow(invert bool) error
- func (p *Pin) SetDirection(d Direction) error
- func (p *Pin) SetEdge(e Edge, f EdgeEvent) error
- func (p *Pin) SetHigh() error
- func (p *Pin) SetLow() error
- func (p *Pin) Unexport() error
- func (p *Pin) Value() (int, error)
- type Watcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 ¶
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 ¶
ActiveLow returns true if the the pin is inverted, i.e. it is true when the value is low
func (*Pin) SetActiveLow ¶
SetActiveLow inverts the pins value, i.e. it is true when the value is low.
func (*Pin) SetDirection ¶
SetDirection configures the pin as an input or output.
func (*Pin) SetEdge ¶
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.