gpioreg

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2017 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package gpioreg defines a registry for the known digital pins.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Aliases

func Aliases() []gpio.PinIO

Aliases returns all pin aliases.

The list is guaranteed to be in order of aliase name.

func All

func All() []gpio.PinIO

All returns all the GPIO pins available on this host.

The list is guaranteed to be in order of number.

This list excludes aliases.

This list excludes non-GPIO pins like GROUND, V3_3, etc.

Example
fmt.Print("GPIO pins available:\n")
for _, pin := range All() {
	fmt.Printf("- %s: %s\n", pin, pin.Function())
}
Output:

func ByName

func ByName(name string) gpio.PinIO

ByName returns a GPIO pin from its name.

This can be strings like GPIO2, PB8, etc.

This function parses string representation of numbers, calling with "6" returns the pin registered as number 6.

Returns nil in case the pin is not present.

Example
p := ByName("GPIO6")
if p == nil {
	log.Fatal("Failed to find GPIO6")
}
fmt.Printf("%s: %s\n", p, p.Function())
Output:

Example (Alias)
p := ByName("LCD-D2")
if p == nil {
	log.Fatal("Failed to find LCD-D2")
}
if rp, ok := p.(gpio.RealPin); ok {
	fmt.Printf("%s is an alias for %s\n", p, rp.Real())
} else {
	fmt.Printf("%s is not an alias!\n", p)
}
Output:

Example (Number)
// The string representation of a number works too.
p := ByName("6")
if p == nil {
	log.Fatal("Failed to find GPIO6")
}
fmt.Printf("%s: %s\n", p, p.Function())
Output:

func ByNumber added in v1.0.0

func ByNumber(number int) gpio.PinIO

ByNumber returns a GPIO pin from its number.

Returns nil in case the pin is not present.

Example
p := ByNumber(6)
if p == nil {
	log.Fatal("Failed to find #6")
}
fmt.Printf("%s: %s\n", p, p.Function())
Output:

func Register

func Register(p gpio.PinIO, preferred bool) error

Register registers a GPIO pin.

Registering the same pin number or name twice is an error.

`preferred` should be true when the pin being registered is exposing as much functionality as possible via the underlying hardware. This is normally done by accessing the CPU memory mapped registers directly.

`preferred` should be false when the functionality is provided by the OS and is limited or slower.

The pin registered cannot implement the interface RealPin.

func RegisterAlias

func RegisterAlias(alias string, dest string) error

RegisterAlias registers an alias for a GPIO pin.

It is possible to register an alias for a pin that itself has not been registered yet. It is valid to register an alias to another alias or to a number.

Types

This section is empty.

Jump to

Keyboard shortcuts

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