Rev 1998 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1998 | Rev 2048 | ||
|---|---|---|---|
| 1 | 1 | ||
| 2 | IRIn_ModuleNames = [ "irReceive", "rfTransceive" ]; |
2 | IRIn_ModuleNames = [ "irReceive", "rfTransceive" ]; |
| 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 | 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 | ||
| 17 | if (!remote_storage_name) |
84 | if (!remote_storage_name) |
| 18 | { |
85 | { |
| 19 | Log("No such remote " + remote_name); |
86 | Log("No such remote " + remote_name); |
| 20 | return ""; |
87 | return ""; |
| 21 | } |
88 | } |
| 22 | 89 | ||
| 23 | var buttons = Storage_GetParameters(remote_storage_name); |
90 | var buttons = Storage_GetParameters(remote_storage_name); |
| 24 | 91 | ||
| 25 | for (var button_name in buttons) |
92 | for (var button_name in buttons) |
| 26 | { |
93 | { |
| 27 | var button_data = eval("(" + buttons[button_name]+ ")"); |
94 | var button_data = eval("(" + buttons[button_name]+ ")"); |
| 28 | 95 | ||
| 29 | Log(buttons[button_name]); |
96 | Log(buttons[button_name]); |
| 30 | 97 | ||
| 31 | if (button_data["data"] == (data + '') && button_data["protocol"] == protocol) |
98 | if (button_data["data"] == (data + '') && button_data["protocol"] == protocol) |
| 32 | { |
99 | { |
| 33 | return button_name; |
100 | return button_name; |
| 34 | } |
101 | } |
| 35 | } |
102 | } |
| 36 | 103 | ||
| 37 | Log("Found no matching button on remote " + remote_name); |
104 | Log("Found no matching button on remote " + remote_name); |
| 38 | return ""; |
105 | return ""; |
| 39 | } |
106 | } |
| 40 | 107 | ||
| 41 | function IRIn_Record(alias_name, remote_name) |
108 | function IRIn_Record(alias_name, remote_name) |
| 42 | { |
109 | { |
| 43 | if (arguments.length < 2) |
110 | if (arguments.length < 2) |
| 44 | { |
111 | { |
| 45 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
112 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
| 46 | return false; |
113 | return false; |
| 47 | } |
114 | } |
| 48 | 115 | ||
| 49 | IRIn_RecordRemoteName = Storage_GetParameter("RemoteList", remote_name); |
116 | IRIn_RecordRemoteName = Storage_GetParameter("RemoteList", remote_name); |
| 50 | 117 | ||
| 51 | if (!IRIn_RecordRemoteName) |
118 | if (!IRIn_RecordRemoteName) |
| 52 | { |
119 | { |
| 53 | IRIn_RecordRemoteName = "Remote_" + remote_name; |
120 | IRIn_RecordRemoteName = "Remote_" + remote_name; |
| 54 | 121 | ||
| 55 | Log("\033[32mNo such remote name in list, " + remote_name + ", creating...\033[0m\n"); |
122 | Log("\033[32mNo such remote name in list, " + remote_name + ", creating...\033[0m\n"); |
| 56 | 123 | ||
| 57 | Storage_SetParameter("RemoteList", remote_name, IRIn_RecordRemoteName); |
124 | Storage_SetParameter("RemoteList", remote_name, IRIn_RecordRemoteName); |
| 58 | } |
125 | } |
| 59 | 126 | ||
| 60 | var aliases_data = Module_ResolveAlias(alias_name, IRIn_ModuleNames); |
127 | var aliases_data = Module_ResolveAlias(alias_name, IRIn_ModuleNames); |
| 61 | 128 | ||
| 62 | for (var name in aliases_data) |
129 | for (var name in aliases_data) |
| 63 | { |
130 | { |
| 64 | if (aliases_data[name]["group"]) |
131 | if (aliases_data[name]["group"]) |
| 65 | { |
132 | { |
| 66 | Log("\033[31mAlias must not be an alias group.\033[0m\n"); |
133 | Log("\033[31mAlias must not be an alias group.\033[0m\n"); |
| 67 | return false; |
134 | return false; |
| 68 | } |
135 | } |
| 69 | 136 | ||
| 70 | IRIn_RecordClientId = Console_GetClientId(); |
137 | IRIn_RecordClientId = Console_GetClientId(); |
| 71 | 138 | ||
| 72 | IRIn_RecordAliasData = aliases_data[name]; |
139 | IRIn_RecordAliasData = aliases_data[name]; |
| 73 | Log("To finish press a random key on the remote and then enter dot as name.\n"); |
140 | Log("To finish press a random key on the remote and then enter dot as name.\n"); |
| 74 | 141 | ||
| 75 | Log("\033[29mPress a button on you remote...\033[0m\n"); |
142 | Log("\033[29mPress a button on you remote...\033[0m\n"); |
| 76 | Console_PreventDefaultPrompt(); |
143 | Console_PreventDefaultPrompt(); |
| 77 | 144 | ||
| 78 | Module_RegisterToOnMessage(alias_name, IRIn_RecordOnIrMessage); |
145 | Module_RegisterToOnMessage(alias_name, IRIn_RecordOnIrMessage); |
| 79 | return true; |
146 | return true; |
| 80 | } |
147 | } |
| 81 | 148 | ||
| 82 | Log("\033[31mNo such alias name found, " + alias_name + ".\033[0m\n"); |
149 | Log("\033[31mNo such alias name found, " + alias_name + ".\033[0m\n"); |
| 83 | return false; |
150 | return false; |
| 84 | 151 | ||
| 85 | } |
152 | } |
| 86 | Console_RegisterCommand(IRIn_Record, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, IRIn_Aliases(), IRIn_Remotes()); }); |
153 | Console_RegisterCommand(IRIn_Record, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, IRIn_Aliases(), IRIn_Remotes()); }); |
| 87 | 154 | ||
| 88 | function IRIn_RecordOnResponse(response) |
155 | function IRIn_RecordOnResponse(response) |
| 89 | { |
156 | { |
| 90 | if (response == ".") |
157 | if (response == ".") |
| 91 | { |
158 | { |
| 92 | IRIn_RecordClientId = null; |
159 | IRIn_RecordClientId = null; |
| 93 | return true; |
160 | return true; |
| 94 | } |
161 | } |
| 95 | 162 | ||
| 96 | Storage_SetParameter(IRIn_RecordRemoteName, response, JSON.stringify(IRIn_RecordLast)); |
163 | Storage_SetParameter(IRIn_RecordRemoteName, response, JSON.stringify(IRIn_RecordLast)); |
| 97 | IRIn_RecordLast = null; |
164 | IRIn_RecordLast = null; |
| 98 | 165 | ||
| 99 | Log("\033[29mPress a button on you remote...\033[0m\n"); |
166 | Log("\033[29mPress a button on you remote...\033[0m\n"); |
| 100 | Console_PreventDefaultPrompt(); |
167 | Console_PreventDefaultPrompt(); |
| 101 | 168 | ||
| 102 | return true; |
169 | return true; |
| 103 | } |
170 | } |
| 104 | 171 | ||
| 105 | function IRIn_RecordOnIrMessage(alias_name, command, variables) |
172 | function IRIn_RecordOnIrMessage(alias_name, command, variables) |
| 106 | { |
173 | { |
| 107 | if (variables["Status"] != "Pressed" || IRIn_RecordLast != null) |
174 | if (variables["Status"] != "Pressed" || IRIn_RecordLast != null) |
| 108 | { |
175 | { |
| 109 | return; |
176 | return; |
| 110 | } |
177 | } |
| 111 | 178 | ||
| 112 | ConsoleExport_LogToClient(IRIn_RecordClientId, "\033[32mGot code " + variables["IRdata"] + " on protocol " + variables["Protocol"] + ".\033[0m\n"); |
179 | ConsoleExport_LogToClient(IRIn_RecordClientId, "\033[32mGot code " + variables["IRdata"] + " on protocol " + variables["Protocol"] + ".\033[0m\n"); |
| 113 | 180 | ||
| 114 | IRIn_RecordLast = { "protocol" : variables["Protocol"], "data" : variables["IRdata"] }; |
181 | IRIn_RecordLast = { "protocol" : variables["Protocol"], "data" : variables["IRdata"] }; |
| 115 | 182 | ||
| 116 | Console_PromptRequest("\033[29mEnter name: \033[0m", IRIn_RecordOnResponse); |
183 | Console_PromptRequest("\033[29mEnter name: \033[0m", IRIn_RecordOnResponse); |
| 117 | 184 | ||
| 118 | return true; |
185 | return true; |
| 119 | } |
186 | } |
| 120 | 187 | ||