gpio

package
v0.0.0-...-5ffa399 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2015 License: Apache-2.0, Apache-2.0 Imports: 4 Imported by: 0

README

GPIO

This package provides drivers for General Purpose Input/Output (GPIO) devices . It is normally not used directly, but instead is registered by an adaptor such as firmata that supports the needed interfaces for GPIO devices.

Getting Started

Installing

go get github.com/hybridgroup/gobot && go install github.com/hybridgroup/gobot/platforms/gpio

Hardware Support

Gobot has a extensible system for connecting to hardware devices. The following GPIO devices are currently supported:

  • Analog Sensor
  • Button
  • Direct Pin
  • LED
  • Makey Button
  • Motor
  • Servo

More drivers are coming soon...

Documentation

Overview

Package gpio provides Gobot drivers for General Purpose Input/Output devices.

Installing:

go get -d -u github.com/hybridgroup/gobot/... && go install github.com/hybridgroup/gobot/platforms/gpio

For further information refer to gpio README: https://github.com/hybridgroup/gobot/blob/master/platforms/gpio/README.md

Index

Constants

View Source
const (
	// Release event
	Release = "release"
	// Push event
	Push = "push"
	// Error event
	Error = "error"
	// Data event
	Data = "data"
)

Variables

View Source
var (
	// ErrServoWriteUnsupported is the error resulting when a driver attempts to use
	// hardware capabilities which a connection does not support
	ErrServoWriteUnsupported = errors.New("ServoWrite is not supported by this platform")
	// ErrPwmWriteUnsupported is the error resulting when a driver attempts to use
	// hardware capabilities which a connection does not support
	ErrPwmWriteUnsupported = errors.New("PwmWrite is not supported by this platform")
	// ErrAnalogReadUnsupported is error resulting when a driver attempts to use
	// hardware capabilities which a connection does not support
	ErrAnalogReadUnsupported = errors.New("AnalogRead is not supported by this platform")
	// ErrDigitalWriteUnsupported is the error resulting when a driver attempts to use
	// hardware capabilities which a connection does not support
	ErrDigitalWriteUnsupported = errors.New("DigitalWrite is not supported by this platform")
	// ErrDigitalReadUnsupported is the error resulting when a driver attempts to use
	// hardware capabilities which a connection does not support
	ErrDigitalReadUnsupported = errors.New("DigitalRead is not supported by this platform")
	// ErrServoOutOfRange is the error resulting when a driver attempts to use
	// hardware capabilities which a connection does not support
	ErrServoOutOfRange = errors.New("servo angle must be between 0-180")
)

Functions

This section is empty.

Types

type AnalogReader

type AnalogReader interface {
	gobot.Adaptor
	AnalogRead(string) (val int, err error)
}

AnalogReader interface represents an Adaptor which has Analog capabilities

type AnalogSensorDriver

type AnalogSensorDriver struct {
	gobot.Eventer
	gobot.Commander
	// contains filtered or unexported fields
}

AnalogSensorDriver represents an Analog Sensor

func NewAnalogSensorDriver

func NewAnalogSensorDriver(a AnalogReader, name string, pin string, v ...time.Duration) *AnalogSensorDriver

NewAnalogSensorDriver returns a new AnalogSensorDriver with a polling interval of 10 Milliseconds given an AnalogReader, name and pin.

Optinally accepts:

time.Duration: Interval at which the AnalogSensor is polled for new information

Adds the following API Commands:

"Read" - See AnalogSensor.Read

func (*AnalogSensorDriver) Connection

func (a *AnalogSensorDriver) Connection() gobot.Connection

Connection returns the AnalogSensorDrivers Connection

func (*AnalogSensorDriver) Halt

func (a *AnalogSensorDriver) Halt() (errs []error)

Halt stops polling the analog sensor for new information

func (*AnalogSensorDriver) Name

func (a *AnalogSensorDriver) Name() string

Name returns the AnalogSensorDrivers name

func (*AnalogSensorDriver) Pin

func (a *AnalogSensorDriver) Pin() string

Pin returns the AnalogSensorDrivers pin

