Documentation > nControl > API Reference
Generic Tile
nControl™ 2021.0
Generic tiles are intended to create custom operations.

Introduction
Generic tiles have a number of 'states', for example, a traffic light tile would have three states: green, yellow and red. By clicking the generic tile it automatically moves to the next state.
Event Scripts
Generic tiles support the following event scripts:
  • Activate tile event: is executed when the tile is activated by switching to simulation of operational mode.
  • Deactivate tile event: is executed when the tile is deactivated by switching to design of configuration mode.
  • Mouse click event: is executed when the user press the mouse on the tile.
  • Mouse release event: is executed when the user releases the mouse on the tile.
  • MQTT event: is executed when the tile receives an MQTT message.
API Functions
Tile Specific Functions
nGenericTile.addMouseClickZone(vertexList)
Defines new mouse click zone for the tile. The zone is specified by the vertexList variable. This variable contains a list with the x and y coordinates of the vertices of the polygon that encircles the mouse click zone. For example, [0, 0 , 10, 0, 10, 20, 0 20] specifies a rectangle of 10 pixels wide and 20 pixel high in the upper left corner of the tile. The generic tiles are 150 pixels wide and 200 pixel high.
nGenericTile.clickTile(zone)
Simulates a mouse click on the tile; this executes the mouse click event script. The argument zone specifies the mouse click zone where the virtual click appeared:
  • zone = 0: simulates a click on a region of the tile that is not part of any mouse click zone
  • zone = 1: simulates a click inside mouse click zone 1
  • zone = 2: simulates a click inside mouse click zone 2
  • zone = 3: ...
nGenericTile.getMessageData()
Returns the data of the last MQTT message that was received.
nGenericTile.getMessageTopic()
Returns the topic of the last MQTT message that was received.
nGenericTile.getMouseClickZone()
Returns the index of the mouse click zone of the last click on the tile. A zero value indicates that the click was outside the defined mouse click zones.
nGenericTile.getState()
Returns the index of the current state of the tile.
nGenericTile.publish(topic, data)
Publishes a message through the internal MQTT broker using the specified topic and data.
nGenericTile.showMouseClickZones()
Specifies whether to show the mouse click zones or not. Showing the mouse click zones is handy during the design of the generic tile.
nGenericTile.subscribe(topic)
Subscribes the tile to receive all MQTT messages with the specified topic.
nGenericTile.tapTile()
Obsolete. Has been replaced by clickTile().
Inherited from nTile
nGenericTile.clearScreen()
Clear all the text in the console window.
nGenericTile.getTile(label)
Returns the tile object specified by label. If there is no tile with the specified label, the function returns a None value.
nGenericTile.print(text)
Prints text in the console window. If the console window it not yet visible, printing text will make it visible.
nGenericTile.showConsole(mode)
Shows (mode = True) or hides (mode = False) the console window.
nGenericTile.sleep(duration)
Stops the execution of the script for the the given number of seconds. Note that duration can be a floating point number, e.g. to suspend the script for half a seconds use self.sleep(0.5).
nGenericTile.timestamp()
Returns the number of seconds that passed since nControl™ was launched. It returns a floating point value with the highest possible time resolution supported by your system. The difference between two time stamps provides the number of seconds elapsed between those two events.
nGenericTile.localVars
Base property to which you can add local variables that retain their value after the event script finishes. For example self.localVars.myVar = 5 adds a new property myVar to self.localVars and gives it the value 5. The localVars property is local to the current tile meaning that each tile has its own independent localVars property.
nGenericTile.globalVars
Base property to which you can add global variables that retain their value after the event script finishes. For example self.globalVars.myVar = 5 adds a new property myVar to self.globalVars and gives it the value 5. The globalVars property is global to nControl meaning that all tiles use the same globalVars property. As such globalVars can be used to exchange information between the tiles.