device

package
v0.0.0-...-8099344 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: BSD-3-Clause Imports: 38 Imported by: 0

Documentation

Overview

Package device provides types for managing a dex device.

Index

Constants

View Source
const DefaultPage = "default"

DefaultPage is the initial name of the default page.

Variables

This section is empty.

Functions

func DecodeImage

func DecodeImage(rect image.Rectangle, data, datadir string) (image.Image, error)

DecodeImage decodes image data from a data uri corresponding to the CUE _#data_uri definitions in the config package rendered to the size of rect if it is text. Image files are opened relative to the datadir path unless the filename is an absolute path. Any error is rendered as a text image and returned as an error.

func Funcs

func Funcs[K sys.Kernel, D sys.Device[B], B sys.Button](manager *sys.Manager[K, D, B], log *slog.Logger) rpc.Funcs

Funcs returns an rpc.Funcs with a function table for accessing a store and device held by the manager.

The RPC methods in the table are:

func GoFuncs

func GoFuncs[K sys.Kernel, D sys.Device[B], B sys.Button](ctx context.Context) func(*sys.Manager[K, D, B], *slog.Logger) rpc.Funcs

GoFuncs returns an rpc.Funcs constructor with a function table for accessing a device held by the manager. It differs from Funcs in that the context.Context passed to the functions is provided in the initial call rather than by the RPC handler, and so will not be cancelled on RPC call return. This allows asynchronous calls with long running actions to be started and live beyond the RPC call's return. These include methods that draw to device buttons.

The RPC methods in the table are:

Types

type BrightnessMessage

type BrightnessMessage struct {
	// Valid actions are "add", "get" and "set".
	Action string `json:"action"`
	// Absolute brightness for "get" and "set".
	// Relative for "add", use a negative value
	// to reduce brightness.
	Brightness int `json:"brightness"`
	// The service owning the device to request
	// the brightness for. If nil, query the
	// calling manager's service.
	Service *rpc.UID `json:"service"`
}

BrightnessMessage is the RPC message for getting or setting the brightness of a device.

type Button

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

Button is an interface to an individual button on a device.

func (*Button) Draw

func (b *Button) Draw(ctx context.Context, img image.Image)

Draw draws the provided image to the button using the ardilla.Deck.SetImage method. If the image satisfies animation.Animator the animation will be run on the button's screen.

func (*Button) Image

func (b *Button) Image() image.Image

Image returns the buttons image.

func (*Button) OnPress

func (b *Button) OnPress(do func(ctx context.Context, page string, row, col int, t time.Time) error)

OnPress registers a function to call when the button is pressed. The function must not block.

func (*Button) OnRelease

func (b *Button) OnRelease(do func(ctx context.Context, page string, row, col int, t time.Time) error)

OnRelease registers a function to call when the button is releases. The function must not block.

func (*Button) Pause

func (b *Button) Pause()

Pause pauses a button's draw operations.

func (*Button) Redraw

func (b *Button) Redraw(ctx context.Context)

Redraw redraws the buttons image if required.

func (*Button) Stop

func (b *Button) Stop()

Stop stops a button, releasing any resources it holds.

func (*Button) Unpause

func (b *Button) Unpause()

Unpause unpauses a button's paused draw operations.

type Controller

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

Controller is an event-driven El Gato device controller.

func NewController

func NewController(ctx context.Context, kernel sys.Kernel, pid ardilla.PID, serial string, log *slog.Logger) (*Controller, error)

NewController returns a new device controller. The pid and serial parameters are interpreted according to the documentation for ardilla.NewDeck.

func (*Controller) Blank

func (c *Controller) Blank() error

Blank pauses the current page and blanks it.

func (*Controller) Bounds

func (c *Controller) Bounds() (image.Rectangle, error)

Bounds returns the image bounds for buttons on the device. If the device is not visual an error is returned.

func (*Controller) Clear

func (c *Controller) Clear() error

Clear pauses the current page and clears it.

func (*Controller) Close

func (c *Controller) Close() error

Close resets and closes the device.

func (*Controller) CurrentName

func (c *Controller) CurrentName() string

CurrentName returns the name of the currently displayed page.

func (*Controller) CurrentPage

func (c *Controller) CurrentPage() Page

CurrentPage returns the currently displayed page.

func (*Controller) DefaultName

func (c *Controller) DefaultName() string

