display

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FontSmall  = 8
	FontMedium = 12
	FontLarge  = 16
)

Font sizes

Variables

View Source
var (
	ColorOn  = color.White
	ColorOff = color.Black
)

Color definitions

Functions

This section is empty.

Types

type Display

type Display interface {
	// Init initializes the display hardware
	Init() error

	// Clear clears the image buffer without flushing to the display.
	// Call Show() afterwards to update the physical display.
	Clear() error

	// DrawText draws text at the specified position
	DrawText(x, y int, text string, size int) error

	// DrawLine draws a horizontal line
	DrawLine(x, y, width int) error

	// DrawPixel draws a single pixel
	DrawPixel(x, y int, on bool) error

	// DrawRect draws a rectangle
	DrawRect(x, y, width, height int, fill bool) error

	// DrawImage draws an image at the specified position
	DrawImage(x, y int, img image.Image) error

	// Show flushes the buffer to the display
	Show() error

	// Close closes the display
	Close() error

	// GetBounds returns the display dimensions
	GetBounds() image.Rectangle

	// GetBuffer returns a copy of the current display buffer (for testing)
	GetBuffer() []byte

	// SetBrightness sets the display brightness (0-255)
	SetBrightness(level uint8) error
}

Display is the interface for OLED display operations

func NewDisplay

func NewDisplay(cfg *config.DisplayConfig) (Display, error)

NewDisplay creates a display implementation based on configuration

type MockDisplay

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

MockDisplay is a mock implementation for testing

func NewMockDisplay

func NewMockDisplay(width, height int) *MockDisplay

NewMockDisplay creates a new mock display

func (*MockDisplay) Clear

func (m *MockDisplay) Clear() error

Clear clears the display buffer

func (*MockDisplay) ClearCalls

func (m *MockDisplay) ClearCalls()

ClearCalls clears the recorded calls

func (*MockDisplay) Close

func (m *MockDisplay) Close() error

Close simulates closing the display

func (*MockDisplay) DrawImage

func (m *MockDisplay) DrawImage(x, y int, img image.Image) error

DrawImage draws an image

func (*MockDisplay) DrawLine

func (m *MockDisplay) DrawLine(x, y, width int) error

DrawLine draws a horizontal line

func (*MockDisplay) DrawPixel

func (m *MockDisplay) DrawPixel(x, y int, on bool) error

DrawPixel draws a single pixel

func (*MockDisplay) DrawRect

func (m *MockDisplay) DrawRect(x, y, width, height int, fill bool) error

DrawRect draws a rectangle

func (*MockDisplay) DrawText

func (m *MockDisplay) DrawText(x, y int, text string, size int) error

DrawText simulates drawing text

func (*MockDisplay) GetBounds

func (m *MockDisplay) GetBounds() image.Rectangle

GetBounds returns the display dimensions

func (*MockDisplay) GetBuffer

func (m *MockDisplay) GetBuffer() []byte

GetBuffer returns a copy of the display buffer

func (*MockDisplay) GetCalls

func (m *MockDisplay) GetCalls() []string

GetCalls returns all recorded method calls

func (*MockDisplay) GetPixel

func (m *MockDisplay) GetPixel(x, y int) bool

GetPixel returns the state of a pixel (for testing)

func (*MockDisplay) Init

func (m *MockDisplay) Init() error

Init initializes the mock display

func (*MockDisplay) SetBrightness

func (m *MockDisplay) SetBrightness(level uint8) error

SetBrightness simulates setting display brightness

func (*MockDisplay) SetError

func (m *MockDisplay) SetError(shouldError bool, msg string)

SetError configures the mock to return an error

func (*MockDisplay) Show

func (m *MockDisplay) Show() error

Show simulates flushing to hardware

func (*MockDisplay) String

func (m *MockDisplay) String() string

String returns a simple ASCII representation of the display

type SSD1306Display

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

SSD1306Display implements Display interface for real SSD1306 hardware

func NewSSD1306Display

func NewSSD1306Display(i2cBus, i2cAddr string, width, height, rotation int) (*SSD1306Display, error)

NewSSD1306Display creates a new SSD1306 display driver

func (*SSD1306Display) Clear

func (d *SSD1306Display) Clear() error

Clear clears the display

func (*SSD1306Display) Close

func (d *SSD1306Display) Close() error

Close closes the display connection

func (*SSD1306Display) DrawImage

func (d *SSD1306Display) DrawImage(x, y int, img image.Image) error

DrawImage draws an image at the specified position

func (*SSD1306Display) DrawLine

func (d *SSD1306Display) DrawLine(x, y, width int) error

DrawLine draws a horizontal line

func (*SSD1306Display) DrawPixel

func (d *SSD1306Display) DrawPixel(x, y int, on bool) error

DrawPixel draws a single pixel

func (*SSD1306Display) DrawRect

func (d *SSD1306Display) DrawRect(x, y, width, height int, fill bool) error

DrawRect draws a rectangle

func (*SSD1306Display) DrawText

func (d *SSD1306Display) DrawText(x, y int, text string, size int) error

DrawText draws text at the specified position Note: This is a simple implementation. For real text rendering, you would need a font library like golang.org/x/image/font

func (*SSD1306Display) GetBounds

func (d *SSD1306Display) GetBounds() image.Rectangle

GetBounds returns the display dimensions

func (*SSD1306Display) GetBuffer

func (d *SSD1306Display) GetBuffer() []byte

GetBuffer returns a copy of the current display buffer

func (*SSD1306Display) Init

func (d *SSD1306Display) Init() error

