SEAL Functions: Difference between revisions
No edit summary |
mNo edit summary |
||
| Line 4: | Line 4: | ||
Naming convention used in this document: |
Naming convention used in this document: |
||
* Sensor value |
* Sensor value – name of a SEAL sensor. |
||
* |
* Scalar value – a predefined constant, a variable, or an integer literal. |
||
| Line 21: | Line 21: | ||
'''Example syntax:''' |
'''Example syntax:''' |
||
# <code>sum(Light, Humidity, -12)</code> |
# <code>sum(Light, Humidity, -12)</code> – calculates sum of last light sensor reading with last humidity sensor reading and -12 (i.e. subtracts 12). |
||
# <code>sum(take(Light, 10))</code> |
# <code>sum(take(Light, 10))</code> – calculates sum of last 10 light sensor readings |
||
=== plus(value1, value2) === |
=== plus(value1, value2) === |
||
| Line 32: | Line 32: | ||
'''Synonym:''' <code>add</code> |
'''Synonym:''' <code>add</code> |
||
'''Example syntax:''' <code>plus(Light, Humidity)</code> |
'''Example syntax:''' <code>plus(Light, Humidity)</code> – calculates sum of light and humidity sensor readings |
||
=== minus(value1, value2) === |
=== minus(value1, value2) === |
||
| Line 42: | Line 42: | ||
'''Synonym:''' <code>subtract</code> |
'''Synonym:''' <code>subtract</code> |
||
'''Example syntax:''' <code>minus(Light, Humidity)</code> |
'''Example syntax:''' <code>minus(Light, Humidity)</code> – calculates value of the expression: light sensor reading - humidity sensor reading. |
||
=== times(value1, value2) === |
=== times(value1, value2) === |
||
| Line 52: | Line 52: | ||
'''Synonym:''' <code>multiply</code> |
'''Synonym:''' <code>multiply</code> |
||
'''Example syntax:''' <code>times(Light, 3)</code> |
'''Example syntax:''' <code>times(Light, 3)</code> – calculates value of light sensor reading multiplied by three. |
||
=== divide(value1, value2) === |
=== divide(value1, value2) === |
||
| Line 60: | Line 60: | ||
'''Arguments:''' sensor values or scalars. |
'''Arguments:''' sensor values or scalars. |
||
'''Example syntax:''' <code>divide(Light, 3)</code> |
'''Example syntax:''' <code>divide(Light, 3)</code> – calculates value of light sensor reading divided by three and rounded down to the nearest integer. |
||
=== modulo(value1, value2) === |
=== modulo(value1, value2) === |
||
| Line 68: | Line 68: | ||
'''Arguments:''' sensor values or scalars. |
'''Arguments:''' sensor values or scalars. |
||
'''Example syntax:''' <code>modulo(Random, 3)</code> |
'''Example syntax:''' <code>modulo(Random, 3)</code> – calculates the remainder of a random number value divided by three. |
||
=== difference(value1, value2) === |
=== difference(value1, value2) === |
||
| Line 84: | Line 84: | ||
'''Argument:''' a sensor value or a scalar. |
'''Argument:''' a sensor value or a scalar. |
||
'''Example syntax:''' <code>abs(Temperature)</code> |
'''Example syntax:''' <code>abs(Temperature)</code> – calculate the absolute valute of temperature sensor reading |
||
=== neg(value) === |
=== neg(value) === |
||
| Line 92: | Line 92: | ||
'''Argument:''' a sensor value or a scalar. |
'''Argument:''' a sensor value or a scalar. |
||
'''Example syntax:''' <code>neg(Humidity)</code> |
'''Example syntax:''' <code>neg(Humidity)</code> – calculate the negation valute of humidity sensor reading |
||
=== invert(value) === |
=== invert(value) === |
||
| Line 100: | Line 100: | ||
'''Argument:''' a sensor value or a scalar. |
'''Argument:''' a sensor value or a scalar. |
||
'''Example syntax:''' <code>invert(Random)</code> |
'''Example syntax:''' <code>invert(Random)</code> – evaluates to true if the last random number is zero. |
||
=== square(value) === |
=== square(value) === |
||
Square |
Square – second power. |
||
'''Argument:''' a sensor value or a scalar. |
'''Argument:''' a sensor value or a scalar. |
||
'''Example syntax:''' <code>square(Random)</code> |
'''Example syntax:''' <code>square(Random)</code> – calculate the square of the last random number. |
||
=== sqrt(value) === |
=== sqrt(value) === |
||
| Line 116: | Line 116: | ||
'''Argument:''' a sensor value or a scalar. |
'''Argument:''' a sensor value or a scalar. |
||
'''Example syntax:''' <code>sqrt(Random)</code> |
'''Example syntax:''' <code>sqrt(Random)</code> – calculates the square root of the last random number rounded to the nearest integer. Depending on the implmentation, approximate values may be returned! |
||
=== power(base, exponent) === |
=== power(base, exponent) === |
||
| Line 124: | Line 124: | ||
'''Arguments:''' base is a sensor value or a scalar, exponent must be scalar. |
'''Arguments:''' base is a sensor value or a scalar, exponent must be scalar. |
||
'''Example syntax:''' <code>power(Random, 3)</code> |
'''Example syntax:''' <code>power(Random, 3)</code> – calculate the cube of the last random number. |
||
== Data aggregation functions == |
== Data aggregation functions == |
||
| Line 139: | Line 139: | ||
'''Example syntax:''' |
'''Example syntax:''' |
||
# <code>min(Light, 10)</code> |
# <code>min(Light, 10)</code> – calculate the minimum of light sensor reading and the number 10; |
||
# <code>min(take(Light, 100))</code> |
# <code>min(take(Light, 100))</code> – calculate the minimum of the last 100 light sensor readings. |
||
=== max(value, ...) === |
=== max(value, ...) === |
||
| Line 153: | Line 153: | ||
'''Example syntax:''' |
'''Example syntax:''' |
||
# <code>max(Light, 10)</code> |
# <code>max(Light, 10)</code> – calculate the maximum of the light sensor reading and the number 10; |
||
# <code>max(take(Light, 100))</code> |
# <code>max(take(Light, 100))</code> – calculate the maximum of the last 100 light sensor readings. |
||
=== average(value) === |
=== average(value) === |
||
| Line 167: | Line 167: | ||
'''Example syntax:''' |
'''Example syntax:''' |
||
# <code>average(Light)</code> |
# <code>average(Light)</code> – calculate the average of light sensor readings during program's execution; |
||
# <code>average(take(Light, 100))</code> |
# <code>average(take(Light, 100))</code> – calculate the average of the last 100 light sensor readings. |
||
=== stdev(value) === |
=== stdev(value) === |
||
| Line 181: | Line 181: | ||
'''Example syntax:''' |
'''Example syntax:''' |
||
# <code>stdev(Light)</code> |
# <code>stdev(Light)</code> – calculate the standard deviation of light sensor readings during program's execution; |
||
# <code>stdev(take(Light, 100))</code> |
# <code>stdev(take(Light, 100))</code> – calculate the standard deviation of the last 100 light sensor readings. |
||
=== variance(value) === |
=== variance(value) === |
||
| Line 193: | Line 193: | ||
'''Example syntax:''' |
'''Example syntax:''' |
||
# <code>variance(Light)</code> |
# <code>variance(Light)</code> – calculate the variance of light sensor readings during program's execution; |
||
# <code>variance(take(Light, 100))</code> |
# <code>variance(take(Light, 100))</code> – calculate the variance of the last 100 light sensor readings. |
||
=== ewma(value, alpha) === |
=== ewma(value, alpha) === |
||
| Line 203: | Line 203: | ||
'''Example syntax:''' |
'''Example syntax:''' |
||
# <code>ewma(Light, 0.5)</code> |
# <code>ewma(Light, 0.5)</code> – calculate the exponential moving average of light sensor readings during program's execution with coefficient 0.5; |
||
# <code>ewma(take(Light, 100), 0.5)</code> |
# <code>ewma(take(Light, 100), 0.5)</code> – calculate the same, but for the last 100 light sensor readings. |
||
=== changed(value) === |
=== changed(value) === |
||
| Line 213: | Line 213: | ||
'''Example syntax:''' |
'''Example syntax:''' |
||
#<code>changed(Light)</code> |
#<code>changed(Light)</code> – true if light sensor reading have changed during program's execution. |
||
#<code>changed(take(Light, 100))</code> |
#<code>changed(take(Light, 100))</code> – true if light sensor reading have changed during last 100 readings. |
||
#<code>changed(13)</code> |
#<code>changed(13)</code> – always false, because the value is constant. |
||
== Signal processing functions == |
== Signal processing functions == |
||
| Line 225: | Line 225: | ||
'''Arguments:''' 'value' is a sensor value or a scalar. The arguments 'fromRangeLow' and 'fromRangeHigh' are scalars that define the lower and upper bound of the range from which to map; the arguments 'toRangeLow' and 'toRangeHigh' are scalars that define the range to which to map. |
'''Arguments:''' 'value' is a sensor value or a scalar. The arguments 'fromRangeLow' and 'fromRangeHigh' are scalars that define the lower and upper bound of the range from which to map; the arguments 'toRangeLow' and 'toRangeHigh' are scalars that define the range to which to map. |
||
'''Example syntax:''' <code>map(Light, 0, 1023, 0, 255)</code> |
'''Example syntax:''' <code>map(Light, 0, 1023, 0, 255)</code> – map light sensor reading from range [0..1023] (10 bit range, e.g. ADC) to range [0..255] (eight bit range, e.g. for a variable of <code>char</code> type). |
||
=== sharpen(value, numSamples, weight) === |
=== sharpen(value, numSamples, weight) === |
||
| Line 231: | Line 231: | ||
Add contrast. |
Add contrast. |
||
'''Arguments:''' 'value' is a sensor value or a scalar. 'numSamples' (optional, default value 3) |
'''Arguments:''' 'value' is a sensor value or a scalar. 'numSamples' (optional, default value 3) – a scalar value that describes the number of samples to take. 'weight' (optional, default value 1) – a scalar value (can be florating point) that describes the amplitude of the sharpening. |
||
'''Synonym:''' <code>contrast</code> |
'''Synonym:''' <code>contrast</code> |
||
'''Example syntax:''' <code>sharpen(Light)</code> |
'''Example syntax:''' <code>sharpen(Light)</code> – add contrast to light sensor readings using the default values. |
||
| Line 242: | Line 242: | ||
Remove contrast. |
Remove contrast. |
||
'''Arguments:''' 'value' is a sensor value or a scalar. 'numSamples' (optional, default value 3) |
'''Arguments:''' 'value' is a sensor value or a scalar. 'numSamples' (optional, default value 3) – a scalar value that describes the number of samples to take. 'weight' (optional, default value 1) – a scalar value (can be florating point) that describes the amplitude of the bluring. |
||
'''Synonym:''' <code>blur</code> |
'''Synonym:''' <code>blur</code> |
||
'''Example syntax:''' <code>smoothen(Light)</code> |
'''Example syntax:''' <code>smoothen(Light)</code> – add blur to light sensor readings using the default values. |
||
== Filtering functions == |
== Filtering functions == |
||
| Line 256: | Line 256: | ||
'''Arguments:''' 'value' is a sensor value or a scalar. 'pattern' is the name of a predefined pattern in the source file. |
'''Arguments:''' 'value' is a sensor value or a scalar. 'pattern' is the name of a predefined pattern in the source file. |
||
'''Example syntax:''' <code>pattern P (0, 0, 0, 0); ...; match(Light, pattern)</code> |
'''Example syntax:''' <code>pattern P (0, 0, 0, 0); ...; match(Light, pattern)</code> – compare last four light sensor reading with four consecutive zeros and evaluate to True in case of match, False otherwise. |
||
=== filterRange(value, thresholdMin, thresholdMin) === |
=== filterRange(value, thresholdMin, thresholdMin) === |
||
| Line 264: | Line 264: | ||
'''Arguments:''' 'value' is a sensor value or a scalar. 'thresholdMin' and 'thresholdMin' are scalars that define the range [thresholdMin..thresholdMin]. |
'''Arguments:''' 'value' is a sensor value or a scalar. 'thresholdMin' and 'thresholdMin' are scalars that define the range [thresholdMin..thresholdMin]. |
||
'''Example syntax:''' <code>filterRange(Light, 1000, 2000)</code> |
'''Example syntax:''' <code>filterRange(Light, 1000, 2000)</code> – read only those light sensor values that are between 1000 and 2000, inclusive, and ignore the rest. |
||
=== filterEqual(value, threshold) === |
=== filterEqual(value, threshold) === |
||
| Line 270: | Line 270: | ||
'''Arguments:''' 'value' is a sensor value or a scalar. 'threshold' is a scalar. |
'''Arguments:''' 'value' is a sensor value or a scalar. 'threshold' is a scalar. |
||
'''Example syntax:''' <code>filterEqual(Light, 1000)</code> |
'''Example syntax:''' <code>filterEqual(Light, 1000)</code> – read only those light sensor values that are equal to 1000, and ignore the rest. |
||
=== filterNotEqual(value, threshold) === |
=== filterNotEqual(value, threshold) === |
||
| Line 276: | Line 276: | ||
'''Argument:''' 'value' is a sensor value or a scalar. 'threshold' is a scalar. |
'''Argument:''' 'value' is a sensor value or a scalar. 'threshold' is a scalar. |
||
'''Example syntax:''' <code>filterNotEqual(Light, 1000)</code> |
'''Example syntax:''' <code>filterNotEqual(Light, 1000)</code> – read only those light sensor values that are not equal to 1000, and ignore the rest. |
||
=== filterLess(value, threshold) === |
=== filterLess(value, threshold) === |
||
| Line 282: | Line 282: | ||
'''Argument:''' 'value' is a sensor value or a scalar. 'threshold' is a scalar. |
'''Argument:''' 'value' is a sensor value or a scalar. 'threshold' is a scalar. |
||
'''Example syntax:''' <code>filterLess(Light, 1000)</code> |
'''Example syntax:''' <code>filterLess(Light, 1000)</code> – read only those light sensor values that are less than 1000, and ignore the rest. |
||
=== filterLessOrEqual(value, threshold) === |
=== filterLessOrEqual(value, threshold) === |
||
| Line 288: | Line 288: | ||
'''Argument:''' 'value' is a sensor value or a scalar. 'threshold' is a scalar. |
'''Argument:''' 'value' is a sensor value or a scalar. 'threshold' is a scalar. |
||
'''Example syntax:''' <code>filterLessOrEqual(Light, 1000)</code> |
'''Example syntax:''' <code>filterLessOrEqual(Light, 1000)</code> – read only those light sensor values that are less than or equal to 1000, and ignore the rest. |
||
=== filterMore(value, threshold) === |
=== filterMore(value, threshold) === |
||
| Line 294: | Line 294: | ||
'''Argument:''' 'value' is a sensor value or a scalar. 'threshold' is a scalar. |
'''Argument:''' 'value' is a sensor value or a scalar. 'threshold' is a scalar. |
||
'''Example syntax:''' <code>filterMore(Light, 1000)</code> |
'''Example syntax:''' <code>filterMore(Light, 1000)</code> – read only those light sensor values that more than to 1000, and ignore the rest. |
||
=== filterMoreOrEqual(value, threshold) === |
=== filterMoreOrEqual(value, threshold) === |
||
| Line 300: | Line 300: | ||
'''Argument:''' 'value' is a sensor value or a scalar. 'threshold' is a scalar. |
'''Argument:''' 'value' is a sensor value or a scalar. 'threshold' is a scalar. |
||
'''Example syntax:''' <code>filterMoreOrEqual(Light, 1000)</code> |
'''Example syntax:''' <code>filterMoreOrEqual(Light, 1000)</code> – read only those light sensor values that are more than or equal to 1000, and ignore the rest. |
||
=== invertFilter(value) === |
=== invertFilter(value) === |
||
| Line 308: | Line 308: | ||
'''Argument:''' 'value' is a sensor value or a scalar |
'''Argument:''' 'value' is a sensor value or a scalar |
||
'''Example syntax:''' <code>invertFilter(filterRange(Light, 1000, 2000))</code> |
'''Example syntax:''' <code>invertFilter(filterRange(Light, 1000, 2000))</code> – read only those light sensor values that are NOT bewteen 1000 and 2000, inclusive, and ignore those that are. |
||
| Line 317: | Line 317: | ||
Take one or more sensor value. The values are read one at time, but the enclosing function is evaluated on all of them. At the start of program, the values that are not read yet are treated as zero. |
Take one or more sensor value. The values are read one at time, but the enclosing function is evaluated on all of them. At the start of program, the values that are not read yet are treated as zero. |
||
<code>take</code> can only be used in context of specific enclosing functions |
<code>take</code> can only be used in context of specific enclosing functions – those that are marked as aggregate. |
||
'''Arguments:''' 'value' is a sensor value. 'numberToTake' is a scalar value that describes the number of sensor values to read. 'timeToTake' (optional, default value is not specified) is the time period in which to limit the values. |
'''Arguments:''' 'value' is a sensor value. 'numberToTake' is a scalar value that describes the number of sensor values to read. 'timeToTake' (optional, default value is not specified) is the time period in which to limit the values. |
||
'''Example syntax:''' |
'''Example syntax:''' |
||
#<code>sum(take(Random, 100))</code> |
#<code>sum(take(Random, 100))</code> – calculate sum of 100 random numbers. |
||
#<code>sum(take(Light, 600, 1h))</code> |
#<code>sum(take(Light, 600, 1h))</code> – calculate sum of light sensor readings sampled in the last hour, and limit their count to six hundred (600). |
||
=== tuple(value, ...) === |
=== tuple(value, ...) === |
||
| Line 329: | Line 329: | ||
Read multiple, heterogenous sensor values. |
Read multiple, heterogenous sensor values. |
||
<code>tuple</code> can only be used in context of specific enclosing functions |
<code>tuple</code> can only be used in context of specific enclosing functions – those that are marked as aggregate. |
||
'''Argument:''' sensor values. |
'''Argument:''' sensor values. |
||
'''Example syntax:''' <code>tuple(Light, Temperature, Humidity)</code> |
'''Example syntax:''' <code>tuple(Light, Temperature, Humidity)</code> – read a tuple of light, temperature, and humidity sensor values. |
||
=== sync(value, ...) === |
=== sync(value, ...) === |
||
| Line 341: | Line 341: | ||
'''Arguments:''' sensor values. |
'''Arguments:''' sensor values. |
||
'''Example syntax:''' <code>sync(Light, Temperature, Humidity)</code> |
'''Example syntax:''' <code>sync(Light, Temperature, Humidity)</code> – synchronize light, temperature, and humidity sensor reading. |
||
Revision as of 08:28, 2 October 2012
Overview
All of the following functions are available from SEAL code.
Naming convention used in this document:
- Sensor value – name of a SEAL sensor.
- Scalar value – a predefined constant, a variable, or an integer literal.
Arithmetic functions
sum(value, ...)
Sum of one or more values.
Argument: a sensor value or a scalar.
Argument can be repeated zero to many times.
Aggregate function (i.e. can have take() as parameter).
Example syntax:
sum(Light, Humidity, -12)– calculates sum of last light sensor reading with last humidity sensor reading and -12 (i.e. subtracts 12).sum(take(Light, 10))– calculates sum of last 10 light sensor readings
plus(value1, value2)
Addition.
Arguments: sensor values or scalars.
Synonym: add
Example syntax: plus(Light, Humidity) – calculates sum of light and humidity sensor readings
minus(value1, value2)
Subtraction.
Arguments: sensor values or scalars.
Synonym: subtract
Example syntax: minus(Light, Humidity) – calculates value of the expression: light sensor reading - humidity sensor reading.
times(value1, value2)
Multiplication.
Arguments: sensor values or scalars.
Synonym: multiply
Example syntax: times(Light, 3) – calculates value of light sensor reading multiplied by three.
divide(value1, value2)
Division.
Arguments: sensor values or scalars.
Example syntax: divide(Light, 3) – calculates value of light sensor reading divided by three and rounded down to the nearest integer.
modulo(value1, value2)
The remainder in division.
Arguments: sensor values or scalars.
Example syntax: modulo(Random, 3) – calculates the remainder of a random number value divided by three.
difference(value1, value2)
Symmetrical difference.
Argument: sensor values or scalars.
Example syntax: difference(13, 14) calculates the absolute value of the difference between two values 13 and 14. Same as abs(minus(13, 14)).
abs(value)
Absolute value
Argument: a sensor value or a scalar.
Example syntax: abs(Temperature) – calculate the absolute valute of temperature sensor reading
neg(value)
Negation.
Argument: a sensor value or a scalar.
Example syntax: neg(Humidity) – calculate the negation valute of humidity sensor reading
invert(value)
Return the Boolean inverse of the value passed: True if the value is zero, False otherwise.
Argument: a sensor value or a scalar.
Example syntax: invert(Random) – evaluates to true if the last random number is zero.
square(value)
Square – second power.
Argument: a sensor value or a scalar.
Example syntax: square(Random) – calculate the square of the last random number.
sqrt(value)
Square root.
Argument: a sensor value or a scalar.
Example syntax: sqrt(Random) – calculates the square root of the last random number rounded to the nearest integer. Depending on the implmentation, approximate values may be returned!
power(base, exponent)
Exponentiation.
Arguments: base is a sensor value or a scalar, exponent must be scalar.
Example syntax: power(Random, 3) – calculate the cube of the last random number.
Data aggregation functions
min(value, ...)
Minimal value.
Argument: a sensor value or a scalar
Argument can be repeated one to many times.
Aggregate function (i.e. can have take() as parameter).
Example syntax:
min(Light, 10)– calculate the minimum of light sensor reading and the number 10;min(take(Light, 100))– calculate the minimum of the last 100 light sensor readings.
max(value, ...)
Maximal value.
Argument: a sensor value or a scalar
Argument can be repeated one to many times.
Aggregate function (i.e. can have take() as parameter).
Example syntax:
max(Light, 10)– calculate the maximum of the light sensor reading and the number 10;max(take(Light, 100))– calculate the maximum of the last 100 light sensor readings.
average(value)
Average value (the mean).
Argument: a sensor value or a scalar
Aggregate function (i.e. can have take() as parameter).
Synonym: avg
Example syntax:
average(Light)– calculate the average of light sensor readings during program's execution;average(take(Light, 100))– calculate the average of the last 100 light sensor readings.
stdev(value)
Standard deviation.
Argument: a sensor value or a scalar
Aggregate function (i.e. can have take() as parameter).
Synonym: std
Example syntax:
stdev(Light)– calculate the standard deviation of light sensor readings during program's execution;stdev(take(Light, 100))– calculate the standard deviation of the last 100 light sensor readings.
variance(value)
Signal variance.
Argument: a sensor value or a scalar
Aggregate function (i.e. can have take() as parameter).
Example syntax:
variance(Light)– calculate the variance of light sensor readings during program's execution;variance(take(Light, 100))– calculate the variance of the last 100 light sensor readings.
ewma(value, alpha)
Exponential moving average with coefficient alpha.
Arguments: 'value' is a sensor value or a scalar, 'alpha' is a scalar (including floating point) value.
Example syntax:
ewma(Light, 0.5)– calculate the exponential moving average of light sensor readings during program's execution with coefficient 0.5;ewma(take(Light, 100), 0.5)– calculate the same, but for the last 100 light sensor readings.
changed(value)
Calculate a Boolean value that describes whether the value has changed.
Argument: a sensor value or a scalar
Example syntax:
changed(Light)– true if light sensor reading have changed during program's execution.changed(take(Light, 100))– true if light sensor reading have changed during last 100 readings.changed(13)– always false, because the value is constant.
Signal processing functions
map(value, fromRangeLow, fromRangeHigh, toRangeLow, toRangeHigh)
Do mapping.
Arguments: 'value' is a sensor value or a scalar. The arguments 'fromRangeLow' and 'fromRangeHigh' are scalars that define the lower and upper bound of the range from which to map; the arguments 'toRangeLow' and 'toRangeHigh' are scalars that define the range to which to map.
Example syntax: map(Light, 0, 1023, 0, 255) – map light sensor reading from range [0..1023] (10 bit range, e.g. ADC) to range [0..255] (eight bit range, e.g. for a variable of char type).
sharpen(value, numSamples, weight)
Add contrast.
Arguments: 'value' is a sensor value or a scalar. 'numSamples' (optional, default value 3) – a scalar value that describes the number of samples to take. 'weight' (optional, default value 1) – a scalar value (can be florating point) that describes the amplitude of the sharpening.
Synonym: contrast
Example syntax: sharpen(Light) – add contrast to light sensor readings using the default values.
smoothen(value, numSamples, weight)
Remove contrast.
Arguments: 'value' is a sensor value or a scalar. 'numSamples' (optional, default value 3) – a scalar value that describes the number of samples to take. 'weight' (optional, default value 1) – a scalar value (can be florating point) that describes the amplitude of the bluring.
Synonym: blur
Example syntax: smoothen(Light) – add blur to light sensor readings using the default values.
Filtering functions
match(value, pattern)
Match sensor readings against a predefined patter.
Arguments: 'value' is a sensor value or a scalar. 'pattern' is the name of a predefined pattern in the source file.
Example syntax: pattern P (0, 0, 0, 0); ...; match(Light, pattern) – compare last four light sensor reading with four consecutive zeros and evaluate to True in case of match, False otherwise.
filterRange(value, thresholdMin, thresholdMin)
Threshold sensor readings against predefined lower and upper bounds.
Arguments: 'value' is a sensor value or a scalar. 'thresholdMin' and 'thresholdMin' are scalars that define the range [thresholdMin..thresholdMin].
Example syntax: filterRange(Light, 1000, 2000) – read only those light sensor values that are between 1000 and 2000, inclusive, and ignore the rest.
filterEqual(value, threshold)
Arguments: 'value' is a sensor value or a scalar. 'threshold' is a scalar.
Example syntax: filterEqual(Light, 1000) – read only those light sensor values that are equal to 1000, and ignore the rest.
filterNotEqual(value, threshold)
Argument: 'value' is a sensor value or a scalar. 'threshold' is a scalar.
Example syntax: filterNotEqual(Light, 1000) – read only those light sensor values that are not equal to 1000, and ignore the rest.
filterLess(value, threshold)
Argument: 'value' is a sensor value or a scalar. 'threshold' is a scalar.
Example syntax: filterLess(Light, 1000) – read only those light sensor values that are less than 1000, and ignore the rest.
filterLessOrEqual(value, threshold)
Argument: 'value' is a sensor value or a scalar. 'threshold' is a scalar.
Example syntax: filterLessOrEqual(Light, 1000) – read only those light sensor values that are less than or equal to 1000, and ignore the rest.
filterMore(value, threshold)
Argument: 'value' is a sensor value or a scalar. 'threshold' is a scalar.
Example syntax: filterMore(Light, 1000) – read only those light sensor values that more than to 1000, and ignore the rest.
filterMoreOrEqual(value, threshold)
Argument: 'value' is a sensor value or a scalar. 'threshold' is a scalar.
Example syntax: filterMoreOrEqual(Light, 1000) – read only those light sensor values that are more than or equal to 1000, and ignore the rest.
invertFilter(value)
Invert the effect of any previosly applied filters, or filter out the value if there were none.
Argument: 'value' is a sensor value or a scalar
Example syntax: invertFilter(filterRange(Light, 1000, 2000)) – read only those light sensor values that are NOT bewteen 1000 and 2000, inclusive, and ignore those that are.
Subset selection & special purpose functions
take(value, numberToTake, timeToTake)
Take one or more sensor value. The values are read one at time, but the enclosing function is evaluated on all of them. At the start of program, the values that are not read yet are treated as zero.
take can only be used in context of specific enclosing functions – those that are marked as aggregate.
Arguments: 'value' is a sensor value. 'numberToTake' is a scalar value that describes the number of sensor values to read. 'timeToTake' (optional, default value is not specified) is the time period in which to limit the values.
Example syntax:
sum(take(Random, 100))– calculate sum of 100 random numbers.sum(take(Light, 600, 1h))– calculate sum of light sensor readings sampled in the last hour, and limit their count to six hundred (600).
tuple(value, ...)
Read multiple, heterogenous sensor values.
tuple can only be used in context of specific enclosing functions – those that are marked as aggregate.
Argument: sensor values.
Example syntax: tuple(Light, Temperature, Humidity) – read a tuple of light, temperature, and humidity sensor values.
sync(value, ...)
Synchronize reading of multiple sensors.
Arguments: sensor values.
Example syntax: sync(Light, Temperature, Humidity) – synchronize light, temperature, and humidity sensor reading.