Documentation
¶
Overview ¶
Package sequence defines the validated host playback model for nb1.
Index ¶
Constants ¶
const ( TimingSerial = "serial" TimingInterval = "interval" MaxExecutedSteps = 1024 MaxNominalDurationMS = 24 * 60 * 60 * 1000 MaxFadeMS = 600000 FadeQuantumMS = 10 MaxHoldMS = 3600000 MinIntervalMS = 50 MaxIntervalMS = 600000 UpdateAllowanceMS = 10 TargetWriteSpacingMS = 10 MaxInputBytes = 1 << 20 )
const PlaybackContract = "nb1-sequence-playback/v1"
PlaybackContract versions the backend-neutral timing descriptors produced by Plan. A plan contains no timers, device handles, USB reports or runtime state.
Variables ¶
var ErrInvalid = errors.New("invalid sequence")
Functions ¶
This section is empty.
Types ¶
type PlaybackPlan ¶
type PlaybackPlan struct {
Contract string `json:"contract"`
Timing string `json:"timing"`
Initial []PlaybackTarget `json:"initial"`
Steps []PlaybackStep `json:"steps"`
Finish []PlaybackTarget `json:"finish"`
NominalDurationMS int64 `json:"nominal_duration_ms"`
TotalSteps int `json:"total_steps"`
TotalTargetWrites int `json:"total_target_writes"`
OnFinish string `json:"on_finish"`
}
PlaybackPlan expands a finite Sequence into ordered writes and waits. The nominal offsets exclude I/O time and timer lateness: they are for previews, never deadlines that an executor should catch up with a burst of writes.
The owner must stop autonomous device playback before Initial, serialize all device access, and apply Finish after the final wait. Cancellation and error handling belong to that owner: in particular an unknown USB write outcome must not trigger automatic retries or additional cleanup writes. A plan does not assert that I/O, cleanup, readback or optical output succeeded.
func Plan ¶
func Plan(input Sequence) (PlaybackPlan, error)
Plan validates input before producing any descriptors. It does not modify or retain mutable fields of input. Sequence limits bound the result to 1024 Steps and at most 2051 target writes (two initial, two per Step, one off), excluding the owner's preflight. Initial is applied only once. Nominal timing matches Sequence previews and excludes Finish, device I/O and timer lateness.
type PlaybackStep ¶
type PlaybackStep struct {
Index int `json:"index"`
RepeatIndex int `json:"repeat_index"`
StepIndex int `json:"step_index"`
NominalOffsetMS int64 `json:"nominal_offset_ms"`
Targets []PlaybackTarget `json:"targets"`
WaitAfterMS int `json:"wait_after_ms"`
DeadlineMS int `json:"deadline_ms"`
SettleAfterMS int `json:"settle_after_ms"`
}
PlaybackStep is one executed Step, with repetition already expanded. Indices are zero-based. Serial execution waits WaitAfterMS after the target returns.
Interval execution starts a fresh DeadlineMS budget at the actual start of this Step. Every target write must begin and return strictly before that deadline; then the executor waits until the deadline. A late write fails the run. After a late timer wake-up, an executor may start a fresh interval or fail stopped; it must never shorten intervals to catch up a nominal timeline.
Only the final interval Step has SettleAfterMS: after its interval, also wait until the final target's actual write return plus SettleAfterMS. This wait can overlap the interval. Check cancellation between every write and wait; an in-flight native/USB write cannot be cancelled by these descriptors.
type PlaybackTarget ¶
type PlaybackTarget struct {
LED int `json:"led"`
Color string `json:"color"`
FadeMS int `json:"fade_ms"`
WaitBeforeMS int `json:"wait_before_ms"`
WaitAfterMS int `json:"wait_after_ms"`
}
PlaybackTarget is one ordered device fade. WaitBeforeMS starts when the previous target's write returns; WaitAfterMS starts when this write returns. Initial targets use WaitAfterMS, including the final initial target. Step targets use WaitBeforeMS to preserve spacing between physical LED writes.
type Sequence ¶
type Sequence struct {
Timing string `json:"timing"`
Initial []Target `json:"initial,omitempty"`
Steps []Step `json:"steps"`
Repeat int `json:"repeat"`
OnFinish string `json:"on_finish"`
}
func Decode ¶
Decode accepts one strict Sequence JSON object and returns its normalized playback plan. A target's LED selector is required, including for LED 0.
func DecodeAuthoring ¶
func DecodeAuthoring(data []byte, resolveColor func(json.RawMessage) (string, error)) (Sequence, error)
DecodeAuthoring accepts ColorInput notation for target colors, then returns the same canonical playback plan as Decode. A caller can supply the shared application resolver to handle local color aliases. A nil resolver accepts the pure color grammar without accessing a library or device.
func Normalize ¶
Normalize validates the playback plan and returns an independent copy with defaults and canonical RGB values. Zero Repeat and empty OnFinish represent omitted defaults in Go. Decode distinguishes omission from explicit JSON.
func (Sequence) NominalDurationMS ¶
NominalDurationMS gives the planned duration of a normalized sequence, including the device update allowance. Native I/O and final cleanup take additional time. An interval sequence applies its initial targets once and waits for its last target to settle beyond the final interval if necessary.