inky

package
v3.6.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package inky drives an Inky pHAT E ink display.

Datasheet

Inky lacks a true datasheet, so the code here is derived from the reference implementation by Pimoroni: https://github.com/pimoroni/inky

Example
package main

import (
	"flag"
	"image"
	"image/png"
	"log"
	"os"

	"periph.io/x/periph/conn/gpio/gpioreg"
	"periph.io/x/periph/conn/spi/spireg"
	"periph.io/x/periph/experimental/devices/inky"
	"periph.io/x/periph/host"
)

func main() {
	path := flag.String("image", "", "Path to image file (212x104) to display")
	flag.Parse()

	f, err := os.Open(*path)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

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

	if _, err := host.Init(); err != nil {
		log.Fatal(err)
	}

	b, err := spireg.Open("SPI0.0")
	if err != nil {
		log.Fatal(err)
	}

	dc := gpioreg.ByName("22")
	reset := gpioreg.ByName("27")
	busy := gpioreg.ByName("17")

	dev, err := inky.New(b, dc, reset, busy, &inky.Opts{
		Model:       inky.PHAT,
		ModelColor:  inky.Red,
		BorderColor: inky.Black,
	})
	if err != nil {
		log.Fatal(err)
	}

	if err := dev.Draw(img.Bounds(), img, image.ZP); err != nil {
		log.Fatal(err)
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Color

type Color int

Color is used to define which model of inky is being used, and also for setting the border color.

const (
	Black Color = iota
	Red
	Yellow
	White
)

Valid Color.

type Dev

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

Dev is a handle to an Inky.

func New

func New(p spi.Port, dc gpio.PinOut, reset gpio.PinOut, busy gpio.PinIn, o *Opts) (*Dev, error)

New opens a handle to an Inky pHAT.

func (*Dev) Bounds

func (d *Dev) Bounds() image.Rectangle

Bounds implements display.Drawer

func (*Dev) ColorModel

func (d *Dev) ColorModel() color.Model

ColorModel implements display.Drawer Maps white to white, black to black and anything else as red. Red is used as a placeholder for the display's third color, i.e., red or yellow.

func (*Dev) Draw

func (d *Dev) Draw(dstRect image.Rectangle, src image.Image, srcPtrs image.Point) error

Draw implements display.Drawer

func (*Dev) Halt

func (d *Dev) Halt() error

Halt implements conn.Resource

func (*Dev) SetBorder

func (d *Dev) SetBorder(c Color)

SetBorder changes the border color. This will not take effect until the next Draw().

func (*Dev) String

func (d *Dev) String() string

String implements conn.Resource.

type Model

type Model int

Model lists the supported e-ink display models.

const (
	PHAT Model = iota
)

Supported Model.

type Opts

type Opts struct {
	// Model being used.
	Model Model
	// Model color.
	ModelColor Color
	// Initial border color. Will be set on the first Draw().
	BorderColor Color
}

Opts is the options to specify which device is being controlled and its default settings.

Jump to

Keyboard shortcuts

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