slab

package
v0.0.0-...-461d2ee Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignIDs

func AssignIDs(bus evbus.Bus, number int, db dbW)

AssignIDs of given number of slabs available from event bus in database.

func CloseAll

func CloseAll(slabs []*Slab)

CloseAll closes all slab ports.

func DiscardEvents

func DiscardEvents() chan Event

DiscardEvents returns channel that discards events sent to it.

func ListenAll

func ListenAll(slabs []*Slab, bus evbus.Bus, wg *sync.WaitGroup)

ListenAll starts ObjectListener in parallel on all slabs, sending events to event bus.

func ObjectListener

func ObjectListener(s *Slab, bus evbus.Bus) error

ObjectListener emits event when sensor status changes on a slab. It can signal detection with lighting slab.

func SignalObject

func SignalObject(bus evbus.Bus, c *RGB) error

SignalObject light a slab when an object appears.

func TestLights

func TestLights(slabs []*Slab) error

TestLights turns off each slab, then turns them back off after a while.

Types

type CommandDTO

type CommandDTO struct {
	ID      byte `json:"id"`
	Command byte `json:"command,omitempty"`
	RGB     *RGB `json:"rgb,omitempty"`
	Delay   byte `json:"delay,omitempty"`
}

CommandDTO describes data that has to be provided for hardware.

type Config

type Config struct {
	Repository struct {
		Filter string `envconfig:"default=ACM"`

		Path string `envconfig:"default=./slabs.db"`
	}
}

Config for slabs supporting envconfig for environmental variable parsing.

type DB

type DB interface {
	Close() error
	// contains filtered or unexported methods
}

DB is an abstract for accessing database.

func OpenDB

func OpenDB(path string) (DB, error)

OpenDB from given path.

type Event

type Event struct {
	Slab   *Slab
	Sensor bool
}

Event is returned by object listener.

type RGB

type RGB struct {
	R, G, B byte
}

RGB stores color info for slabs.

type Repo

type Repo struct {
	evbus.Bus
	// contains filtered or unexported fields
}

Repo stores slabs' data. It allows controlling multiple slabs at once.

func NewRepo

func NewRepo(filter string) (r Repo, err error)

NewRepo creates Repo of all slabs, iterating through /dev files and connecting to those, containing `filter`.

func (*Repo) AssignIDs

func (r *Repo) AssignIDs()

AssignIDs to all slabs.

func (*Repo) Close

func (r *Repo) Close() error

Close closes all managed slabs and database.

func (*Repo) Execute

func (r *Repo) Execute(cmdAlien *mqtt.Command)

Execute given MQTT command.

func (*Repo) LoadIDs

func (r *Repo) LoadIDs()

LoadIDs of all slabs.

func (*Repo) LoadOrAssign

func (r *Repo) LoadOrAssign()

LoadOrAssign IDs of all slabs.

func (*Repo) OffAll

func (r *Repo) OffAll() error

OffAll disables all lights.

func (*Repo) OpenDB

func (r *Repo) OpenDB(path string) error

OpenDB from given path.

func (*Repo) SignalObject

func (r *Repo) SignalObject(color *RGB)

SignalObject with given color represented as RGB.

func (*Repo) Slab

func (r *Repo) Slab(id byte) *Slab

Slab finds slab by ID assigned from database

func (*Repo) WaitGroup

func (r *Repo) WaitGroup() *sync.WaitGroup

WaitGroup waits for a collection of goroutines to finish. Proxy method.

type Slab

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

Slab contains single slab info.

func New

func New(portPath string) (*Slab, error)

New creates new slab connected to usb port `portPath`.

func (*Slab) Close

func (s *Slab) Close() error

Close closes the port used for slab communication.

func (*Slab) FadeIn

func (s *Slab) FadeIn(delay time.Duration, upto byte, c *RGB) error

FadeIn slowly brightens the slab with given color.

func (*Slab) ID

func (s *Slab) ID() string

ID is a unique string identifying slab. Currently /dev/... path.

func (*Slab) Off

func (s *Slab) Off() error

Off turns off the light.

func (*Slab) On

func (s *Slab) On(c *RGB) error

On turns on slab with given color.

func (*Slab) RawSensor

func (s *Slab) RawSensor() (byte, error)

RawSensor asks slab for raw sensor data.

func (*Slab) Sensor

func (s *Slab) Sensor() (bool, error)

Sensor asks slab if something is on it.

func (*Slab) SetBrightness

func (s *Slab) SetBrightness(value byte) error

SetBrightness set brightness, which isn't updated until next color set.

func (*Slab) SetThreshold

func (s *Slab) SetThreshold(threshold byte) error

SetThreshold sets value below which object is detected as 'on slab'.

Jump to

Keyboard shortcuts

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