Subversion Repositories HomeAutomation

Rev

Rev 2114 | Rev 2117 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 2114 Rev 2116
1
 
1
 
2
IROut_ModuleNames    = [ "irTransmit", "rfTransceive" ];
2
IROut_ModuleNames    = [ "irTransmit", "rfTransceive" ];
3
IROut_Channels       = function() { return [ 0 ]; };
3
IROut_Channels       = function() { return [ 0 ]; };
4
IROut_Statuses       = function() { return [ "Pressed", "Released", "Burst" ]; };
4
IROut_Statuses       = function() { return [ "Pressed", "Released", "Burst" ]; };
5
IROut_Protocols      = function() { return [ "RC5", "RC6", "RCMM", "SIRC", "Sharp", "NEC", "Samsung", "Marantz", "Panasonic", "Sky", "Nexa2", "Nexa" ]; };
5
IROut_Protocols      = function() { return [ "RC5", "RC6", "RCMM", "SIRC", "Sharp", "NEC", "Samsung", "Marantz", "Panasonic", "Sky", "Nexa2", "Nexa" ]; };
6
IROut_Aliases        = function() { return Module_GetAliasNames(IROut_ModuleNames); };
6
IROut_Aliases        = function() { return Module_GetAliasNames(IROut_ModuleNames); };
7
IROut_AvailableIds   = function() { return Module_GetAvailableIds(IROut_ModuleNames); };
7
IROut_AvailableIds   = function() { return Module_GetAvailableIds(IROut_ModuleNames); };
8
 
8
 
9
function IROut_StopSend(alias_name)
9
function IROut_StopSend(alias_name)
10
{
10
{
11
    if (arguments.length < 1)
11
    if (arguments.length < 1)
12
    {
12
    {
13
        Log("\033[31mNot enough parameters given.\033[0m\n");
13
        Log("\033[31mNot enough parameters given.\033[0m\n");
14
        return false;
14
        return false;
15
    }
15
    }
16
   
16
   
17
    var aliases_data = Module_ResolveAlias(alias_name, IROut_ModuleNames);
17
    var aliases_data = Module_ResolveAlias(alias_name, IROut_ModuleNames);
18
    var found = false;
18
    var found = false;
19
   
19
   
20
    for (var name in aliases_data)
20
    for (var name in aliases_data)
21
    {
21
    {
22
        var variables = {
22
        var variables = {
23
        "Channel"  : aliases_data[name]["specific"]["Channel"],
23
        "Channel"  : aliases_data[name]["specific"]["Channel"],
24
        "Status"   : "Released" };
24
        "Status"   : "Released" };
25
       
25
       
26
        if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "IR", variables))
26
        if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "IR", variables))
27
        {
27
        {
28
            Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n");
28
            Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n");
29
        }
29
        }
30
        else
30
        else
31
        {
31
        {
32
            Log("\033[31mFailed to send command to " + name + ".\033[0m\n");
32
            Log("\033[31mFailed to send command to " + name + ".\033[0m\n");
33
        }
33
        }
34
       
34
       
35
        found = true;
35
        found = true;
36
    }
36
    }
37
   
37
   
38
    if (!found)
38
    if (!found)
39
    {
39
    {
40
        Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n");
40
        Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n");
41
        return false;
41
        return false;
42
    }
42
    }
43
   
43
   
44
    return true;
44
    return true;
45
}
45
}
46
Console_RegisterCommand(IROut_StopSend, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, IROut_Aliases()); });
46
Console_RegisterCommand(IROut_StopSend, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, IROut_Aliases()); });
47
 
47
 
