Lua UI Methods
The Artok HMI uses a high-performance Lua 5.4 interpreter. All UI interactions are performed via the global UI table. When an event script runs, the global variable self is automatically populated with the handle of the widget that triggered the event.
🔍 Widget & Screen Management
UI.getWidget(identifier)
Finds a widget by its string ID (UUID). Returns a widget handle or nil.
- Example:
local my_btn = UI.getWidget("BTN_RUN")
UI.loadScreen(uuid)
Switches the active display to a new screen. The UUID string is automatically hashed (CRC32) to match internal memory.
UI.getScreen()
Returns the CRC32 hash of the currently active screen.
🛠 Basic Property Control
UI.setText(obj, text)
Sets the text for Labels or Text Areas.
UI.setValue(obj, value)
Sets the numeric value for Sliders, Bars, Arcs, and Gauges.
UI.getValue(obj)
Retrieves the current numeric value of a widget.
UI.setVisible(obj, boolean)
Shows or hides a widget.
🎨 Visuals & Assets
UI.setColor(obj, r, g, b)
Applies a color to text (for labels) or background (for objects).
- Example:
UI.setColor(self, 255, 0, 0)-- Set to Red
UI.setImage(obj, asset_uuid)
Swaps the image source of an Image widget using its asset UUID.
UI.setImageColor(obj, r, g, b, [opacity])
Tints an image asset. Useful for changing icon colors dynamically.
⏳ Logic & Data
UI.setTimeout(ms, function)
Runs a function once after a specified delay. Timers are lifecycle-safe and cleared automatically on screen transitions to prevent crashes.
UI.put(key, value) / UI.get(key)
Accesses the persistent Artok Data Store. This allows you to save variables (like user settings) that persist even if the screen changes.
UI.notify(event_name, [value])
Sends a JSON-formatted event back to the Host (Master) device.
- Output Format:
{"res":"notify","id":"NAME","val":1}