gpio

package
v0.0.0-...-5935107 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

The gpio package can be used to setup and access the raspberrie's gpio pins. If the configuration and access happens via file access an internal loop is implemented in the corresponding method that ensures the file access is repeated until a fixed bound of repeats is reached or the file access was successfully.

Index

Constants

View Source
const (
	OUTPUT PinMode = 1 + iota
	INPUT
	GPIO2 GpioId = iota
	GPIO3
	GPIO4
	GPIO5
	GPIO6
	GPIO7
	GPIO8
	GPIO9
	GPIO10
	GPIO11
	GPIO12
	GPIO13
	GPIO14
	GPIO15
	GPIO16
	GPIO17
	GPIO18
	GPIO19
	GPIO20
	GPIO21
	GPIO22
	GPIO23
	GPIO24
	GPIO25
	GPIO26
	GPIO27

	DIRECTION_FILE_NAME  = "direction"
	IN                   = "in"
	OUT                  = "out"
	ACTIVE_LOW_FILE_NAME = "active_low"
	ALTRUE               = "1"
	ALFALSE              = "0"
	VALUE_FILE_NAME      = "value"
	FILE_ACCESS_BOUND    = 1000
)

Constants declatation

Variables

View Source
var (
	EXPORT_FILE   = "/sys/class/gpio/export"
	UNEXPORT_FILE = "/sys/class/gpio/unexport"
	PATH_PREFIX   = "/sys/class/gpio/gpio"
)

Functions

This section is empty.

Types

type GpioId

type GpioId uint8

Type for the ID of gpio pins on raspberry board

type Pin

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

struct representing a gpio pin internally

func NewPin

func NewPin() (p *Pin)

Constructor method for the Pin struct mode set to INPUT by default value set to FALSE by default @return pointer to Pin struct with

func (*Pin) GetGpioId

func (g *Pin) GetGpioId() GpioId

Getter for the GPIO board id of the pin

func (*Pin) GetValue

func (g *Pin) GetValue() (val bool)

Reads and returns the current value from any kind of pins. If the pin's direction is set to OUT the internal value is returned directly. For INPUT pins the actual value is read from the file each time the function is called. This function is active_low safe which means, if the returned value is TRUE the pin's physical signal is HIGH. @return true if signal at pin is HIGH, false if signal is LOW

func (*Pin) PinMode

func (g *Pin) PinMode(pin GpioId, mode PinMode, activeLow ...bool)

Configures the internal fields of a Pin struct and calls the export function, which introduces the pin to the os with the given configuration. @param: pin the Pin's id on the raspberry board @param: mode weather read or write access is required @param: activeLow (optional) true if the pin should be run in active_low mode (raspberry default is false)

func (*Pin) SetValue

func (g *Pin) SetValue(val bool)

Sets the value for a gpio pin. This method is only applicable to OUT direction pins and as no effect if Pin.mode is INPUT. The method sets the associated gpio value at the raspberry via file access to the corresponding value file. The function is active_low safe. @param val if true the pin is set to mode HIGH else to mode LOW

func (*Pin) Unexport

func (g *Pin) Unexport()

Unexports the pin which deactivates it for further use.

type PinMode

type PinMode uint8

Type for the mode of a gpio pin

Jump to

Keyboard shortcuts

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