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 ¶
- Variables
- func NewEncoder() transform.Transformer
- func Update(m *Module, old, new *LCDState) error
- type FanSpeed
- type Key
- type KeyActivity
- type LCDState
- type Module
- func (m *Module) Clear() error
- func (m *Module) Close()
- func (m *Module) Ping(payload []byte) error
- func (m *Module) Put(col, row int, data []byte) error
- func (m *Module) RawCommand(req byte, reqP []byte) (resp byte, respP []byte, err error)
- func (m *Module) ReadReport() any
- func (m *Module) SetBacklight(lcd, keypad int) error
- func (m *Module) SetCharacter(i int, data *[8]byte) error
- func (m *Module) SetLED(led int, green bool, duty int) error
- type Temperature
Constants ¶
This section is empty.
Variables ¶
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.
Types ¶
type Key ¶
type Key int
Key represents a button on the CFA635.
const ( UpButton Key DownButton LeftButton RightButton EnterButton ExitButton )
type KeyActivity ¶
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 ¶
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) Put ¶
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 ¶
RawCommand sends an arbitrary command (request and payload) to the CFA635, returning the response (and payload) or error.
func (*Module) ReadReport ¶
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 ¶
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 ¶
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.
type Temperature ¶
Temperature is a report on the system temperature.