Loops and Transitions
By default, FociStm / PatternStm play back the same pattern sequence infinitely.
To make the playback count finite, proceed as follows.
Finite loops
Section titled “Finite loops”The playback count is specified with loop_behavior of FociStmOption and the like.
LoopBehavior::Infinite (default) loops infinitely, while LoopBehavior::Finite(n) plays back n times (up to 65535 times) and then stops.
Note that on stopping, the last pattern continues to be output.
An important point is that a finite loop takes effect only when switching to a bank different from the current one.
// Play the circular motion only 3 times, then stop.// A finite loop (and non-immediate transition) only fires when switching to a// different bank, so write to bank B1 instead of the current B0.client.send(FociStm::new( config, &foci, FociStmOption { loop_behavior: LoopBehavior::Finite(NonZeroU16::new(3).unwrap()), bank: PatternBank::B1, transition_mode: TransitionMode::SyncIdx, ..Default::default() },)).await?;# Play the circular motion only 3 times, then stop.# A finite loop (and non-immediate transition) only fires when switching to a# different bank, so write to bank B1 instead of the current B0.await client.send( FociStm( config, foci, FociStmOption( loop_behavior=LoopBehavior.Finite(3), bank=PatternBank.B1, transition_mode=TransitionMode.SyncIdx, ), ))// Play the circular motion only 3 times, then stop.// A finite loop (and non-immediate transition) only fires when switching to a// different bank, so write to bank B1 instead of the current B0.await client.SendAsync(new FociStm( new SamplingConfig(50.0f * Hz * foci.Length), foci, new FociStmOption { LoopBehavior = LoopBehavior.Finite(3), Bank = PatternBank.B1, TransitionMode = TransitionMode.SyncIdx, }));Transition timing
Section titled “Transition timing”The timing at which the playback target switches to a bank is specified with transition_mode.
The modes that can be used are constrained by the loop setting (loop_behavior) of the destination bank.
Modes available when the destination is an infinite loop.
Immediate(default): switches the bank immediately after the write.Ext: extended mode. Automatically switches to the next bank when playback within the bank finishes.
Modes available when the destination is a finite loop.
SyncIdx: switches at the timing when the playback index of the target bank returns to 0.SysTime { time }: switches at the specified device timetime(TransitionMode.SysTime(time)in Python / C#).Gpio(GpioIn): switches on the trigger of the specified GPIO input pin.
As with the loop setting, the transition timing takes effect only when a bank is switched.
For fine-grained control such as preloading the next output into another bank in advance and switching at an arbitrary timing, refer to the low-level commands in the API reference.