Documentation ¶
Overview ¶
Package device provides types for managing a dex device.
Index ¶
- Constants
- func DecodeImage(rect image.Rectangle, data, datadir string) (image.Image, error)
- func Funcs[K sys.Kernel, D sys.Device[B], B sys.Button](manager *sys.Manager[K, D, B], log *slog.Logger) rpc.Funcs
- 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
- type BrightnessMessage
- type Button
- func (b *Button) Draw(ctx context.Context, img image.Image)
- func (b *Button) Image() image.Image
- func (b *Button) OnPress(do func(ctx context.Context, page string, row, col int, t time.Time) error)
- func (b *Button) OnRelease(do func(ctx context.Context, page string, row, col int, t time.Time) error)
- func (b *Button) Pause()
- func (b *Button) Redraw(ctx context.Context)
- func (b *Button) Stop()
- func (b *Button) Unpause()
- type Controller
- func (c *Controller) Blank() error
- func (c *Controller) Bounds() (image.Rectangle, error)
- func (c *Controller) Clear() error
- func (c *Controller) Close() error
- func (c *Controller) CurrentName() string
- func (c *Controller) CurrentPage() Page
- func (c *Controller) DefaultName() string
- func (c *Controller) Delete(ctx context.Context, name string) error
- func (c *Controller) GoUntilWake(ctx context.Context, fn func(ctx context.Context))
- func (c *Controller) Key(row, col int) int
- func (c *Controller) Last() time.Time
- func (c *Controller) Layout() (rows, cols int)
- func (c *Controller) NewPage(name string) error
- func (c *Controller) PID() ardilla.PID
- func (c *Controller) Page(name string) (p Page, ok bool)
- func (c *Controller) PageNames() []string
- func (c *Controller) RawImage(img image.Image) (*ardilla.RawImage, error)
- func (c *Controller) Rename(old, new string) error
- func (c *Controller) Reset() error
- func (c *Controller) ResetKeyStream() error
- func (c *Controller) Serial() string
- func (c *Controller) SetBrightness(percent int) error
- func (c *Controller) SetDefaultName(name string) error
- func (c *Controller) SetDisplayTo(ctx context.Context, name string) error
- func (c *Controller) SleepState() SleepState
- func (c *Controller) Wake(ctx context.Context)
- type DrawMessage
- type Manager
- func (m *Manager) Blank() error
- func (m *Manager) Bounds() (image.Rectangle, error)
- func (m *Manager) Clear() error
- func (m *Manager) Close() error
- func (m *Manager) CurrentName() string
- func (m *Manager) Key(row, col int) int
- func (m *Manager) Last() time.Time
- func (m *Manager) Layout() (rows, cols int)
- func (m *Manager) Page(name string) (p sys.Page[*Button], ok bool)
- func (m *Manager) PageDetails() map[string][]config.Button
- func (m *Manager) PageNames() []string
- func (m *Manager) RawImage(img image.Image) (*ardilla.RawImage, error)
- func (m *Manager) SendTo(service rpc.UID, actions []config.Button) error
- func (m *Manager) Serial() string
- func (m *Manager) SetBrightness(percent int) error
- func (m *Manager) SetDisplayTo(ctx context.Context, name string) error
- func (m *Manager) SetPages(ctx context.Context, deflt *string, pages []string) error
- func (m *Manager) SleepState() string
- func (m *Manager) Wake(ctx context.Context)
- type Notification
- type Page
- type PageMessage
- type PageStateMessage
- type SleepMessage
- type SleepState
Constants ¶
const DefaultPage = "default"
DefaultPage is the initial name of the default page.
Variables ¶
This section is empty.
Functions ¶
func DecodeImage ¶
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:
- "page": see Controller.SetDisplayTo and PageMessage
- "page_names": see Controller.PageNames and PageStateMessage, returns []string
- "page_details": see Controller.PageNames and PageStateMessage, returns map[string][]config.Button
- "brightness": see sys.Device.SetBrightness and BrightnessMessage
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:
- "draw": see sys.Page.Button/DecodeImage/sys.Button.Draw and DrawMessage
- "sleep": see sys.Device.Wake/sys.Device.Blank/sys.Device.Clear and SleepMessage
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 ¶
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) 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.
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) 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 ¶
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) Bounds ¶
Bounds returns the image bounds for buttons on the managed device. If the device is not visual an error is returned.
func (*Manager) CurrentName ¶
CurrentName returns the name of the currently displayed page.
func (*Manager) Key ¶
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 ¶
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 ¶
Layout returns the number of rows and columns of buttons on the managed device.
func (*Manager) PageDetails ¶
PageDetails returns the device's page details.
func (*Manager) RawImage ¶
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 ¶
SendTo queues requests to send button actions to the specified service. requests are not acted on until a subsequent call to SetPages.
func (*Manager) SetBrightness ¶
SetBrightness sets the global screen brightness of the Stream Deck, across all the device's buttons.
func (*Manager) SetDisplayTo ¶
SetDisplayTo sets the current display the named page. SetDisplayTo returns an error if the page does not exist.
func (*Manager) SetPages ¶
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 ¶
SleepState returns the current sleep state.
type Notification ¶
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.
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