gomax7219

package module
v0.0.0-...-5b05b8f Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2025 License: MIT Imports: 7 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

go-max7219

This is a project I've been working on to spice up the use of MAX7219 displays on a Raspberry Pi SPI interface and have near full control over what gets displayed without having to spend too much time tinkering with the low level SPI interface.

Inspiration

Sample usage

This should display a clock with the system time.

func main() {
	err := stuffies()
	if err != nil {
		panic(err)
	}
}

const (
	SPI_BUS         uint = 0
	SPI_DEVICE      uint = 0
	CASCADE_COUNT   uint = 8
	BRIGHTNESS      uint = 0
	ROTATE_COUNT    uint = 3
	FLIP_HORIZONTAL bool = false
	FLIP_VERTICAL   bool = false
)

func stuffies() error {
	ss, err := NewDeviceAndOpen(SPI_BUS, SPI_DEVICE, CASCADE_COUNT, BRIGHTNESS, ROTATE_COUNT, FLIP_HORIZONTAL, FLIP_VERTICAL)
	if err != nil {
		return err
	}
	defer ss.Close()

	for range time.Tick(time.Second) {
		clockIcon := NewRawGridFromPattern(ClockRefString)
		timeText := time.Now().Format("15:04:05")
		timeRenderUntrimmed := NewStringTextRender(ATARI_FONT, timeText)
		timeRenderTrimmed := NewFitInsideGrid(timeRenderUntrimmed, 8*CASCADE_COUNT-clockIcon.GetWidth())
		concat := NewConcatenateGrid([]Renderer{clockIcon, timeRenderTrimmed})
		err = ss.Draw(concat, 10*time.Millisecond)
		if err != nil {
			return err
		}
	}

	return nil
}

Fonts

Currently I copy-pasted the CP437 and the Atari fonts. The Atari font has support for some latin diacritics (tested in French and German). Feel free to send a PR if you want to suggest more fonts and extend language support.

Documentation

Index

Constants

View Source
const (
	MAX7219_REG_NOOP   max7219Reg = 0
	MAX7219_REG_DIGIT0            = iota
	MAX7219_REG_DIGIT1
	MAX7219_REG_DIGIT2
	MAX7219_REG_DIGIT3
	MAX7219_REG_DIGIT4
	MAX7219_REG_DIGIT5
	MAX7219_REG_DIGIT6
	MAX7219_REG_DIGIT7
	MAX7219_REG_DECODEMODE
	MAX7219_REG_INTENSITY
	MAX7219_REG_SCANLIMIT
	MAX7219_REG_SHUTDOWN
	MAX7219_REG_DISPLAYTEST = 0x0F
)
View Source
const ClockRefString string = "  XXXXX \n X     X\n X     X\n X  XXXX\n X X   X\n XX    X\n  XXXXX "
View Source
const HeadphonesRefString string = " XXX    \n XXXXXXX\n       X\n       X\n       X\n       X\n XXXXXXX\n XXX    "
View Source
const MIN_CLOCK_TIME = 80 * time.Microsecond //try slowing down the whole thing

const MIN_CLOCK_TIME = 20 * time.Microsecond //TODO get the exact time from the spec

View Source
const TrainRefString string = " XXXXX  \n XX  X  \n XX  X  \n XXXXX  \nXXX  XX \nXXX  X X\n XXXXX X\nXXX  X  \nXXX X   \n XXX    \n XX     "
View Source
const TramRefString string = "" /* 158-byte string literal not displayed */
View Source
const VERTICAL_TRANSITION_FRAMECOUNT = 16

Variables

View Source
var ALCOVE_FONT = [][]byte{}/* 1112 elements not displayed */

original font by https://fontstruct.com/fontstructions/show/2461533/alcove-5x7 rendered and encoded by rom-vtn

View Source
var ATARI_FONT = [][]byte{}/* 255 elements not displayed */
View Source
var CP437_FONT = [][]byte{} // end of CP437_FONT

/* 256 elements not displayed */

copied from https://github.com/d2r2/go-max7219/blob/master/fonts.go

