inky

package
v3.8.0+incompatible Latest Latest
Warning

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

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

Documentation

Overview

Package inky drives an Inky pHAT or wHAT 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

The display seems to use a SSD1675 controller: https://www.china-epaper.com/uploads/soft/DEPG0420R01V3.0.pdf

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.Point{}); 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.

func (*Color) Set

func (c *Color) Set(s string) error

Set sets the Color to a value represented by the string s. Set implements the flag.Value interface.

func (*Color) String

func (c *Color) String() string

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 or wHAT.

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) DrawAll

func (d *Dev) DrawAll(src image.Image) error

DrawAll redraws the whole display.

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) SetModelColor

func (d *Dev) SetModelColor(c Color) error

SetModelColor changes the model color. This will not take effect until the next Draw(). Useful if you want to switch between two-color and three-color drawing.

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
	WHAT
)

Supported Model.

func (*Model) Set

func (m *Model) Set(s string) error

Set sets the Model to a value represented by the string s. Set implements the flag.Value interface.

func (*Model) String

func (m *Model) String() string

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