Events Programming

From HSYCO
Revision as of 14:24, 30 January 2014 by Hsyco (talk | contribs) (→‎Comments)
Jump to navigation Jump to search

The EVENTS programming environment is based on a simple language that associates one or more actions to a field event or combination of conditions.

Programming EVENTS is as simple as editing the events.txt file, located in the main directory. Compared to Java, there is no compilation process. When you save the file, it is automatically reloaded and becomes immediately effective.

An event is an expression that refers to the persistent status or transient event of devices, to conditions applied to local variables, and to various internal events. An action is a control command sent to a device, or several other internal functions, like setting variables and program timers.

Example:

IO k.33 = 1 : k.34 = 1

when the light actuator with data point name k.33 is turned on, HSYCO automatically turns on the actuator with data point name k.34.

Example:

DAY : IO k.33 k.34 k.35 k.36 = 0

at sunrise, the actuators named k.33, k.34, k.35 and k.36 are turned off.

In this chapter we will describe the general format of events.txt, and all the built-in events and actions.

The events.txt file is usually modified with the text editor in HSYCO’s File Manager. When you save the file, it is automatically checked and, if errors are found, a warning icon appears in the top bar.

Touch that icon to show the list of errors. Errors are also written in the log file. Lines containing errors are ignored.

Events editor errors.png

You can also enable the editor’s syntax highlighter for improved readability.

Events editor highlighting.png

The EVENTS Language

EVENTS uses the simple format:

event : actions

Several events can be combined together to implement complex expressions which represent the combination of different conditions.

The logical operators AND, OR, NOT and the round brackets are available to define the operations precedence.

If the brackets are not used, the AND and OR operations are executed from left to right. The NOT operator has priority and is executed on the first expression after it, before AND or OR conditions.

Example:

IO k.33 OR IO K.34

this event occurs any time the actuators 33 or 34 change their status.

Example:

CAMERA "entrance" AND NOT IO K.34 = 0

is an event that occurs when the camera “entrance” starts recording, but only if the K.34 datapoint is not 0.

Example:

IO k.33 > 5 OR IO K.34 = 0 AND IO K.35 = 0

is equivalent to

(IO k.33 > 5 OR IO K.34 = 0) AND IO K.35 = 0

Example:

NOT IO k.33 = 1 AND IO k.34 = 1

is equivalent to

(NOT IO k.33 = 1) AND IO k.34 = 1

Comments

Comments are vital to describe the functions, even if the EVENTS language is very easy to understand.

A comment is identified by the # character.

All characters following # will be ignored until the end of line, unless the # character is enclosed between double quotes.

Example:

# actions executed at sunset
NIGHT:
IO k.33 k.34 k.35 k.36 = 1, # garden lights on
IO k.43 k.44 = UP, 			 # rise the awnings
LOG = "# and this is not a comment"

Other General Rules

Keywords are case insensitive. Devices ids are also case insensitive. The EVENTS interpreter converts all ids to lower case, so it is recommended to use only lower case ids in hsyco.ini if you use EVENTS.

The built-in constant values (ON, OFF, UP, DOWN, STOP, FLIP, RECON, RECOFF, MERGE, UNMERGE, PLAY) can be written in capital letters or in lower case. All other custom values will retain the case.

Example:

IO k.43 = UP and IO k.44 = DOWN : CAMERA cam1 = 60

is equivalent to:

io k.43 = up AND io k.44 = down : camera cam1 = 60

Example:

IO k.36 = 1 : UISET message.text = "Stairs light ON"

The text “Stairs light ON” remains unchanged.

Spaces and not-relevant tabulation characters are ignored.

In some cases separation spaces are not necessary:

IO k.36=1 

is a valid expression, while

IOk.36 = 1 

is not valid because the keywords must be separated by their attributes.

The EVENTS interpreter tries to understand strings even when not enclosed in double quotes, but we consider a good practice to always use double quotes to delimit text strings, and this may even become mandatory in future releases.

Example:

IO k.36 = 1 : LOG = "I turn on the light: 36"