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)
}
Index ¶
- type Color
- type Dev
- func (d *Dev) Bounds() image.Rectangle
- func (d *Dev) ColorModel() color.Model
- func (d *Dev) Draw(dstRect image.Rectangle, src image.Image, srcPtrs image.Point) error
- func (d *Dev) DrawAll(src image.Image) error
- func (d *Dev) Halt() error
- func (d *Dev) Height() int
- func (d *Dev) SetBorder(c Color)
- func (d *Dev) SetFlipHorizontally(f bool)
- func (d *Dev) SetFlipVertically(f bool)
- func (d *Dev) SetModelColor(c Color) error
- func (d *Dev) String() string
- func (d *Dev) Width() int
- type DevImpression
- func (d *DevImpression) At(x, y int) color.Color
- func (d *DevImpression) ColorModel() color.Model
- func (d *DevImpression) Draw(r image.Rectangle, src image.Image, sp image.Point) error
- func (d *DevImpression) DrawAll(src image.Image) error
- func (d *DevImpression) Render() error
- func (d *DevImpression) Saturation() uint
- func (d *DevImpression) Set(x, y int, c color.Color)
- func (d *DevImpression) SetBorder(c ImpressionColor)
- func (d *DevImpression) SetSaturation(level uint) error
- type ImpressionColor
- type Model
- type Opts
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.
func (*Color) Set ¶
Set sets the Color to a value represented by the string s. Set implements the flag.Value interface.
type Dev ¶
type Dev struct {
// contains filtered or unexported fields
}
Dev is a handle to an Inky.
func (*Dev) Bounds ¶
Bounds implements interface display.Drawer.
func (*Dev) ColorModel ¶
ColorModel implements interface 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 ¶
Draw implements interface display.Drawer.
func (*Dev) SetBorder ¶
SetBorder changes the border color. This will take effect on the next call to *Dev.Draw().
func (*Dev) SetFlipHorizontally ¶
SetFlipHorizontally flips the image horizontally.
func (*Dev) SetFlipVertically ¶
SetFlipVertically flips the image horizontally.
func (*Dev) SetModelColor ¶
SetModelColor changes the model color. This will take effect on the next call to *Dev.Draw(). Useful if you want to switch between two-color and three-color drawing.
type DevImpression ¶
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 ¶
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)
}
func (*DevImpression) At ¶
func (d *DevImpression) At(x, y int) color.Color
At returns the color of the pixel at (x, y).
func (*DevImpression) ColorModel ¶
func (d *DevImpression) ColorModel() color.Model
ColorModel returns the device native color model.
func (*DevImpression) DrawAll ¶
func (d *DevImpression) DrawAll(src image.Image) error
DrawAll redraws the whole display.
func (*DevImpression) Render ¶
func (d *DevImpression) Render() error
Render renders the content of the [*DevImpression.Pix] to the screen.
func (*DevImpression) Saturation ¶
func (d *DevImpression) Saturation() uint
Saturation returns the current saturation level.
func (*DevImpression) Set ¶
func (d *DevImpression) Set(x, y int, c color.Color)
Set sets the pixel at (x, y) to the given color. This will take effect on the next *DevImpression.Draw().
func (*DevImpression) SetBorder ¶
func (d *DevImpression) SetBorder(c ImpressionColor)
SetBorder changes the border color. This will take effect on the next call to *DevImpression.Draw().
func (*DevImpression) SetSaturation ¶
func (d *DevImpression) SetSaturation(level uint) error
SetSaturaton changes the saturation level. This will take effect on the next call to *DevImpression.Draw().
type ImpressionColor ¶
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 ¶
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 ¶
func (i ImpressionColor) String() string
type Model ¶
type Model int
Model lists the supported e-ink display models.
Supported Model.
func (*Model) Set ¶
Set sets the Model to a value represented by the string s. Set implements the flag.Value interface.
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.