light

package module
v0.0.0-...-49e7f23 Latest Latest
Warning

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

Go to latest
Published: May 10, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

README

Go library to control a light. Works with the WebLight.

Usage

Run light.Update() in its own goroutine, perhaps with a short delay (sub-second).

	light.Add(light.Task{
		Color: &light.Red,
	})

	color, err := light.Update()
	if err != nil {
		log.Fatal(err) // or ignore, whatever
	}
	log.Printf("set color: %+v", color)

To add colors that take priority expire after a time:

	light.Add(light.Task{
		Priority: 100,     // higher takes precedence
		Color: &light.Red,
		Duration: time.Second,
	})

To cancel tasks:

	ref := light.Add(light.Task{
		Priority: 10,
		Color: &light.Color{128, 0, 255},
	})

	// later
	ref.Cancel()

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Red   = Color{255, 0, 0}
	Green = Color{0, 255, 0}
	Blue  = Color{0, 0, 255}
	White = Color{255, 255, 255}
)

Functions

func Debug

func Debug()

Debug dumps the light task list to console.

Types

type Bit

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

Bit describes a toggleable light.

func NewBit

func NewBit(priority int, color HasColor) *Bit

NewBit creates a new Bit light.

func (*Bit) Flip

func (b *Bit) Flip() bool

Flip flips the Bit light, returning the new status.

func (*Bit) Set

func (b *Bit) Set(on bool)

Set enables or disables the Bit light.

func (*Bit) Update

func (b *Bit) Update(color HasColor)

Update updates the config of this Bit light.

type Color

type Color [3]byte

Color is a triple of r,g,b.

func Update

func Update() (*Color, error)

Update enacts any current state at the current time.

func (*Color) Equal

func (c *Color) Equal(other *Color) bool

Equal returns whether the two colors are equal.

type ColorConfig

type ColorConfig func(time.Duration) *Color

ColorConfig is a method that takes a duration and returns a Color.

type HSLColor

type HSLColor [3]float64

HSLColor is a triple of h,s,l: in expected ranges 0-1.

type HSLColorConfig

type HSLColorConfig func(time.Duration) *HSLColor

HSLColorConfig is a method that takes a duration and returns a HSLColor.

type HasColor

type HasColor interface {
	// contains filtered or unexported methods
}

type Ref

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

Ref is a reference to a created Task.

func Add

func Add(t Task) Ref

Run adds the task to the light system.

func (*Ref) Cancel

func (r *Ref) Cancel() bool

Cancel this task. Returns true if a change was made. Safe on nil or zero Ref.

type Task

type Task struct {
	Priority int
	Start    time.Time     // optional start time, if blank, always/now
	Duration time.Duration // optional duration (<=0 is forever)
	Color    HasColor
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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