hamdeck

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigDefaultFilename = "hamdeck.json"
	ConfigMainKey         = "hamdeck"
	ConfigConnections     = "connections"
	ConfigStartPageID     = "start_page"
	ConfigPages           = "pages"
	ConfigButtons         = "buttons"
	ConfigType            = "type"
	ConfigIndex           = "index"
	ConfigConnection      = "connection"
)
View Source
const (
	ConfigPage  = "page"
	ConfigLabel = "label"
)
View Source
const FlashingInterval = 500 * time.Millisecond
View Source
const LegacyConnectionName = ""
View Source
const LongpressDuration = 1 * time.Second
View Source
const (
	PageButtonType = "hamdeck.Page"
)

Variables

View Source
var (
	Black        = color.Black
	White        = color.White
	DisabledGray = color.RGBA{54, 60, 62, 255}
	Red          = color.RGBA{255, 0, 0, 255}
	Green        = color.RGBA{0, 255, 0, 255}
	Blue         = color.RGBA{0, 0, 255, 255}
	Yellow       = color.RGBA{255, 255, 0, 255}
	Magenta      = color.RGBA{255, 0, 255, 255}
	Cyan         = color.RGBA{0, 255, 255, 255}
	DarkGreen    = color.RGBA{0, 150, 0, 255}
	Orange       = color.RGBA{255, 165, 0, 255}
)
View Source
var (
	DefaultBackground = Black
	DefaultForeground = White
	DefaultFont       = "DejaVuSans.ttf"
	DefaultFontSize   = 24.0
)

Functions

func NotifyEnablers

func NotifyEnablers(listeners []interface{}, enabled bool)

func ToBool

func ToBool(raw any) (bool, bool)

func ToFloat

func ToFloat(raw any) (float64, bool)

func ToInt

func ToInt(raw any) (int, bool)

func ToString

func ToString(raw any) (string, bool)

func ToStringArray

func ToStringArray(raw any) ([]string, bool)

Types

type BaseButton

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

func (*BaseButton) Attached

func (b *BaseButton) Attached(ctx ButtonContext)

func (*BaseButton) Detached

func (b *BaseButton) Detached()

func (*BaseButton) Invalidate

func (b *BaseButton) Invalidate(redrawImages bool)

type Button

type Button interface {
	Image(GraphicContext, bool) image.Image
	Pressed()
	Released()
	Attached(ButtonContext)
	Detached()
}

type ButtonContext

type ButtonContext interface {
	Invalidate(bool)
}

type ButtonFactory

type ButtonFactory interface {
	Close()
	CreateButton(config map[string]interface{}) Button
}

type ConnectionConfig added in v0.4.0

type ConnectionConfig map[string]any

type ConnectionConfigProvider added in v0.4.0

type ConnectionConfigProvider interface {
	GetConnection(string, string) (ConnectionConfig, bool)
}

type ConnectionFactory added in v0.4.0

type ConnectionFactory[T any] func(string, ConnectionConfig) (T, error)

type ConnectionManager added in v0.4.0

type ConnectionManager[T any] struct {
	// contains filtered or unexported fields
}

func NewConnectionManager added in v0.4.0

func NewConnectionManager[T any](connectionType string, provider ConnectionConfigProvider, factory ConnectionFactory[T]) *ConnectionManager[T]

func (*ConnectionManager[T]) ForEach added in v0.4.0

func (m *ConnectionManager[T]) ForEach(f func(T))

func (*ConnectionManager[T]) Get added in v0.4.0

func (m *ConnectionManager[T]) Get(name string) (T, error)

func (*ConnectionManager[T]) SetLegacy added in v0.4.0

func (m *ConnectionManager[T]) SetLegacy(legacyConnection T)

type Device

type Device interface {
	Close() error
	ID() string
	Serial() string
	FirmwareVersion() string
	Pixels() int
	Rows() int
	Columns() int
	Clear() error
	Reset() error
	SetBrightness(int) error
	SetImage(int, image.Image) error
	ReadKeys() (chan Key, error)
}

type Enabler

type Enabler interface {
	Enable(enabled bool)
}

type Factory added in v0.4.0

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

func NewButtonFactory added in v0.4.0

func NewButtonFactory(pageSwitcher PageSwitcher) *Factory

func (*Factory) Close added in v0.4.0

func (f *Factory) Close()

func (*Factory) CreateButton added in v0.4.0

func (f *Factory) CreateButton(config map[string]any) Button

type FlashingButton

type FlashingButton interface {
	Flash(on bool)
}

type GC

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

func (*GC) DrawDoubleLineToggleTextButton

func (gc *GC) DrawDoubleLineToggleTextButton(text1, text2 string, activeLine int) image.Image

