cfa635

package
v0.0.0-...-64f7390 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package cfa635 interfaces with Crystalfontz CFA635-xxx-KU LCD modules.

The Connect function adopts an existing serial port:

s, err := serial.OpenPort(&serial.Config{Name: "/dev/ttyUSB0", Baud: 115200})
if err != nil {
	panic(err)
}
m := cfa635.Connect(s)
defer m.Close()

Having connected, you can then issue commands to the module:

msg, _, err := transform.String(cfa635.NewEncoder(), "Hello, world!")
if err != nil {
	panic(err)
}
if err := m.Put(0, 0, []byte(msg)); err != nil {
	panic(err)
}

You can also use the State type and Update function to send the optimal sequence of commands to the module to transform its state:

if err := m.Reset(); err != nil {
	panic(err)
}
s := new(cfa635.State)
t := new(cfa635.State)
copy(t.LCD[0][0:19], msg)
if err := cfa635.Update(m, s, t); err != nil {
	panic(err)
}
s = t

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPayloadTooLarge = errors.New("payload too large")
	ErrCGRAM           = errors.New("CGRAM index out of range")
	ErrSprite          = errors.New("invalid sprite")
	ErrPosition        = errors.New("position out of range")
	ErrBacklight       = errors.New("backlight brightness out of range")
	ErrLEDIndex        = errors.New("LED index out of range")
	ErrLEDDuty         = errors.New("LED duty cycle out of range")

	ErrTimeout = errors.New("timed out")

	ErrFailed = errors.New("command failed")
)

Functions

func NewEncoder

func NewEncoder() transform.Transformer

NewEncoder returns a Transformer that converts UTF-8 to the CFA635 display character set. The Transformer uses ¿ as the replacement character.

The returned Transformer is lossy, converting various Unicode code points to the same byte. For example, U+DF LATIN SMALL LETTER SHARP S (ß) and U+03B2 GREEK SMALL LETTER BETA (β) are both converted to 0xbe.

The returned Transformer will never map anything to bytes in the range 0x00, …, 0x0f.

func Update

func Update(m *Module, old, new *LCDState) error

Types

type FanSpeed

type FanSpeed struct {
	N          int
	TachCycles int
	TimerTicks int
}

FanSpeed is a report on the speed of a system fan.

type Key

type Key int

Key represents a button on the CFA635.

const (
	UpButton Key
	DownButton
	LeftButton
	RightButton
	EnterButton
	ExitButton
)

type KeyActivity

type KeyActivity struct {
	K       Key
	Pressed bool
}

KeyActivity is a report that a key has been pressed or released.

type LCDState

type LCDState [4][20]byte

State represents the state of the CFA635 LCD.

func ClearedLCDState

func ClearedLCDState() *LCDState

type Module

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

Module is a handle to a CFA635 module.

func Connect

func Connect(cfa635 io.ReadWriteCloser) *Module

Connect constructs a Module from a serial connection to a CFA635.

func (*Module) Clear

func (m *Module) Clear() error

Clear clears the CFA635 LCD. After Clear returns successfully, all LCD cells hold 0x20 (space).

func (*Module) Close

func (m *Module) Close()

Close releases the CFA635 and closes the underlying connection.

func (*Module) Ping

func (m *Module) Ping(payload []byte) error

Ping pings the CFA635 with a payload of up to 16 bytes.

func (*Module) Put

func (m *Module) Put(col, row int, data []byte) error

Put writes data to the LCD at a row and column. No wrapping occurs; if the data are too large, they are truncated. Data are interpreted in the CFA635 character set; see NewEncoder.

func (*Module) RawCommand

func (m *Module) RawCommand(req byte, reqP []byte) (resp byte, respP []byte, err error)

RawCommand sends an arbitrary command (request and payload) to the CFA635, returning the response (and payload) or error.

func (*Module) ReadReport

func (m *Module) ReadReport() any

ReadReport blocks until the CFA635 sends a report to the host and then returns it. The returned report will be a *KeyActivity, *FanSpeed, or *Temperature.

func (*Module) SetBacklight

func (m *Module) SetBacklight(lcd, keypad int) error

SetBacklight controls the LEDs backing the LCD and keypad. Each LED value can range from 0 to 100, inclusive, with 0 turning off the light and 100 turning it on to its maximum brightness.

func (*Module) SetCharacter

func (m *Module) SetCharacter(i int, data *[8]byte) error

SetCharacter sets a sprite (six columns by eight rows) in character generator RAM. The index of the sprite must be between 0 and 7, inclusive.

The sprite itself is specified as an 8-element byte array, each byte representing a row. In each byte, the upper two bits must be 0; the lower six determine the six pixels in the row, with 1 bits corresponding to active pixels and 0 bits corresponding to inactive ones.

func (*Module) SetLED

func (m *Module) SetLED(led int, green bool, duty int) error

SetLED controls the four red/green LEDs to the left of the LCD. The LEDs are numbered 0 through 3 from top to bottom; for each, the red and green components can be set separately to a value from 0 (off) to 100 (full duty cycle).

type Temperature

type Temperature struct {
	N       int // Sensor number.
	Celsius float64
}

Temperature is a report on the system temperature.

Jump to

Keyboard shortcuts

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