48
function IROut_StartSendAutoComplete(arg_index, args)
48
function IROut_StartSendAutoComplete(arg_index, args)
49
{
49
{
50
    if (arg_index == 0)
50
    if (arg_index == 0)
51
    {
51
    {
52
        return IROut_Aliases();
52
        return IROut_Aliases();
53
    }
53
    }
54
    else if (arg_index == 1)
54
    else if (arg_index == 1)
55
    {
55
    {
56
        return get_keys(Storage_GetParameters("RemoteList"));
56
        return get_keys(Storage_GetParameters("RemoteList"));
57
    }
57
    }
58
    else if (arg_index == 2)
58
    else if (arg_index == 2)
59
    {
59
    {
60
        var remote_storage_name = Storage_GetParameter("RemoteList", args[arg_index - 1]);
60
        var remote_storage_name = Storage_GetParameter("RemoteList", args[arg_index - 1]);
61
 
61
 
62
        return get_keys(Storage_GetParameters(remote_storage_name));
62
        return get_keys(Storage_GetParameters(remote_storage_name));
63
    }
63
    }
64
   
64
   
65
    return [];
65
    return [];
66
}
66
}
67
 
67
 
68
function IROut_Send_Raw(alias_name, protocol, data, status)
68
function IROut_Send_Raw(alias_name, protocol, data, status)
69
{
69
{
70
    if (arguments.length < 4)
70
    if (arguments.length < 4)
71
    {
71
    {
72
        Log("\033[31mNot enough parameters given.\033[0m\n");
72
        Log("\033[31mNot enough parameters given.\033[0m\n");
73
        return false;
73
        return false;
74
    }
74
    }
75
   
75
   
76
    var aliases_data = Module_ResolveAlias(alias_name, IROut_ModuleNames);
76
    var aliases_data = Module_ResolveAlias(alias_name, IROut_ModuleNames);
77
   
77
   
78
    for (var name in aliases_data)
78
    for (var name in aliases_data)
79
    {
79
    {
80
        var variables = {
80
        var variables = {
81
        "Channel"  : aliases_data[name]["specific"]["Channel"],
81
        "Channel"  : aliases_data[name]["specific"]["Channel"],
82
        "Protocol" : protocol,
82
        "Protocol" : protocol,
83
        "IRdata"   : data,
83
        "IRdata"   : data,
84
        "Status"   : status };
84
        "Status"   : status };
85
       
-
 
-
 
85
        Log("will send data to: "+aliases_data[name]["module_name"]+":"+aliases_data[name]["module_id"]+" Data: "+ data + " Prot: "+protocol+" Sts: "+status+"\n");
86
        if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "IR", variables))
86
        if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "IR", variables))
87
        {
87
        {
88
            Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n");
88
            Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n");
89
        }
89
        }
90
        else
90
        else
91
        {
91
        {
92
            Log("\033[31mFailed to send command to " + name + ".\033[0m\n");
92
            Log("\033[31mFailed to send command to " + name + ".\033[0m\n");
93
        }
93
        }
94
       
94
       
95
        found = true;
95
        found = true;
96
    }
96
    }
97
   
97
   
98
    if (!found)
98
    if (!found)
99
    {
99
    {
100
        Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n");
100
        Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n");
101
        return false;
101
        return false;
102
    }
102
    }
103
   
103
   
104
    return true;
104
    return true;
105
}
105
}
106
 
-
 
-
 
106
Console_RegisterCommand(IROut_SendBurst, IROut_StartSendAutoComplete);
107
 
107
 
