led

package module
v0.0.0-...-cf99bc6 Latest Latest
Warning

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

Go to latest
Published: May 22, 2019 License: MIT Imports: 6 Imported by: 0

README

Package to control USB-LED devices

Supported OS

  • OSX
  • Windows
  • Linux

Supported devices

References

Most of the device control knowledge is taken from the NotifierLight project.

Documentation

See GoDoc

Code example

package main

import (
    "fmt"
    "github.com/boombuler/led"
    "image/color"
    "time"
)

var RED color.RGBA = color.RGBA{0xFF, 0x00, 0x00, 0xFF}

func main() {
    for devInfo := range led.Devices() {
        dev, err := devInfo.Open()
        if err != nil {
            fmt.Println(err)
            continue
        }
        defer dev.Close()
        dev.SetColor(RED)

        time.Sleep(2 * time.Second) // Wait 2 seconds because the device will turn off once it is closed!
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDeviceClosed = errors.New("Device is already closed")

Error: Device was already closed and is not ready for interaction anymore

View Source
var ErrKeepActiveNotSupported = errors.New("KeepActive is not supported by this device")

Some devices does not support KeepActive.

Functions

func Devices

func Devices() <-chan DeviceInfo

Devices returns a channel with all connected LED devices

func NewLedAnimation

func NewLedAnimation() *ledAnimationFrame

func NewLedSound

func NewLedSound() *ledSound

Types

type Device

type Device interface {
	// SetColor sets the color of the LED to the closest supported color.
	SetColor(c color.Color) error

	// SetKeepActive sets a value that tells the device not turn off the device on calling Close. By default the device is turned off!
	SetKeepActive(v bool) error

	// Close the device and release all resources
	Close()

	// Check if device is closed
	IsClosed() bool
}

Device is an opened LED device.

type DeviceInfo

type DeviceInfo interface {
	// GetPath returns a system specific path which can be used to find the device
	GetPath() string
	// GetType returns the "driver type" of the device
	GetType() DeviceType
	// Open opens the device for usage
	Open() (Device, error)
}

DeviceInfo keeps information about a physical LED device

func ByPath

func ByPath(path string) (DeviceInfo, error)

ByPath searches a device by given system specific path. (The path can be obtained from the GetPath func from DeviceInfo)

type DeviceNG

type DeviceNG interface {
	// SetAnimation sets an animation for LED if device supports this feature
	SetAnimation(ani *ledAnimationFrame) error

	// Turns off device (TODO: maybe move this to "Device")
	TurnOff() error
}

Some "NG" devices have additional features

type DeviceType

type DeviceType int

Device type identifies the device type. the IDs may change on each program start.

var Blink1 DeviceType

Device type: blink(1)

var BlinkM DeviceType

Device type: LinkM / BlinkM

var BlinkStick DeviceType

Device type: BlinkStick

var Blync DeviceType

Device type: Blync

var BusyLightLync DeviceType

Device type: BusyLight Lync

var BusyLightNGUCOmega DeviceType

Device type: BusyLight UC Omega

var BusyLightUC DeviceType

Device type: BusyLight UC

var DealExtreme DeviceType

Device type: DealExtreme USBMailNotifier

var DreamCheeky DeviceType

Device type: DreamCheeky USBMailNotifier

func (DeviceType) String

func (dt DeviceType) String() string

String returns a representation of the device type

Jump to

Keyboard shortcuts

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