func (*AnalogSensorDriver) Read

func (a *AnalogSensorDriver) Read() (val int, err error)

Read returns the current reading from the Analog Sensor

func (*AnalogSensorDriver) Start

func (a *AnalogSensorDriver) Start() (errs []error)

Start starts the AnalogSensorDriver and reads the Analog Sensor at the given interval. Emits the Events:

Data int - Event is emitted on change and represents the current reading from the sensor.
Error error - Event is emitted on error reading from the sensor.

type ButtonDriver

type ButtonDriver struct {
	Active bool

	gobot.Eventer
	// contains filtered or unexported fields
}

ButtonDriver Represents a digital Button

func NewButtonDriver

func NewButtonDriver(a DigitalReader, name string, pin string, v ...time.Duration) *ButtonDriver

NewButtonDriver returns a new ButtonDriver with a polling interval of 10 Milliseconds given a DigitalReader, name and pin.

Optinally accepts:

time.Duration: Interval at which the ButtonDriver is polled for new information

func (*ButtonDriver) Connection

func (b *ButtonDriver) Connection() gobot.Connection

Connection returns the ButtonDrivers Connection

func (*ButtonDriver) Halt

func (b *ButtonDriver) Halt() (errs []error)

Halt stops polling the button for new information

func (*ButtonDriver) Name

func (b *ButtonDriver) Name() string

Name returns the ButtonDrivers name

func (*ButtonDriver) Pin

func (b *ButtonDriver) Pin() string

Pin returns the ButtonDrivers pin

func (*ButtonDriver) Start

func (b *ButtonDriver) Start() (errs []error)

Start starts the ButtonDriver and polls the state of the button at the given interval.

Emits the Events:

Push int - On button push
Release int - On button release
Error error - On button error

type DigitalReader

type DigitalReader interface {
	gobot.Adaptor
	DigitalRead(string) (val int, err error)
}

DigitalReader interface represents an Adaptor which has DigitalRead capabilities

type DigitalWriter

type DigitalWriter interface {
	gobot.Adaptor
	DigitalWrite(string, byte) (err error)
}

DigitalWriter interface represents an Adaptor which has DigitalWrite capabilities

type DirectPinDriver

type DirectPinDriver struct {
	gobot.Commander
	// contains filtered or unexported fields
}

DirectPinDriver represents a GPIO pin

func NewDirectPinDriver

func NewDirectPinDriver(a gobot.Connection, name string, pin string) *DirectPinDriver

NewDirectPinDriver return a new DirectPinDriver given a Connection, name and pin.

Adds the following API Commands:

"DigitalRead" - See DirectPinDriver.DigitalRead
"DigitalWrite" - See DirectPinDriver.DigitalWrite
"AnalogRead" - See DirectPinDriver.AnalogRead
"AnalogWrite" - See DirectPinDriver.AnalogWrite
"PwmWrite" - See DirectPinDriver.PwmWrite
"ServoWrite" - See DirectPinDriver.ServoWrite

func (*DirectPinDriver) AnalogRead

func (d *DirectPinDriver) AnalogRead() (val int, err error)

AnalogRead reads the current analog reading of the pin

func (*DirectPinDriver) Connection

func (d *DirectPinDriver) Connection() gobot.Connection

Connection returns the DirectPinDrivers Connection

func (*DirectPinDriver) DigitalRead

func (d *DirectPinDriver) DigitalRead() (val int, err error)

DigitalRead returns the current digital state of the pin

func (*DirectPinDriver) DigitalWrite

func (d *DirectPinDriver) DigitalWrite(level byte) (err error)

DigitalWrite writes to the pin. Acceptable values are 1 or 0

func (*DirectPinDriver) Halt

func (d *DirectPinDriver) Halt() (errs []error)

Halt implements the Driver interface

func (*DirectPinDriver) Name

func (d *DirectPinDriver) Name() string

Name returns the DirectPinDrivers name

func (*DirectPinDriver) Pin

func (d *DirectPinDriver) Pin() string

Pin returns the DirectPinDrivers pin

