Rev 2123 | Rev 2125 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 2123 | Rev 2124 | ||
|---|---|---|---|
| 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 | Log("will send data to: "+aliases_data[name]["module_name"]+":"+aliases_data[name]["module_id"]+" Data: "+ data + " Prot: "+protocol+" Sts: "+status+"\n"); |
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 | Console_RegisterCommand(IROut_SendBurst, IROut_StartSendAutoComplete); |
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 | 154 | ||
| 155 | function IROut_SendBurst_Raw(alias_name, protocol, data) |
155 | function IROut_SendBurst_Raw(alias_name, protocol, data) |
| 156 | { |
156 | { |
| 157 | return IROut_Send_Raw(alias_name, protocol, data, "Burst"); |
157 | return IROut_Send_Raw(alias_name, protocol, data, "Burst"); |
| 158 | } |
158 | } |
| 159 | Console_RegisterCommand(IROut_SendBurst_Raw, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, IROut_Aliases(), IROut_Protocols()); }); |
159 | Console_RegisterCommand(IROut_SendBurst_Raw, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, IROut_Aliases(), IROut_Protocols()); }); |
| 160 | 160 | ||
| 161 | function IROut_SendDimmer(alias_name, remote_name, button_name, level) |
161 | function IROut_SendDimmer(alias_name, remote_name, button_name, level) |
| 162 | { |
162 | { |
| 163 | if (arguments.length < 4) |
163 | if (arguments.length < 4) |
| 164 | { |
164 | { |
| 165 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
165 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
| 166 | return false; |
166 | return false; |
| 167 | } |
167 | } |
| 168 | 168 | ||
| 169 | var remote_storage_name = Storage_GetParameter("RemoteList", remote_name); |
169 | var remote_storage_name = Storage_GetParameter("RemoteList", remote_name); |
| 170 | 170 | ||
| 171 | if (!remote_storage_name) |
171 | if (!remote_storage_name) |
| 172 | { |
172 | { |
| 173 | Log("\033[31mNo such remote name in list, " + remote_name + ".\033[0m\n"); |
173 | Log("\033[31mNo such remote name in list, " + remote_name + ".\033[0m\n"); |
| 174 | return false; |
174 | return false; |
| 175 | } |
175 | } |
| 176 | 176 | ||
| 177 | var button_string = Storage_GetParameter(remote_storage_name, button_name); |
177 | var button_string = Storage_GetParameter(remote_storage_name, button_name); |
| 178 | 178 | ||
| 179 | if (!button_string) |
179 | if (!button_string) |
| 180 | { |
180 | { |
| 181 | Log("\033[31mNo such button " + button_name + " found on remote " + |
181 | Log("\033[31mNo such button " + button_name + " found on remote " + remote_name + ".\033[0m\n"); |
| 182 | return false; |
182 | return false; |
| 183 | } |
183 | } |
| 184 | 184 | ||
| 185 | var button_data = eval("(" + button_string + ")"); |
185 | var button_data = eval("(" + button_string + ")"); |
| 186 | 186 | ||
| 187 | if (typeof button_data["protocol"] == 'undefined' || typeof button_data["data"] == 'undefined') |
187 | if (typeof button_data["protocol"] == 'undefined' || typeof button_data["data"] == 'undefined') |
| 188 | { |
188 | { |
| 189 | Log("\033[31mButton data is corrupt.\033[0m\n"); |
189 | Log("\033[31mButton data is corrupt.\033[0m\n"); |
| 190 | return false; |
190 | return false; |
| 191 | } |
191 | } |
| 192 | levelInt = parseInt(level); |
192 | levelInt = parseInt(level); |
| 193 | dataInt = parseInt(button_data["data"]); |
193 | dataInt = parseInt(button_data["data"]); |
| 194 | if (levelInt >= 0 && levelInt <= 15) { |
194 | if (levelInt >= 0 && levelInt <= 15) { |
| 195 | switch(levelInt) { |
195 | switch(levelInt) { |
| 196 | case 0: |
196 | case 0: |
| 197 | levelInt = 15; |
197 | levelInt = 15; |
| 198 | break; |
198 | break; |
| 199 | case 1: |
199 | case 1: |
| 200 | levelInt = 7; |
200 | levelInt = 7; |
| 201 | break; |
201 | break; |
| 202 | case 2: |
202 | case 2: |
| 203 | levelInt = 11; |
203 | levelInt = 11; |
| 204 | break; |
204 | break; |
| 205 | case 3: |
205 | case 3: |
| 206 | levelInt = 3; |
206 | levelInt = 3; |
| 207 | break; |
207 | break; |
| 208 | case 4: |
208 | case 4: |
| 209 | levelInt = 13; |
209 | levelInt = 13; |
| 210 | break; |
210 | break; |
| 211 | case 5: |
211 | case 5: |
| 212 | levelInt = 5; |
212 | levelInt = 5; |
| 213 | break; |
213 | break; |
| 214 | case 6: |
214 | case 6: |
| 215 | levelInt = 9; |
215 | levelInt = 9; |
| 216 | break; |
216 | break; |
| 217 | case 7: |
217 | case 7: |
| 218 | levelInt = 1; |
218 | levelInt = 1; |
| 219 | break; |
219 | break; |
| 220 | case 8: |
220 | case 8: |
| 221 | levelInt = 14; |
221 | levelInt = 14; |
| 222 | break; |
222 | break; |
| 223 | case 9: |
223 | case 9: |
| 224 | levelInt = 6; |
224 | levelInt = 6; |
| 225 | break; |
225 | break; |
| 226 | case 10: |
226 | case 10: |
| 227 | levelInt = 10; |
227 | levelInt = 10; |
| 228 | break; |
228 | break; |
| 229 | case 11: |
229 | case 11: |
| 230 | levelInt = 2; |
230 | levelInt = 2; |
| 231 | break; |
231 | break; |
| 232 | case 12: |
232 | case 12: |
| 233 | levelInt = 12; |
233 | levelInt = 12; |
| 234 | break; |
234 | break; |
| 235 | case 13: |
235 | case 13: |
| 236 | levelInt = 4; |
236 | levelInt = 4; |
| 237 | break; |
237 | break; |
| 238 | case 14: |
238 | case 14: |
| 239 | levelInt = 8; |
239 | levelInt = 8; |
| 240 | break; |
240 | break; |
| 241 | case 15: |
241 | case 15: |
| 242 | levelInt = 0; |
242 | levelInt = 0; |
| 243 | break; |
243 | break; |
| 244 | } |
244 | } |
| 245 | dataInt += 549755813888; //Set MSB |
245 | dataInt += 549755813888; //Set MSB |
| 246 | dataInt += levelInt*4294967296//Add dimmer level |
246 | dataInt += levelInt*4294967296//Add dimmer level |
| - | 247 | Log("button_data[protocol]=" + button_data["protocol"] + "\n"); |
|
| 247 | return IROut_Send_Raw(alias_name, button_data["protocol"], dataInt.toString(), "Burst"); |
248 | return IROut_Send_Raw(alias_name, button_data["protocol"], dataInt.toString(), "Burst"); |
| 248 | } else { |
249 | } else { |
| 249 | Log("\033[31mDimmer level out of range [0 -> 16].\033[0m\n"); |
250 | Log("\033[31mDimmer level out of range [0 -> 16].\033[0m\n"); |
| 250 | return false; |
251 | return false; |
| 251 | } |
252 | } |
| 252 | } |
253 | } |
| 253 | Console_RegisterCommand(IROut_SendDimmer, IROut_StartSendAutoComplete); |
254 | Console_RegisterCommand(IROut_SendDimmer, IROut_StartSendAutoComplete); |
| 254 | 255 | ||
| 255 | 256 | ||
| 256 | 257 | ||
| 257 | function IROut_SendDuration(alias_name, remote_name, button_name, duration_ms) |
258 | function IROut_SendDuration(alias_name, remote_name, button_name, duration_ms) |
| 258 | { |
259 | { |
| 259 | IROut_Send(alias_name, remote_name, button_name, "Pressed"); |
260 | IROut_Send(alias_name, remote_name, button_name, "Pressed"); |
| 260 | Timer_SetTimer(function(timer) {IROut_StopSend(alias_name);}, duration_ms, false); |
261 | Timer_SetTimer(function(timer) {IROut_StopSend(alias_name);}, duration_ms, false); |
| 261 | } |
262 | } |
| 262 | Console_RegisterCommand(IROut_SendDuration, IROut_StartSendAutoComplete); |
263 | Console_RegisterCommand(IROut_SendDuration, IROut_StartSendAutoComplete); |
| 263 | 264 | ||
| 264 | 265 | ||