Subversion Repositories HomeAutomation

Rev

Rev 1648 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1648 Rev 1649
1
 
1
 
2
IRIn_ModuleNames    = [ "irReceive" ];
2
IRIn_ModuleNames    = [ "irReceive" ];
3
IRIn_Channels       = function() { return [ 0 ]; };
3
IRIn_Channels       = function() { return [ 0 ]; };
4
IRIn_Aliases        = function() { return Module_GetAliasNames(IRIn_ModuleNames); };
4
IRIn_Aliases        = function() { return Module_GetAliasNames(IRIn_ModuleNames); };
5
IRIn_AvailableIds   = function() { return Module_GetAvailableIds(IRIn_ModuleNames); };
5
IRIn_AvailableIds   = function() { return Module_GetAvailableIds(IRIn_ModuleNames); };
6
IRIn_Remotes        = function() { return get_keys(Storage_GetParameters("RemoteList")); };
6
IRIn_Remotes        = function() { return get_keys(Storage_GetParameters("RemoteList")); };
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
 
11
 
12
function IRIn_CodeToName(data, protocol, remote_name)
12
function IRIn_CodeToName(data, protocol, remote_name)
13
{
13
{
14
    var remote_storage_name = Storage_GetParameter("RemoteList", remote_name);
14
    var remote_storage_name = Storage_GetParameter("RemoteList", remote_name);
15
 
15
 
16
        if (!remote_storage_name)
16
        if (!remote_storage_name)
17
        {
17
        {
18
        Log("No such remote " + remote_name);
18
        Log("No such remote " + remote_name);
19
                return "";
19
                return "";
20
        }
20
        }
21
 
21
 
22
    var buttons = Storage_GetParameters(remote_storage_name);
22
    var buttons = Storage_GetParameters(remote_storage_name);
23
 
23
 
24
    for (var button_name in buttons)
24
    for (var button_name in buttons)
25
    {
25
    {
26
        var button_data = eval("(" + buttons[button_name]+ ")");
26
        var button_data = eval("(" + buttons[button_name]+ ")");
27
 
27
 
28
        Log(buttons[button_name]);
28
        Log(buttons[button_name]);
29
 
29
 
30
        if (button_data["data"] == (data + '') && button_data["protocol"] == protocol)
30
        if (button_data["data"] == (data + '') && button_data["protocol"] == protocol)
31
        {
31
        {
32
            return button_name;
32
            return button_name;
33
        }
33
        }
34
    }
34
    }
35
 
35
 
36
    Log("Found no matching button on remote " + remote_name);
36
    Log("Found no matching button on remote " + remote_name);
37
    return "";
37
    return "";
38
}
38
}
39
 
39
 
