iRidi API. System
Functions, methods, and object properties for working with application startup, execution, shutdown, and operating system changes IR is the global object containing all iRidi API functions and constants. Its methods control system events in the iRidi application.
Methods
IR.ShowSystemMenu
Open the system menu. Executing the command opens the system menu.
Syntax
IR.ShowSystemMenu();
| Input | Value | Description |
|---|---|---|
| - |
| Output | ||
|---|---|---|
| - |
Example
function ShowMenu () {
IR.ShowSystemMenu();
};
IR.SetEnableSystemMenu
Disable / enable opening the system menu.
Syntax
IR.SetEnableSystemMenu();
| Input | Value | Description |
|---|---|---|
| mode | true | type: boolean * true - allow the system menu to open. * false - prevent the system menu from opening. |
| Output | ||
|---|---|---|
| - |
Example
function SystemMenu()
{
IR.SetEnableSystemMenu(true);
}
IR.GetEnableSystemMenu
Check whether the system menu can be opened.
Syntax
IR.GetEnableSystemMenu();
| Input | Value | Description |
|---|---|---|
| - |
| Output | ||
|---|---|---|
| mode | true | type: boolean * true - opening the system menu is allowed. * false - opening the system menu is prohibited. |
Example
`IR.Log(IR.GetEnableSystemMenu());`
IR.SetEnableProjectMenu
Disable / enable opening the i3 Pro project menu.
Syntax
IR.SetEnableProjectMenu();
| Input | Value | Description |
|---|---|---|
| - |
| Output | ||
|---|---|---|
| mode | true | type: boolean * true - allow the i3 Pro project menu to open. * false - prevent the i3 Pro project menu from opening. |
Example
function ProjectMenu()
{
IR.SetEnableProjectMenu(true);
}
IR.GetEnableProjectMenu
Check whether the system menu can be opened.
Syntax
IR.GetEnableSystemMenu();
| Input | Value | Description |
|---|---|---|
| mode | true | type: boolean * true - opening the i3 Pro project menu is allowed. * false - opening the i3 Pro project menu is prohibited. |
| Output | ||
|---|---|---|
| - |
Example
`IR.Log(IR.GetEnableProjectMenu());`
IR.ShowSettingsMenu
Open the i3 pro project selection sidebar on the specified tab
Syntax
IR.ShowSettingsMenu();
| Input | Value | Description |
|---|---|---|
| - |
| Output | ||
|---|---|---|
| - |
Example
function ShowMenu () {
IR.ShowSettingsMenu();
};
IR.SetFullScreen
Switch the application to full-screen mode (or return it to a window)
Syntax
IR.SetFullScreen(mode);
| Input | Value | Description |
|---|---|---|
| mode | true | type: boolean enable/disable full-screen mode * true - enable full-screen mode * false - disable full-screen mode |
| Output | ||
|---|---|---|
| - |
Example
`IR.SetFullScreen(true);`
Notes
- The method works only on Windows
IR.IsFullScreen
Check whether full-screen mode is enabled
Syntax
IR.IsFullScreen;
| Output | ||
|---|---|---|
| mode | true | type: boolean * true - full-screen mode is enabled * false - full-screen mode is disabled |
| - |
Example
`IR.Log(IR.IsFullScreen);`
Notes
- The method works only on Windows
IR.HWID
IR object property containing the HWID of the control panel running i3 pro.
Syntax
IR.HWID
| Input | Value | Description |
|---|---|---|
| - |
| Output | ||
|---|---|---|
| hwid | ff2c...1958 | type: string control panel HWID |
Example
IR.AddListener(IR.EVENT_START,0,function()
{
IR.Log("Panel HWID: "+IR.HWID); // Panel HWID: ff2c589a2879c0fe1158697d5d4c1958
});
Notes
- To retrieve a character from the HWID, use charAt(symbol). Character indexing starts at zero:
IR.Log(IR.HWID.charAt(0));
IR.Exit
Close the application. Available only on Android and Windows
Syntax
IR.Exit();
| Input | Value | Description |
|---|---|---|
| - |
| Output | ||
|---|---|---|
| - |
Example
function CloseApp () {
IR.Exit();
};
Notes
- Available only on Android and Windows
IR.ShowKeyboard
Show the iOS or Android device's system keyboard
Syntax
IR.ShowKeyboard(type, ok_text, color, capitalization)
| Input | Value | Description |
|---|---|---|
| type | 1 | type: Number keyboard type; it can also close the keyboard (value 0): Works on iOS and Android: 0 - Hide 1 - Regular 2 - URL address 3 - Numeric 4 - Phone number 5 - E-mail address 6 - Decimal 7 - Text 8 - Twitter 9 - Web search 10 - Numeric 11 - Password Works only on Android: 12 - Date and Time 13 - Date 14 - Time 15 - Numeric signed 16 - Numeric password 17 - Text characters 18 - Text sentences 19 - Text words 20 - Text ime multi line 21 - Text multi line 22 - Text suggestions 23 - Text email subject 24 - Text filter 25 - Text long message 26 - Text password 27 - Text phonetic 28 - Text postal address 29 - Text short message 30 - Text visible password 31 - Text web email address 32 - Text web password 33 - Smart 34 - Voice |
| ok_text | 0 | type: Number text displayed on the return key: 1 - default 2 - go 3 - google 4 - join 5 - next 6 - route 7 - search 8 - send 9 - yahoo 10 - done 11 - call 12 - continue |
| color | 0 | type: Number keyboard color: 1 - select automatically 2 - dark 3 - light |
| capitalization | 0 | type: Number automatic text capitalization: 1 - none 2 - first letters of words 3 - first letters of sentences 4 - all characters |
| Output | ||
| --- | --- | --- |
| - |
Example
IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem("Item 1"), function()
{
IR.ShowKeyboard(1); // regular
IR.ShowKeyboard(1, 1, 1, 1); // regular, default, default, no capitalization
});
Notes
- On iOS, hide the keyboard using
IR.ShowKeyboard(0); this does not work on Android. - All other keyboards must be hidden before opening a keyboard. If one is already open, for example a numeric keyboard, a command to open an alphabetic keyboard will fail.
- To open the keyboard on Windows, use
IR.Execute("osk").
IR.Execute
Execute any URL scheme (operating system command) supported by the device. Examples include opening a hyperlink in a browser, sending an SMS, calling a phone number, composing email, and launching an application by name or path.
Syntax
IR.Execute(scheme)
| Input | Value | Description |
|---|---|---|
| scheme | http://iridiummobile.net | type: string command to execute |
| Output | ||
|---|---|---|
| - |
Example
IR.AddListener(IR.EVENT_START, 0, function() {
IR.Execute('http://iridiummobile.net');
});
- URL scheme examples
// All
IR.Execute("http://iridiummobile.net"); // open link
IR.Execute("mailto:support@iridiummobile.ru"); // send email
// Windows
IR.Execute("cmd"); // command string
IR.Execute("ping","-t ya.ru"); //launch ping with link
IR.Execute("calc"); // calculator
IR.Execute("c:\\Program Files\\iRidium\\iRidium.exe"); // launch app
// iOS, Android
IR.Execute("music:"); // open Music
IR.Execute("videos:"); // open Videos
IR.Execute("ibooks://"); // open iBooks
IR.Execute("fb://feed"); //open Facebook
IR.Execute("twitter://"); // open Twitter
// iPhone, Android smartphone
IR.Execute("tel://+1234567890"); // call to
IR.Execute("sms://+1234567890"); // send SMS
- Windows: To launch an application on Windows, replace each single slash in the file path with a double backslash
IR.GetSystemInfo
Get application memory and cache information
Syntax
IR.GetSystemInfo("GC_MEMORY_INFO").property
| Input | Value | Description |
|---|---|---|
| property | UsedMemory | type: object property to return: * .UsedMemory * .TotalMemory * .ChunkHeaps * .ChunkCache * .MemoryHeaps * .MemoryBusyBlocks * .MemoryFreeBlocks |
| Output | ||
|---|---|---|
| property | type: string property value |
Example
IR.AddListener(IR.EVENT_START,0,function() {
IR.Log(IR.GetSystemInfo("GC_MEMORY_INFO").UsedMemory);
});
IR.GetCurrentWlanInfo
Get information about the wireless network connected to the control panel. Networks are combined into an array; each network is an array element with a fixed set of properties.
Syntax
IR.GetCurrentWlanInfo()[element].property
| Input | Value | Description |
|---|---|---|
| element | 0...n | type: number array element index corresponding to the network connection's position |
| property | Name | type: object property to return: * .Name - network connection type * .SSID - network name |
| Output | ||
|---|---|---|
| property | type: string property value |
Example
`IR.Log(IR.GetCurrentWlanInfo()[0].SSID)`
IR.AddListener(IR.EVENT_START,0,function()
{
var l_aWlanInfo = IR.GetCurrentWlanInfo();
if (l_aWlanInfo.length) {
IR.Log("Name = " + l_aWlanInfo[0].Name);
IR.Log("SSID = " + l_aWlanInfo[0]['SSID']);
} else {
IR.Log("There is no network connections found");
}
});
- Check the array length to ensure at least one network exists
IR.GetCurrentLocalIPInfo
Get network settings of the control panel running i3 pro
- On iOS 7 and later, this method cannot retrieve the network interface MAC address.
Syntax
IR.GetCurrentLocalIPInfo()[element].property
| Input | Value | Description |
|---|---|---|
| element | 0...n | type: number array element index corresponding to the network connection's position |
| property | Name | type: object property to return: * .Name - network connection name * .IP - control panel IP address * .Mask - subnet mask * .MAC - MAC address |
| Output | ||
|---|---|---|
| property | type: string property value |
Example
IR.AddListener(IR.EVENT_START,0,function()
{
var l_aIPInfo = IR.GetCurrentLocalIPInfo();
IR.Log("Name = " + l_aIPInfo[0].Name);
IR.Log("IP = " + l_aIPInfo[0].IP);
IR.Log("Mask = " + l_aIPInfo[0].Mask);
IR.Log("MAC = " + l_aIPInfo[0].MAC);
});
The MAC address is unavailable starting with Android 11.
IR.SetStatusAutoUpdateProject
Enable / disable automatic project updates.
Syntax
IR.SetStatusAutoUpdateProjects(mode););
| Input | Value | Description |
|---|---|---|
| mode | true | type: boolean enable/disable automatic project updates: * true - enable automatic project updates; * false - disable automatic project updates. |
| Output | ||
|---|---|---|
| - |
Example
function AutoUpdate()
{
IR.SetStatusAutoUpdateProjects(true);
};
IR.Log
Write data to the i3 pro debug console (press F4 to open the console on Windows)
Syntax
IR.Log(data);
| Input | Value | Description |
|---|---|---|
| data | type: object data to log: string, number, array |
| Output | ||
|---|---|---|
| data | type: string string data in the application log |
Example
IR.AddListener(IR.EVENT_START,0,function() {
IR.Log("Hello World!");
});
- Data sent to the console is converted to a string
- On Windows 7, the maximum size of one console output line is 30 KB.
IR.SetInterval
Repeat actions at the specified interval (ms)
Syntax
IR.SetInterval(time, action)
| Input | Value | Description |
|---|---|---|
| time | 500 | type: number (ms) function execution interval |
| action | function() { } | type: number anonymous function or name of a function containing actions to repeat |
| Output | ||
|---|---|---|
| - |
Example
function actions()
{
IR.Log("do action");
}
IR.SetInterval (2000, actions);
IR.SetInterval (2000, function()
{
IR.Log("do action");
});
var Inv = IR.SetInterval (2000, function()
{
IR.Log("do action");
});
IR.ClearInterval(Inv);
function action()
{
IR.Log("do action");
for(var i in this)
{
IR.Log(this + "=" + this[i]);
};
IR.ClearInterval(Id);
}
var param = {a:1, b:2, c:3};
var Id = IR.SetInterval(2000, action, param);
- A running IR.SetInterval continues while the project is open unless stopped using IR.ClearInterval
- An interval can be stopped only through its variable name, so assign it to a variable when creating it
- Use in large projects is not recommended
- JavaScript in iRidi is single-threaded, so all functions execute sequentially. With IR.SetInterval, each script execution cycle may therefore take a different time, causing interval timing error dependent on the number and type of operations. The system automatically compensates for this error to maintain long-term accuracy and prevent accumulated timing errors. Individual intervals may consequently be tens to hundreds of milliseconds longer or shorter. Consider this when creating commands with a critical minimum interval: specify a longer interval or use IR.SetTimeout, which does not use compensation.
IR.SetTimeout
Execute a function after a delay (ms)
Syntax
IR.SetTimeout(time, action)
| Input | Value | Description |
|---|---|---|
| time | 500 | type: number (ms) function execution delay |
| action | function() { } | type: number anonymous function or name of a function containing actions to execute after a delay |
| Output | ||
|---|---|---|
| - |
Example
function actions()
{
IR.Log("do action");
}
IR.SetTimeout(2000, actions);
IR.SetTimeout(2000, function()
{
IR.Log("do action");
});
var Tmr = IR.SetTimeout(2000, function()
{
IR.Log("do action");
});
IR.ClearInterval(Tmr);
Notes
- A running IR.SetTimeout can be stopped using IR.ClearInterval (there is no separate IR.ClearTimeout function).
- A timer can be stopped only through its variable name, so assign it to a variable when creating the interval
- Use in large projects is not recommended
IR.ClearInterval
Remove timers created using IR.SetInterval and IR.SetTimeout by identifier. Obtain the identifier by storing it in a variable when creating the timer; it cannot be obtained later.
Syntax
IR.ClearInterval(timer_id)
| Input | Value | Description |
|---|---|---|
| timer_id | var timer | type: object identifier of the timer to remove |
| Output | ||
|---|---|---|
| - |
Example
var id = IR.SetTimeout (10000, function ()
{
IR.Log("do something");
});
IR.SetTimeout(5000, function () // stop after 5000 ms
{
IR.ClearInterval(id);
});
-
Used to remove IR.SetInterval and IR.SetTimeout
-
The identifier needed for removal can be obtained only when creating the timer
IR.AddListener
Create a listener: a function executed when its specified event occurs. An event is a process exposed to scripts with an identifier for monitoring. Events are listed by type in the reference.
Syntax
IR.AddListener(event, input, function, [pointer]);
| Input | Value | Description |
|---|---|---|
| event | type: object identifier of the event monitored by the listener | |
| input | type: object input parameter required to create the listener. If there is no parameter, specify 0 | |
| function | function() {} | type: function anonymous function or reference to a declared function containing the actions |
| pointer | type: object pointer to the object serving as the function context (optional) |
| Output | ||
|---|---|---|
| - |
Example
IR.AddListener(IR.EVENT_START,0,function()
{
IR.Log("app started");
});
IR.AddListener(IR.EVENT_ITEM_PRESS,IR.GetItem("Page 1").GetItem("Item 61"),function()
{
IR.Log("button 61 pressed");
});
**Пример 2:**
for(var i = 0; i < IR.GetItem("Page 1").ItemsCount; i++){
// объявление слушателя и добавление pointer'а
IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem(i), press, IR.GetPage("Page 1").GetItem(i) );
}
function press(){
//выводим в лог имя сработавшей кнопки, используя this как ссылку на объект
IR.Log(this.Name);
}
- For script execution using listeners, see the Guide
IR.RemoveListener
Remove a listener created using IR.AddListener. Pass the same parameters specified when creating the listener.
Syntax
IR.RemoveListener(event, input, function, [pointer]);
| Input | Value | Description |
|---|---|---|
| event | type: object identifier of the event monitored by the listener | |
| input | type: object input parameter required to create the listener. If there is no parameter, specify 0 | |
| function | function() {} | type: function named function or reference to a declared function containing the actions |
| pointer | type: object pointer to the object serving as the function context (optional) |
| Output | ||
|---|---|---|
| - |
Example
function pressed ()
{
IR.Log("action");
}
// add listener
IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem("Item 61"), pressed);
// remove listener
IR.RemoveListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem("Item 61"), pressed);
var l_pressed;
// add listener
IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem("Item 61"), l_pressed = function ()
{
IR.Log("action");
});
// remove listener
IR.RemoveListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem("Item 61"), l_pressed);
IR.SetGlobalListener
Create a global listener: a function executed when its specified event occurs. It can work with only two events: IR.EVENT_GLOBAL_TAG_CHANGE (occurs when any tag in iRidi changes).
Unlike IR.AddListener, a global listener can be declared only 1 time. If declared again, only the last listener created by the interpreter at script startup works.
For the listener to be triggered when a tag changes in an iRidi project, subscribe to that change using the method IR.SubscribeTagChange
Syntax
IR.SetGlobalListener(event, function, [pointer]);
| Input | Value | Description |
|---|---|---|
| event | IR.EVENT_GLOBAL_TAG_CHANGE | type: object identifier of the event monitored by the global listener:IR.EVENT_GLOBAL_TAG_CHANGE - triggered when any iRidi tag changes |
| function | function(name, value) {} | type: function anonymous function or reference to a declared function containing the actions. Receives the subscribed tag's name and its changed value |
| pointer | type: object pointer to the object serving as the function context (optional) |
| Output | ||
|---|---|---|
| - |
Example
// Set global listener
IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function(name, value)
{
IR.Log("Active Global Listener: " + name + "\tValue: " + value);
});
// Subscribe
IR.SubscribeTagChange("Drivers.KNX.Online"); // driver token
IR.SubscribeTagChange("Drivers.KNX.Address 1"); // driver feedback
IR.SubscribeTagChange("Global.Token 1"); // project token
IR.SubscribeTagChange("UI.Page 1.Item 1.Text"); // item property
IR.SubscribeTagChange("System.Time.Hour"); // system time, hours
IR.SubscribeTagChange("System.Time.Minutes"); // system time, minutes
// resend the data from KNX Address 1 to Address 2 on change (for iRidi Server)
IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function(name, value)
{
if (name == "Server.Channels.KNX.Address 1")
IR.SetVariable("Server.Channels.KNX.Address 2", value);
});
IR.SubscribeTagChange("Server.Channels.KNX.Address 1");
- The listener receives the full name of the subscribed tag (name)
- A global listener can be created only 1 time in a project; otherwise only the last one works
- The listener responds to a tag change only if subscribed to that tag using IR.SubscribeTagChange
- The listener responds only to changes (it does not trigger if the received value equals the current value)
- The maximum number of global listener subscriptions is practically unlimited (close to a million)
- Unsubscribe from a tag: IR.UnsubscribeTagChange
IR.SubscribeTagChange
Subscribe to iRidi tag changes through a global listener for IR.EVENT_GLOBAL_TAG_CHANGE. Subscribed tags return their values on every change.
Syntax
IR.SubscribeTagChange(name);
| Input | Value | Description |
|---|---|---|
| name | "Drivers.AV (TCP).Feedback 1" | type: string full name of the tag to subscribe to using the global listener IR.EVENT_GLOBAL_TAG_CHANGE |
| Output | ||
|---|---|---|
| - |
Example
//Set global listener
IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function(name, value)
{
IR.Log("Global Listener Activated: " + name + "\tValue: " + value);
});
// Subscribe
IR.SubscribeTagChange("Drivers.KNX IP Router.Address 1");
IR.SubscribeTagChange("Drivers.AV & Custom Systems (TCP).Online");
IR.SubscribeTagChange("UI.Page 1.Item 1.Text");
IR.SubscribeTagChange("System.Time.24");
// resend the data from KNX Address 1 to Address 2 on change (for iRidi Server)
IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function(name, value)
{
if (name == "Server.Channels.KNX.Address 1")
IR.SetVariable("Server.Channels.KNX.Address 2", value);
});
IR.SubscribeTagChange("Server.Channels.KNX.Address 1");
- Unsubscribe from a tag using IR.UnsubscribeTagChange
IR.UnsubscribeTagChange
Unsubscribe from an iRidi tag whose changes are monitored by a global listener for IR.EVENT_GLOBAL_TAG_CHANGE. Subscribe to the tag using IR.SubscribeTagChange
Syntax
IR.UnsubscribeTagChange(name);
| Input | Value | Description |
|---|---|---|
| name | "Drivers.AV (TCP).Feedback 1" | type: string full name of the tag to unsubscribe from |
| Output | ||
|---|---|---|
| - |
Example
//Set global listener
IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function(name, value)
{
IR.Log("Global Listener Activated: " + name + "\tValue: " + value);
});
// Subscribe
IR.SubscribeTagChange("UI.Page 1.Item 1.Text");
// Unsubscribe
IR.UnsubscribeTagChange("UI.Page 1.Item 1.Text");
- Subscribe to a tag using IR.SubscribeTagChange
IR.CopyToClipboard
Copy a string to the clipboard on an iOS, Android, or Windows device
Syntax
IR.CopyToClipboard(text)
| Input | Value | Description |
|---|---|---|
| text | 'data' | type: string string to place on the clipboard |
| Output | ||
|---|---|---|
| - |
Example
IR.AddListener(IR.EVENT_START, 0, function()
{
IR.CopyToClipboard(IR.GetVariable("System.Device.Name") + " HWID: " + IR.HWID);
});
IR.PasteFromClipboard
Paste clipboard text into the active Editbox. Text is pasted only if the clipboard contains text, rather than an image or other content. The cursor is placed after the inserted text
Syntax
IR.PasteFromClipboard()
| Input | Value | Description |
|---|---|---|
| - |
| Output | ||
|---|---|---|
| - |
Example
IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem("Paste Button"),function()
{
IR.PasteFromClipboard();
});
- Use case: a paste-text button placed next to the input field
IR.GetClipboard
Get text from the clipboard
Syntax
IR.GetClipboard()
| Input | Value | Description |
|---|---|---|
| - |
| Output | ||
|---|---|---|
| - |
Example
`var clipboard = IR.GetClipboard();`
- Use case: pass clipboard text to a script
IR.ShowPasteHelper
Show a native PasteHelper popup above the cursor in the active EditBox, scaled to the project resolution and labeled Paste, similar to the paste tool on iOS and Android. Pressing the popup executes IR.PasteFromClipboard();. Pressing the paste popup, pressing the input field again, or changing focus immediately closes PasteHelper
Syntax
IR.ShowPasteHelper()
| Input | Value | Description |
|---|---|---|
| - |
| Output | ||
|---|---|---|
| - |
Example
IR.AddListener(IR.EVENT_ITEM_HOLD, IR.GetItem("Page 1").GetItem("EditBox"),function()
{
IR.ShowPasteHelper();
});
Paste tool behavior (EditBox):
- Windows:
- Pressing Ctrl+V automatically calls IR.PasteFromClipboard(); if the clipboard is nonempty and contains text
- Right-clicking the input field displays the standard paste dialog
- The cursor moves to the end of the string
- iOS, Android:
- Holding a finger on the input field for 1 second automatically calls IR.ShowPasteHelper();; pressing any item hides the Paste dialog
- The cursor moves to the end of the string
IR.GetDesignsCount
Count Panel Projects in application memory.
Syntax
IR.GetDesignsCount();
| Input | Value | Description |
|---|---|---|
| - |
| Output | ||
|---|---|---|
| number | 1 | type: number number of projects loaded into control panel memory |
Example
IR.AddListener(IR.EVENT_START, 0, function() {
var l_iCount = IR.GetDesignsCount();
IR.Log("Designs Count = " + l_iCount);
IR.Log("Current Project: " + IR.ProjectName);
for(var i = 0; i < l_iCount; i++) {
var l_sName = IR.GetDesignByIndex(i);
IR.Log("Design(" + i + "): " + l_sName.Name);
}
});
Also used:
- IR.ProjectName - IR object property containing the name of the project currently open in i3 pro
- IR.GetDesignByIndex(i) - get a project object reference by its index in the loaded project list
IR.DesignSwitch
Switch between Panel Projects in panel memory.
Syntax
IR.DesignSwitch(name,[id]);
| Input | Value | Description |
|---|---|---|
| name | "Welcome" | type: string name of the project on the panel or in the cloud to switch to |
| id | 116897 | type: number identifier of the cloud project to switch to (optional, but required for cloud projects) |
| Output | ||
|---|---|---|
| - |
Example
var ID;
IR.AddListener(IR.EVENT_START, 0, function() {
var l_iCount = IR.GetDesignsCount();
IR.Log("Designs Count = " + l_iCount);
IR.Log("Current Project: " + IR.ProjectName);
for(var i = 0; i < l_iCount; i++) {
var l_sName = IR.GetDesignByIndex(i);
IR.Log("Design(" + i + "): " + l_sName.OriginalName + ", ID "+l_sName.CloudID);
if (l_sName.OriginalName == "ProjectName") //project name
ID = l_sName.CloudID
}
});
function switch_to() {
//IR.DesignSwitch("Welcome"); // local project name .irpz you want to switch to
IR.DesignSwitch("ProjectName", ID); // project name and id in iRidi Cloud you want to switch to
IR.Log("test");
}
In this example, pressing a button switches to the application's startup page (Welcome.irpz project). Also used:
- IR.GetDesignsCount() - get the number of projects loaded in i3 pro
- IR.ProjectName - IR object property containing the name of the project currently open in i3 pro
- IR.GetDesignByIndex(i) - get a project object reference by its index in the loaded project list
- IR.GetDesignByIndex().OriginalName - original project name specified on the panel or in the cloud
- IR.GetDesignByIndex().CloudID - unique cloud project identifier
Example: DesignSwitch
IR.AndroidSendIR
Send an IR command through the Android device's built-in IR emitter (IRDA)
Syntax
IR.AndroidSendIR(frequency, command);
| Input | Value | Description |
|---|---|---|
| frequency | 38000 | type: number (Hz) IR command transmission frequency |
| command | [67,67,44,...,55,53,13] | type: array IR command as an array containing signal pulses and pauses |
| Output | ||
|---|---|---|
| - |
Example
`IR.AndroidSendIR(38000, [67,67,67,67,67,66,67,67,67,67,67,67,66,67,66,66,66,66,66,66,44,50,49,44,55,53,54,13]);`
- Convert a HEX command to the transmission format using iConvert from Global Cache
IR.CalculateCRC
Calculate a string checksum (CRC) using CRC8, CRC16, or CRC32
Syntax
IR.CalculateCRC(algorithm, string);
| Input | Value | Description |
|---|---|---|
| algorithm | IR.CRC_16 | type: object CRC calculation algorithm: * IR.CRC_8 * IR.CRC_16 * IR.CRC_32 |
| string | "Test" | type: string string for which to calculate the CRC |
| Output | ||
|---|---|---|
| CRC | 7205 | type: number CRC calculation result |
Example
var crc8 = IR.CalculateCRC(IR.CRC_8, "Test");
var crc16 = IR.CalculateCRC(IR.CRC_16, "Test");
var crc32 = IR.CalculateCRC(IR.CRC_32, "Test");
IR.Log(crc8) // 207
IR.Log(crc16) // 7205
IR.Log(crc32) // 2018365746
IR.CalculateHash
Calculate a string hash using MD5, SHA1, SHA256, SHA384, SHA512, HMACSHA1, HMACSHA256, HMACSHA384, HMACSHA512, or HMACMD5.
IR.CalculateCRC(algorithm, string, type, key);
| Input | Value | Description |
|---|---|---|
| algorithm | IR.HASH_MD5 | type: object hash calculation algorithm (use only algorithm and string): IR.HASH_MD5, IR.HASH_SHA1, IR.HASH_SHA256, IR.HASH_SHA384, IR.HASH_SHA512 (use all 4 parameters): IR.HASH_HMACSHA1, IR.HASH_HMACSHA256, IR.HASH_HMACSHA384, IR.HASH_HMACSHA512, IR.HASH_HMACMD5 |
| string | "Test" | type: string string for which to calculate the hash |
| type | 0 | type: number output format: 0 - string, 1 - byte array. |
| key | "6af02e...286d2" | type: string data encryption key. |
| Output | Value | Description |
| hash | 0cbc66...5a615b | type: number hash calculation result |
Example for MD5, SHA1, SHA256, SHA384, SHA512:
var hashMD5 = IR.CalculateHash(IR.HASH_MD5, "Test");
var hashSHA1 = IR.CalculateHash(IR.HASH_SHA1, "Test");
var hashSHA256 = IR.CalculateHash(IR.HASH_SHA256, "Test");
var hashSHA384 = IR.CalculateHash(IR.HASH_SHA384, "Test");
var hashSHA512 = IR.CalculateHash(IR.HASH_SHA512, "Test");
IR.Log(hashMD5); // 0cbc6611f5540bd0809a388dc95a615b
IR.Log(hashSHA1); // 640ab2bae07bedc4c163f679a746f7ab7fb5d1fa
IR.Log(hashSHA256); // 532eaabd9574880dbf76b9b8cc00832c20a6ec113d682299550d7a6e0f345e25
IR.Log(hashSHA384); // 7b8f4654076b80eb963911f19cfad1aaf4285ed48e826f6cde1b01a79aa73fadb5446e667fc4f90417782c91270540f3
IR.Log(hashSHA512); // c6ee9e33cf5c6715a1d148fd73f7318884b41adcb916021e2bc0e800a5c5dd97f5142178f6ae88c8fdd98e1afb0ce4c8d2c54b5f37b30b7da1997bb33b0b8a31
Example for HMACSHA1, HMACSHA256, HMACSHA384, HMACSHA512, HMACMD5:
var textData = 'iRidi';
var secretKey = '9212a1010dde4d4fbcb0';
var HASH_HMACSHA256 = IR.CalculateHash(IR.HASH_HMACSHA256, textData, 1, secretKey);
var HASH_HMACSHA = IR.CalculateHash(IR.HASH_HMACSHA1, textData, 1, secretKey);
var HASH_HMACSHA384 = IR.CalculateHash(IR.HASH_HMACSHA384, textData, 1, secretKey);
var HASH_HMACSHA512 = IR.CalculateHash(IR.HASH_HMACSHA512, textData, 1, secretKey);
var HASH_HMACMD5 = IR.CalculateHash(IR.HASH_HMACMD5, textData, 1, secretKey);
IR.Log(HASH_HMACSHA256); // 14,70,95,95,20,12,211,73,234,5,235,195,81,174,41,46,156,92,193,71,9,81,240,87,16,228,88,130,224,193,151,95
IR.Log(HASH_HMACSHA); // 244,101,165,67,222,85,108,145,20,89,16,231,57,40,39,48,136,49,151,163
IR.Log(HASH_HMACSHA384); // 92,90,124,178,158,199,230,160,28,34,156,136,1,248,177,174,191,32,82,108,124,107,203,61,203,204,14,141,143,132,175,104,20,46,227,3,100,3,30,66,110,240,4,194,120,85,187,66
IR.Log(HASH_HMACSHA512); // 106,247,151,52,13,155,173,249,228,182,129,10,4,56,118,233,176,26,104,200,65,250,133,35,229,1,201,249,143,8,125,234,72,16,202,211,119,121,28,173,3,23,206,137,69,159,196,221,53,90,43,222,142,20,254,56,210,122,152,229,132,150,189,25
IR.Log(HASH_HMACMD5); // 253,150,247,65,231,140,184,168,151,164,208,197,253,148,230,104
IR.UrlDecode
Replace UTF-8 escape sequences with their corresponding characters (decode UTF-8)
Syntax
IR.UrlDecode(url);
| Input | Value | Description |
|---|---|---|
| url | 'http://www.google.com/search?&q=%D0%BE%D0%BA' | type: string UTF-8 string, usually a URL to decode |
| Output | ||
|---|---|---|
| url | http://www.google.com/search?&q=ок | type: string result |
Example
IR.AddListener(IR.EVENT_START,0,function()
{
var utf8_encode = encodeURI('http://www.google.com/search?&q=ок');
IR.Log(utf8_encode); // http://www.google.com/search?&q=%D0%BE%D0%BA
var decode = IR.UrlDecode(utf8_encode);
IR.Log(decode); // http://www.google.com/search?&q=ок
});
IR.HtmlDecode
Decode special characters (character entities) in HTML
Syntax
IR.HtmlDecode(text)
| Input | Value | Description |
|---|---|---|
| text | ">" | type: string source text |
| Output | ||
|---|---|---|
| text | > | type: string decoded text |
Example
IR.AddListener(IR.EVENT_START, 0, function() {
var data = IR.HtmlDecode(">");
IR.Log(data); // >
});
The function does not decode all standard entities. Complete list of decoded entities:
< > " & ¡ ¢ £ ¤ ¥ ¦ § ¨
© ª « » ¬ ­ ® ¯ ° ± ² ³
´ µ ¶ · ¸ ¹ º ¼ ½ ¾
¿ À Á Â Ã Ä Å Æ
Ç È É Ê Ë Ì Í Î Ï Ð Ñ
Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü
Ý Þ ß à á â ã ä å æ ç
è é ê ë ì í î ï
ð ñ ò ó ô õ ö ÷
ø ù ú û ü ý þ ÿ
' Œ œ Š š Ÿ ˆ ˜
– — ‘ ’ ‚ “ ” „
† ‡ ‰ ‹ › €
IR.Base64Encode
Encode a string / array as Base64. Syntax
IR.Base64Encode(data, data_type)
| Input | Value | Description |
|---|---|---|
| data | "Hello" | type: string source data. / array |
| data_type | 0 / 1 | type: number data type: 0 - string, 1 - array. |
| Output | ||
|---|---|---|
| code | "SGVsbG8=" | type: string Base64-encoded text |
Example
<translate><!--T:372-->
//Пример 1:</translate>
IR.Log(IR.Base64Encode([0x48, 0x65, 0x6c, 0x6c, 0x6f], 1)); // <translate><!--T:373-->
зашифровать массив данных</translate>
<translate><!--T:374-->
//Пример 2:</translate>
IR.Log(IR.Base64Encode("Hello", 0)); // <translate><!--T:375-->
зашифровать строку</translate>
//Пример 3:
IR.Log(IR.Base64Encode("Hello")); // <translate><!--T:376-->
зашифровать строку (устаревший метод)</translate>
IR.Base64Decode
Decode a Base64 string / array. Syntax
IR.Base64Decode(code, data_type)
| Output | ||
|---|---|---|
| data | "Hello" | type: string / array source text / data array |
| Output | ||
|---|---|---|
| data | "Hello" | type: string / array source text / data array |
Example
<translate><!--T:382-->
//Пример 1:</translate>
IR.Log(IR.Base64Decode("SGVsbG8=", 1)); // <translate><!--T:383-->
расшифровать массив</translate>
<translate><!--T:384-->
//Пример 2:</translate>
IR.Log(IR.Base64Decode("SGVsbG8=", 0)); // <translate><!--T:385-->
расшифровать строку</translate>
<translate><!--T:386-->
//Пример 3:</translate>
IR.Log(IR.Base64Decode("SGVsbG8=")); // <translate><!--T:387-->
расшифровать строку (устаревший метод)</translate>
IR.IsModuleLicensed
A method for commercializing custom scripts. Checks whether an iRidi license includes a particular product. Products are included in commercial iRidi mobile licenses by special agreement with the script developer. Workflow:
- Create the script you want to encrypt and distribute commercially
- Contact an iRidi mobile manager to obtain a unique ID for your product: the script
- Add an ID check using IR.IsModuleLicensed(id) so the script does not run until the project has the corresponding license
- Password-protect the script file before distributing it to other users
- Contact the managers to agree how to include your product ID in commercial licenses
Syntax
IR.IsModuleLicensed(id)
| Input | Value | Description |
|---|---|---|
| id | 57599 | type: number unique product ID provided to the developer by iRidi mobile and stored in the license |
| Output | ||
|---|---|---|
| success | true | type: boolean check result: * true - the product is included in the license * false - it is not |
Example
function RunProtectedModule () {
// protected content
}
// unique module ID = 65537;
if (IR.IsModuleLicensed(65537)) RunProtectedModule ();
-
Trial licenses and test mode always return true when checking a module ID, consistent with free use of iRidi products in test mode
-
For AV & Custom Systems, ID = 6; for AV & Custom HTTP, ID = 14.
IR.ValidatePassword()
Use the project's standard 4-level password system from scripts. For example, create a custom password dialog or request a password on any event. The method compares an entered password with the configured project password, allowing one password set for all operations and password changes at runtime.
Syntax
IR.ValidatePassword(pwd_number, check_string)
| Input | Value | Description |
|---|---|---|
| pwd_number | 1 | type: number 1...4 - number of the configured project password to compare against (passwords are set in project properties) |
| check_string | "password" | type: string password to compare with the one configured in project properties |
| Output | ||
|---|---|---|
| result | true | type: boolean check result: true - correct password, false - incorrect password |
Example
var editbox = IR.GetItem("Page 1").GetItem("Item 1"); // editbox item on page
IR.AddListener(IR.EVENT_ITEM_CHANGE, editbox, function (action, key) // listen to changes in Editbox
{
if (action == 2) { // when press Enter in Editbox item
var confirm = IR.ValidatePassword(1, editbox.Text) // check the password from Editbox
if (confirm) {
IR.Log("Access confirmed!");
// any action have to be activated by correct password
} else {
IR.Log("Access denied!");
}
}
});
- If no password is configured in project settings, the method always returns true
IR.TouchIDStart()
Invoke the system function requesting the user's fingerprint.
- The method works only on iOS 11 and later and Android devices equipped with a fingerprint scanner.
- On iOS, a system fingerprint dialog appears. On Android, no system dialog appears; the system function runs in the background.
Syntax
IR.TouchIDStart(function(status){}, {}, reason)
| Input | Value | Description |
|---|---|---|
| reason | "Place your finger on the fingerprint scanner to authorize." | type: string text displayed in the system dialog explaining why a fingerprint is requested. For iOS only. On Android, the text is not displayed; pass any string, such as an empty one. |
| Output | ||
|---|---|---|
| status | true | type: boolean fingerprint scan result: true - successful, false - scan canceled. |
| function() | - | type: function fingerprint scan result handler |
Example
var button = IR.GetPage("Page 1").GetItem("Button");
var result = IR.GetPage("Page 1").GetItem("Result");
IR.AddListener(IR.EVENT_ITEM_RELEASE, button, function() {
IR.TouchIDStart(function(status) {
IR.Log("STATUS: " + status);
result.Value = status;
}, {}, "reason");
});
- On iOS, i3 pro is minimized and does not run while the TouchID system dialog is open.
- If the fingerprint is not recognized, the user is prompted for the operating system login password. Entering the correct password also passes the handler the value true. download :
- TouchID example
IR.BiometricAuthStart()
Invoke the system function requesting facial recognition or the user's fingerprint.
- The method works only on iOS (version 11 and later) and Android devices with a fingerprint scanner or facial recognition.
- When first using facial recognition in i3 Pro, grant the application permission to use face id; otherwise the function will not work.
Syntax
IR.BiometricAuthStart( function(status) {} , {}, reason)
| Input | Value | Description |
|---|---|---|
| reason | "Place your finger on the fingerprint scanner to authorize." | type: string text displayed in the system dialog explaining why a fingerprint or facial scan is requested (iOS only). On Android, the text is not displayed; pass any string, such as an empty one. |
| Output | ||
|---|---|---|
| status | true | type: boolean biometric scan result: true - successful, false - scan canceled. |
| function() | - | type: function scan result handler. |
Example
var button = IR.GetPage("Page 1").GetItem("Item 1");
IR.AddListener(IR.EVENT_ITEM_RELEASE, button, function()
{
IR.BiometricAuthStart(function(status) {
if(status)
IR.ShowPopup("Popup 1"); //action, when status is true
},{}, "For opening popup");
});
- On iOS, i3 pro is minimized and does not run while the system dialog is open.
- If an error occurs (no face id, unsupported face id in ios, etc.), the user is prompted for the operating system login password. Entering the correct password also passes the handler the value true. download :
- BiometricAuthStart example
IR.OpenPhotoGallery()
Open the system image file picker. The selected file's name and path are passed to the listener through IR.EVENT_RECEIVE_PHOTO_FROM_GALLERY.
- The method works on Windows, iOS, and Android panels. Server is not supported.
Syntax
var result = IR.OpenPhotoGallery();
| Input | Value | Description |
|---|---|---|
| Output | ||
|---|---|---|
| result | true | type: boolean result: true - the operating system supports the method, false - the method is not supported. |
Example
if (IR.OpenPhotoGallery()) {
IR.AddListener(IR.EVENT_RECEIVE_PHOTO_FROM_GALLERY, 0, function(filename, filepath) {
IR.Log("Photo selected.\n Filename: " + filename + "\n Filepath: " + filepath);
})
};
Example: PhotoGallery.irpz
IR.OpenPhotoCamera()
Open the system camera to take a picture and pass it to iRidi. Retrieve the picture using the listener IR.EVENT_RECEIVE_PHOTO_FROM_CAMERA.
Syntax
IR.OpenPhotoCamera();
| Input | Value | Description |
|---|---|---|
| Output | ||
|---|---|---|
| result | true | type: boolean result: true - the operating system supports the method, false - the method is not supported. |
Example
IR.AddListener(IR.EVENT_ITEM_RELEASE,IR.GetPage("Page 1").GetItem("Item 2"),function()
{
IR.OpenPhotoCamera();
})
The method works on iOS and Android panels.
IR.UploadFile()
Upload a file over HTTP.
- The method works in both Panel Projects and server projects.
Syntax
var uploadResult = IR.UploadFile({
Host: host,
Port: port,
SSL: ssl,
UrlPath: urlpath,
FilePath: filepath,
Disposition: disposition,
Headers: headers,
Params: params,
<other>,
Callback: function(resultObj){}
| Input | Value | Description |
|---|---|---|
| Host | "192.168.1.2" | type: string IP address of the recipient receiving the file |
| Port | 8457 | type: number port of the recipient receiving the file |
| SSL | IR.SSL_CONTEXT_ _TYPE_NONE | type: number encryption type: IR.SSL_CONTEXT_TYPE_NONE - no encryption IR.SSL_CONTEXT_TYPE_TLS_V12 - TLS v1.2 IR.SSL_CONTEXT_TYPE_SSL_V23 - SSL v2.3 IR.SSL_CONTEXT_TYPE_SSL_V30 - SSL v3.0 |
| UrlPath | "/bin" | type: string recipient URL path for receiving the file |
| FilePath | "C:/images/face01.jpg" | type: string path and name of the file to upload |
| Disposition | "image" | type: string attachment type (determines the HTTP Content-Disposition header) |
| Headers | {Connection: Keep-Alive, Content-Length: 100, Accept: /} | type: object object containing POST request headers |
| Params | {param1: value1, param2: value2} | type: object object containing POST request parameters |
| <other> | - | type: other parameters applicable to the AV & Custom Systems (HTTP) driver |
| function | function(resultObj){} | type: function anonymous function or reference to a declared function containing the actions |
| Output | ||
|---|---|---|
| uploadResult | true | type: boolean result of the upload attempt: false - error; upload is not performed, true - success; upload has started |
| resultObj | - | type: object object containing file upload results |
| resultObj.State | IR.UPLOADER_MANAGER_ _NOTIFY_STEP | type: number current file upload state: IR.UPLOADER_MANAGER_NOTIFY_START - started IR.UPLOADER_MANAGER_NOTIFY_STEP - upload in progress; the callback is called every second IR.UPLOADER_MANAGER_NOTIFY_END - finished IR.UPLOADER_MANAGER_NOTIFY_ERROR - error |
| resultObj.Size | 10000 | type: number current uploaded file size in bytes. At the start of the upload, resultObj.Size is the entire file size. |
| resultObj.Answer | "{Status: 0}" | type: string HTTP response body received from the recipient when the file upload finishes |
Example
IR.UploadFile({
Host: "192.168.0.21",
Port: 8587,
SSL: IR.SSL_CONTEXT_TYPE_NONE,
UrlPath: "/api/upload/plain",
FilePath: "C:/image.png",
Disposition: "image",
Headers: {
"Cache-Control": "no-cache",
"Pragma": "no-cache",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36",
"Accept-Language": "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7",
"Accept-Encoding": "gzip, deflate, br"
},
Callback: function(obj) {
switch(obj.State) {
case IR.UPLOADER_MANAGER_NOTIFY_START:
IR.Log("UPLOADER_MANAGER_NOTIFY_START: " + obj.Size + " bytes to load");
break;
case IR.UPLOADER_MANAGER_NOTIFY_STEP:
IR.Log("UPLOADER_MANAGER_NOTIFY_STEP: " + obj.Size + " bytes loaded");
break;
case IR.UPLOADER_MANAGER_NOTIFY_END:
IR.Log("UPLOADER_MANAGER_NOTIFY_END");
var data = JSON.Parse(obj.Answer);
IR.Log("Answer Status: " + data.Status);
break;
case IR.UPLOADER_MANAGER_NOTIFY_ERROR:
IR.Log("UPLOADER_MANAGER_NOTIFY_ERROR");
break;
}
}
});
IR.EnableProximity()
Enable monitoring of the device's proximity sensor.
Syntax
var result = IR.EnableProximity();
| Input | Value | Description |
|---|---|---|
| Output | ||
|---|---|---|
| result | true | type: boolean result: true - the operating system supports the method, false - the method is not supported. |
Example
{
IR.EnableProximity(this.Value == 1);
}
IR.OnTop()
Bring the window above other system windows along the Z axis.
Syntax
IR.OnTop();
| Input | Value | Description |
|---|---|---|
| Output | ||
|---|---|---|
| succes | true | type: boolean true |
Example
IR.TimeOut(5000, function() {
IR.OnTop();
});
Works only on Windows.
Popen
Popen is a process allowing iRidi Server to execute a Windows or Linux command-line command. Popen does not work in the i3 pro client. It opens a process file pointer and passes command execution information to the specified listener function instance. Create Popen instances to execute several commands and distinguish their output.
Syntax
var cmd_process = new Popen (command, function);
| Input | Value | Description |
|---|---|---|
| command | 'ping 192.168.0.1' | type: string command to execute on the command line (cmd.exe) |
| function | cmd_result | type: function listener function instance receiving command execution results |
| Output | ||
|---|---|---|
| line | .onRecieve | type: string data generated by the running command. .OnReceive runs in the Popen context and receives line as input. Log the string or write it to an iRidi Server variable |
| result | .onEnd | type: number code generated when the command finishes. .onEnd runs in the Popen context and receives result as input. Log the code or write it to an iRidi Server variable: * 0 - command completed successfully * 259 and other numbers - error. An error code is generated by .Stop() terminating the command early, or by a negative result (for example, when ping cannot reach the IP address) |
| .Stop() | .Stop() | type: method forcibly stop the Popen process. No termination is needed after .onEnd, but the process must be terminated if the command does not stop by itself (for example, an endless ping) |
Example
function Listener (cmd)
{
this.onRecieve = function(line)
{
IR.Log(line);
}
this.onEnd = function(result)
{
IR.Log('Command: '+ cmd + " Result: " + result);
}
}
function stop()
{
cmd_process.Stop();
}
var cmd_result = new Listener ('ping 192.168.0.1');
var cmd_process = new Popen ('ping 192.168.0.1', cmd_result);
- Use .Stop() to terminate the process. Commands that do not finish by themselves must be stopped forcibly, because each consumes operating system resources and affects performance
- popen works only in iRidi Server on Windows and Linux, not in i3 pro
iDate (object)
iDate represents a date as a 64-bit floating-point number. It can handle dates and times from January 1, 100 to December 31, 9999.
The integer part represents the number of days since December 30, 1899; for example, the number 2 represents January 1, 1900. To specify dates before December 30, 1899, use a negative number; for example, -1 represents January 29, 1899.
The fractional part determines the time. To increase the time by 1 hour, add 1/24; to add 1 minute, add 1/1440. A drawback of the object is its low precision when working with milliseconds, with an error of +/-150 milliseconds.
iDate without arguments
When created without arguments, the object is initialized with the current date and time.
var date = new iDate();
IR.Log("Date " + date.year + "." + date.month + "." + date.day);
IR.Log("Time " + date.hours + ":" + date.minutes + ":" + date.seconds + "." + date.ms);
IR.Log("Value " + date.value);
/*
result:
Date 2014.11.29
Time 20:49:20.778
Value 41972.86760159722
*/
iDate with 1 argument
The argument is value, a floating-point number representing the combined date and time.
When the object is created, the floating-point number is converted into an object from which the date and time can then be obtained.
// создадим объект iDate, передав ему целое положительное число.
var d1 = new iDate(16384);
IR.Log("Date 1 " + d1.year + "." + d1.month + "." + d1.date);
IR.Log("Time 1 " + d1.hours + ":" + d1.minutes + ":" + d1.seconds + "." + d1.ms);
IR.Log("Value 1" + d1.value);
/*
result:
Date 1 1944.11.8
Time 1 0:0:0.0
Value 1 16384
*/
// создадим объект iDate, передав ему целое отрицательное число.
var d2 = new iDate(-16384);
IR.Log("Date 2" + d2.year + "." + d2.month + "." + d2.date);
IR.Log("Time 2" + d2.hours + ":" + d2.minutes + ":" + d2.seconds + "." + d2.ms);
IR.Log("Value 2" + d2.value);
/*
result:
Date 2 1855.2.20
Time 2 0:0:0.0
Value 2 -16384
*/
iDate with more than 1 argument
Arguments:
- year is the year
- month is the month
- date is the day
- hours is the hour
- minutes is the minute
- seconds is the second
- ms is the millisecond
When the object is created, the year, month, date, hour, minute, second, and millisecond are set separately. If not all parameters are supplied, the remaining parameters use their current values.
// создание объекта iDate, с текущими значениями даты и времени.
var cur = new iDate();
IR.Log("Cur Date " + cur.year + "." + cur.month + "." + cur.date);
IR.Log("Cur Time " + cur.hours + ":" + cur.minutes + ":" + cur.seconds + "." + cur.ms);
IR.Log("Cur Value" + cur.value);
/*
result:
Cur Date 2014.11.29
Cur Time 21:6:45.128
Cur Value41972.879688981484
*/
// создание объекта iDate, с указанием года, месяца и числа
var date2 = new iDate(1999, 1, 21);
IR.Log("Date 2 " + date2.year + "." + date2.month + "." + date2.date);
IR.Log("Time 2 " + date2.hours + ":" + date2.minutes + ":" + date2.seconds + "." + date2.ms);
IR.Log("Value 2 " + date2.value);
/*
result:
Date 2 1999.1.21
Time 2 21:6:45.133
Value 2 36181.87968903935
*/
// создание объекта iDate, с указанием года, месяца, числа, часа и минуты
var date4 = new iDate(1999, 1, 21, 4, 16);
IR.Log("Date 4 " + date4.year + "." + date4.month + "." + date4.date);
IR.Log("Time 4 " + date4.hours + ":" + date4.minutes + ":" + date4.seconds + "." + date4.ms);
IR.Log("Value 4 " + date4.value);
/*
result:
Date 4 1999.1.21
Time 4 4:16:45.138
Value 4 36181.17830020833
*/
// создание объекта iDate, с указанием года, месяца, числа, часа, минуты, секунды и миллисекунды
var date6 = new iDate(1999, 1, 21, 4, 16, 12, 400);
IR.Log("Date 6 " + date6.year + "." + date6.month + "." + date6.date);
IR.Log("Time 6 " + date6.hours + ":" + date6.minutes + ":" + date6.seconds + "." + date6.ms);
IR.Log("Value 6 " + date6.value);
/*
result:
Date 6 1999.1.21
Time 6 4:16:12.400
Value 6 36181.177921296294
*/
The iDate class includes toTimeString() and toDateString(), which reproduce the behavior of the corresponding Date methods. Their output uses the server's local (system) time.
Example:
IR.AddListener(IR.EVENT_START, 0, function()
{
function getTime()
{
var currentDate = new iDate(); // Создадим экземпляр класса iDate
var time = currentDate.ToTimeString(); // Преобразуем iDate к строке вида - HH:MM:SS
var date = currentDate.ToDateString(); // Преобразуем iDate к строке вида - Day, DD Mon YEAR
IR.Log("iDate: " + time + " " + date); // Выведем результат
IR.SetTimeout(2000, getTime);
}
IR.SetTimeout(2000, getTime);
});
Output:
…INFO SCRIPT iDate: 16:30:28 Thu, 4 Jul
JSON
JSON.Stringify
Convert a JSON object to a string
Syntax
JSON.Stringify(object, bool)
| Input | Value | Description |
|---|---|---|
| object | type: object JSON object |
| Output | ||
|---|---|---|
| mode | true | type: boolean * true - output duplicate objects.* false - do not output duplicate objects (false by default). |
| text | type: string JSON object converted to a string |
Example
IR.AddListener(IR.EVENT_START,0,function()
{
var object = {"Room" : [{"Floor" : "Ground", "Name" : "Kitchen"}]}
var string = JSON.Stringify(object);
IR.Log(string) // {"Room":[{"Floor":"Ground", "Name":"Kitchen"}]}
});
JSON.Parse
Convert a string to a JSON object
Syntax
JSON.Parse(text)
| Input | Value | Description |
|---|---|---|
| text | type: string string |
| Output | ||
|---|---|---|
| object | type: object JSON object |
Example
IR.AddListener(IR.EVENT_START,0,function()
{
var string = '{"Room":[{"Floor":"Ground", "Name":"Kitchen"}]}'
var object = JSON.Parse(string);
IR.Log(object) // [object Object]
});
XML
new XML
Create an XML object
Syntax
new XML(text)
| Input | Value | Description |
|---|---|---|
| text | type: string string containing an XML message |
| Output | ||
|---|---|---|
| object | type: object XML object |
Example
IR.AddListener(IR.EVENT_START,0,function()
{
var xml_string = '<file id="123" quote="true"><name>project 1</name><version>v 1.0</version></file><Panel>"panel #1"</Panel><Panel>"panel #2"</Panel>'
var xml_object = new XML(xml_string); // create XML object
var name = xml_object.file["name"];
var attrib_id = xml_object.file["@id"];
var attrib_quote = xml_object.file["@quote"];
var version = xml_object.file.version;
var panel1 = xml_object.Panel[0];
var panel2 = xml_object.Panel[1];
var i = 0;
while (xml_object.Panel[i]) {
IR.Log(xml_object.Panel[i]);
i++;
// "panel #1"
// "panel #2"
}
IR.Log(name+" "+version+" "+panel1+" "+panel2); // project 1 v 1.0 "panel #1" "panel #2"
IR.Log(attrib_id); //view attribute "id"
IR.Log(attrib_quote); //view attribute "quote"
});
Iterate over tags with the same name using a while loop and index [i] while the element exists.
.ToString()
Convert an XML object to a string
Syntax
xml.ToString()
| Input | Value | Description |
|---|---|---|
| object | type: object XML object |
| Output | ||
|---|---|---|
| string | type: string string |
Example
IR.AddListener(IR.EVENT_START,0,function()
{
var xml_string = '<file><name>project 1</name><version>v 1.0</version></file><Panel>panel #1</Panel><Panel>"panel #2"</Panel>'
var xml_object = new XML(xml_string);
var xml_string_from_object = xml_object.ToString() // XML object to XML string
IR.Log(xml_string_from_object);
});
IR.SetPanelBacklight()
Control side backlighting on iRidi Panel 7.
Syntax
IR.SetPanelBacklight(imax, brightness, color)
| Input | Value | Description |
|---|---|---|
| imax | 1 - 4 | type: Number |
| brightness | 0 - 255 | type: Number lighting brightness. |
| color | 0 - off, 1 - blue, 2 - green, 3 - cyan, 4 - red, 5 - purple, 6 - yellow, 7 - white. | type: Number lighting color. |
Create a new script in the project and add the example for switching on the side lighting:
//<translate>
<!--T:352-->
пример для зеленого цвета:</translate>
IR.AddListener(IR.EVENT_ITEM_RELEASE, IR.GetPage("Page 1").GetItem("Item 1"), function()
{
IR.SetPanelBacklight(4, 255, 2);
//IR.GetPage("Page 1").GetItem("color_Light").GetState(0).FillColor = 0x0000ffff;
IR.Log("green");
});
Example: iRidi Panel 7
Events
IR.EVENT_START
Event identifier triggered when i3 pro starts
Syntax
IR.AddListener(IR.EVENT_START, 0, function, [pointer]);
| Input | Value | Description |
|---|---|---|
| function | function() {} | type: function anonymous function or function reference |
| pointer | - | type: object pointer to the object serving as the function context (optional) |
| Output | ||
|---|---|---|
| - |
Example
IR.AddListener(IR.EVENT_START, 0, function ()
{
IR.Log("app started"); // action
});
In i3 Pro JavaScript, parseInt() without a radix interprets strings with leading zeros as octal numbers:
| Call | Result |
|---|---|
parseInt("01") … parseInt("07") | 1 … 7 |
parseInt("08") | 0 |
parseInt("09") | 0 |
Always specify the radix:
IR.Log(parseInt("0" + i, 10)); // десятичное число
Alternative: Do not use parseInt for values such as 01, 02, …; parse them another way (for example, Number("08") or remove the leading zero before conversion).
IR.EVENT_WORK
Event identifier triggered on every processor cycle while the application runs.
Syntax
IR.AddListener(IR.EVENT_WORK, 0, function, [pointer]);
| Input | Value | Description |
|---|---|---|
| function | function() {} | type: function anonymous function or function reference |
| pointer | - | type: object pointer to the object serving as the function context (optional) |
| Output | ||
|---|---|---|
| - |
Example
// IS NOT RECOMMENDED FOR REAL TASKS!
IR.AddListener(IR.EVENT_WORK, 0, function ()
{
IR.Log("app works"); // action
});
- Using this event is not recommended because it uses resources inefficiently. Instead, use IR.SetInterval() or driver change listeners.
IR.EVENT_EXIT
Event identifier triggered when i3 pro exits. Activated by a command to close the application.
Syntax
IR.AddListener(IR.EVENT_EXIT, 0, function, [pointer]);
| Input | Value | Description |
|---|---|---|
| function | function() {} | type: function anonymous function or function reference |
| pointer | - | type: object pointer to the object serving as the function context (optional) |
| Output | ||
|---|---|---|
| - |
Example
IR.AddListener(IR.EVENT_EXIT, 0, function ()
{
IR.Log("app closed"); // action
});
- The event is not triggered if the application crashes.
- IR.Execute() and driver operations are not supported.
IR.EVENT_GLOBAL_TAG_CHANGE
Event identifier triggered when any iRidi application tag changes. Tags are queryable interface item or driver properties. To register tag changes, subscribe using IR.SubscribeTagChange
Syntax
IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function() {}, [pointer]); IR.SubscribeTagChange(tag);
| Input | Value | Description |
|---|---|---|
| function | function() {} | type: function anonymous function or function reference |
| tag | "Drivers.AV (TCP).Online" | type: string full name of the tag whose changes you want to subscribe to using IR.SubscribeTagChange. Without a subscription, tag changes are not reflected in the system |
| pointer | - | type: object pointer to the object serving as the function context (optional) |
| Output | ||
|---|---|---|
| - |
Example
//Set global listener
IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function(name, value)
{
IR.Log("Global Listener Activated: " + name + "\tValue: " + value);
});
// Subscribe
IR.SubscribeTagChange("Drivers.KNX IP Router.Address 1");
IR.SubscribeTagChange("Drivers.AV & Custom Systems (TCP).Online");
IR.SubscribeTagChange("UI.Page 1.Item 1.Text");
IR.SubscribeTagChange("System.Time.24");
// Unsubscribe
IR.UnsubscribeTagChange("UI.Page 1.Item 1.Text");
// resend the data from KNX Address 1 to Address 2 on change (for iRidi Server)
IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function(name, value)
{
if (name == "Server.Channels.KNX.Address 1")
IR.SetVariable("Server.Channels.KNX.Address 2", value);
});
IR.SubscribeTagChange("Server.Channels.KNX.Address 1");
- A global listener can be created only 1 time in a project; otherwise only the last one works
- Activate the listener: IR.SetGlobalListener
- The listener responds to a tag change only if subscribed to that tag using IR.SubscribeTagChange
- The listener responds only to changes (it does not trigger if the received value equals the current value)
- Unsubscribe from a tag: IR.UnsubscribeTagChange
IR.EVENT_ORIENTATION
Event identifier triggered when a control panel equipped with an accelerometer rotates. Emulate it on Windows by pressing F5
Syntax
IR.AddListener(IR.EVENT_ORIENTATION, 0, function, [pointer]);
| Input | Value | Description |
|---|---|---|
| function | function() {} | type: function anonymous function or function reference |
| pointer | - | type: object pointer to the object serving as the function context (optional) |
| Output | ||
|---|---|---|
| orientation_id | 1 | type: number new device orientation number: *1 - portrait, Home button at the bottom; constant: IR.ORIENTATION_PORTRAIT *2 - portrait, Home button at the top; constant: IR.ORIENTATION_PORTRAIT_UPSIDE_DOWN *3 - landscape, Home button on the right; constant: IR.ORIENTATION_LANDSCAPE_LEFT *4 - landscape, Home button on the left; constant: IR.ORIENTATION_LANDSCAPE_RIGHT |
Example
IR.AddListener(IR.EVENT_ORIENTATION, 0, Message);
function Message(orientation)
{
IR.Log("new orientation id: " + orientation);
switch (orientation) {
case IR.ORIENTATION_PORTRAIT:
IR.Log("Vertical")
break;
case IR.ORIENTATION_PORTRAIT_UPSIDE_DOWN:
IR.Log("Upside down")
break;
case IR.ORIENTATION_LANDSCAPE_LEFT:
IR.Log("Turned to the left");
break;
case IR.ORIENTATION_LANDSCAPE_RIGHT:
IR.Log("Turned to the right");
break;
}
}
- Get the initial value at application startup from the system token IR.GetVariable("System.ViewOrientation");
- Emulate rotation on Windows by pressing F5
IR.EVENT_KEYBOARD_SHOW
Event identifier triggered when the keyboard opens or closes on iOS or Android
Syntax
IR.AddListener(IR.EVENT_KEYBOARD_SHOW, 0, function(id), [pointer]);
| Input | Value | Description |
|---|---|---|
| function | function(id) {} | type: function anonymous function or function reference |
| pointer | - | type: object pointer to the object serving as the function context (optional) |
| Output | ||
|---|---|---|
| id | true | type: boolean result: true - keyboard open, false - keyboard closed |
Example
IR.AddListener(IR.EVENT_KEYBOARD_SHOW, 0, function(id)
{
if (id)
{
IR.Log("keyboard showed");
}
else
{
IR.Log("keyboard hidden");
}
});
IR.EVENT_RECEIVE_SCHEME
Event identifier triggered when a browser, email client, or another application launches i3 pro on iOS or Android through a URL scheme. The URL scheme for launching i3 pro is:
iridium://script?data1&data2
data1&data2 - data string passed to the script in query
Syntax
IR.AddListener(IR.EVENT_RECEIVE_SCHEME, 0, function, [pointer]);
| Input | Value | Description |
|---|---|---|
| function | function | type: function anonymous function or function reference |
| pointer | - | type: object pointer to the object serving as the function context (optional) |
| Output | ||
|---|---|---|
| query | - | type: string data string passed in the URL |
| source | - | type: string application that invoked the URL scheme |
Example
// called URL scheme: iridium://script?Page1
IR.AddListener(IR.EVENT_RECEIVE_SCHEME,0,function(query, source)
{
if (query == "Page1")
IR.ShowPage("Page 1");
});
IR.ANDROID_BACK_PRESS
Event identifier triggered by the Android Back button (hardware or software). If subscribed to this event, Back performs only the actions programmed in the listener function. Without a subscription, Back minimizes the application
Syntax
IR.AddListener(IR.ANDROID_BACK_PRESS, 0, function, [pointer]);
| Input | Value | Description |
|---|---|---|
| function | function() {} | type: function anonymous function or function reference |
| Output | ||
|---|---|---|
| - |
Example
var back_subscribe = function ()
{
IR.Log("Back button pressed!");
}
IR.AddListener(IR.ANDROID_BACK_PRESS, 0, back_subscribe);
// to unsunscribe you can call the function back_unsubscribe (); in any moment
function back_unsubscribe ()
{
IR.RemoveListener(IR.ANDROID_BACK_PRESS, 0, back_subscribe);
}
- If subscribed to this event, Back performs only the actions programmed in the listener. Without a subscription, Back minimizes the application
IR.EVENT_RECEIVE_PHOTO_FROM_GALLERY
Event triggered when an image is selected from the gallery, initiated by IR.OpenPhotoGallery().
Syntax
IR.AddListener(IR.EVENT_RECEIVE_PHOTO_FROM_GALLERY, 0, function(filename, filepath) { }, [pointer]);
| Input | Value | Description |
|---|---|---|
| function | function() {} | type: function anonymous function or function reference |
| Output | ||
|---|---|---|
| filename | "flower.png" | type: string image file name |
| filepath | "D:/collection/flower.png" | type: string image file path and name |
| pointer | - | type: pointer pointer to the listener context (optional) |
Example
if (IR.OpenPhotoGallery()) {
IR.AddListener(IR.EVENT_RECEIVE_PHOTO_FROM_GALLERY, 0, function(filename, filepath) {
IR.Log("Photo selected.\n Filename: " + filename + "\n Filepath: " + filepath);
}
});
Example: PhotoGallery.irpz
IR.EVENT_RECEIVE_PHOTO_FROM_CAMERA
Event triggered when an image is received from the camera, initiated by IR.OpenPhotoCamera().
Syntax
IR.AddListener(IR.EVENT_RECEIVE_PHOTO_FROM_CAMERA, 0, function(filename, filepath) { }, [pointer]);
| Input | Value | Description |
|---|---|---|
| function | function() {} | type: function anonymous function or function reference |
| Output | ||
|---|---|---|
| filename | "flower.png" | type: string image file name |
| filepath | "D:/collection/flower.png" | type: string image file path and name |
| pointer | - | type: pointer pointer to the listener context (optional) |
Example
if (IR.OpenPhotoCamera()) {
IR.AddListener(IR.EVENT_RECEIVE_PHOTO_FROM_CAMERA, 0, function(filename, filepath) {
IR.Log("Photo selected.\n Filename: " + filename + "\n Filepath: " + filepath);
}
});
IR.EVENT_LICENCE_ACCEPT
The listener triggers when a license is received for i3 pro or iRidi Server.
Syntax
IR.AddListener(IR.EVENT_LICENCE_ACCEPT, 0, [function](#irevent_licence_accept));
| Input | Value | Description |
|---|---|---|
| function | type: function() {} |
| Output | ||
|---|---|---|
Example
Unsupported
Support for the following methods was discontinued in iRidi v3
IR.DownLoadProject
Download a project available at an HTTP URL to the control panel. Assign a unique name during download for Multiproject mode.
Syntax
IR.DownLoadProject({type: protocol, host: host, path: path, multiproject: mode, name: name});
| Input | Value | Description |
|---|---|---|
| protocol | 'https' | type: string protocol type: http or https |
| host | 'drive.google.com' | type: string resource IP address or domain name |
| path | '/folder/file.irpz' | type: string project file path |
| mode | 0 | type: number multiproject mode: 0 - disabled, 1 - enabled |
| name | 'Main' | type: string project name; Main is the default interface |
| Output | ||
|---|---|---|
| object | [Object DevicePrototype] | type: object reference to the iRidium HTTP Updater driver initiating the project update |
Example
IR.AddListener(IR.EVENT_START, 0, function()
{
IR.DownLoadProject({
type: 'https',
host: 'drive.google.com',
path: '/uc?export=view&id=0B2nsHBulOZWTR2tUaW85Vlo1Yzg',
multiproject: 0,
name: 'Main'
});
});
// regular expression returns the parsed link to Project
function parse_url(url)
{
var pattern = RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?");
var matches = url.match(pattern);
return {
scheme: matches[2],
authority: matches[4],
path: matches[5],
query: matches[7],
fragment: matches[9]
};
}
// start the uroject uploading
function HTTPUpdate(url)
{
var parsed_url = parse_url(url);
var downloader = IR.DownLoadProject({
type:parsed_url.scheme,
host:parsed_url.authority,
path:parsed_url.path + '?' + parsed_url.query,
multiproject: 1,
name: "TestNew"
});
}
// call the uploading function and send the URL for parsing
function Update_new()
{
HTTPUpdate('https://drive.google.com/uc?export=view&id=0B2nsHBulOZWTR2tUaW85Vlo1Yzg');
}
- Set the project name in name: during download, the file system receives the new name, creates a file with that name, and writes the data into it. With multiproject mode enabled, the newly named project is added alongside the current one rather than replacing it.
IR.SendNotification
Send a local notification to the same iOS device running i3 pro (does not work on other operating systems)
Syntax
IR.SendNotification(text, delay, sound_id, badge_increment_num, id
| Input | Value | Description |
|---|---|---|
| text | "event N" | type: string notification text |
| delay | 0 | type: number (sec.) notification delay |
| sound_id | 1 | type: number identifier of the notification sound: * 0 - no sound * 1 - default iOS notification sound * 2 - default iOS ringtone |
| badge_increment_num | 1 | type: number amount by which to increase the notification count badge on the application icon |
| id | "None" | type: string unique notification identifier |
| Output | ||
|---|---|---|
| - |
Example
IR.AddListener(IR.EVENT_APP_ENTER_BACKGROUND, 0, function()
{
IR.SendNotification("iRidium minimized", 0, 1, 1, "None");
});
- Works only on iOS; this is not a push notification
IR.ClearNotification
Clear local notifications generated by i3 pro on the iOS device
Syntax
IR.ClearNotification()
| Input | Value | Description |
|---|---|---|
| - |
| Output | ||
|---|---|---|
| - |
Example
IR.AddListener(IR.EVENT_APP_ENTER_FOREGROUND, 0, function()
{
IR.ClearNotification();
});
- Works only on iOS
IR.EVENT_RECEIVE_NOTIFY
Event identifier triggered when the application receives a local notification
Syntax
IR.AddListener(IR.EVENT_RECEIVE_NOTIFY, 0, function, [pointer]);
| Input | Value | Description |
|---|---|---|
| function | function() {} | type: function anonymous function or function reference |
| pointer | - | type: object pointer to the object serving as the function context (optional) |
| Output | ||
|---|---|---|
| text | - | type: string notification text |
| id | - | type: string notification text identifier |
Example
IR.AddListener(IR.EVENT_RECEIVE_NOTIFY, 0, notify)
function notify (text, id)
{
switch (id)
{
case "Notify 1": // notification ID
IR.ShowPopup("Popup 1");
IR.GetItem("Popup 1").GetItem("Item 1").Text = text; // notification text
break;
case "Notify 2":
IR.ShowPopup("Popup 2");
IR.GetItem("Popup 2").GetItem("Item 1").Text = text;
break;
}
}
IR.EVENT_APP_ENTER_BACKGROUND
Event identifier triggered when the application is minimized or closed on iOS or Android
Syntax
IR.AddListener(IR.EVENT_APP_ENTER_BACKGROUND, 0, function, [pointer]);
| Input | Value | Description |
|---|---|---|
| function | function() {} | type: function anonymous function or function reference |
| pointer | - | type: object pointer to the object serving as the function context (optional) |
| Output | ||
|---|---|---|
| - |
Example
IR.AddListener(IR.EVENT_APP_ENTER_BACKGROUND, 0, function()
{
IR.Log("app minimized");
});
- The event does not trigger if the application crashes
IR.EVENT_APP_ENTER_FOREGROUND
Event identifier triggered when the application returns to the foreground on iOS or Android
Syntax
IR.AddListener(IR.EVENT_APP_ENTER_FOREGROUND, 0, function, [pointer]);
| Input | Value | Description |
|---|---|---|
| function | function() {} | type: function anonymous function or function reference |
| pointer | - | type: object pointer to the object serving as the function context (optional) |
| Output | ||
|---|---|---|
| - |
Example
IR.AddListener(IR.EVENT_APP_ENTER_FOREGROUND, 0, function()
{
IR.Log("app maximized");
});
- The event does not trigger at application startup
IR.EVENT_APP_WILL_TERMINATE
Event identifier triggered immediately before the application terminates on iOS or Android.
Syntax
IR.AddListener(IR.EVENT_APP_WILL_TERMINATE, 0, function, [pointer]);
| Input | Value | Description |
|---|---|---|
| function | function() {} | type: function anonymous function or function reference |
| pointer | - | type: object pointer to the object serving as the function context (optional) |
| Output | ||
|---|---|---|
| - |
Example
IR.AddListener(IR.EVENT_APP_WILL_TERMINATE, 0, function()
{
IR.Log("app will be closed right now");
});
- The event does not trigger if the application crashes