DefaultName returns the name of the default page.

func (*Controller) Delete

func (c *Controller) Delete(ctx context.Context, name string) error

Delete removes the named page. Delete returns an error if the page is the default display. If the named page is the current display, the display is set to the default page.

func (*Controller) GoUntilWake

func (c *Controller) GoUntilWake(ctx context.Context, fn func(ctx context.Context))

GoUntilWake runs fn in a separate goroutine. The context.Context passed to fn is cancelled when Wake is called. The function should return when the context is cancelled.

func (*Controller) Key

func (c *Controller) Key(row, col int) int

Key returns the key number corresponding to the given row and column. It panics if row or col are out of bounds.

func (*Controller) Last

func (c *Controller) Last() time.Time

Last returns the time of the last button press or release. If the returned time.Time is zero, no button action has occurred.

func (*Controller) Layout

func (c *Controller) Layout() (rows, cols int)

Layout returns the number of rows and columns of buttons on the device.

func (*Controller) NewPage

func (c *Controller) NewPage(name string) error

NewPage inserts a new page into the controller. NewPage returns an error if the name already exists.

func (*Controller) PID

func (c *Controller) PID() ardilla.PID

PID returns the model PID of the device.

func (*Controller) Page

func (c *Controller) Page(name string) (p Page, ok bool)

Page returns the named page.

func (*Controller) PageNames

func (c *Controller) PageNames() []string

PageNames returns a list of the device's page names.

func (*Controller) RawImage

func (c *Controller) RawImage(img image.Image) (*ardilla.RawImage, error)

RawImage returns an image.Image has had the internal image representation pre-computed after resizing to fit the Deck's button size. The original image is retained in the returned image.

func (*Controller) Rename

func (c *Controller) Rename(old, new string) error

Rename renames a page from an old name to a new name. Rename returns an error if the old name does not exist or the new name already exists.

func (*Controller) Reset

func (c *Controller) Reset() error

Resets the Stream Deck, clearing all button images and showing the standby image.

func (*Controller) ResetKeyStream

func (c *Controller) ResetKeyStream() error

ResetKeyStream sends a blank key report to the Stream Deck, resetting the key image streamer in the device. This prevents previously started partial writes from corrupting images sent later.

func (*Controller) Serial

func (c *Controller) Serial() string

Serial returns the serial number of the device.

func (*Controller) SetBrightness

func (c *Controller) SetBrightness(percent int) error

SetBrightness sets the global screen brightness of the Stream Deck, across all the device's buttons.

func (*Controller) SetDefaultName

func (c *Controller) SetDefaultName(name string) error

SetDefaultName sets the name of the default page.

func (*Controller) SetDisplayTo

func (c *Controller) SetDisplayTo(ctx context.Context, name string) error

SetDisplayTo sets the current display the named page. SetDisplayTo returns an error if the page does not exist.

func (*Controller) SleepState

func (c *Controller) SleepState() SleepState

SleepState returns the current controller sleep state.

func (*Controller) Wake

func (c *Controller) Wake(ctx context.Context)

Wake unpauses the current page and redraws it.

type DrawMessage

type DrawMessage struct {
	Page  string `json:"page"`
	Row   int    `json:"row"`
	Col   int    `json:"col"`
	Image string `json:"image"`
	// The service owning the device to request
	// drawing operation on. If nil, query the
	// calling manager's service.
	Service *rpc.UID `json:"service"`
}

DrawMessage is the RPC message for drawing an image to a device.

type Manager

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

Manager controls a set of El Gato device pages and manages their interactions.

func NewManager

func NewManager[K sys.Kernel](ctx context.Context, pid ardilla.PID, serial string, kernel K, log *slog.Logger) (*Manager, error)

NewManager returns a new device manager controlling the physical device specified by pid and serial and communicating via the provided RPC kernel.

func (*Manager) Blank

func (m *Manager) Blank() error

Blank pauses the current page and blanks it.

func (*Manager) Bounds

func (m *Manager) Bounds() (image.Rectangle, error)

Bounds returns the image bounds for buttons on the managed device. If the device is not visual an error is returned.

func (*Manager) Clear

func (m *Manager) Clear() error

Clear pauses the current page and clears it to the default image.

func (*Manager) Close

func (m *Manager) Close() error

Close closes the manager and releases its resources.

func (*Manager) CurrentName

func (m *Manager) CurrentName() string