func (*DirectPinDriver) PwmWrite

func (d *DirectPinDriver) PwmWrite(level byte) (err error)

PwmWrite writes the 0-254 value to the specified pin

func (*DirectPinDriver) ServoWrite

func (d *DirectPinDriver) ServoWrite(level byte) (err error)

ServoWrite writes value to the specified pin

func (*DirectPinDriver) Start

func (d *DirectPinDriver) Start() (errs []error)

Start implements the Driver interface

type LedDriver

type LedDriver struct {
	gobot.Commander
	// contains filtered or unexported fields
}

LedDriver represents a digital Led

func NewLedDriver

func NewLedDriver(a DigitalWriter, name string, pin string) *LedDriver

NewLedDriver return a new LedDriver given a DigitalWriter, name and pin.

Adds the following API Commands:

"Brightness" - See LedDriver.Brightness
"Toggle" - See LedDriver.Toggle
"On" - See LedDriver.On
"Off" - See LedDriver.Off

func (*LedDriver) Brightness

func (l *LedDriver) Brightness(level byte) (err error)

Brightness sets the led to the specified level of brightness

func (*LedDriver) Connection

func (l *LedDriver) Connection() gobot.Connection

Connection returns the LedDrivers Connection

func (*LedDriver) Halt

func (l *LedDriver) Halt() (errs []error)

Halt implements the Driver interface

func (*LedDriver) Name

func (l *LedDriver) Name() string

Name returns the LedDrivers name

func (*LedDriver) Off

func (l *LedDriver) Off() (err error)

Off sets the led to a low state.

func (*LedDriver) On

func (l *LedDriver) On() (err error)

On sets the led to a high state.

func (*LedDriver) Pin

func (l *LedDriver) Pin() string

Pin returns the LedDrivers name

func (*LedDriver) Start

func (l *LedDriver) Start() (errs []error)

Start implements the Driver interface

func (*LedDriver) State

func (l *LedDriver) State() bool

State return true if the led is On and false if the led is Off

func (*LedDriver) Toggle

func (l *LedDriver) Toggle() (err error)

Toggle sets the led to the opposite of it's current state

type MakeyButtonDriver

type MakeyButtonDriver struct {
	Active bool

	gobot.Eventer
	// contains filtered or unexported fields
}

MakeyButtonDriver Represents a Makey Button

func NewMakeyButtonDriver

func NewMakeyButtonDriver(a DigitalReader, name string, pin string, v ...time.Duration) *MakeyButtonDriver

NewMakeyButtonDriver returns a new MakeyButtonDriver with a polling interval of 10 Milliseconds given a DigitalReader, name and pin.

Optinally accepts:

time.Duration: Interval at which the ButtonDriver is polled for new information

func (*MakeyButtonDriver) Connection

func (b *MakeyButtonDriver) Connection() gobot.Connection

Connection returns the MakeyButtonDrivers Connection

func (*MakeyButtonDriver) Halt

func (b *MakeyButtonDriver) Halt() (errs []error)

Halt stops polling the makey button for new information

func (*MakeyButtonDriver) Name

func (b *MakeyButtonDriver) Name() string

Name returns the MakeyButtonDrivers name

func (*MakeyButtonDriver) Pin

func (b *MakeyButtonDriver) Pin() string

Pin returns the MakeyButtonDrivers pin

func (*MakeyButtonDriver) Start

func (b *MakeyButtonDriver) Start() (errs []error)

Start starts the MakeyButtonDriver and polls the state of the button at the given interval.

Emits the Events:

Push int - On button push
Release int - On button release
Error error - On button error

type MotorDriver

type MotorDriver struct {
	SpeedPin         string
	SwitchPin        string
	DirectionPin     string
	ForwardPin       string
	BackwardPin      string
	CurrentState     byte
	CurrentSpeed     byte
	CurrentMode      string
	CurrentDirection string
	// contains filtered or unexported fields
}

MotorDriver Represents a Motor

func NewMotorDriver

func NewMotorDriver(a DigitalWriter, name string, speedPin string) *MotorDriver

