Subversion Repositories HomeAutomation

Rev

Rev 1998 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1998 Rev 2048
Line 7... Line 7...
7
 
7
 
8
IRIn_RecordRemoteName = null;
8
IRIn_RecordRemoteName = null;
9
IRIn_RecordAliasData = null;
9
IRIn_RecordAliasData = null;
10
IRIn_RecordLast = null;
10
IRIn_RecordLast = null;
11
IRIn_RecordClientId = null;
11
IRIn_RecordClientId = null;
-
 
12
IRIn_OnMessageFunctions = null;
-
 
13
 
-
 
14
for (var i=0; i<IRIn_Aliases().length; i++)
-
 
15
{
-
 
16
    /* Register to messages from all ir aliases */
-
 
17
    Module_RegisterToOnMessage(IRIn_Aliases()[i], IRIn_IrMessage);
-
 
18
}
-
 
19
function IRIn_IrMessage(alias_name, command, variables)
-
 
20
{
-
 
21
    /* First check if there are any callbacks registered */
-
 
22
    if (IRIn_OnMessageFunctions == null)
-
 
23
    {
-
 
24
        return false;
-
 
25
    }
-
 
26
    /* Also check if there are any callbacks registered to this alias */
-
 
27
    if (!IRIn_OnMessageFunctions[alias_name])
-
 
28
    {
-
 
29
        return false;
-
 
30
    }
-
 
31
    /* Check if code and protocol maches one or more remote */
-
 
32
    var remotes = get_keys(Storage_GetParameters("RemoteList"));
-
 
33
    for (var i=0; i < remotes.length; i++)
-
 
34
    {
-
 
35
        var buttons = get_keys(Storage_GetParameters("Remote_"+remotes[i]));
-
 
36
        for (var j=0; j < buttons.length; j++)
-
 
37
        {
-
 
38
            var button_string = Storage_GetParameter("Remote_"+remotes[i], buttons[j]);
-
 
39
            var button_data = eval("(" + button_string + ")");
-
 
40
   
-
 
41
            if (typeof button_data["protocol"] == 'undefined' || typeof button_data["data"] == 'undefined')
-
 
42
            {
-
 
43
                Log("\033[31mButton data is corrupt.\033[0m\n");
-
 
44
                return false;
-
 
45
            }
-
 
46
           
-
 
47
            if (button_data["protocol"] == variables["Protocol"] && button_data["data"] == variables["IRdata"])
-
 
48
            {
-
 
49
                //Log("Found match: "+remotes[i]+" "+buttons[j]+" "+button_data["protocol"]+" "+button_data["data"]+"");
-
 
50
                if (IRIn_OnMessageFunctions[alias_name])
-
 
51
                {
-
 
52
                    for (var n in IRIn_OnMessageFunctions[alias_name])
-
 
53
                    {
-
 
54
                        //Log("Found callback, calling");
-
 
55
                        /* Call callback with arguments remotes[i] buttons[j] and variables["Status"]*/
-
 
56
                        IRIn_OnMessageFunctions[alias_name][n](alias_name, remotes[i], buttons[j], variables["Status"]);
-
 
57
                    }
-
 
58
                }
-
 
59
            }
-
 
60
        }
-
 
61
    }
-
 
62
    return true;
-
 
63
}
-
 
64
 
-
 
65
function IRIn_RegisterToMessage(alias_name, callback)
-
 
66
{
-
 
67
    if (IRIn_OnMessageFunctions == null)
-
 
68
    {
-
 
69
        IRIn_OnMessageFunctions = new Array();
-
 
70
    }
-
 
71
   
-
 
72
    if (!IRIn_OnMessageFunctions[alias_name])
-
 
73
    {
-
 
74
        IRIn_OnMessageFunctions[alias_name] = new Array();
-
 
75
    }
-
 
76
   
-
 
77
    IRIn_OnMessageFunctions[alias_name].push(callback);
-
 
78
}
12
 
79
 
13
function IRIn_CodeToName(data, protocol, remote_name)
80
function IRIn_CodeToName(data, protocol, remote_name)
14
{
81
{
15
    var remote_storage_name = Storage_GetParameter("RemoteList", remote_name);
82
    var remote_storage_name = Storage_GetParameter("RemoteList", remote_name);
16
 
83