Numeric Expressions

tyckr uses numeric expressions to evaluate the value for a facelet or provider input from the (raw) output of one or more providers. For example, the battery provider gives an output value from 0 - 100 as battery level and a circular marker needs an input angle from 0 - 360. So a simple expression like

range(A, 0, 100, 0, 360)

converts the output to the according input range. Color values may be an expression result as well.

An invalid expression always returns NaN, Not A (valid) Number.

Examples
  • The environment provider gives the ambient pressure in millibar and a gauge (range 0-100) should display the range from 980 to 1020 mbar. The expression of the gauge input looks like:

    range(A, 980, 1020, 0, 100)

    a is the output of the first gauge input provider (A), 980 is mapped to 0 and 1020 is mapped to 100 for the gauge input

  • A time second display should be yellow for even seconds (0,2,4…​58) and red for odd seconds (1,3,5…​59). The expression of the text color input for the seconds text may look like:

    floor(time / 1000) % 2 == 1 ? color_yellow : color_red

The following operators, constants, variables and functions are available in expressions:

Operators

Precedence is from top to bottom of the table below, higher precedence is evaluated first.

Operator Description

+, -, *, /

Mathematical operators

%

Modulo, returns the remainder of a division

^

Exponentiation

&&, ||, !

Logical 'and', 'or', 'not' operators

and, or, not

Logical 'and', 'or', 'not' operators (alternative names)

==, !=

Equality operators

<, >, , >=

Comparison operators

x ? a : b

Ternary operator, if x is true it returns a, else b

true, false

Boolean 'true' and 'false'


Numbers

Number Description

123

Decimal integer

123.456

Decimal number with fraction

#FFAA

Hexadecimal number


Constants

The following constants are defined.
utc and time are updated when the expression is evaluated.

Constant Description

pi

Pi, approx. 3.14159

e

Euler’s number, approx. 2.71828

nan

Not a number, undefined result

utc

UTC time in epoch milliseconds (milliseconds since 1970)

time

Local time (using the system timezone) in epoch milliseconds

color_none

Color #00000000 (transparent)

color_black

Color #FF000000

color_dkgray

Color #FF444444

color_ltgray

Color #FFCCCCCC

color_gray

Color #FF888888

color_white

Color #FFFFFFFF

color_red

Color #FFFF0000

color_green

Color #FF00FF00

color_blue

Color #FF0000FF

color_yellow

Color #FFFFFF00

color_cyan

Color #FF00FFFF

color_magenta

Color #FFFF00FF

color_ltlime

Color #FFAEFD6C

color_orange

Color #FFFF9933

myfaceconst

A constant defined in the face settings with the name "My Face Const"


Variables

The expression can use the output of a provider as a variable, using letter 'a' for the first provider in the provider value list, 'b' for the second one and so on:

Variable Description

a

Output of the first Provider (A)

b

Output of the second Provider (B)

c

Output of the third Provider (C)

d

Output of the fourth Provider (D)


Functions

Name Description

acos(x)

Arccosine

asin(x)

Arcsine

atan(x)

Arctangent

atan2(y,x)

2-argument Arctangent

cos(x)

Cosine

cosh(x)

Hyperbolic Cosine

sin(x)

Sine

sinh(x)

Hyperbolic Sine

tan(x)

Tangent

tanh(x)

Hyperbolic Tangent

deg(x)

Convert radians to degree

rad(x)

Convert degree to radians

ln(x)

Natural logarithm

log(x, base)

Logarithm

exp(x)

Computes Euler’s number e raised to the power of x

sqrt(x)

Square root of x

avg(a1,a2,a3,…​,an)

Average of at least N values

sum(a1,a2,a3,…​,an)

Summation of at least N values

max(a1,a2,a3,…​,an)

Maximum of at least N values

min(a1,a2,a3,…​,an)

minimum of at least N values

abs(x)

Absolute value, cuts off the sign

round(x)

Round x to the nearest integer

trunc(x)

Truncate, cuts off the fraction part of x

ceil(x)

Ceiling function, rounds x to an integer towards positive infinity

floor(x)

Floor function, rounds x to an integer towards negative infinity

sign(x)

Returns the sign of x, -1 if x is negative, 0 if x is zero, 1 if x is positive

if(x,a,b)

'If' function, same as the Ternary operator, if x is true it returns a, else b

rnd(x)

'Random' function, returns a random value in the range from 0 (inclusive) to x (exclusive)

range(x,i1,i2,o1,o2)

Range function, converts x from the input range i1 - i2 to the output range o1 - o2

limit(x,i1,i2)

Limit function, limits x in the range from i1 (inclusive) to i2 (inclusive)

rgb(r,g,b)

Returns an opaque color of the red, green and blue components

rgba(r,g,b,a)

Returns a color of the red, green and blue components and alpha (0 is transparent, 255 is opaque)

blend(c1,c2,ratio)

Returns a blended vivid color of the two colors c1 and c2.
c1 if ratio is 0, c2 if ratio is 100. This function uses a gain factor to produce vivid colors

blend2(c1,c2,ratio)

Returns a blended accurate color of the two colors c1 and c2. c1 if ratio is 0, c2 if ratio is 100

bwcol(c1)

Black/White Color function that returns a black (c1 is bright) or white (c1 is dark) color depending of c1

stcol(st)

Status Color function that returns the status color of st (0-5)

lpf(x,tau,delta)

Low Pass Filter function of x, where tau is a millisecond constant (1 / cutoff frequency [Hz]) and delta is time in milliseconds between two samples, if 0, delta time is measured

hold(x,mode,sus,rel)

Function to hold the minimum/maximum of the value x for the sustain (sus) time in milliseconds. Release (rel) is the release rate in [units / milliseconds]. If mode is 0 it holds the minimum value, 1 for the maximum value.


Format

Using a numeric expression as a text (Text field empty or $X), a format string can be used to format the output value.
The default format string is a combination of the following characters:

0,;**### m

Minimum integer digits are 0, fraction separator is ,, grouping is used, minimum fraction digits are 2, maximum fraction digits are 3 and a metric symbol representation is used.

If the format string is empty, the default is used:

0.##

Minimum integer digits are 0, fraction separator is ., minimum fraction digits are 0, maximum fraction digits are 2.

Name

Description

0

Minimum integer digits (count of 0)

, .

Fraction separator (can be , or .)

*

Minimum fraction digits (count of *)

#

Maximum fraction digits (count of #)

;

Use grouping like 1.000,00 if present

m

Use metric symbol representation (1000 used for units) if present, symbols are k, M, G, T, P, E

b

Use binary symbol representation (1024 used for units) if present, symbols are K, M, G, T, P, E

` m`

Use spacing between value and symbol if present