108
function IROut_Send(alias_name, remote_name, button_name, status)
108
function IROut_Send(alias_name, remote_name, button_name, status)
109
{
109
{
110
    if (arguments.length < 4)
110
    if (arguments.length < 4)
111
    {
111
    {
112
        Log("\033[31mNot enough parameters given.\033[0m\n");
112
        Log("\033[31mNot enough parameters given.\033[0m\n");
113
        return false;
113
        return false;
114
    }
114
    }
115
   
115
   
116
    var remote_storage_name = Storage_GetParameter("RemoteList", remote_name);
116
    var remote_storage_name = Storage_GetParameter("RemoteList", remote_name);
117
   
117
   
118
    if (!remote_storage_name)
118
    if (!remote_storage_name)
119
    {
119
    {
120
        Log("\033[31mNo such remote name in list, " + remote_name + ".\033[0m\n");
120
        Log("\033[31mNo such remote name in list, " + remote_name + ".\033[0m\n");
121
        return false;
121
        return false;
122
    }
122
    }
123
   
123
   
124
    var button_string = Storage_GetParameter(remote_storage_name, button_name);
124
    var button_string = Storage_GetParameter(remote_storage_name, button_name);
125
   
125
   
126
    if (!button_string)
126
    if (!button_string)
127
    {
127
    {
128
        Log("\033[31mNo such button " + button_name + " found on remote " + remote + ".\033[0m\n");
128
        Log("\033[31mNo such button " + button_name + " found on remote " + remote + ".\033[0m\n");
129
        return false;
129
        return false;
130
    }
130
    }
131
   
131
   
132
    var button_data = eval("(" + button_string + ")");
132
    var button_data = eval("(" + button_string + ")");
133
   
133
   
134
    if (typeof button_data["protocol"] == 'undefined' || typeof button_data["data"] == 'undefined')
134
    if (typeof button_data["protocol"] == 'undefined' || typeof button_data["data"] == 'undefined')
135
    {
135
    {
136
        Log("\033[31mButton data is corrupt.\033[0m\n");
136
        Log("\033[31mButton data is corrupt.\033[0m\n");
137
        return false;
137
        return false;
138
    }
138
    }
139
   
139
   
140
    return IROut_Send_Raw(alias_name, button_data["protocol"], button_data["data"], status);
140
    return IROut_Send_Raw(alias_name, button_data["protocol"], button_data["data"], status);
141
}
141
}
142
 
142
 
143
function IROut_StartSend(alias_name, remote_name, button_name)
143
function IROut_StartSend(alias_name, remote_name, button_name)
144
{
144
{
145
    return IROut_Send(alias_name, remote_name, button_name, "Pressed");
145
    return IROut_Send(alias_name, remote_name, button_name, "Pressed");
146
}
146
}
147
Console_RegisterCommand(IROut_StartSend, IROut_StartSendAutoComplete);
147
Console_RegisterCommand(IROut_StartSend, IROut_StartSendAutoComplete);
148
 
148
 
149
function IROut_SendBurst(alias_name, remote_name, button_name)
149
function IROut_SendBurst(alias_name, remote_name, button_name)
150
{
150
{
151
    return IROut_Send(alias_name, remote_name, button_name, "Burst");
151
    return IROut_Send(alias_name, remote_name, button_name, "Burst");
152
}
152
}
153
Console_RegisterCommand(IROut_SendBurst, IROut_StartSendAutoComplete);
153
Console_RegisterCommand(IROut_SendBurst, IROut_StartSendAutoComplete);
-
 
154
 
-
 
155
function IROut_SendBurst_Raw(alias_name, data)
-
 
156
{
-
 
157
    return IROut_Send_Raw(alias_name, "Nexa2", data, "Burst");
-
 
158
}
-
 
159
Console_RegisterCommand(IROut_SendBurst_Raw, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, IROut_Aliases()); });
154
 
160
 
155
function IROut_SendDuration(alias_name, remote_name, button_name, duration_ms)
161
function IROut_SendDuration(alias_name, remote_name, button_name, duration_ms)
156
{
162
{
157
    IROut_Send(alias_name, remote_name, button_name, "Pressed");
163
    IROut_Send(alias_name, remote_name, button_name, "Pressed");
158
    Timer_SetTimer(function(timer) {IROut_StopSend(alias_name);}, duration_ms, false);
164
    Timer_SetTimer(function(timer) {IROut_StopSend(alias_name);}, duration_ms, false);
159
}
165
}
160
Console_RegisterCommand(IROut_SendDuration, IROut_StartSendAutoComplete);
166
Console_RegisterCommand(IROut_SendDuration, IROut_StartSendAutoComplete);
161
 
167
 
162
 
168