Help us shape the future of Go! Take the 2026 Go Developer Survey

pertelian

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MIT Imports: 6 Imported by: 0

README

Pertelian

Talking to Pertelian character LCD displays in Go

Note that only the Pertelian X2040 is supported at the moment. I don't know if there are any other Pertelian displays in existance. This is the one I had laying around in a drawer, so this is the one I wanted to play with.

Underdocumented

This is just something I threw together for my own use. It's only public becasue I'm also playing around with putting my Go code on GitHub.

Originally part of a different project, but I figured I might as well toss it out there for general use.

Enjoy to the extent possible.

Example

package main

import (
	"log"
	"time"
	"github.com/DemmyDemon/pertelian"
	"github.com/google/gousb"
)

func main() {

    // First we need to get a hold of a USB context to work with.
    // Explaining how to get gousb up and running with the Pertelian X2040 is out of scope here.
	ctx := gousb.NewContext()
    // Suffice to say, read the gousb documentation.
    // Windows? Strongly consider https://zadig.akeo.ie/

    // Releasing the USB context after use is very important, or so I've heard.
	defer ctx.Close()

    // Once we have a USB context, it all gets a lot simpler!
    // Instantiate a display object:
	pert, err := pertelian.NewX2040(ctx)

    // Errors can be stuff like "Device not found" (if you forgot to plug it in)
    // or "Unsupported" (if you have the wrong driver)
	if err != nil {
		log.Fatal(err)
	}

    // You should always close USB devices. If not, the USB gods will eat your cookies!
	defer pert.Close()
    // Note that this only closes the connection to the display, it does not turn it off.
    // It doesn't even blank it or turn off the light. It leaves it in whatever state it's in.

    // Turning the display on is a good idea if you want to put information on it.
	err = pert.On()
	if err != nil {
		log.Fatal(err)
	}

    // Splash screen. Very fancy.
	pert.Splash()

    // Sleeep for a while to show off the very fancy splash screen.
	time.Sleep(5 * time.Second)

    // Clear out the very fancy splash screen.
	pert.Clear()

    // Print some text roughly centered on the second line (first line is 0)
    pert.Centered(1, "Some Text")

    // Print more text on the third line, 0 characters offset from the left edge.
    pert.PrintAt(2, 0, "More Text")

    // Sleep again, of nobody will see the text.
	time.Sleep(5 * time.Second)

    // Shut down the display, because electricity is very expensive right now.
	err = pert.Off()
	if err != nil {
		log.Fatal(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrX2040CharWant8Lines = errors.New("characters must be made up of exactly 8 lines")
View Source
var ErrX2040CharWidth5 = errors.New("character lines must be exactly 5 runes long")
View Source
var ErrX2040DeviceNotFound = errors.New("x2040 device not found")
View Source
var ErrX2040InvalidCharacterPosition = errors.New("invalid character position")
View Source
var ErrX2040OutOfRange = errors.New("target out of display range")
View Source
var ErrX2040UnknownWriteError = errors.New("unknown error writing to device")

Functions

This section is empty.

Types

type PertelianX2040

type PertelianX2040 struct {
	// contains filtered or unexported fields
}

func NewX2040

func NewX2040(ctx *gousb.Context) (PertelianX2040, error)

NewX2040 instantiates a new PertelianX2040 for you to play with.

func (*PertelianX2040) Blank

func (pert *PertelianX2040) Blank(line uint8) error

Blank overwrites the given line with all spaces, effectively blanking it.

func (*PertelianX2040) Centered

func (pert *PertelianX2040) Centered(line uint8, text string) error

Centered attempts to send the given string so it's centered on the given line.

func (*PertelianX2040) Clear

func (pert *PertelianX2040) Clear() error

Clear removes all data visible on the display.

func (*PertelianX2040) Close

func (pert *PertelianX2040) Close() error

Close closes down the interface and closes the device. **DOES NOT** clear the display, turn off the light, or any of that.

func (*PertelianX2040) GetCharacters

func (pert *PertelianX2040) GetCharacters(slots ...uint8) string

GetCharacters returns a string built with the characters previously stored with SetCharacter.

func (*PertelianX2040) Light

func (pert *PertelianX2040) Light(state bool) error

Light sets the display light to the requested state.

func (*PertelianX2040) Off

func (pert *PertelianX2040) Off() error

Off turns off the light, and then the display.

func (*PertelianX2040) On

func (pert *PertelianX2040) On() error

On turns on the display, initializes it, clears any data already on there and turns the light on.

func (*PertelianX2040) Print

func (pert *PertelianX2040) Print(text string) error

Print sends a string entry to wherever the cursor happens to be.

func (*PertelianX2040) PrintAt

func (pert *PertelianX2040) PrintAt(line uint8, char uint8, textString string) error

PrintAt sends a string entry to the given line and character.

func (*PertelianX2040) SetCharacter

func (pert *PertelianX2040) SetCharacter(position uint8, char PertelianX2040Character) error

SetCharacter stores the given character in the display for later display. You get 7 slots, 0-6.

func (*PertelianX2040) SetLineDrawingCharacters

func (pert *PertelianX2040) SetLineDrawingCharacters()

SetLineDrawingCharacters stores a set of line drawing characters in the display.

func (*PertelianX2040) Splash

func (pert *PertelianX2040) Splash()

Splash does some line drawing and text to look fancy.

func (*PertelianX2040) Write

func (pert *PertelianX2040) Write(data []byte) (int, error)

Write writes directly to the device, pausing slightly after the first two characters. Note that this is done in one transmission per byte to minimize the chance of corruption.

func (*PertelianX2040) WriteGibberish

func (pert *PertelianX2040) WriteGibberish(data []byte) (int, error)

WriteGibberish writes directly to the device with no waiting for command processing, which *often* leads to corruption.

type PertelianX2040Character

type PertelianX2040Character struct {
	Lines [charSize]byte
}

func NewX2040Char

func NewX2040Char(lines ...string) (PertelianX2040Character, error)

NewX2040Char assists in creating a properly formatted custom character for the display.

Jump to

Keyboard shortcuts

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