func (*GC) DrawIconButton

func (gc *GC) DrawIconButton(icon image.Image) image.Image

func (*GC) DrawIconLabelButton

func (gc *GC) DrawIconLabelButton(icon image.Image, label string) image.Image

func (*GC) DrawNoButton

func (gc *GC) DrawNoButton() image.Image

func (*GC) DrawSingleLineTextButton

func (gc *GC) DrawSingleLineTextButton(text string) image.Image

func (*GC) LoadFontAsset

func (gc *GC) LoadFontAsset(name string, points float64) font.Face

func (*GC) LoadFontFaceFromReader

func (gc *GC) LoadFontFaceFromReader(r io.Reader, points float64) (font.Face, error)

func (*GC) LoadIconAsset

func (gc *GC) LoadIconAsset(name string) image.Image

func (*GC) LoadIconFromFile

func (gc *GC) LoadIconFromFile(filename string) (image.Image, error)

func (*GC) LoadIconFromReader

func (gc *GC) LoadIconFromReader(r io.Reader) (image.Image, error)

func (*GC) Pixels

func (gc *GC) Pixels() int

func (*GC) Reset

func (gc *GC) Reset()

func (*GC) SetBackground

func (gc *GC) SetBackground(background color.Color)

func (*GC) SetFont

func (gc *GC) SetFont(filename string)

func (*GC) SetFontSize

func (gc *GC) SetFontSize(points float64)

func (*GC) SetForeground

func (gc *GC) SetForeground(foreground color.Color)

func (*GC) SwapColors

func (gc *GC) SwapColors()

type GraphicContext

type GraphicContext interface {
	Pixels() int
	Reset()
	SetBackground(background color.Color)
	SetForeground(foreground color.Color)
	SwapColors()
	SetFont(filename string)
	SetFontSize(points float64)
	DrawNoButton() image.Image
	DrawSingleLineTextButton(text string) image.Image
	DrawDoubleLineToggleTextButton(text1, text2 string, activeLine int) image.Image
	LoadIconFromFile(filename string) (image.Image, error)
	LoadIconFromReader(r io.Reader) (image.Image, error)
	LoadIconAsset(name string) image.Image
	DrawIconButton(icon image.Image) image.Image
	DrawIconLabelButton(icon image.Image, label string) image.Image
}

func NewGraphicContext

func NewGraphicContext(pixels int) GraphicContext

type HamDeck

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

func New

func New(device Device) *HamDeck

func (*HamDeck) Attach

func (d *HamDeck) Attach(index int, button Button)

func (*HamDeck) AttachPage added in v0.4.0

func (d *HamDeck) AttachPage(id string) error

func (*HamDeck) CloseUnusedFactories added in v0.3.0

func (d *HamDeck) CloseUnusedFactories()

func (*HamDeck) Detach

func (d *HamDeck) Detach(index int)

func (*HamDeck) GetConnection added in v0.4.0

func (d *HamDeck) GetConnection(name string, connectionType string) (ConnectionConfig, bool)

func (*HamDeck) ReadConfig

func (d *HamDeck) ReadConfig(r io.Reader) error

func (*HamDeck) Redraw

func (d *HamDeck) Redraw(index int, redrawImages bool)

func (*HamDeck) RedrawAll

func (d *HamDeck) RedrawAll(redrawImages bool)

func (*HamDeck) RegisterFactory

func (d *HamDeck) RegisterFactory(factory ButtonFactory)

func (*HamDeck) Run

func (d *HamDeck) Run(stop <-chan struct{}) error

type Key

type Key struct {
	Index   int
	Pressed bool
}

type LongpressHandler

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

func NewLongpressHandler

func NewLongpressHandler(callback func()) *LongpressHandler

func (*LongpressHandler) Pressed

func (h *LongpressHandler) Pressed()

func (*LongpressHandler) Released

func (h *LongpressHandler) Released()

type Page added in v0.4.0

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

type PageButton added in v0.4.0

type PageButton struct {
	BaseButton
	// contains filtered or unexported fields
}

func NewPageButton added in v0.4.0

func NewPageButton(pageSwitcher PageSwitcher, id string, label string) *PageButton

func (*PageButton) Image added in v0.4.0

func (b *PageButton) Image(gc GraphicContext, redrawImages bool) image.Image

func (*PageButton) Pressed added in v0.4.0

func (b *PageButton) Pressed()

func (*PageButton) Released added in v0.4.0

func (b *PageButton) Released()

type PageSwitcher added in v0.4.0

type PageSwitcher interface {
	AttachPage(string) error
}

Jump to

Keyboard shortcuts

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