new Trigger(type, nameopt) → {Object}
Creates an event trigger object, which sets the trigger event and the method to be executed. When a Trigger is defined, setCallback is required for the Trigger to be valid, otherwise the Trigger object will not be created.
Supports:
Trigger(type, name)
Trigger(type)
Trigger("Image:SeekImage", <function>, {file: "<filename>.bmp"})
type:
- tcConst.TC_START: Total Control system starts;
- tcConst.TC_END: The Total Control system is stopped;
- tcConst.DEV_CONNECT: Device connection;
- tcConst.DEV_DISCONNECT: The device is disconnected;
Example
var { Trigger } = require("sigma/trigger");
// Create an event trigger listener function callTest.
function callTest() {
print("T start");
}
// Create an event trigger object of type "tcConst.TC_START" with name "T_Start_Trigger".
var t = new Trigger(tcConst.TC_START, "T_Start_Trigger");
// Call the event trigger listener function
t.setCallback(callTest);
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
type |
string | The subtype of the trigger (e.g., "Image:SeekImage", or type from tcConst) |
|
name |
string |
<optional> |
Optional parameters, the name of the event trigger. |
Returns:
Returns the trigger object if successful. If it fails, you can get the specific error message through the lastError() function.
- Type
- Object
Members
disable
Disable event triggers. The default state of the event trigger is true.
Example
var { Trigger } = require("sigma/trigger");
// Create listener function for event trigger
function callback1() {
print("this is test");
}
// Create an event trigger with type "tcConst.TC_START" and name "T_Start_Trigger".
var t = new Trigger(tcConst.TC_START, "T_Start_Trigger");
// Call listener function
t.setCallback(callback1);
// Enable event triggers.
t.enable();
// Disable event triggers.
t.disable();
// Get the status of the event trigger.
var mode = t.getMode();
print("The state of the trigger is: " + mode);
// If it executes successfully, it will return:
The state of the trigger is: false
enable
Enable event triggers. The default state of the event trigger is true.
Example
var { Trigger } = require("sigma/trigger");
// Create listener function for event trigger
function callback1() {
print("this is test");
}
// Create an event trigger with type "tcConst.TC_START" and name "T_Start_Trigger".
var t = new Trigger(tcConst.TC_START, "T_Start_Trigger");
// Call listener function
t.setCallback(callback1);
// Enable event triggers.
t.enable();
// Get the status of the event trigger.
var mode = t.getMode();
print("The state of the trigger is: " + mode);
// If it executes successfully, it will return:
The state of the trigger is: true
getMode
Gets the state of the event trigger. The default state of the event trigger is true.
Example
var { Trigger } = require("sigma/trigger");
// Create listener function for event trigger
function callback1() {
print("this is test");
}
// Create an event trigger with type "tcConst.TC_START" and name "T_Start_Trigger".
var t = new Trigger(tcConst.TC_START, "T_Start_Trigger");
// Call listener function
t.setCallback(callback1);
// Enable event triggers.
t.enable();
// Disable event triggers.
t.disable();
// Get the status of the event trigger.
var mode = t.getMode();
print("The state of the trigger is: " + mode);
// If it executes successfully, it will return:
The state of the trigger is: false
getName
Get the name of the event trigger. This name must be globally unique to the Total Control system.
Example
var { Trigger } = require("sigma/trigger");
// Create listener function for event trigger
function callback1() {
print("this is test");
}
// Create an event trigger object of type "tcConst.TC_START".
var t = new Trigger(tcConst.TC_START);
// Call listener function
t.setCallback(callback1);
// Set the name of the event trigger to ' T_Start_Trigger'.
t.setName("T_Start_Trigger");
// Get the name of the event trigger.
var name = t.getName();
print("Trigger name is :" + name);
// If it executes successfully, it will return:
Trigger name is :T_Start_Trigger
getSubtype
Get the event type of the trigger.
Example
var { Trigger } = require("sigma/trigger");
// Create listener function for event trigger
function callback1() {
print("this is test");
}
// Create an event trigger with type "tcConst.TC_START" and name "T_Start_Trigger".
var t = new Trigger(tcConst.TC_START, "T_Start_Trigger");
// Call listener function
t.setCallback(callback1);
// Get the event type of the event trigger.
var subtype= t.getSubtype();
print("The type of the trigger is: " + subtype);
// If it executes successfully, it will return:
The type of the trigger is: TC_START
setCallback
Add an event trigger listener function.
Example
// Example:The function callTest1, callTest2 is called when Total Control is connected to the phone.
var { Trigger } = require("sigma/trigger");
// Function: callTest1
function callTest1(device) {
print('callTest1: device ' + device.name + ' connect');
}
// Function: callTest2
function callTest2(device) {
print('callTest2: device ' + device.name + ' connect');
}
// Create an event trigger object of type "tcConst.DEV_CONNECT" with name "DeviceConnectTrigger".
var t = new Trigger(tcConst.DEV_CONNECT,"DeviceConnectTrigger");
// Call the function callTest1
t.setCallback(callTest1);
// Call the function callTest2
t.setCallback(callTest2);
// If it executes successfully, it will return:
callTest2: device HUAWEI-HUAWEI P7-L07 connect
callTest1: device HUAWEI-HUAWEI P7-L07 connect
setName
Set the event trigger name. This name must be globally unique to the Total Control system.
Example
var { Trigger } = require("sigma/trigger");
// Create listener function for event trigger
function callback1() {
print("this is test");
}
// Create an event trigger object of type "tcConst.TC_START".
var t = new Trigger(tcConst.TC_START);
// Call listener function
t.setCallback(callback1);
// Set the name of the event trigger to " my_T_Start_Trigger ".
t.setName("my_T_Start_Trigger");