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
- By category
- Alphabetical
Sources and control flow
| Operation | Description |
|---|---|
| source | Names the data source — pin, register, tag, or another variable — that feeds the chain. |
| state | Emits a constant value based on a series of expression tests, like an if/else-if/else. |
| branch | Routes the incoming value through the first matching branch's chain of operations. |
| if, else-if, else | Keywords used to form the conditions of a branch. |
| map | Applies a chain of operations to every element of an array. |
Expressions and logic
| Operation | Description |
|---|---|
| expression | Applies an expression to the input and outputs the result. |
| and | Combines the input with an expression result using a logical AND. |
| or | Combines the input with an expression result using a logical OR. |
| invert | Inverts a boolean, or negates a number. |
Analog conditioning
| Operation | Description |
|---|---|
| threshold | Converts a numeric value to digital high or low at a cutoff. |
| min | Outputs the smallest of the last N samples, filtering out short rises. |
| max | Outputs the largest of the last N samples, filtering out short drops. |
| average | Outputs the average of the last N samples. |
| min-delta | Holds the last value until the input moves by at least the given amount. |
| resample | Resamples a stream to a fixed sample rate. |
| rate-of-change | Outputs the change between samples divided by the time between them. |
Digital conditioning
| Operation | Description |
|---|---|
| debounce | Filters out changes shorter than the given window. |
| on-delay | Switches true only after the input has stayed true for the given time. |
| off-delay | Switches false only after the input has stayed false for the given time. |
| toggle | Flips between true and false on each rising edge. |
| latch-value | Holds a value until a reset expression evaluates true. |
| ignore-value | Drops values matching a test, repeating the last value that passed. |
Event detection
| Operation | Description |
|---|---|
| edge | Emits an event pulse on any transition, in either direction. |
| rising-edge | Emits an event pulse on each low-to-high transition. |
| falling-edge | Emits an event pulse on each high-to-low transition. |
| value-change | Emits an event pulse each time the value changes. |
| value-increase | Emits an event pulse each time the value increases. |
| value-decrease | Emits an event pulse each time the value decreases. |
| value-increase-diff | Emits the size of each increase, then returns to zero. |
Counting
| Operation | Description |
|---|---|
| count | Increments by one for each event received. |
| window-count | Counts the events seen within a trailing time window. |
| accumulate | Maintains and outputs a running sum of incoming values. |
Text and patterns
| Operation | Description |
|---|---|
| pattern-match | Captures the part of a string matching a pattern. |
| pattern-replace | Replaces the part of a string matching a pattern. |
| pattern-test | Outputs true when a pattern is present in the string. |
| pattern-escape | Escapes a value so it can be embedded safely in a pattern. |
| trim | Removes whitespace and non-printable characters from both ends of a string. |
| max-length | Truncates a string to a number of characters, or an array to a number of elements. |
| hash | Applies an md5 or sha1 hash to the input. |
Objects, arrays and buffers
| Operation | Description |
|---|---|
| object-keys | Emits an array of an object's keys, or of an array's indexes. |
| object-values | Emits an array of an object's values. |
| reject | Removes elements matching a test from an array. |
| to-buffer | Converts a value into a binary buffer. |
| from-buffer | Reads a typed value out of a binary buffer at a given offset. |
Special values
| Operation | Description |
|---|---|
| when-unavailable | Substitutes a value when the input is UNAVAILABLE. |
| Operation | Description |
|---|---|
| accumulate | Maintains and outputs a running sum of incoming values. |
| and | Combines the input with an expression result using a logical AND. |
| average | Outputs the average of the last N samples. |
| branch | Routes the incoming value through the first matching branch's chain of operations. |
| count | Increments by one for each event received. |
| debounce | Filters out changes shorter than the given window. |
| edge | Emits an event pulse on any transition, in either direction. |
| else | Keyword forming the fallback condition of a branch. |
| else-if | Keyword forming an additional condition of a branch. |
| expression | Applies an expression to the input and outputs the result. |
| falling-edge | Emits an event pulse on each high-to-low transition. |
| from-buffer | Reads a typed value out of a binary buffer at a given offset. |
| hash | Applies an md5 or sha1 hash to the input. |
| if | Keyword forming the first condition of a branch. |
| ignore-value | Drops values matching a test, repeating the last value that passed. |
| invert | Inverts a boolean, or negates a number. |
| latch-value | Holds a value until a reset expression evaluates true. |
| map | Applies a chain of operations to every element of an array. |
| max | Outputs the largest of the last N samples, filtering out short drops. |
| max-length | Truncates a string to a number of characters, or an array to a number of elements. |
| min | Outputs the smallest of the last N samples, filtering out short rises. |
| min-delta | Holds the last value until the input moves by at least the given amount. |
| object-keys | Emits an array of an object's keys, or of an array's indexes. |
| object-values | Emits an array of an object's values. |
| off-delay | Switches false only after the input has stayed false for the given time. |
| on-delay | Switches true only after the input has stayed true for the given time. |
| or | Combines the input with an expression result using a logical OR. |
| pattern-escape | Escapes a value so it can be embedded safely in a pattern. |
| pattern-match | Captures the part of a string matching a pattern. |
| pattern-replace | Replaces the part of a string matching a pattern. |
| pattern-test | Outputs true when a pattern is present in the string. |
| rate-of-change | Outputs the change between samples divided by the time between them. |
| reject | Removes elements matching a test from an array. |
| resample | Resamples a stream to a fixed sample rate. |
| rising-edge | Emits an event pulse on each low-to-high transition. |
| source | Names the data source — pin, register, tag, or another variable — that feeds the chain. |
| state | Emits a constant value based on a series of expression tests, like an if/else-if/else. |
| threshold | Converts a numeric value to digital high or low at a cutoff. |
| to-buffer | Converts a value into a binary buffer. |
| toggle | Flips between true and false on each rising edge. |
| trim | Removes whitespace and non-printable characters from both ends of a string. |
| value-change | Emits an event pulse each time the value changes. |
| value-decrease | Emits an event pulse each time the value decreases. |
| value-increase | Emits an event pulse each time the value increases. |
| value-increase-diff | Emits the size of each increase, then returns to zero. |
| when-unavailable | Substitutes a value when the input is UNAVAILABLE. |
| window-count | Counts the events seen within a trailing time window. |