Init initializes the display

func (*SSD1306Display) SetBrightness

func (d *SSD1306Display) SetBrightness(level uint8) error

SetBrightness sets the display contrast/brightness (0-255) For SSD1306, this maps directly to the contrast control command

func (*SSD1306Display) Show

func (d *SSD1306Display) Show() error

Show flushes the buffer to the display

type ST7735Display added in v0.3.0

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

ST7735Display implements Display interface for ST7735 TFT displays via SPI

func NewST7735Display added in v0.3.0

func NewST7735Display(spiBus, dcPin, rstPin string, width, height, rotation int, displayType string) (*ST7735Display, error)

NewST7735Display creates a new ST7735 display driver

func (*ST7735Display) Clear added in v0.3.0

func (d *ST7735Display) Clear() error

Clear fills the image buffer with black without flushing to the display.

func (*ST7735Display) Close added in v0.3.0

func (d *ST7735Display) Close() error

Close closes the SPI port.

func (*ST7735Display) DrawImage added in v0.3.0

func (d *ST7735Display) DrawImage(x, y int, img image.Image) error

DrawImage draws an image at the specified position, preserving source colours.

func (*ST7735Display) DrawLine added in v0.3.0

func (d *ST7735Display) DrawLine(x, y, width int) error

DrawLine draws a horizontal line.

func (*ST7735Display) DrawPixel added in v0.3.0

func (d *ST7735Display) DrawPixel(x, y int, on bool) error

DrawPixel sets a single pixel (white if on, black if off).

func (*ST7735Display) DrawRect added in v0.3.0

func (d *ST7735Display) DrawRect(x, y, width, height int, fill bool) error

DrawRect draws a rectangle outline or filled rectangle.

func (*ST7735Display) DrawText added in v0.3.0

func (d *ST7735Display) DrawText(x, y int, text string, size int) error

DrawText draws text as simple character outlines.

func (*ST7735Display) GetBounds added in v0.3.0

func (d *ST7735Display) GetBounds() image.Rectangle

GetBounds returns the display dimensions.

func (*ST7735Display) GetBuffer added in v0.3.0

func (d *ST7735Display) GetBuffer() []byte

GetBuffer returns the current frame as RGB565-encoded bytes.

func (*ST7735Display) Init added in v0.3.0

func (d *ST7735Display) Init() error

Init initializes the display (already done in constructor; clears screen).

func (*ST7735Display) SetBrightness added in v0.3.0

func (d *ST7735Display) SetBrightness(_ uint8) error

SetBrightness is a no-op placeholder (backlight control not in scope).

func (*ST7735Display) Show added in v0.3.0

func (d *ST7735Display) Show() error

Show flushes the NRGBA buffer to the display as RGB565.

type UCTRONICSDisplay added in v0.3.0

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

UCTRONICSDisplay implements Display for UCTRONICS I2C-bridged ST7735 displays.

func NewUCTRONICSDisplay added in v0.3.0

func NewUCTRONICSDisplay(i2cBus, i2cAddr string, width, height int) (*UCTRONICSDisplay, error)

NewUCTRONICSDisplay creates a new UCTRONICS display driver.

func (*UCTRONICSDisplay) Clear added in v0.3.0

func (d *UCTRONICSDisplay) Clear() error

Clear fills the image buffer with black without flushing to the display.

func (*UCTRONICSDisplay) Close added in v0.3.0

func (d *UCTRONICSDisplay) Close() error

Close closes the I2C bus.

func (*UCTRONICSDisplay) DrawImage added in v0.3.0

func (d *UCTRONICSDisplay) DrawImage(x, y int, img image.Image) error

DrawImage draws an image at the specified position, preserving source colours.

func (*UCTRONICSDisplay) DrawLine added in v0.3.0

func (d *UCTRONICSDisplay) DrawLine(x, y, width int) error

DrawLine draws a horizontal line.

func (*UCTRONICSDisplay) DrawPixel added in v0.3.0

func (d *UCTRONICSDisplay) DrawPixel(x, y int, on bool) error

DrawPixel sets a single pixel (white if on, black if off).

func (*UCTRONICSDisplay) DrawRect added in v0.3.0

func (d *UCTRONICSDisplay) DrawRect(x, y, width, height int, fill bool) error

DrawRect draws a rectangle outline or filled rectangle.

func (*UCTRONICSDisplay) DrawText added in v0.3.0

func (d *UCTRONICSDisplay) DrawText(x, y int, text string, size int) error

DrawText draws text as simple character outlines.

func (*UCTRONICSDisplay) GetBounds added in v0.3.0

func (d *UCTRONICSDisplay) GetBounds() image.Rectangle

GetBounds returns the display dimensions.

func (*UCTRONICSDisplay) GetBuffer added in v0.3.0

func (d *UCTRONICSDisplay) GetBuffer() []byte

GetBuffer returns the current frame as RGB565-encoded bytes.

func (*UCTRONICSDisplay) Init added in v0.3.0

func (d *UCTRONICSDisplay) Init() error

Init initializes the display (MCU handles ST7735 init; we just clear).

func (*UCTRONICSDisplay) SetBrightness added in v0.3.0

func (d *UCTRONICSDisplay) SetBrightness(_ uint8) error

SetBrightness is a no-op (UCTRONICS MCU does not expose brightness control).

func (*UCTRONICSDisplay) Show added in v0.3.0

func (d *UCTRONICSDisplay) Show() error

Show flushes the NRGBA buffer to the display as RGB565 via I2C burst transfer.

Jump to

Keyboard shortcuts

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