nodes

package
v0.0.0-...-db03bfd Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package nodes describes the shared nodes definition language between the controller and the devices.

Index

Constants

This section is empty.

Variables

View Source
var TypesMap map[Type]reflect.Type

TypesMap is the list of known types and their associated name.

Functions

This section is empty.

Types

type Anim1D

type Anim1D struct {
	APA102 bool
	I2C    I2CRef
	SPI    SPIRef
	// NumberLights is the number of lights controlled by this device. If lower
	// than the actual number of lights, the remaining lights will flash oddly.
	NumberLights int
	FPS          int
}

Anim1D is an APA102 LED strip.

func (*Anim1D) Validate

func (a *Anim1D) Validate() error

Validate implements Validator.

type Button

type Button struct {
	Pin string
}

Button represents a physical GPIO input pin of type Button.

func (*Button) Validate

func (b *Button) Validate() error

Validate implements Validator.

type Dev

type Dev struct {
	// Name is the display name of this nodes collection: the device.
	Name  string
	Nodes map[ID]*Node
}

Dev is the configuration for all the nodes on a device.

The Dev is the micro-computer (a Rasberry Pi, C.H.I.P., ESP8266) that exposes nodes.

The controller stores this data on the MQTT server upon startup and upon configuration update.

The device fetches this data from the MQTT server upon startup. So when a device configuration occurs, the device should restart. This is really just restarting the Go process so this is nearly instant.

func (*Dev) ToSerialized

func (d *Dev) ToSerialized() *SerializedDev

ToSerialized is used by the controller to serialize the device description.

Serialization should never fail.

func (*Dev) Validate

func (d *Dev) Validate() error

Validate implements Validator.

type Display

type Display struct {
	SSD1306 bool
	I2C     struct {
		ID string
	}
	W, H int
}

Display is an ssd1306 display.

TODO(maruel): make it more generic so other kind of display are supported.

func (*Display) Validate

func (d *Display) Validate() error

Validate implements Validator.

type I2CRef

type I2CRef struct {
	ID string
}

type ID

type ID string

ID is a valid homie ID.

func (ID) Validate

func (i ID) Validate() error

Validate implements Validator.

type IR

type IR struct {
}

IR is an InfraRed Remote receiver.

In practice, only lirc is supported.

func (*IR) Validate

func (i *IR) Validate() error

Validate implements Validator.

type Node

type Node struct {
	// Name is the display name of this node.
	Name   string
	Config NodeCfg
}

Node is the descriptor for a configured node on a device.

func (*Node) Type

func (n *Node) Type() Type

Type returns the node's Type.

func (*Node) Validate

func (n *Node) Validate() error

Validate implements Validator.

type NodeCfg

type NodeCfg interface {
	Validator
	// contains filtered or unexported methods
}

NodeCfg is the descriptor of a node.

type PIR

type PIR struct {
	Pin string
}

PIR represents a GPIO physical pin that is connected to a motion detector.

func (*PIR) Validate

func (p *PIR) Validate() error

Validate implements Validator.

type Property

type Property struct {
	Unit     string `json:"$unit"`
	DataType string `json:"$datatype"`
	Format   string `json:"$format"`
	Settable bool   `json:"$settable"`
}

Property defines one property of a node.

A Node can have multiple properties. For example a buzzer could have separate knob for frequency and intensity.

type SPIRef

type SPIRef struct {
	ID string
	Hz physic.Frequency
}

type SerializedDev

type SerializedDev struct {
	Name  string `json:"$name"`
	Nodes map[ID]*SerializedNode
}

SerializedDev is the serialized form of Dev as stored on the MQTT server.

func (*SerializedDev) ToDev

func (s *SerializedDev) ToDev() (*Dev, error)

ToDev is used by the device to deserialize the configuration.

type SerializedNode

type SerializedNode struct {
	Name       string          `json:"$name"`
	Type       Type            `json:"$type"`
	Properties map[ID]Property `json:"$properties"`
	Config     []byte          `json:"$config"`
}

SerializedNode is loosely based on https://github.com/marvinroger/homie#node-attributes

It is the serialized form of Node.

type Sound

type Sound struct {
	DeviceID string // Empty to use the default sound card.
}

Sound is a sound output device.

func (*Sound) Validate

func (s *Sound) Validate() error

Validate implements Validator.

type Type

type Type string

Type is all the known node types.

func (Type) Validate

func (t Type) Validate() error

Validate implements Validator.

type Validator

type Validator interface {
	Validate() error
}

Validator ensures a configuration is valid.

Jump to

Keyboard shortcuts

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