NewMotorDriver return a new MotorDriver given a DigitalWriter, name and pin

func (*MotorDriver) Backward

func (m *MotorDriver) Backward(speed byte) (err error)

Backward sets the backward pin to the specified speed

func (*MotorDriver) Connection

func (m *MotorDriver) Connection() gobot.Connection

Connection returns the MotorDrivers Connection

func (*MotorDriver) Direction

func (m *MotorDriver) Direction(direction string) (err error)

Direction sets the direction pin to the specified speed

func (*MotorDriver) Forward

func (m *MotorDriver) Forward(speed byte) (err error)

Forward sets the forward pin to the specified speed

func (*MotorDriver) Halt

func (m *MotorDriver) Halt() (errs []error)

Halt implements the Driver interface

func (*MotorDriver) IsOff

func (m *MotorDriver) IsOff() bool

IsOff returns true if the motor is off

func (*MotorDriver) IsOn

func (m *MotorDriver) IsOn() bool

IsOn returns true if the motor is on

func (*MotorDriver) Max

func (m *MotorDriver) Max() (err error)

Max sets the motor to the maximum speed

func (*MotorDriver) Min

func (m *MotorDriver) Min() (err error)

Min sets the motor to the minimum speed

func (*MotorDriver) Name

func (m *MotorDriver) Name() string

Name returns the MotorDrivers name

func (*MotorDriver) Off

func (m *MotorDriver) Off() (err error)

Off turns the motor off or sets the motor to a 0 speed

func (*MotorDriver) On

func (m *MotorDriver) On() (err error)

On turns the motor on or sets the motor to a maximum speed

func (*MotorDriver) Speed

func (m *MotorDriver) Speed(value byte) (err error)

Speed sets the speed of the motor

func (*MotorDriver) Start

func (m *MotorDriver) Start() (errs []error)

Start implements the Driver interface

func (*MotorDriver) Toggle

func (m *MotorDriver) Toggle() (err error)

Toggle sets the motor to the opposite of it's current state

type PwmWriter

type PwmWriter interface {
	gobot.Adaptor
	PwmWrite(string, byte) (err error)
}

PwmWriter interface represents an Adaptor which has Pwm capabilities

type ServoDriver

type ServoDriver struct {
	gobot.Commander
	CurrentAngle byte
	// contains filtered or unexported fields
}

ServoDriver Represents a Servo

func NewServoDriver

func NewServoDriver(a ServoWriter, name string, pin string) *ServoDriver

NewServoDriver returns a new ServoDriver given a ServoWriter, name and pin.

Adds the following API Commands:

"Move" - See ServoDriver.Move
"Min" - See ServoDriver.Min
"Center" - See ServoDriver.Center
"Max" - See ServoDriver.Max

func (*ServoDriver) Center

func (s *ServoDriver) Center() (err error)

Center sets the servo to it's center position

func (*ServoDriver) Connection

func (s *ServoDriver) Connection() gobot.Connection

Connection returns the ServoDrivers connection

func (*ServoDriver) Halt

func (s *ServoDriver) Halt() (errs []error)

Halt implements the Driver interface

func (*ServoDriver) Max

func (s *ServoDriver) Max() (err error)

Max sets the servo to its maximum position

func (*ServoDriver) Min

func (s *ServoDriver) Min() (err error)

Min sets the servo to it's minimum position

func (*ServoDriver) Move

func (s *ServoDriver) Move(angle uint8) (err error)

Move sets the servo to the specified angle. Acceptable angles are 0-180

func (*ServoDriver) Name

func (s *ServoDriver) Name() string

Name returns the ServoDrivers name

func (*ServoDriver) Pin

func (s *ServoDriver) Pin() string

Pin returns the ServoDrivers pin

func (*ServoDriver) Start

func (s *ServoDriver) Start() (errs []error)

Start implements the Driver interface

type ServoWriter

type ServoWriter interface {
	gobot.Adaptor
	ServoWrite(string, byte) (err error)
}

ServoWriter interface represents an Adaptor which has Servo capabilities

Jump to

Keyboard shortcuts

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