Documentation ¶
Overview ¶
Package ledserial implements the LED serial protocol.
Index ¶
- Variables
- func WriteIncomingPacket(w io.Writer, p IncomingPacket) error
- func WriteOutgoingPacket(w io.Writer, p OutgoingPacket) error
- type AckPacket
- type ClearPacket
- type ErrorPacket
- type IncomingPacket
- type IncomingPacketType
- type InitializePacket
- type LogPacket
- type OutgoingPacket
- type OutgoingPacketType
- type PanicPacket
- type ReadContext
- type Reader
- type SetPacket
Constants ¶
This section is empty.
Variables ¶
var Endianness = binary.LittleEndian
Endianness defines the endianness of the protocol.
Functions ¶
func WriteIncomingPacket ¶
func WriteIncomingPacket(w io.Writer, p IncomingPacket) error
WriteIncomingPacket writes an incoming packet to the given writer.
func WriteOutgoingPacket ¶
func WriteOutgoingPacket(w io.Writer, p OutgoingPacket) error
WriteOutgoingPacket writes an outgoing packet to the given writer.
Types ¶
type AckPacket ¶
type AckPacket struct {
IncomingPacketType IncomingPacketType
}
AckPacket is a packet that is sent by the controller to acknowledge a packet.
func (AckPacket) Type ¶
func (p AckPacket) Type() OutgoingPacketType
type ClearPacket ¶
type ClearPacket struct{}
ClearPacket is a packet that clears the LED strip.
func (ClearPacket) Type ¶
func (p ClearPacket) Type() IncomingPacketType
type ErrorPacket ¶
type ErrorPacket struct {
Message string
}
ErrorPacket is a packet that indicates an error occurred.
func (ErrorPacket) Type ¶
func (p ErrorPacket) Type() OutgoingPacketType
type IncomingPacket ¶
type IncomingPacket interface { // Type returns the type of packet. Type() IncomingPacketType }
IncomingPacket is a packet sent over the wire.
func ReadIncomingPacket ¶
func ReadIncomingPacket(r io.Reader, context ReadContext) (IncomingPacket, error)
ReadIncomingPacket reads an incoming packet from the given reader.
type IncomingPacketType ¶
type IncomingPacketType uint8
IncomingPacketType is a type of packet.
const ( TypeInitializePacket IncomingPacketType = iota TypeClearPacket TypeSetPacket )
func (IncomingPacketType) String ¶
func (t IncomingPacketType) String() string
String returns a string representation of the packet type.
type InitializePacket ¶
type InitializePacket struct {
NumLEDs uint16
}
InitializePacket is a packet that initializes the LED strip.
func (InitializePacket) Type ¶
func (p InitializePacket) Type() IncomingPacketType
type LogPacket ¶
type LogPacket struct {
Message string
}
LogPacket is a packet that contains a log message.
func (LogPacket) Type ¶
func (p LogPacket) Type() OutgoingPacketType
type OutgoingPacket ¶
type OutgoingPacket interface { // Type returns the type of packet. Type() OutgoingPacketType }
OutgoingPacket is a packet sent over the wire.
func ReadOutgoingPacket ¶
func ReadOutgoingPacket(r io.Reader, context ReadContext) (OutgoingPacket, error)
ReadOutgoingPacket reads an outgoing packet from the given reader.
type OutgoingPacketType ¶
type OutgoingPacketType uint8
OutgoingPacketType is a type of packet.
const ( TypeErrorPacket OutgoingPacketType = iota TypeLogPacket TypeAckPacket )
const TypePanicPacket OutgoingPacketType = 'p'
TypePanicPacket is a special constant. It is the first letter of the word "panic" in order to parse the string itself as a packet type.
func (OutgoingPacketType) String ¶
func (t OutgoingPacketType) String() string
String returns a string representation of the packet type.
type PanicPacket ¶
type PanicPacket struct {
Message string
}
PanicPacket is a packet that indicates the program cannot recover.
func (PanicPacket) Type ¶
func (p PanicPacket) Type() OutgoingPacketType
type ReadContext ¶
type ReadContext struct { // LEDBuffer is the buffer that contains the current state of the LED strip. // This buffer will be used for reading SetPacket. // Its length must be NumLEDs * 3. LEDBuffer []uint8 }
ReadContext is the state of the LED strip. Data in this structure are required for the device to read incoming packets.