dcled

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2022 License: MIT Imports: 5 Imported by: 0

README

go-dcled

Go library for interacting with Dream Cheeky Message Board

Usage

You can load images (best: 21x7px like or ) and display them on the LED message board. Any pixel (R: 255 G: 0 B: 0) will cause a LED to be on.

package main

import (
	"fmt"
	"image/png"
	"os"
	"time"

	"github.com/karalabe/hid"
	"github.com/redtoad/go-dcled"
)

func main() {
	var list = hid.Enumerate(0x1D34, 0x0013)
	var device, err = list[0].Open() // Use first device
	if err != nil {
		panic(err)
	}

	println(fmt.Sprintf("Connected to %s %s", device.Manufacturer, device.Product))

	// load image from file
	f, err := os.Open("go-logo.png")
	if err != nil {
		panic(err)
	}
	defer f.Close()

	img, err := png.Decode(f)
	if err != nil {
		panic(err)
	}

	// display image on device
	for {
		dcled.DisplayCanvas(img, device)
		time.Sleep(dcled.MinimumRefreshRate)
	}
}

See examples/ for more information.

Based on code by MylesIsCool. Very helpful: The Last Outpost

Documentation

Index

Examples

Constants

View Source
const (
	DeviceHeight = 7
	DeviceWidth  = 21
)
View Source
const (
	VendorID           = 0x1d34
	ProductID          = 0x0013
	ManufacturerString = "Dream Link"
	ProductString      = "USB LED Message Board v1.0"
	Version            = 0x01
	SerialNumber       = 1
)

USB Descriptor Information

View Source
const MinimumRefreshRate = 400 * time.Millisecond

Variables

View Source
var (
	On  = color.RGBA{0xff, 0x00, 0x00, 0xff} // red
	Off = color.RGBA{0x00, 0x00, 0x00, 0xff} // black
)

Colors used when displaying Canvas as image.

View Source
var MonochromeModel = color.ModelFunc(monochromeModel)

MonochromeModel can convert any Color to colours On or Off. The conversion is lossy!

Functions

func Center

func Center(dev Device, img draw.Image)

Center will center an image on the Device.

func DisplayCanvas

func DisplayCanvas(img image.Image, device Device) error

DisplayCanvas displays an image.Image on the Dream Cheeky Message board. Pixels of color #ff0000 (On) will turn the respective leds on, other color will turn them off.

func DisplayGrid

func DisplayGrid(grid [][]int, device Device) error

DisplayGrid displays an 21 x 7 grid on a Dream Cheeky Message board (device)

Example
var list = hid.Enumerate(VendorID, ProductID)
if len(list) == 0 {
	println("Could not find USB device! Is it plugged in?")
	return
}

// Use first device
device, err := list[0].Open()
if err != nil {
	panic(err)
}

println(fmt.Sprintf("Connected to %s %s", device.Manufacturer, device.Product))

grid := [][]int{
	{1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0},
	{1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1},
	{1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0},
	{1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0},
	{1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0},
	{1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1},
	{0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0},
}

for {
	_ = DisplayGrid(grid, device)
	time.Sleep(MinimumRefreshRate)
}
Output:

func IsOff

func IsOff(c color.Color) bool

IsOn will return true if Color c represents off.

func IsOn

func IsOn(c color.Color) bool

IsOn will return true if Color c represents on.

func NewCanvas

func NewCanvas() draw.Image

NewCanvas returns a new blank image of 21x7 pixels.

func Scroll

func Scroll(dev Device, img draw.Image)

Scroll will scroll an image across the device.

Types

type Device

type Device interface {
	// Write sends bytes to LED board.
	Write(b []byte) (int, error)
}

Device is an interface that wraps the basic Write method.

Directories

Path Synopsis
examples
Package fonts provides functions to write text in specific fonts to an image which can then be display on the LED message board.
Package fonts provides functions to write text in specific fonts to an image which can then be display on the LED message board.
generator
This program generates fonts.
This program generates fonts.

Jump to

Keyboard shortcuts

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