Functions

This section is empty.

Types

type Renderer

type Renderer interface {
	Render(frame uint) StaticGrid //renders on a given frame
	GetFrameCount() uint          //gives the total number of frames
	GetWidth() uint               //number of columns the content takes on the screen
}

a Renderer is "something that can be displayed", consisting of 1 or more frames and a given width

func NewBlinkingGrid

func NewBlinkingGrid(r Renderer, visibleFrames, totalFrames uint) Renderer

NewBlinkingGrid returns a Renderer which will show r for visibleFrames frames, and then show a blank grid until totalFrames

func NewConcatenateGrid

func NewConcatenateGrid(innerGrids []Renderer) Renderer

NewConcatenateGrid returns a Renderer which will concatenate the given Renderers (width = sum of widths, frame count = maximum frame count given)

func NewFitInsideGrid

func NewFitInsideGrid(r Renderer, fitToSize uint) Renderer

NewFitInsideGrid returns a Renderer that shows r's content while ensuring it fits in the given size, padding (and centering) if too small and scrolling if too large

func NewRepeatGrid

func NewRepeatGrid(r Renderer, repeatCount uint) Renderer

NewRepeatGrid returns a Renderer which behaved identically to r, but with an extended frame count to repeat it the given amount of times

func NewScrollingGrid

func NewScrollingGrid(r Renderer, width uint) Renderer

NewScrollingGrid returns a Renderer which scrolls the content of r on the given width

func NewSequenceGrid

func NewSequenceGrid(contents []Renderer, frameDurations []uint) (Renderer, error)

NewSequenceGrid returns a Renderer that displays the given Renderers for the given frame durations.

func NewVerticalSequenceGrid

func NewVerticalSequenceGrid(contents []Renderer, frameDurations []uint) (Renderer, error)

NewVerticalSequenceGrid returns a Renderer that displays the given Renderers for the given frame durations with the appropriate vertical scroll transitions.

type SpiScreen

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

an SpiScreen is a physical SPI device (hopefully) connected to a max7219 array.

func NewDeviceAndOpen

func NewDeviceAndOpen(spibus, spidevice uint, cascadeCount uint, brightness uint, rotateCount uint, flipHorizontal, flipVertical bool) (*SpiScreen, error)

NewDeviceAndOpen opens the SPI interface at the given bus/device and sets config parameters, then sends init signals to the screen to prepare it to display

func (*SpiScreen) Clear

func (ss *SpiScreen) Clear() error

clears the display

func (*SpiScreen) Close

func (ss *SpiScreen) Close()

close the spi screen

func (*SpiScreen) Draw

func (ss *SpiScreen) Draw(r Renderer, delay time.Duration) error

Draw draws the given Renderer on the SpiScreen with the given delay between each frame

type StaticGrid

type StaticGrid []byte

StaticGrid represents static raw content; its width is its content's width and its frame count is 1

func NewBytesTextRender

func NewBytesTextRender(codePage [][]byte, codePoints []byte) StaticGrid

NewBytesTextRender renders the given code points (byte per byte) using the given code page. This requires all codepoints to fit in a signle byte (not compatible with >255 codepoints)

func NewRawGridFromPattern

func NewRawGridFromPattern(pattern string) StaticGrid

TODO make a better function? Returns a StaticGrid which renders the given pattern as a multiline string (separated by \n)

func NewRunesTextRender

func NewRunesTextRender(codePage [][]byte, codePoints []rune) StaticGrid

NewRunesTextRender renders text as a series of runes, but allows runes to be >=256

func NewStringTextRender

func NewStringTextRender(codePage [][]byte, content string) StaticGrid

NewStringTextRender renders the given string (converting it to runes, then to bytes) using the given code page

func (StaticGrid) GetFrameCount

func (sg StaticGrid) GetFrameCount() uint

func (StaticGrid) GetWidth

func (sg StaticGrid) GetWidth() uint

func (StaticGrid) Render

func (sg StaticGrid) Render(frame uint) StaticGrid

Jump to

Keyboard shortcuts

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