Documentation
¶
Overview ¶
This is a Go library that exposes the interface of Waveshare's 4.3inch e-Paper UART Module
Most of the interface follows the wiki page (http://www.waveshare.com/wiki/4.3inch_e-Paper), but some of it was derived by experimenting with the device.
Please see the project page for more information on how to get started: https://github.com/fstanis/epaper
Example ¶
package main
import (
"fmt"
"log"
"github.com/fstanis/epaper"
)
const port = "/dev/ttyUSB0"
func main() {
ep, err := epaper.New(port)
if err != nil {
log.Fatalf("Failed to open device: %v", err)
}
defer ep.Close()
if err := ep.Handshake(); err != nil {
log.Fatalf("Handshake failed: %v", err)
}
if err := ep.Clear(); err != nil {
log.Fatalf("Clear failed: %v", err)
}
if err := ep.DisplayText(100, 100, "Hello world!"); err != nil {
log.Fatalf("DisplayText failed: %v", err)
}
fmt.Println("Text displayed")
if err := ep.DrawRect(50, 50, 250, 150); err != nil {
log.Fatalf("DrawRect failed: %v", err)
}
fmt.Println("Rect drawn")
if err := ep.Update(); err != nil {
log.Fatalf("Update failed: %v", err)
}
}
Output: Text displayed Rect drawn
Index ¶
- Variables
- type Client
- func (c *Client) Clear() error
- func (c *Client) Close() error
- func (c *Client) ColorLine(x1 uint16, y1 uint16, x2 uint16, y2 uint16, color Color) error
- func (c *Client) ColorPixel(x uint16, y uint16, color Color) error
- func (c *Client) DisplayImage(x uint16, y uint16, file string) error
- func (c *Client) DisplayText(x uint16, y uint16, text string) error
- func (c *Client) DrawCircle(x uint16, y uint16, r uint16) error
- func (c *Client) DrawLine(x1 uint16, y1 uint16, x2 uint16, y2 uint16) error
- func (c *Client) DrawRect(x1 uint16, y1 uint16, x2 uint16, y2 uint16) error
- func (c *Client) DrawTriangle(x1 uint16, y1 uint16, x2 uint16, y2 uint16, x3 uint16, y3 uint16) error
- func (c *Client) FillCircle(x uint16, y uint16, r uint16) error
- func (c *Client) FillPixel(x uint16, y uint16) error
- func (c *Client) FillRect(x1 uint16, y1 uint16, x2 uint16, y2 uint16) error
- func (c *Client) FillScreen(color Color) error
- func (c *Client) FillTriangle(x1 uint16, y1 uint16, x2 uint16, y2 uint16, x3 uint16, y3 uint16) error
- func (c *Client) GetBaudRate() (int, error)
- func (c *Client) GetChineseFontSize() (FontSize, error)
- func (c *Client) GetColor() (Color, Color, error)
- func (c *Client) GetEnglishFontSize() (FontSize, error)
- func (c *Client) Handshake() error
- func (c *Client) IsRotated() (bool, error)
- func (c *Client) IsStorageSDCard() (bool, error)
- func (c *Client) LoadFonts() error
- func (c *Client) LoadImages() error
- func (c *Client) SetBaudRate(rate int) error
- func (c *Client) SetChineseFontSize(size FontSize) error
- func (c *Client) SetColor(foreground Color, background Color) error
- func (c *Client) SetEnglishFontSize(size FontSize) error
- func (c *Client) SetRotation(rotated bool) error
- func (c *Client) SetStorageType(useMicroSD bool) error
- func (c *Client) Sleep() error
- func (c *Client) Update() error
- type Color
- type Device
- type FontSize
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidCommand = errors.New("invalid command (error 0)") ErrSDInitiationFailed = errors.New("SD card initiation failed (error 1)") ErrInvalidArguments = errors.New("invalid arguments (error 2)") ErrNoSD = errors.New("SD card not inserted (error 3)") ErrFileNotFound = errors.New("file not found (error 4)") ErrValidationFailed = errors.New("validation failed (error 20)") ErrInvalidFrame = errors.New("invalid frame (error 21)") ErrUndefined = errors.New("undefined error (error 250)") ErrUnknown = errors.New("unknown error") )
var Colors = [...]Color{ ColorBlack, ColorDarkGray, ColorLightGray, ColorWhite, }
All the colors available on the device.
var FontSizes = [...]FontSize{ FontSize(0), FontSize32, FontSize48, FontSize64, }
All the font sizes available on the device. `FontSize(0)` is invalid, kept solely to ensure array indices are aligned with the constant values.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is used to communicate with an e-Paper device and send commands to it.
func New ¶
New connects to the e-Paper device on the given port. It uses the default bitrate of 115200.
func NewWithBaud ¶
NewWithBaud connects to the e-Paper device on the given port using the given bitrate (baud rate).
func (*Client) ColorLine ¶
ColorLine draws a line connecting the given two points using the given color.
func (*Client) ColorPixel ¶
ColorPixel fills the pixel at the given coordinates with the given color.
func (*Client) DisplayImage ¶
Displays the image with the given file name, loaded either from the internal flash memory or the SD card, depending on the selected storage type.
func (*Client) DisplayText ¶
Displays the given text at the given coordinates. The coordinates will be used as the top left corner of the box containing the text.
func (*Client) DrawCircle ¶
DrawCircle draws a circle with the given center and radius using the foreground color.
func (*Client) DrawLine ¶
DrawLine draws a line connecting the given two points using the foreground color.
func (*Client) DrawRect ¶
DrawRect draws a rectangle with the given top left and bottom right corner using the foreground color.
func (*Client) DrawTriangle ¶
func (c *Client) DrawTriangle(x1 uint16, y1 uint16, x2 uint16, y2 uint16, x3 uint16, y3 uint16) error
DrawTriangle draws a triangle with the given three edges using the foreground color.
func (*Client) FillCircle ¶
FillCircle fills a circle with the given center and radius using the foreground color.
func (*Client) FillPixel ¶
FillPixel fills the pixel at the given coordinates with the foreground color.
func (*Client) FillRect ¶
FillRect fills a rectangle with the given top left and bottom right corner using the foreground color.
func (*Client) FillScreen ¶
Fills the screen with the given color.
func (*Client) FillTriangle ¶
func (c *Client) FillTriangle(x1 uint16, y1 uint16, x2 uint16, y2 uint16, x3 uint16, y3 uint16) error
FillTriangle fills a triangle with the given three edges using the foreground color.
func (*Client) GetBaudRate ¶
Gets the current serial baud rate.
func (*Client) GetChineseFontSize ¶
GetChineseFontSize returns the currently set size of the font used for displaying Chinese characters.
func (*Client) GetEnglishFontSize ¶
GetEnglishFontSize returns the currently set size of the font used for displaying English (ASCII) characters.
func (*Client) Handshake ¶
Handshake command. Essentially no-op, used to confirm a connection with the device is established.
func (*Client) IsRotated ¶
IsRotated returns true if the screen is currently rotated to portrait mode.
func (*Client) IsStorageSDCard ¶
IsStorageSDCard returns true if the storage type is set to SD card. The storage type is only relevant for the `DisplayImage` method. By default, the SD card is not used.
func (*Client) LoadFonts ¶
LoadFonts clears the fonts on the internal flash storage and copies the fonts from the SD card, if there are any present. Fails if SD card is not present.
func (*Client) LoadImages ¶
LoadFonts clears the images on the internal flash storage and copies the images from the SD card, if there are any present. Fails if SD card is not present.
func (*Client) SetBaudRate ¶
Sets the serial baud rate on the device. Avoid or use with caution.
func (*Client) SetChineseFontSize ¶
SetChineseFontSize sets the size of the font used for displaying Chinese characters.
func (*Client) SetColor ¶
SetColor sets the foreground and background color for future commands. The background color is used solely by the `Clear` method while the foreground color is used by all other drawing methods.
func (*Client) SetEnglishFontSize ¶
SetEnglishFontSize sets the size of the font used for displaying English (ASCII) characters.
func (*Client) SetRotation ¶
SetRotation enables when the parameter is true) or disables portrait mode.
func (*Client) SetStorageType ¶
SetStorageType sets the default storage type. The storage type is only relevant for the `DisplayImage` method. By default, the SD card is not used.
type Device ¶
type Device interface {
Handshake() error
SetBaudRate(rate int) error
GetBaudRate() (int, error)
IsStorageSDCard() (bool, error)
SetStorageType(useMicroSD bool) error
Sleep() error
Update() error
IsRotated() (bool, error)
SetRotation(rotated bool) error
LoadFonts() error
LoadImages() error
SetColor(foreground Color, background Color) error
GetColor() (Color, Color, error)
GetEnglishFontSize() (FontSize, error)
GetChineseFontSize() (FontSize, error)
SetEnglishFontSize(size FontSize) error
SetChineseFontSize(size FontSize) error
FillPixel(x uint16, y uint16) error
ColorPixel(x uint16, y uint16, color Color) error
DrawLine(x1 uint16, y1 uint16, x2 uint16, y2 uint16) error
ColorLine(x1 uint16, y1 uint16, x2 uint16, y2 uint16, color Color) error
FillRect(x1 uint16, y1 uint16, x2 uint16, y2 uint16) error
DrawRect(x1 uint16, y1 uint16, x2 uint16, y2 uint16) error
DrawCircle(x uint16, y uint16, r uint16) error
FillCircle(x uint16, y uint16, r uint16) error
DrawTriangle(x1 uint16, y1 uint16, x2 uint16, y2 uint16, x3 uint16, y3 uint16) error
FillTriangle(x1 uint16, y1 uint16, x2 uint16, y2 uint16, x3 uint16, y3 uint16) error
Clear() error
FillScreen(color Color) error
DisplayText(x uint16, y uint16, text string) error
DisplayImage(x uint16, y uint16, file string) error
Close() error
}
Device is an interface representing an e-Paper device. It's implemented by epaper.Client.