Operators
Filtering
Operations that output a subset of their input items.
- Drop Output all input items except the first
n - Take Output only the first
ninput items. - Dedup Output every input item that is not equal to the previous input item.
- Dedup (expiring) Output the input item if it is not equal to the previous input or it has been more than
millimilliseconds since the last output. - Debounce Outputs each input after
millismilliseconds if no other input has been received. - Throttle Rate limits the input stream to average at most one value per
millismilliseconds. It functions by outputing the first input received (if any) in successive windows ofmillismilliseconds. - Sample Generates a stream of values with the latest value from its input stream every
millismilliseconds. - Over Output only input items greater than
threshold. - Under Output only input items less than
threshold. - AtLeast Output only input items greater than or equal to
threshold. - AtMost Output only input items less than or equal to
threshold. - Positive Output only input items that are greater than 0.
- Negative Output only input items that are less than 0.
- Zero Output only input items that are less than 0.
- True Output only input items equal to true.
- False Output only input items equal to false.
- Filter For each input item, apply the given function and output the input if the function returns true.
Transformation
Operations that transforms each input item to produce an output item.
- Const For each input item, output
value. - Abs For each input item, output it's absolute value.
- Scale For each input item, output
k× input value. - Add For each input item, output
b+ input value. - Clamp For each input item, output
loif the input is less thanlo,hiif the input more thanhi, or the input value if it is betweenloandhi. - ClampLow For each input item, output the maximum of the input value or
lo. - ClampHigh For each input item, output the minimum of the input value or
hi. - IsOver Output true for each input item greater than
thresholdotherwise false. - IsUnder Output true for each input item less than
thresholdotherwise false. - IsAtLeast Output true for each input item greater than or equal to
thresholdotherwise false. - IsAtMost Output true for each input item less than or equal to
thresholdotherwise false. - IsPositive Output true for each input item that is greater than 0 otherwise false.
- IsNegative Output true for each input item that is less than 0 otherwise false.
- IsZero Output true for each input item that is less than 0 otherwise false.
- Toggle On the first input, output !
initialand thereafter output ! previous output. - Project1 For each tuple input item, output the 1st element of the tuple
- Project2 For each tuple input item, output the 2nd element of the tuple
- Project3 For each tuple input item, output the 3rd element of the tuple
- Counted For each tuple input item, output a tuple with the input item and total number of inputs seen.
- Map For each tuple input item, apply the given
functionto the input and output the returned value.
The signature of function is
out-type function(const in-type&)
- Map (no copy) For each tuple input item, call the given
functionwith the input and result and output the result.
The signature of function is
void function(const in-type&, out-type&)
- Scan The scan operator keeps a state of
state-typewhich is initiallyinit. For each input item, the givenfunctionis called with the input item and the current state as arguments. The returned value is output and becomes the new state.
The function signature of the update function is
state-type update(const in-type&, const state-type&)
- Scan (no copy) The scan operator keeps a state of
state-typewhich is initialized byinitfunction (optional). For each input item, the givenupdatefunction is called with the input item and the current state as arguments. The update can modify the state argument and the new state is the output of the operator.
The function signature of the update function is
void update(const in-type&, state-type&)
and the function signature of the init funciton is
void init(state-type&)
Aggregation
Operators that aggregate or summarize information from multiple items in output items.
- Count For each item received, output the total number of items received since the start.
- WinSum Outputs the sum of a
widthsize sliding window over the input stream. - SumOf Outputs the sum of each batch of
countinput items. - SumOver Outputs the sum of each batch of input items received over
millismilliseconds. - WinAverage Outputs the average of a
widthsize sliding window over the input stream. - AverageOf Outputs the average of each batch of
countinput items. - AverageOver Outputs the average of each batch of input items received over
millismilliseconds. - WinMin Outputs the minimum of a
widthsize sliding window over the input stream. - MinOf Outputs the minimum of each batch of
countinput items. - MinOver Outputs the minimum of each batch of input items received over
millismilliseconds. - WinMax Outputs the maximum of a
widthsize sliding window over the input stream. - MaxOf Outputs the maximum of each batch of
countinput items. - MaxOver Outputs the maximum of each batch of input items received over
millismilliseconds.
String operators
- Lines Output a stream of lines (strbuf class) from an input stream of characters (char).
- Format Build a formatted string from input items using the
formattemplate. Any occurrence of$1in the template is replaced by the input value. Occurrences of$tare replaced by the current time as a Unix timestamp (number of seconds since Jan. 1, 1970). - Split Splits each input string at the given
delimiterand outputs the resulting strings in a vector. The C++ types arestrbufinput andVec<strbuf,max-fields>output. - ToString Converts the input values to a string and outputs it as a
strbuf - ToJson Converts the input values to a JSON string and outputs it as a
jsons
Miscellaneous
- Iterate Generates a stream of values from a generator (e.g.
Range). The values are generated one everymillismilliseconds. Ifrepeatis true then the iterater will start over with the 1st value after it reaches the last. The millis and repeat parameters are optional with defaults 0 and false respectively. - Poll Generates a stream of values from an input by polling the current value every
millismilliseconds. - Build This operator replaces the scan -> filter -> map pattern with a single operator and also only allocates one result object at creation time. The operator keeps a state of
state-typewhich is initiallyinit. For each input item, the givenfunctionis called with the input item and the current state and result as reference arguments. If the function returns true, the current value of result is output otherwise nothing is output.
Classes
Generators
Classes that generated data on demand (e.g. via Iterate)
- Range Generates integers in the range
fromtotobyincrement. The increment is optional and defaults to 1. Combine withIterateto generate a stream.
Producers
Classes that produce a stream of data
Inputs
Classes that receive or sample input data
- AnalogIn Reads analog values from an ADC
pin. - BitIn Reads values from a digital
pin. - GpioSerial Reads serial input from
rxPinand outputs char values. AtxPinis required, and will be put in output mode, but is never set.
Outputs
Classes that send or output data
- AnalogOut Writes values to a PWM
pin. - BitOut Writes values to a digital
pin. - Console C++: Writes value to the serial output at the given
baud. Javascript: Writes value to the console. - HttpPost Sends data to an HTTP endpoint using the HTTP POST method using transport (e.g. an instance of WiFiClient). Optional headers are provided as n array of strings.
- MqttPub Publishs data to an MQTT endpoint with QOS 0. The username, password, and keepAlive parameters are optional.
- SocketIO Sends data to a WebSocket via the socket.io module
iowith the event nameevent.
Consumers
- Consume Calls the function for each input value with that value as an argument.
Methods
Configuration
Functions for device/system configuration.
- ConnectWifi Connect to a WiFi access point with the given
ssidandpassword. - NetworkTime Set the date/time using an Internet time server with the given
transport(e.g. aWiFiClient) - Sleepy The
Sleepyfunction enables automatic sleep management on both AVR and Atmel SAMD (ARM) devices. When sleep management is enabled, the scheduler will attempt to put the CPU in sleep/standby mode whenever there is 2 seconds or more before the next scheduled event. Tests on both architectures showed slightly over 2mA current draw while sleeping, which is probably a 1/10th or less of your awake mode usage.
The sleep manager uses the RTC on SAMD architectures and the
WDT on AVR. Sleepy can be called from the beginning or
end of the app function to enable sleep management. If
you set the RTC time during setup, you must do that before
calling Sleepy.
The resolution of both the RTC and WDT is 1 second. Using even second values in your program schedule will minimize the amount of time the CPU will be idle between the time it wakes and the next event happens.
USB Interaction - The USB interface tends to interfere
with applications using sleep mode, and it is disabled by
default when you enable sleep management. I recommend using
the SPI interface for output when using sleep mode. If you
must use the USB you can call Sleepy with the
SLEEP_MGR_USB argument to enable the management of the
USB. In this case, the USB will be detached before sleeping
and reattached upon wake up.