gpio

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2018 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

Package gpio provides receiver and transmitter functionality for reading remote control codes and sending them out to control remote controlled outlets.

Most of the receiver and transmitter code as well as the protocols were ported from the rc-switch c++ implementation to go. Check out the rc-switch repository at https://github.com/sui77/rc-switch for the awesome work.

Index

Constants

View Source
const (
	// DefaultTransmitPin defines the default gpio pin for transmitting rf codes
	DefaultTransmitPin uint = 17

	// DefaultReceivePin defines the default gpio pin for receiving rf codes
	DefaultReceivePin uint = 27

	// DefaultProtocol defines the default rf protocol
	DefaultProtocol int = 1

	// DefaultPulseLength defines the default pulse length
	DefaultPulseLength uint = 189
)

Variables

View Source
var Protocols = []Protocol{
	{350, HighLow{1, 31}, HighLow{1, 3}, HighLow{3, 1}},
	{650, HighLow{1, 10}, HighLow{1, 2}, HighLow{2, 1}},
	{100, HighLow{30, 71}, HighLow{4, 11}, HighLow{9, 6}},
	{380, HighLow{1, 6}, HighLow{1, 3}, HighLow{3, 1}},
	{500, HighLow{6, 14}, HighLow{1, 2}, HighLow{2, 1}},
}

Protocols defines known remote control protocols. These are exported to give users the ability to add more protocols if needed.

View Source
var TransmitRetries int = 10

TransmitRetries defines how many times a code should be transmitted in a row. The higher the value, the more likely it is that an outlet actually received the code.

Functions

This section is empty.

Types

type CodeReceiver

type CodeReceiver interface {
	Receive() <-chan ReceiveResult
	Close() error
}

CodeReceiver defines the interface for a rf code receiver.

func NewReceiver

func NewReceiver(gpioPin uint) CodeReceiver

NewReceiver create a new receiver on the gpio pin

type CodeTransmitter

type CodeTransmitter interface {
	Transmit(uint64, int, uint) error
	Wait()
	Close() error
}

CodeTransmitter defines the interface for a rf code transmitter.

func NewTransmitter

func NewTransmitter(gpioPin uint) (CodeTransmitter, error)

NewTransmitter creates a NativeTransmitter when /dev/gpiomem is available, NullTransmitter otherwise.

type HighLow

type HighLow struct {
	High, Low uint
}

HighLow type definition

type NativeReceiver

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

NativeReceiver type definition

func NewNativeReceiver

func NewNativeReceiver(gpioPin uint, watcher Watcher) *NativeReceiver

NewNativeReceiver create a new receiver on the gpio pin using watcher

func (*NativeReceiver) Close

func (r *NativeReceiver) Close() error

Close stops the watcher and receiver goroutines and perform cleanup

func (*NativeReceiver) Receive

func (r *NativeReceiver) Receive() <-chan ReceiveResult

Receive blocks until there is a result on the receive channel

type NativeTransmitter

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

NativeTransmitter type definition.

func NewNativeTransmitter

func NewNativeTransmitter(gpioPin Pin) (*NativeTransmitter, error)

NewNativeTransmitter create a native transmitter on the gpio pin.

func (*NativeTransmitter) Close

func (t *NativeTransmitter) Close() error

Close stops started goroutines and closes the gpio pin

func (*NativeTransmitter) Transmit

func (t *NativeTransmitter) Transmit(code uint64, protocol int, pulseLength uint) error

Transmit transmits a code using given protocol and pulse length. It will return an error if the provided protocol is does not exist.

This method returns immediately. The code is transmitted in the background. If you need to ensure that a code has been fully transmitted, call Wait() after calling Transmit().

func (*NativeTransmitter) Wait

func (t *NativeTransmitter) Wait()

Wait blocks until a code is fully transmitted.

type NullTransmitter

type NullTransmitter struct{}

NullTransmitter type definition.

func NewNullTransmitter

func NewNullTransmitter() (*NullTransmitter, error)

NewNullTransmitter create a transmitter that does nothing except logging the transmissions. This is mainly useful for development on systems where /dev/gpiomem is not available.

func (*NullTransmitter) Close

func (t *NullTransmitter) Close() error

Close does nothing.

func (*NullTransmitter) Transmit

func (t *NullTransmitter) Transmit(code uint64, protocol int, pulseLength uint) error

Transmit does nothing.

func (*NullTransmitter) Wait

func (t *NullTransmitter) Wait()

Wait does nothing.

type Pin

type Pin interface {
	High() error
	Low() error
	Close()
}

Pin defines an interface for a gpio pin

type Protocol

type Protocol struct {
	PulseLength     uint
	Sync, Zero, One HighLow
}

Protocol type definition

type ReceiveResult

type ReceiveResult struct {
	Code        uint64
	BitLength   uint
	PulseLength int64
	Protocol    int
}

ReceiveResult type definition

type Watcher

type Watcher interface {
	Watch() (uint, uint)
	AddPin(uint)
	Close()
}

Watcher defines the interface for a gpio pin watcher

Jump to

Keyboard shortcuts

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