wavesharecloud

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: GPL-3.0 Imports: 11 Imported by: 0

README

wavesharecloud

A Go Package to control and display data on Waveshare's 4.2 inch black and white e-paper cloud module easily.

Development

I reverse-engineered the original protocol used to communicate to the display by using Wireshark to monitor TCP traffic to and from the device, then later found official documentation (although not very clear), and created a neat library to display images to the screen, and read data from the device, quickly and easily.

Features

The library can:

  • Display images, resizing and dithering when needed.
  • Restart the display
  • Get the display's battery level
  • Shutdown/Sleep the display
  • Get the display's ID
  • Unlock displays that are locked, using their PIN/password.

Examples

All examples support multiple displays connecting simultaneously.

Device documentation

The offical waveshare documentation does not cover everything about the device and is very poorly written.

I re-created the most important parts of the documentation in the DISPLAYDOCS.md file, adding small code examples in Go, and re-writing the majority of it to hopefully be understood easier than the official version.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Display

type Display struct {
	Connection io.ReadWriteCloser

	Width  int
	Height int
	// contains filtered or unexported fields
}

Display represents the physical display.

func NewDisplay

func NewDisplay(conn io.ReadWriteCloser, password string) *Display

NewDisplay returns a new display, using a width of 400 and a height of 300. If the password is left empty, it is assumed that the display if unlocked.

func (*Display) Disconnect

func (display *Display) Disconnect()

Disconnect closes the connection to the display

func (*Display) GetBatteryLevel

func (display *Display) GetBatteryLevel() (batteryLevel int, err error)

GetBatteryLevel sends a command to the display to get its battery level. This requires the device to be unlocked.

func (*Display) GetID

func (display *Display) GetID() (ID string, err error)

GetID gets the ID of the display

func (*Display) GetLocked

func (display *Display) GetLocked() (unlocked bool, err error)

GetLocked gets whether the display is locked with a password

func (*Display) ReadBlindly

func (display *Display) ReadBlindly() (data string, err error)

ReadBlindly reads any avalible data from the display and returns it (after formatting).

func (*Display) ReadBlindlyAndIgnore

func (display *Display) ReadBlindlyAndIgnore() (err error)

ReadBlindlyAndIgnore mindlessly reads data from the display and does not do anything wth it.

func (*Display) ReceiveCommandOutput

func (display *Display) ReceiveCommandOutput(sentCommand string) (data string, err error)

ReceiveCommandOutput receives a previously sent command's output from the display.

func (*Display) Restart

func (display *Display) Restart() (err error)

Restart sends a command to the display to restart it. This requires the device to be unlocked.

func (*Display) SendCloseFrame

func (display *Display) SendCloseFrame() (err error)

SendCloseFrame sends the last frame to the display

func (*Display) SendCommand

func (display *Display) SendCommand(command string) (err error)

SendCommand sends a command to the display.

func (*Display) SendFrame

func (display *Display) SendFrame(addr uint32, num uint8, data []byte) (err error)

SendFrame sends a frame of image data to the display. This requires the display to be in data mode.

func (*Display) SendImage

func (display *Display) SendImage(img image.Image) (err error)

SendImage converts an image into bytes, then sends it to the display. If the image is not 400x300, it will crop it from the top left. This requires the display to be unlocked.

func (*Display) SendImageBytes

func (display *Display) SendImageBytes(data []byte) (err error)

SendImageBytes displays an array of bytes on the screen.

func (*Display) SendImageScaled

func (display *Display) SendImageScaled(img image.Image) (err error)

SendImageScaled converts an image into bytes, then sends it to the display. If the image is not 400x300, it will resize it. This requires the display to be unlocked.

func (*Display) Shutdown

func (display *Display) Shutdown() (err error)

Shutdown sends a command to the display to shut it down. This requires the device to be unlocked.

func (*Display) Unlock

func (display *Display) Unlock(password string) (err error)

Unlock unlocks the display with a password. It will error if the display is already unlocked.

type LoggingConn

type LoggingConn struct {
	Connection net.Conn
	Debug      bool
}

LoggingConn is a connection that will optionally log all traffic.

func NewLoggingConn

func NewLoggingConn(conn net.Conn, debug bool) *LoggingConn

NewLoggingConn returns a new connection that will optionally log all traffic.

func (*LoggingConn) Close

func (lc *LoggingConn) Close() error

Close closes the connection.

func (*LoggingConn) Read

func (lc *LoggingConn) Read(b []byte) (n int, err error)

Read reads raw data from the connection.

func (*LoggingConn) Write

func (lc *LoggingConn) Write(b []byte) (n int, err error)

Write writes raw data to the connection.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