40
function IRIn_Record(alias_name, remote_name)
40
function IRIn_Record(alias_name, remote_name)
41
{
41
{
42
   
42
   
43
    if (arguments.length < 2)
43
    if (arguments.length < 2)
44
    {
44
    {
45
        Log("\033[31;1mNot enough parameters given.\033[0m\n");
45
        Log("\033[31mNot enough parameters given.\033[0m\n");
46
        return false;
46
        return false;
47
    }
47
    }
48
   
48
   
49
    IRIn_RecordRemoteName = Storage_GetParameter("RemoteList", remote_name);
49
    IRIn_RecordRemoteName = Storage_GetParameter("RemoteList", remote_name);
50
   
50
   
51
    if (!IRIn_RecordRemoteName)
51
    if (!IRIn_RecordRemoteName)
52
    {
52
    {
53
        IRIn_RecordRemoteName = "Remote_" + remote_name;
53
        IRIn_RecordRemoteName = "Remote_" + remote_name;
54
       
54
       
55
        Log("\033[32;1mNo such remote name in list, " + remote_name + ", creating...\033[0m\n");
55
        Log("\033[32mNo such remote name in list, " + remote_name + ", creating...\033[0m\n");
56
       
56
       
57
        Storage_SetParameter("RemoteList", remote_name, IRIn_RecordRemoteName);
57
        Storage_SetParameter("RemoteList", remote_name, IRIn_RecordRemoteName);
58
    }
58
    }
59
   
59
   
60
    var aliases_data = Module_ResolveAlias(alias_name, IRIn_ModuleNames);
60
    var aliases_data = Module_ResolveAlias(alias_name, IRIn_ModuleNames);
61
   
61
   
62
    for (var name in aliases_data)
62
    for (var name in aliases_data)
63
    {
63
    {
64
        if (aliases_data[name]["group"])
64
        if (aliases_data[name]["group"])
65
        {
65
        {
66
            Log("\033[31;1mAlias must not be an alias group.\033[0m\n");
66
            Log("\033[31mAlias must not be an alias group.\033[0m\n");
67
            return false;
67
            return false;
68
        }
68
        }
69
       
69
       
70
        IRIn_RecordAliasData = aliases_data[name];
70
        IRIn_RecordAliasData = aliases_data[name];
71
        Log("Enter a single dot to finish.\n");
71
        Log("Enter a single dot to finish.\n");
72
       
72
       
73
        Log("\033[29;1mPress a button on you remote...\033[0m\n");
73
        Log("\033[29mPress a button on you remote...\033[0m\n");
74
        Console_PreventDefaultPrompt();
74
        Console_PreventDefaultPrompt();
75
   
75
   
76
        Module_RegisterToOnMessage(alias_name, IRIn_RecordOnIrMessage);
76
        Module_RegisterToOnMessage(alias_name, IRIn_RecordOnIrMessage);
77
        return true;
77
        return true;
78
    }
78
    }
79
   
79
   
80
    Log("\033[31;1mNo such alias name found, " + alias_name + ".\033[0m\n");
80
    Log("\033[31mNo such alias name found, " + alias_name + ".\033[0m\n");
81
    return false;
81
    return false;
82
   
82
   
83
}
83
}
84
Console_RegisterCommand(IRIn_Record, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, IRIn_Aliases(), IRIn_Remotes()); });
84
Console_RegisterCommand(IRIn_Record, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, IRIn_Aliases(), IRIn_Remotes()); });
85
 
85
 
86
function IRIn_RecordOnResponse(response)
86
function IRIn_RecordOnResponse(response)
87
{
87
{
88
    if (response == ".")
88
    if (response == ".")
89
    {
89
    {
90
        return true;
90
        return true;
91
    }
91
    }
92
   
92
   
93
    Storage_SetParameter(IRIn_RecordRemoteName, response, JSON.stringify(IRIn_RecordLast));
93
    Storage_SetParameter(IRIn_RecordRemoteName, response, JSON.stringify(IRIn_RecordLast));
94
    IRIn_RecordLast = null;
94
    IRIn_RecordLast = null;
95
   
95
   
96
    Log("\033[29;1mPress a button on you remote...\033[0m\n");
96
    Log("\033[29mPress a button on you remote...\033[0m\n");
97
    Console_PreventDefaultPrompt();
97
    Console_PreventDefaultPrompt();
98
   
98
   
99
    return true;
99
    return true;
100
}
100
}
101
 
101
 
102
function IRIn_RecordOnIrMessage(alias_name, command, variables)
102
function IRIn_RecordOnIrMessage(alias_name, command, variables)
103
{
103
{
104
    if (variables["Status"] != "Pressed" || IRIn_RecordLast != null)
104
    if (variables["Status"] != "Pressed" || IRIn_RecordLast != null)
105
    {
105
    {
106
        return;
106
        return;
107
    }
107
    }
108
   
108
   
109
    Log("\033[32;1mGot code " + variables["IRdata"] + " on protocol " + variables["Protocol"] + ".\033[0m\n");
109
    Log("\033[32mGot code " + variables["IRdata"] + " on protocol " + variables["Protocol"] + ".\033[0m\n");
110
   
110
   
111
    IRIn_RecordLast = { "protocol" : variables["Protocol"], "data" : variables["IRdata"] };
111
    IRIn_RecordLast = { "protocol" : variables["Protocol"], "data" : variables["IRdata"] };
112
   
112
   
113
    Console_PromptRequest("\033[29;1mEnter name: \033[0m", IRIn_RecordOnResponse);
113
    Console_PromptRequest("\033[29mEnter name: \033[0m", IRIn_RecordOnResponse);
114
   
114
   
115
    return true;
115
    return true;
116
}
116
}
117
 
117
 
118
 
118
 
119
 
119
 
120
 
120