device

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: GPL-3.0 Imports: 22 Imported by: 0 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.

Documentation

Overview

Package device owns the single serialized BUSY Bar output boundary.

Index

Constants

View Source
const (
	ApplicationName = "bsbctl"
)
View Source
const DefaultOutputReadLimit int64 = 64 << 20

Variables

View Source
var (
	ErrOutputClosed    = errors.New("device output is closed")
	ErrOutputReadLimit = errors.New("device readback exceeds limit")
)
View Source
var ErrDeviceUnavailable = errors.New("BUSY Bar device is unavailable")

Functions

func RunAssetRetry

func RunAssetRetry(ctx context.Context, runtime AssetRuntime, reconciler AssetReconciler, options AssetRetryOptions) error

RunAssetRetry retries asset reconciliation only while the device client is ready. Runtime and WebSocket edges wake it immediately; RetryAt drives endpoint recovery without depending on status-stream traffic.

Types

type AssetReconciler

type AssetReconciler interface {
	ReconcileAssets(context.Context) error
	AssetStatus() []assets.State
}

type AssetResolver

type AssetResolver interface {
	ResolveScene(string, presentation.Scene) (presentation.ResolvedScene, error)
}

type AssetRetryOptions

type AssetRetryOptions struct {
	Wake     <-chan struct{}
	Now      func() time.Time
	NewTimer func(time.Duration) AssetRetryTimer
}

type AssetRetryTimer

type AssetRetryTimer interface {
	C() <-chan time.Time
	Stop() bool
	Reset(time.Duration) bool
}

type AssetRuntime

type AssetRuntime interface {
	Status() RuntimeStatus
	Changes() <-chan struct{}
}

type AudioAssetResolver

type AudioAssetResolver interface {
	ResolveAudioCue(string, presentation.AudioCue) (presentation.ResolvedAudioCue, error)
}

type AudioBackend

type AudioBackend interface {
	PlayAudio(context.Context, busylib.PlayAudio) error
}

type AudioClient

type AudioClient interface {
	PlayAudio(context.Context, busylib.PlayAudio) error
}

type AudioDisplay

type AudioDisplay interface {
	PlayAudio(context.Context, busylib.PlayAudio) error
}

type AudioStatus

type AudioStatus struct {
	Attempts      uint64 `json:"attempts"`
	LastErrorCode string `json:"last_error_code,omitempty"`
}

AudioStatus reports redacted diagnostics for best-effort audio delivery. Attempts advances only when the gateway issues a distinct audio write.

type BusyTimerBackend

type BusyTimerBackend interface {
	BusySnapshot(context.Context) (busylib.BusySnapshot, error)
	SetBusySnapshot(context.Context, busylib.BusySnapshot) error
	DeviceTime(context.Context) (busylib.TimestampInfo, error)
}

type BusyTimerClient

type BusyTimerClient interface {
	BusySnapshot(context.Context) (busylib.BusySnapshot, error)
	SetBusySnapshot(context.Context, busylib.BusySnapshot) error
	DeviceTime(context.Context) (busylib.TimestampInfo, error)
}

type BusyTimerDisplay

type BusyTimerDisplay interface {
	BusySnapshot(context.Context) (busylib.BusySnapshot, error)
	SetBusySnapshot(context.Context, busylib.BusySnapshot) error
	DeviceTime(context.Context) (busylib.TimestampInfo, error)
}

BusyTimerDisplay is implemented by the process-wide device output owner. It is separate from Display so scene-only test and alternate displays stay narrow.

type Client

type Client interface {
	Draw(context.Context, busylib.DisplayElements) error
	Clear(context.Context, string) error
	UploadFile(context.Context, string, string, string) error
	ReadTo(context.Context, string, io.Writer) (int64, error)
	Remove(context.Context, string) error
	NewStatusStream() (publicstream.Stream, error)
}

Client is the complete device surface shared by every runtime proxy.

type ClientFactory

type ClientFactory func(context.Context, string, string) (Client, error)

type DelayFunc

type DelayFunc func(context.Context, time.Duration) error

type DeviceIdentity

type DeviceIdentity struct {
	APISemVer       string
	SerialNumber    string
	OTPModel        string
	OTPValid        bool
	FirmwareTarget  int
	FirmwareVersion string
	FirmwareCommit  string
	FirmwareDirty   string
	Uptime          string
}

