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 ¶
const ( // DefaultTransmissionCount defines how many times a code should be // transmitted in a row by default. DefaultTransmissionCount = 10 )
Variables ¶
var DefaultProtocols = []Protocol{ {HighLow{1, 31}, HighLow{1, 3}, HighLow{3, 1}}, {HighLow{1, 10}, HighLow{1, 2}, HighLow{2, 1}}, {HighLow{30, 71}, HighLow{4, 11}, HighLow{9, 6}}, {HighLow{1, 6}, HighLow{1, 3}, HighLow{3, 1}}, {HighLow{6, 14}, HighLow{1, 2}, HighLow{2, 1}}, }
DefaultProtocols defines known remote control protocols. These are exported to give users the ability to add more protocols if needed. However, it is advised to use the ReceiverProtocols ReceiverOption to configure a *Receiver with custom protocols.
Functions ¶
This section is empty.
Types ¶
type Closer ¶ added in v1.0.0
type Closer interface { // Close closes the thing. Close() error }
Closer is something that can be closed.
type CodeReceiver ¶
type CodeReceiver interface { Closer // Receive blocks until there is a result on the receive channel. Receive() <-chan ReceiveResult }
CodeReceiver defines the interface for a rf code receiver.
type CodeTransmitter ¶
type CodeTransmitter interface { Closer // Transmit transmits a code using given protocol and pulse length. // // This method returns immediately. The code is transmitted in the background. // If you need to ensure that a code has been fully transmitted, wait for the // returned channel to be closed. Transmit(code uint64, protocol Protocol, pulseLength uint) <-chan struct{} }
CodeTransmitter defines the interface for a rf code transmitter.
type FakeOutputPin ¶ added in v1.0.0
type FakeOutputPin struct { // Values holds the sequence of values the were set via SetValue. Values []int // Err controls the error returned by Close. Err error // Closed indicates whether Close was called or not. Closed bool }
FakeOutputPin can be used in tests as an OutputPin.
func NewFakeOutputPin ¶ added in v1.0.0
func NewFakeOutputPin() *FakeOutputPin
NewFakeOutputPin creates a new *FakeOutputPin that can be used in tests as an OutputPin.
func (*FakeOutputPin) Close ¶ added in v1.0.0
func (p *FakeOutputPin) Close() error
Close implements Closer.
func (*FakeOutputPin) SetValue ¶ added in v1.0.0
func (p *FakeOutputPin) SetValue(value int) error
SetValue implements OutputPin.
type FakeWatcher ¶ added in v1.0.0
type FakeWatcher struct { // Events can be used to make the FakeWatcher return arbitrary events. Events chan gpiod.LineEvent // Err controls the error returned by Close. Err error // Closed indicates whether Close was called or not. Closed bool }
FakeWatcher can be used in tests as a Watcher.
func NewFakeWatcher ¶ added in v1.0.0
func NewFakeWatcher() *FakeWatcher
NewFakeWatcher creates a new *FakeWatcher that can be used in tests as a Watcher.
func (*FakeWatcher) Close ¶ added in v1.0.0
func (w *FakeWatcher) Close() error
Close implements Closer.
func (*FakeWatcher) Watch ¶ added in v1.0.0
func (w *FakeWatcher) Watch() <-chan gpiod.LineEvent
Watch implements Watcher.
type HighLow ¶
type HighLow struct {
High, Low uint
}
HighLow defines the number of high pulses followed by a number of low pulses to send.
type Protocol ¶
type Protocol struct {
Sync, Zero, One HighLow
}
Protocol defines the HighLow sequences to send to emit ones (One) and zeros (Zero) and the sync sequence (Sync) which signals the end of a code transmission.
type ReceiveResult ¶
type ReceiveResult struct { // Code is the detected code. Code uint64 // BitLength is the detected bit length. BitLength uint // PulseLength is the detected pulse length. PulseLength int64 // Protocol is the detected protocol. The protocol is 1-indexed. Protocol int }
ReceiveResult contains information about a detected code sent by an rf code transmitter.
type Receiver ¶ added in v1.0.0
type Receiver struct {
// contains filtered or unexported fields
}
Receiver can detect and unserialize rf codes received on a gpio pin.
func NewReceiver ¶
NewReceiver creates a *Receiver which listens on the chip's pin at offset for rf codes.
func NewWatcherReceiver ¶ added in v1.0.0
func NewWatcherReceiver(watcher Watcher, options ...ReceiverOption) *Receiver
NewWatcherReceiver create a new receiver which uses given Watcher to detect sent rf codes.
func (*Receiver) Close ¶ added in v1.0.0
Close stops the watcher and receiver goroutines and perform cleanup.
func (*Receiver) Receive ¶ added in v1.0.0
func (r *Receiver) Receive() <-chan ReceiveResult
Receive blocks until there is a result on the receive channel
type ReceiverOption ¶ added in v1.0.0
type ReceiverOption func(*Receiver)
ReceiverOption is the signature of funcs that are used to configure a *Receiver.
func ReceiverProtocols ¶ added in v1.0.0
func ReceiverProtocols(protocols []Protocol) ReceiverOption
ReceiverProtocols configures the protocols the receiver should try to detect. If not overridden explicitly, DefaultProtocols is used.
type Transmitter ¶ added in v1.0.0
type Transmitter struct {
// contains filtered or unexported fields
}
Transmitter can serialize and transmit rf codes.
func NewDiscardingTransmitter ¶ added in v1.0.0
func NewDiscardingTransmitter() *Transmitter
NewDiscardingTransmitter creates a *Transmitter that does not send anything.
func NewPinTransmitter ¶ added in v1.0.0
func NewPinTransmitter(pin OutputPin, options ...TransmitterOption) *Transmitter
NewPinTransmitter creates a *Transmitter that sends on pin.
func NewTransmitter ¶
func NewTransmitter(chip *gpiod.Chip, offset int, options ...TransmitterOption) (*Transmitter, error)
NewTransmitter creates a Transmitter which attaches to the chip's pin at offset.
func (*Transmitter) Close ¶ added in v1.0.0
func (t *Transmitter) Close() error
Close stops started goroutines and closes the gpio pin.
func (*Transmitter) Transmit ¶ added in v1.0.0
func (t *Transmitter) Transmit(code uint64, protocol Protocol, pulseLength uint) <-chan struct{}
Transmit transmits a code using given protocol and pulse length.
This method returns immediately. The code is transmitted in the background. If you need to ensure that a code has been fully transmitted, wait for the returned channel to be closed.
type TransmitterOption ¶ added in v1.0.0
type TransmitterOption func(*Transmitter)
TransmitterOption is the signature of funcs that are used to configure a *Transmitter.
func TransmissionCount ¶ added in v1.0.0
func TransmissionCount(count int) TransmitterOption
TransmissionCount configures 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.