CurrentName returns the name of the currently displayed page.

func (*Manager) Key

func (m *Manager) Key(row, col int) int

Key returns the key number corresponding to the given row and column. It panics if row or col are out of bounds.

func (*Manager) Last

func (m *Manager) Last() time.Time

Last returns the time of the last button press or release. If the returned time.Time is zero, no button action has occurred.

func (*Manager) Layout

func (m *Manager) Layout() (rows, cols int)

Layout returns the number of rows and columns of buttons on the managed device.

func (*Manager) Page

func (m *Manager) Page(name string) (p sys.Page[*Button], ok bool)

Page returns the named page.

func (*Manager) PageDetails

func (m *Manager) PageDetails() map[string][]config.Button

PageDetails returns the device's page details.

func (*Manager) PageNames

func (m *Manager) PageNames() []string

PageNames returns a list of the device's page names.

func (*Manager) RawImage

func (m *Manager) RawImage(img image.Image) (*ardilla.RawImage, error)

RawImage returns an image.Image has had the internal image representation pre-computed after resizing to fit the Deck's button size. The original image is retained in the returned image.

func (*Manager) SendTo

func (m *Manager) SendTo(service rpc.UID, actions []config.Button) error

SendTo queues requests to send button actions to the specified service. requests are not acted on until a subsequent call to SetPages.

func (*Manager) Serial

func (m *Manager) Serial() string

Serial returns the serial number of the underlying dex device.

func (*Manager) SetBrightness

func (m *Manager) SetBrightness(percent int) error

SetBrightness sets the global screen brightness of the Stream Deck, across all the device's buttons.

func (*Manager) SetDisplayTo

func (m *Manager) SetDisplayTo(ctx context.Context, name string) error

SetDisplayTo sets the current display the named page. SetDisplayTo returns an error if the page does not exist.

func (*Manager) SetPages

func (m *Manager) SetPages(ctx context.Context, deflt *string, pages []string) error

SetPages specifies which pages will be active and the name of the default page. If deflt is nil the default page name is unchanged. When SetPages is called, all pending requests queued by SendTo as installed. Any existing button actions that were not in the pending requests are removed.

func (*Manager) SleepState

func (m *Manager) SleepState() string

SleepState returns the current sleep state.

func (*Manager) Wake

func (m *Manager) Wake(ctx context.Context)

Wake unpauses the current page and redraws it.

type Notification

type Notification struct {
	Service rpc.UID         `json:"uid"`
	Buttons []config.Button `json:"buttons"`
}

Notification is an RPC message type sent to services when buttons have had their state changed by the Manager.

type Page

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

Page is a collection of buttons displaying at the same time.

func (Page) Button

func (p Page) Button(row, col int) *Button

Button returns the button at the provided position. It panics if row or col are out of bounds.

func (Page) Pause

func (p Page) Pause()

Pause pauses a page's draw operations.

func (Page) Redraw

func (p Page) Redraw(ctx context.Context)

Redraw redraws all still images.

func (Page) Unpause

func (p Page) Unpause()

Unpause unpauses a pages's paused draw operations.

type PageMessage

type PageMessage struct {
	Page string `json:"page"`
	// The service owning the device to request
	// the page change on. If nil, query the
	// calling manager's service.
	Service *rpc.UID `json:"service"`
}

PageMessage is the RPC message for changing page.

type PageStateMessage

type PageStateMessage struct {
	// The service owning the device to request
	// the page list from. If nil, query the
	// calling manager's service.
	Service *rpc.UID `json:"service"`
}

PageStateMessage is the RPC message for listing pages.

type SleepMessage

type SleepMessage struct {
	// Valid actions are "get" and "set".
	Action string `json:"action"`
	// Valid states are "awake", "blanked" and "cleared"
	State string `json:"state"`
	// Last is the time of the last button event. Only
	// valid for "get".
	Last *time.Time `json:"last,omitempty"`
	// The service owning the device to request
	// the sleep state from. If nil, query the
	// calling manager's service.
	Service *rpc.UID `json:"service"`
}

SleepMessage is the RPC message for setting or getting a device's sleep state.

type SleepState

type SleepState int

SleepState represents a sleep/wake state.

const (
	Awake SleepState = iota
	Cleared
	Blanked
)

func (SleepState) String

func (i SleepState) String() string

Jump to

Keyboard shortcuts

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