Rev 1622 | Rev 1646 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1622 | Rev 1644 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | 1 | ||
| 2 |
|
2 | IROut_ModuleName = "irTransmit"; |
| 3 | { |
- | |
| 4 |
|
3 | IROut_Channels = function() { return [ 0 ]; }; |
| 5 |
|
4 | IROut_Statuses = function() { return [ "Pressed", "Released", "Burst" ]; }; |
| 6 | } |
- | |
| 7 | - | ||
| - | 5 | IROut_Protocols = function() { return [ "RC5", "RC6", "RCMM", "SIRC", "Sharp", "NEC", "Samsung", "Marantz", "Panasonic", "Sky", "Nexa2" ]; }; |
|
| 8 |
|
6 | IROut_Aliases = function() { return Module_GetAliasNames([ IROut_ModuleName ]); }; |
| 9 | - | ||
| 10 |
|
7 | IROut_AvailableIds = function() { return Module_GetAvailableIds([ IROut_ModuleName ]); }; |
| 11 | 8 | ||
| - | 9 | function IROut_MessageAliasLookup(module_id, command, variables) |
|
| - | 10 | { |
|
| - | 11 | var aliases_data = {}; |
|
| - | 12 | ||
| - | 13 | aliases_data = Module_LookupAliases({ |
|
| - | 14 | "module_name" : IROut_ModuleName, |
|
| - | 15 | "module_id" : module_id, |
|
| - | 16 | "channel" : channel |
|
| - | 17 | }); |
|
| - | 18 | ||
| - | 19 | return aliases_data; |
|
| - | 20 | } |
|
| - | 21 | Module_RegisterMessageAliasLookup(IROut_ModuleName, IROut_MessageAliasLookup); |
|
| - | 22 | ||
| - | 23 | function IROut_CreateAlias(alias_name, module_id, channel) |
|
| - | 24 | { |
|
| - | 25 | var alias_data = { |
|
| - | 26 | "group" : false, |
|
| - | 27 | "name" : alias_name, |
|
| - | 28 | "module_name" : IROut_ModuleName, |
|
| - | 29 | "module_id" : module_id, |
|
| - | 30 | "channel" : channel |
|
| - | 31 | }; |
|
| - | 32 | ||
| - | 33 | return Storage_SetParameter("alias", alias_name, JSON.stringify(alias_data)); |
|
| - | 34 | } |
|
| - | 35 | Console_RegisterCommand(IROut_CreateAlias, function(args) { return Console_StandardAutocomplete(args, IROut_Aliases(), IROut_AvailableIds(), IROut_Channels()); }); |
|
| - | 36 | ||
| - | 37 | function IROut_StopSend(alias_name) |
|
| - | 38 | { |
|
| - | 39 | if (arguments.length < 4) |
|
| - | 40 | { |
|
| - | 41 | throw("Not enought parameters given"); |
|
| - | 42 | } |
|
| - | 43 | ||
| - | 44 | var result_text = ""; |
|
| - | 45 | var aliases_data = Module_ResolveAlias(alias_name, [ IROut_ModuleName ]); |
|
| - | 46 | ||
| - | 47 | ||
| - | 48 | for (var name in aliases_data) |
|
| - | 49 | { |
|
| - | 50 | var variables = { |
|
| - | 51 | "Channel" : aliases_data[name]["channel"], |
|
| - | 52 | "Status" : "Released" }; |
|
| - | 53 | ||
| - | 54 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "IR", variables)) |
|
| - | 55 | { |
|
| - | 56 | result_text += "StopSend sent successfully to " + name + "\n"; |
|
| - | 57 | } |
|
| - | 58 | else |
|
| - | 59 | { |
|
| - | 60 | result_text += "StopSend failed to send to " + name + "\n"; |
|
| - | 61 | } |
|
| - | 62 | } |
|
| - | 63 | ||
| - | 64 | if (result_text.length == 0) |
|
| - | 65 | { |
|
| - | 66 | result_text = "No aliases by the name " + alias_name + " were applicable to StopSend."; |
|
| - | 67 | } |
|
| - | 68 | ||
| - | 69 | return result_text; |
|
| - | 70 | } |
|
| - | 71 | Console_RegisterCommand(IROut_StopSend, function(args) { return Console_StandardAutocomplete(args, IROut_Aliases()); }); |
|
| - | 72 | ||
| - | 73 | function IROut_StartSendAutoComplete(args) |
|
| - | 74 | { |
|
| - | 75 | // args[0] == command name |
|
| - | 76 | var arg_index = args.length - 2; |
|
| - | 77 | ||
| - | 78 | if (arg_index == 0) |
|
| - | 79 | { |
|
| - | 80 | return IROut_Aliases(); |
|
| - | 81 | } |
|
| - | 82 | else if (arg_index == 1) |
|
| - | 83 | { |
|
| - | 84 | var remotes = Storage_GetParameters("RemoteList"); |
|
| - | 85 | ||
| - | 86 | var result = []; |
|
| - | 87 | ||
| - | 88 | for (var name in remotes) |
|
| - | 89 | { |
|
| - | 90 | result.push(name); |
|
| - | 91 | } |
|
| - | 92 | ||
| - | 93 | return result; |
|
| - | 94 | } |
|
| - | 95 | else if (arg_index == 2) |
|
| - | 96 | { |
|
| - | 97 | var remote_storage_name = Storage_GetParameter("RemoteList", args[arg_index]); |
|
| - | 98 | ||
| - | 99 | var buttons = Storage_GetParameters(remote_storage_name); |
|
| - | 100 | ||
| - | 101 | var result = []; |
|
| - | 102 | ||
| - | 103 | for (var name in buttons) |
|
| - | 104 | { |
|
| - | 105 | result.push(name); |
|
| - | 106 | } |
|
| - | 107 | ||
| - | 108 | return result; |
|
| - | 109 | } |
|
| - | 110 | ||
| - | 111 | return []; |
|
| - | 112 | } |
|
| - | 113 | ||
| 12 | function |
114 | function IROut_Send(alias_name, remote_name, button_name, status) |
| - | 115 | { |
|
| - | 116 | if (arguments.length < 4) |
|
| - | 117 | { |
|
| - | 118 | throw("Not enought parameters given"); |
|
| - | 119 | } |
|
| - | 120 | ||
| - | 121 | var result_text = ""; |
|
| - | 122 | var aliases_data = Module_ResolveAlias(alias_name, [ IROut_ModuleName ]); |
|
| - | 123 | ||
| - | 124 | var remote_storage_name = Storage_GetParameter("RemoteList", remote_name); |
|
| - | 125 | ||
| - | 126 | if (!remote_storage_name) |
|
| - | 127 | { |
|
| - | 128 | return "No such remote name in list, " + remote_name; |
|
| - | 129 | } |
|
| - | 130 | ||
| - | 131 | var button_string = Storage_GetParameter(remote_storage_name, button_name); |
|
| - | 132 | ||
| - | 133 | if (!button_string) |
|
| - | 134 | { |
|
| - | 135 | return "No such button " + button_name + " found on remote " + remote; |
|
| - | 136 | } |
|
| - | 137 | ||
| - | 138 | var button_data = eval("(" + button_string + ")"); |
|
| - | 139 | ||
| - | 140 | if (typeof button_data["protocol"] == 'undefined' || typeof button_data["data"] == 'undefined') |
|
| - | 141 | { |
|
| - | 142 | return "Button data is corrupt"; |
|
| - | 143 | } |
|
| - | 144 | ||
| - | 145 | ||
| - | 146 | for (var name in aliases_data) |
|
| - | 147 | { |
|
| - | 148 | var variables = { |
|
| - | 149 | "Channel" : aliases_data[name]["channel"], |
|
| - | 150 | "Protocol" : button_data["protocol"], |
|
| - | 151 | "IRdata" : button_data["data"], |
|
| - | 152 | "Status" : status }; |
|
| - | 153 | ||
| - | 154 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "IR", variables)) |
|
| - | 155 | { |
|
| - | 156 | result_text += "StartSend sent successfully to " + name + "\n"; |
|
| - | 157 | } |
|
| - | 158 | else |
|
| - | 159 | { |
|
| - | 160 | result_text += "StartSend failed to send to " + name + "\n"; |
|
| - | 161 | } |
|
| - | 162 | } |
|
| - | 163 | ||
| - | 164 | if (result_text.length == 0) |
|
| - | 165 | { |
|
| - | 166 | result_text = "No aliases by the name " + alias_name + " were applicable to StartSend."; |
|
| - | 167 | } |
|
| - | 168 | ||
| - | 169 | return result_text; |
|
| - | 170 | } |
|
| - | 171 | ||
| - | 172 | function IROut_StartSend(alias_name, remote_name, button_name) |
|
| - | 173 | { |
|
| - | 174 | return IROut_Send(alias_name, remote_name, button_name, "Pressed"); |
|
| - | 175 | } |
|
| - | 176 | Console_RegisterCommand(IROut_StartSend, IROut_StartSendAutoComplete); |
|
| - | 177 | ||
| - | 178 | function IROut_SendBurst(alias_name, remote_name, button_name) |
|
| 13 | { |
179 | { |
| 14 | var variables = [ |
- | |
| 15 | { "Channel" : channel }, |
- | |
| 16 | { "Protocol" : protocol }, |
- | |
| 17 | { "IRdata" : data }, |
- | |
| 18 | { "Status" : status } ]; |
- | |
| 19 | - | ||
| 20 |
|
180 | return IROut_Send(alias_name, remote_name, button_name, "Burst"); |
| 21 | return "OK"; |
- | |
| 22 | } |
181 | } |
| 23 |
|
182 | Console_RegisterCommand(IROut_SendBurst, IROut_StartSendAutoComplete); |
| - | 183 | ||