epaper

package module
v0.0.0-...-e19589c Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2017 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

epaper

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 above, but some of it was derived by experimenting with the device.

Usage

Connecting

To connect the e-Paper module, you'll probably need a USB to TTL serial cable. These are cheap and can be found in many online stores that sell Arduino and Raspberry Pi accessories. Once you connect it to your PC, you need to find out which port it uses. On Linux, it'll likely be /dev/ttyUSB0. On Windows, use Device Manager to find out.

If you intend to use it on the Raspberry Pi, you can use the Pi's own serial interface. See here for more info - specifically, on how to prevent Linux from using the serial port. The serial port on a Raspberry Pi is either /dev/ttyAMA0 (prior to Raspberry Pi 3) or /dev/ttyS0 (Raspberry Pi 3).

Drawing things

Drawing on the device is achieved by first sending one or more commands which modify the "screen state" on the device itself and then calling the Update command which draws the current state.

The following commands are able to modify the "screen state":

  • Manipulating a single pixel
    • FillPixel
    • ColorPixel
  • Drawing shapes
    • DrawLine
    • ColorLine
    • DrawRect
    • DrawCircle
    • DrawTriangle
  • Filling shapes
    • FillRect
    • FillCircle
    • FillTriangle
  • Whole screen manipulation
    • Clear
    • FillScreen
  • Miscellaneous
    • DisplayText
    • DisplayImage
Example
  ep, err := epaper.New("/dev/ttyUSB0")
  // handle error
  err = ep.DrawRect(100, 100, 200, 200)
  // handle error
  err = ep.Update()
  // handle error
  ep.Close()

For a more comprehensive example, see example_test.go.

Documentation

Please see the GoDoc documentation for documentation.

The Waveshare wiki page also provides useful information on what many of the commands do and how they are used.

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

Examples

Constants

This section is empty.

Variables

View Source
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")
)

All the colors available on the device.

View Source
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

func New(port string) (*Client, error)

New connects to the e-Paper device on the given port. It uses the default bitrate of 115200.

func NewWithBaud

func NewWithBaud(port string, baud int) (*Client, error)

NewWithBaud connects to the e-Paper device on the given port using the given bitrate (baud rate).

func (*Client) Clear

func (c *Client) Clear() error

Clears the screen by filling it with the background color.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection on this Client's port.

func (*Client) ColorLine

func (c *Client) ColorLine(x1 uint16, y1 uint16, x2 uint16, y2 uint16, color Color) error

ColorLine draws a line connecting the given two points using the given color.

func (*Client) ColorPixel

func (c *Client) ColorPixel(x uint16, y uint16, color Color) error

ColorPixel fills the pixel at the given coordinates with the given color.

func (*Client) DisplayImage

func (c *Client) DisplayImage(x uint16, y uint16, file string) error

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

func (c *Client) DisplayText(x uint16, y uint16, text string) error

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

func (c *Client) DrawCircle(x uint16, y uint16, r uint16) error

DrawCircle draws a circle with the given center and radius using the foreground color.

func (*Client) DrawLine

func (c *Client) DrawLine(x1 uint16, y1 uint16, x2 uint16, y2 uint16) error

DrawLine draws a line connecting the given two points using the foreground color.

func (*Client) DrawRect

func (c *Client) DrawRect(x1 uint16, y1 uint16, x2 uint16, y2 uint16) error

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

func (c *Client) FillCircle(x uint16, y uint16, r uint16) error

FillCircle fills a circle with the given center and radius using the foreground color.

func (*Client) FillPixel

func (c *Client) FillPixel(x uint16, y uint16) error

FillPixel fills the pixel at the given coordinates with the foreground color.

func (*Client) FillRect

func (c *Client) FillRect(x1 uint16, y1 uint16, x2 uint16, y2 uint16) error

FillRect fills a rectangle with the given top left and bottom right corner using the foreground color.

func (*Client) FillScreen

func (c *Client) FillScreen(color Color) error

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

func (c *Client) GetBaudRate() (int, error)

Gets the current serial baud rate.

func (*Client) GetChineseFontSize

func (c *Client) GetChineseFontSize() (FontSize, error)

GetChineseFontSize returns the currently set size of the font used for displaying Chinese characters.

func (*Client) GetColor

func (c *Client) GetColor() (Color, Color, error)

GetColor returns both the currently set foreground and background colors.

func (*Client) GetEnglishFontSize

func (c *Client) GetEnglishFontSize() (FontSize, error)

GetEnglishFontSize returns the currently set size of the font used for displaying English (ASCII) characters.

func (*Client) Handshake

func (c *Client) Handshake() error

Handshake command. Essentially no-op, used to confirm a connection with the device is established.

func (*Client) IsRotated

func (c *Client) IsRotated() (bool, error)

IsRotated returns true if the screen is currently rotated to portrait mode.

func (*Client) IsStorageSDCard

func (c *Client) IsStorageSDCard() (bool, error)

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

func (c *Client) LoadFonts() error

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

func (c *Client) LoadImages() error

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

func (c *Client) SetBaudRate(rate int) error

Sets the serial baud rate on the device. Avoid or use with caution.

func (*Client) SetChineseFontSize

func (c *Client) SetChineseFontSize(size FontSize) error

SetChineseFontSize sets the size of the font used for displaying Chinese characters.

func (*Client) SetColor

func (c *Client) SetColor(foreground Color, background Color) error

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

func (c *Client) SetEnglishFontSize(size FontSize) error

SetEnglishFontSize sets the size of the font used for displaying English (ASCII) characters.

func (*Client) SetRotation

func (c *Client) SetRotation(rotated bool) error

SetRotation enables when the parameter is true) or disables portrait mode.

func (*Client) SetStorageType

func (c *Client) SetStorageType(useMicroSD bool) error

SetStorageType sets the default storage type. The storage type is only relevant for the `DisplayImage` method. By default, the SD card is not used.

func (*Client) Sleep

func (c *Client) Sleep() error

Sleep makes the device enter sleep mode which disables all commands, turns off the LED indicator and reduces power consumption. The only way to wake up from sleep mode is via the WAKE_UP pin.

func (*Client) Update

func (c *Client) Update() error

Update makes the device the draw the shapes, images and text sent via other commands.

type Color

type Color byte

Color used to draw objects or as background.

const (
	ColorBlack     Color = 0x00
	ColorDarkGray  Color = 0x01
	ColorLightGray Color = 0x02
	ColorWhite     Color = 0x03
)

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.

type FontSize

type FontSize byte

Font size for displaying text.

const (
	FontSize32 FontSize = 0x01
	FontSize48 FontSize = 0x02
	FontSize64 FontSize = 0x03
)

Jump to

Keyboard shortcuts

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