gpiostream

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: 2 Imported by: 0

Documentation

Overview

Package gpiostream defines digital streams.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BitStream

type BitStream struct {
	Bits Bits
	// The duration each bit represents.
	Res time.Duration
}

BitStream is a stream of bits to be written or read.

This struct is useful for dense binary data, like controlling ws2812b LED strip or using the GPIO pin as an digital oscilloscope.

func (*BitStream) Duration

func (b *BitStream) Duration() time.Duration

Duration implement Stream.

func (*BitStream) Resolution

func (b *BitStream) Resolution() time.Duration

Resolution implement Stream.

type Bits

type Bits []byte

Bits is a densely packed bitstream. The format is LSB, bit 0 is sent first, up to bit 7.

The stream is required to be a multiple of 8 samples.

type EdgeStream

type EdgeStream struct {
	// Edges is the list of Level change. It is assumed that the signal starts
	// with gpio.High. Use a duration of 0 to start with a Low.
	Edges []time.Duration
	// Res is the minimum resolution at which the edges should be
	// rasterized.
	//
	// The lower the value, the more memory shall be used when rasterized.
	Res time.Duration
}

EdgeStream is a stream of edges to be written.

This struct is more efficient than BitStream for repetitive pulses, like controlling a servo. A PWM can be created by specifying a slice of twice the same resolution and make it looping.

func (*EdgeStream) Duration

func (e *EdgeStream) Duration() time.Duration

Duration implement Stream.

func (*EdgeStream) Resolution

func (e *EdgeStream) Resolution() time.Duration

Resolution implement Stream.

type Program

type Program struct {
	Parts []Stream // Each part must be a BitStream, EdgeStream or Program
	Loops int      // Set to -1 to create an infinite loop
}

Program is a loop of streams.

This is itself a stream, it can be used to reduce memory usage when repeated patterns are used.

func (*Program) Duration

func (p *Program) Duration() time.Duration

Duration implement Stream.

func (*Program) Resolution

func (p *Program) Resolution() time.Duration

Resolution implement Stream.

type Stream

type Stream interface {
	// Resolution is the minimum resolution of the binary stream at which it is
	// usable.
	Resolution() time.Duration
	// Duration of the binary stream. For infinitely looping streams, it is the
	// duration of the non-looping part.
	Duration() time.Duration
}

Stream is the interface to define a generic stream

Jump to

Keyboard shortcuts

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