DeviceIdentity is the bounded diagnostic tuple read on each connection.

type Display

type Display interface {
	Draw(context.Context, busylib.DisplayElements) error
	Clear(context.Context, string) error
}

Display is the narrow busylib-go surface required by the output worker.

type Gateway

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

Gateway serializes output, suppresses identical scenes, updates stable element topologies in place, and clears before structural replacements.

func NewGateway

func NewGateway(display Display, resolver AssetResolver) (*Gateway, error)

func (*Gateway) InvalidateCanvas

func (g *Gateway) InvalidateCanvas()

InvalidateCanvas forgets the cached HTTP scene after a physical selector transition or Back press. Firmware closes that canvas before the matching input event is handled, so the next selected scene must be drawn even when its digest is unchanged.

func (*Gateway) InvalidateConnection

func (g *Gateway) InvalidateConnection()

InvalidateConnection forgets physical-delivery proofs after reconnect while retaining ownership and structure for clearing a scene or timer that survived.

func (*Gateway) Render

Render updates a structurally compatible bsbctl canvas in place. A nil candidate clears it; structural changes and priority drops replace it.

func (*Gateway) Status

func (g *Gateway) Status() AudioStatus

Status returns the gateway-owned best-effort audio diagnostics. Visual delivery is returned directly by Render.

type Output

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

Output is the sole serialized owner of physical display and asset I/O. Callers wait for their command only; a slow device never occupies their subsystem's actor or lock while another command is admitted.

func NewOutput

func NewOutput(backend OutputBackend, options OutputOptions) *Output

func (*Output) BusySnapshot

func (o *Output) BusySnapshot(ctx context.Context) (busylib.BusySnapshot, error)

func (*Output) Clear

func (o *Output) Clear(ctx context.Context, application string) error

func (*Output) Close

func (o *Output) Close(ctx context.Context) error

Close rejects new work, drains already admitted commands, and joins the actor. Its context bounds admission and joining but does not reorder work.

func (*Output) DeviceTime

func (o *Output) DeviceTime(ctx context.Context) (busylib.TimestampInfo, error)

func (*Output) Draw

func (o *Output) Draw(ctx context.Context, value busylib.DisplayElements) error

func (*Output) PlayAudio

func (o *Output) PlayAudio(ctx context.Context, value busylib.PlayAudio) error

func (*Output) ReadTo

func (o *Output) ReadTo(ctx context.Context, path string, writer io.Writer) (int64, error)

func (*Output) Remove

func (o *Output) Remove(ctx context.Context, path string) error

func (*Output) SetBusySnapshot

func (o *Output) SetBusySnapshot(ctx context.Context, value busylib.BusySnapshot) error

func (*Output) Status

func (o *Output) Status() OutputStatus

func (*Output) UploadFile

func (o *Output) UploadFile(ctx context.Context, application, path, localPath string) error

type OutputOptions

type OutputOptions struct {
	QueueSize   int
	CallTimeout time.Duration
	ReadLimit   int64
}

type OutputPhase

type OutputPhase string
const (
	OutputReady  OutputPhase = "ready"
	OutputBusy   OutputPhase = "busy"
	OutputClosed OutputPhase = "closed"
)

type OutputStatus

type OutputStatus struct {
	Phase         OutputPhase `json:"phase"`
	QueueDepth    int         `json:"queue_depth"`
	LastErrorCode string      `json:"last_error_code,omitempty"`
}

type Phase

type Phase string
const (
	PhaseUnavailable Phase = "unavailable"
	PhaseConnecting  Phase = "connecting"
	PhaseReady       Phase = "ready"
	PhaseBackoff     Phase = "backoff"
)

type Runtime

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

Runtime resolves device credentials and constructs the process-wide client without coupling transient device failure to daemon availability.

func NewRuntime

func NewRuntime(config RuntimeConfig) *Runtime

func (*Runtime) BusySnapshot

func (r *Runtime) BusySnapshot(ctx context.Context) (busylib.BusySnapshot, error)

func (*Runtime) Changes

func (r *Runtime) Changes() <-chan struct{}

Changes is a coalesced edge signal. Consumers read Status after each edge. Buffering preserves a transition that occurs before consumer startup.

