Tuesday, June 20, 2023

Buttons – Appearance, State, and Action

A custom button in Artisan is specified by a name, an event type and value, an action as well as button and text colors (see Events, Buttons Palettes). There can be as many buttons as you like. Additionally, each button has an appearance (normal/pressed) and a state. State and appearance are disconnected by default, but can be connected via button actions.

Artisan versions before 2.8.4 marked the appearance of the last button pressed by inverting its text and button color. The latest Artisan version adds the new flag Mark Last Pressed to the buttons tab of the events dialog (menu Config >> Events, 2nd tab). Uncheck the flag if this behavior interferes with the intended appearance of buttons using the new button action extensions described below.

The command button() toggles the state of the button as well as its visual appearance and is available as MODBUS/S7/WebSocket/IO/Artisan Command action. Note that button actions can be sequenced using a semicolon which allows a button not only to invert its state but also to send out some control commands.

The button command accepts one boolean argument to explicitly set the button state or alternatively two arguments, where the first indicates the button number to be affected and the second argument its new state/appearance.

The following example defines one button that toggles the button state (bound to $) and sends it out to register 2 on MODBUS slave 1 on activation. All buttons start with state 0 (false) and toggle to 1 (true). Pressing this button also toggles its visual appearance. The \t part of the button label specification \t\n\3 is substituted by the event type (here Brenner, the German translation of Burner), the \n introduces a newline and the \3 is substituted by the translation of ON (here you see the German translation EIN) if the button state is 0 and OFF (AUS in German). A list of all button substitutions and actions can be found on the button help page accessible from the Help button in the button tab.

The second example shows how to use the two argument variant of the button command to link two buttons.

The new button state can be set based on an external state as received on communication as well. Here the buttons reflect the state of the external actors. Note that in commands, the placeholder _ is substituted by the result of the last IO Command and calculations like the negation (here via the not operation) can be applied.