Git Product home page Git Product logo

go-blink1's Introduction

Install libusb and libusb-compat (OSX Users)

Before using this library on OSX, you'll need to install the libusb and libusb-compat libraries.

This is easily done using the Homebrew OSX package manager. (Other OSes will need similar installation using their respective package managers)

brew install libusb libusb-compat

blink1

Install

$ go get github.com/hink/go-blink1

Usage

const (
	USBVendorID  = 10168
	USBProductID = 493
)

USB IDs

var OffState = State{Duration: time.Duration(10) * time.Millisecond}

OffState helper

type Device

type Device struct {
	Device          *libusb.Device // USB device
	DefaultFadeTime time.Duration  // Default time to fade between states
	CurrentState    State          // Current state of the Blink(1)
}

Device Thingm Blink(1) USB device

func OpenNextDevice

func OpenNextDevice() (device *Device, err error)

OpenNextDevice opens and returns the next available Blink(1) device

func (*Device) Close

func (b *Device) Close()

Close communication channel to Blink(1)

func (*Device) RunPattern

func (b *Device) RunPattern(pattern *Pattern) (err error)

RunPattern executes a predefined pattern

func (*Device) SetState

func (b *Device) SetState(state State) (err error)

SetState sets the blink(1) to a specific state

type Pattern

type Pattern struct {
	Repeat      uint          // How many times to repeat
	RepeatDelay time.Duration // Delay between repeats
	States      []State       // Slice of states to execute in pattern
}

Pattern is a Blink(1) blink pattern

type State

type State struct {
	Red      uint8         // Red value 0-255
	Green    uint8         // Green value 0-255
	Blue     uint8         // Blue value 0-255
	LED      uint8         // which LED to address (0=all, 1=1st LED, 2=2nd LED)
	FadeTime time.Duration // Fadetime to state
	Duration time.Duration // Duration of state after FadeTime
}

State is a Blink(1) light state

const (
	LEDAll uint8 = iota
	LED1
	LED2
)

LED helper constants, used to target specific LED's on the sides of Blink(1).

Example Usage

package main

import "github.com/hink/go-blink1"

func main() {

	device, err := blink1.OpenNextDevice()
	defer device.Close()

	if err != nil {
		panic(err)
	}

	red := blink1.State{
		Red: 2,
	}

	device.SetState(red)
}

go-blink1's People

Contributors

hink avatar robtec avatar saranrapjs avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.