func (*Runtime) Clear

func (r *Runtime) Clear(ctx context.Context, applicationName string) error

func (*Runtime) DeviceIdentity

func (r *Runtime) DeviceIdentity(ctx context.Context) (DeviceIdentity, error)

func (*Runtime) DeviceTime

func (r *Runtime) DeviceTime(ctx context.Context) (busylib.TimestampInfo, error)

func (*Runtime) Draw

func (r *Runtime) Draw(ctx context.Context, request busylib.DisplayElements) error

func (*Runtime) NewStatusStream

func (r *Runtime) NewStatusStream() (publicstream.Stream, error)

func (*Runtime) ObserveStatusStream

func (r *Runtime) ObserveStatusStream(update StreamHealth)

func (*Runtime) PlayAudio

func (r *Runtime) PlayAudio(ctx context.Context, value busylib.PlayAudio) error

func (*Runtime) ReadTo

func (r *Runtime) ReadTo(ctx context.Context, path string, writer io.Writer) (int64, error)

func (*Runtime) Remove

func (r *Runtime) Remove(ctx context.Context, path string) error

func (*Runtime) Run

func (r *Runtime) Run(ctx context.Context) error

func (*Runtime) SetBusySnapshot

func (r *Runtime) SetBusySnapshot(ctx context.Context, value busylib.BusySnapshot) error

func (*Runtime) Status

func (r *Runtime) Status() RuntimeStatus

func (*Runtime) UploadFile

func (r *Runtime) UploadFile(ctx context.Context, applicationName, path, localPath string) error

type RuntimeConfig

type RuntimeConfig struct {
	BaseURL              string
	AccessTokenReference string
	Resolver             SecretResolver
	Factory              ClientFactory
	Delay                DelayFunc
	Clock                func() time.Time
	Jitter               func() float64
}

type RuntimeStatus

type RuntimeStatus struct {
	Phase           Phase     `json:"phase"`
	Attempt         int       `json:"attempt"`
	RetryAt         time.Time `json:"retry_at,omitempty"`
	LastErrorCode   string    `json:"last_error_code,omitempty"`
	LastConnectedAt time.Time `json:"last_connected_at,omitempty"`
	LastStateAt     time.Time `json:"last_state_at,omitempty"`
}

RuntimeStatus is deliberately safe for local diagnostics. It never contains device addresses, secret references or values, or raw dependency errors.

func (RuntimeStatus) MarshalJSON

func (s RuntimeStatus) MarshalJSON() ([]byte, error)

type SecretResolver

type SecretResolver interface {
	Resolve(context.Context, string) (string, error)
}

type StatusStreamFactory

type StatusStreamFactory func() (publicstream.Stream, error)

type StatusSubscriber

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

StatusSubscriber continuously drains the one-shot busylib status stream and recreates it after terminal failure. Draining is immediate so firmware input cannot be blocked by rendering or plugin work.

func NewStatusSubscriber

func NewStatusSubscriber(options StatusSubscriberOptions) (*StatusSubscriber, error)

func (*StatusSubscriber) Run

func (s *StatusSubscriber) Run(ctx context.Context) error

type StatusSubscriberOptions

type StatusSubscriberOptions struct {
	Factory     StatusStreamFactory
	Submit      func(*inputpb.InputEvent) bool
	Backoff     time.Duration
	OnConnected func()
	Observer    StreamHealthObserver
}

type StreamHealth

type StreamHealth struct {
	Phase       StreamHealthPhase
	Lifecycle   publicstream.Lifecycle
	Access      publicstream.AccessStatus
	Attempt     int
	RetryAt     time.Time
	ConnectedAt time.Time
	LastStateAt time.Time
	ErrorCode   string
}

type StreamHealthObserver

type StreamHealthObserver interface {
	ObserveStatusStream(StreamHealth)
}

type StreamHealthPhase

type StreamHealthPhase string
const (
	StreamCreating         StreamHealthPhase = "creating"
	StreamStarting         StreamHealthPhase = "starting"
	StreamStatusTransition StreamHealthPhase = "status"
	StreamTerminal         StreamHealthPhase = "terminal"
	StreamBackoff          StreamHealthPhase = "backoff"
)

Jump to

Keyboard shortcuts

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