inky

package
v3.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Overview

Package inky drives an Inky pHAT, pHAT v2 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
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
	Multi
)

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 (i 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) Height added in v3.7.1

func (d *Dev) Height() int

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) SetFlipHorizontally added in v3.7.1

func (d *Dev) SetFlipHorizontally(f bool)

SetFlipHorizontally flips the image horizontally.

func (*Dev) SetFlipVertically added in v3.7.1

func (d *Dev) SetFlipVertically(f bool)

SetFlipVertically flips the image horizontally.

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.

func (*Dev) Width added in v3.7.1

func (d *Dev) Width() int

type DevImpression added in v3.7.1

type DevImpression struct {
	*Dev

	// Color Palette used to convert images to the 7 color.
	Palette color.Palette
	// Representation of the pixels.
	Pix []uint8
	// contains filtered or unexported fields
}

DevImpression is a handle to an Inky Impression.

func NewImpression added in v3.7.1

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

NewImpression opens a handle to an Inky Impression.

Example
path := flag.String("image", "", "Path to image file (600x448) to display")
flag.Parse()

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

m, _, err := image.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")

eeprom, err := i2creg.Open("")
if err != nil {
	log.Fatal(err)
}
defer eeprom.Close()

o, err := inky.DetectOpts(eeprom)
if err != nil {
	log.Fatal(err)
}

dev, err := inky.NewImpression(b, dc, reset, busy, o)
if err != nil {
	log.Fatal(err)
}

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

func (*DevImpression) At added in v3.7.1

func (d *DevImpression) At(x, y int) color.Color

At returns the color of the pixel at (x, y).

func (*DevImpression) ColorModel added in v3.7.1

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

ColorModel returns the device native color model.

func (*DevImpression) Draw added in v3.7.1

func (d *DevImpression) Draw(r image.Rectangle, src image.Image, sp image.Point) error

Draw updates the display with the image.

func (*DevImpression) DrawAll added in v3.7.1

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

DrawAll redraws the whole display.

func (*DevImpression) Render added in v3.7.1

func (d *DevImpression) Render() error

Render renders the content of the Pix to the screen.

func (*DevImpression) Saturation added in v3.7.1

func (d *DevImpression) Saturation() uint

Saturation returns the current saturation level.

func (*DevImpression) Set added in v3.7.1

func (d *DevImpression) Set(x, y int, c color.Color)

Set sets the pixel at (x, y) to the given color. This will not take effect until the next Draw().

func (*DevImpression) SetBorder added in v3.7.1

func (d *DevImpression) SetBorder(c ImpressionColor)

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

func (*DevImpression) SetSaturation added in v3.7.1

func (d *DevImpression) SetSaturation(level uint) error

SetSaturaton changes the saturation level. This will not take effect until the next Draw().

type ImpressionColor added in v3.7.1

type ImpressionColor uint8

ImpressionColor is used to define colors used by Inky Impression models.

const (
	BlackImpression ImpressionColor = iota
	WhiteImpression
	GreenImpression
	BlueImpression
	RedImpression
	YellowImpression
	OrangeImpression
	CleanImpression
)

func (*ImpressionColor) Set added in v3.7.1

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

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

func (ImpressionColor) String added in v3.7.1

func (i ImpressionColor) String() string

type Model

type Model int

Model lists the supported e-ink display models.

const (
	PHAT Model = iota
	WHAT
	PHAT2
	IMPRESSION4
	IMPRESSION57
)

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 (i Model) String() string

type Opts

type Opts struct {
	// Boards's width and height.
	Width  int
	Height int

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

	// Board information.
	PCBVariant     uint
	DisplayVariant uint
}

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

func DetectOpts added in v3.6.10

func DetectOpts(bus i2c.Bus) (*Opts, error)

DetectOpts tries to read the device opts from EEPROM.

Jump to

Keyboard shortcuts

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