Skip to main content

Operations

Operations are the building blocks of a variable. The body of a variable is a list of operations — each line beginning with a dash — that run one after the other. Each operation takes the result of the previous one as its input, does some work, and passes its output to the next. The result of the last operation becomes the value of the variable.

variables:
part-count:
- source: AIN0
- threshold: 5
- rising-edge
- count

See Variables for a walkthrough of this example and the rules governing the first and last operations in a chain.

info

Only three operations can start a chain: source, expression, and state. Every other operation needs an input from the operation before it.

Index

Sources and control flow

OperationDescription
sourceNames the data source — pin, register, tag, or another variable — that feeds the chain.
stateEmits a constant value based on a series of expression tests, like an if/else-if/else.
branchRoutes the incoming value through the first matching branch's chain of operations.
if, else-if, elseKeywords used to form the conditions of a branch.
mapApplies a chain of operations to every element of an array.

Expressions and logic

OperationDescription
expressionApplies an expression to the input and outputs the result.
andCombines the input with an expression result using a logical AND.
orCombines the input with an expression result using a logical OR.
invertInverts a boolean, or negates a number.

Analog conditioning

OperationDescription
thresholdConverts a numeric value to digital high or low at a cutoff.
minOutputs the smallest of the last N samples, filtering out short rises.
maxOutputs the largest of the last N samples, filtering out short drops.
averageOutputs the average of the last N samples.
min-deltaHolds the last value until the input moves by at least the given amount.
resampleResamples a stream to a fixed sample rate.
rate-of-changeOutputs the change between samples divided by the time between them.

Digital conditioning

OperationDescription
debounceFilters out changes shorter than the given window.
on-delaySwitches true only after the input has stayed true for the given time.
off-delaySwitches false only after the input has stayed false for the given time.
toggleFlips between true and false on each rising edge.
latch-valueHolds a value until a reset expression evaluates true.
ignore-valueDrops values matching a test, repeating the last value that passed.

Event detection

OperationDescription
edgeEmits an event pulse on any transition, in either direction.
rising-edgeEmits an event pulse on each low-to-high transition.
falling-edgeEmits an event pulse on each high-to-low transition.
value-changeEmits an event pulse each time the value changes.
value-increaseEmits an event pulse each time the value increases.
value-decreaseEmits an event pulse each time the value decreases.
value-increase-diffEmits the size of each increase, then returns to zero.

Counting

OperationDescription
countIncrements by one for each event received.
window-countCounts the events seen within a trailing time window.
accumulateMaintains and outputs a running sum of incoming values.

Text and patterns

OperationDescription
pattern-matchCaptures the part of a string matching a pattern.
pattern-replaceReplaces the part of a string matching a pattern.
pattern-testOutputs true when a pattern is present in the string.
pattern-escapeEscapes a value so it can be embedded safely in a pattern.
trimRemoves whitespace and non-printable characters from both ends of a string.
max-lengthTruncates a string to a number of characters, or an array to a number of elements.
hashApplies an md5 or sha1 hash to the input.

Objects, arrays and buffers

OperationDescription
object-keysEmits an array of an object's keys, or of an array's indexes.
object-valuesEmits an array of an object's values.
rejectRemoves elements matching a test from an array.
to-bufferConverts a value into a binary buffer.
from-bufferReads a typed value out of a binary buffer at a given offset.

Special values

OperationDescription
when-unavailableSubstitutes a value when the input is UNAVAILABLE.