Rev 1657 | Rev 1998 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1657 | Rev 1997 | ||
|---|---|---|---|
| 1 | 1 | ||
| 2 | IRIn_ModuleNames = [ "irReceive" ]; |
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 | 12 | ||
| 13 | function IRIn_CodeToName(data, protocol, remote_name) |
13 | function IRIn_CodeToName(data, protocol, remote_name) |
| 14 | { |
14 | { |
| 15 | var remote_storage_name = Storage_GetParameter("RemoteList", remote_name); |
15 | var remote_storage_name = Storage_GetParameter("RemoteList", remote_name); |
| 16 | 16 | ||
| 17 | if (!remote_storage_name) |
17 | if (!remote_storage_name) |
| 18 | { |
18 | { |
| 19 | Log("No such remote " + remote_name); |
19 | Log("No such remote " + remote_name); |
| 20 | return ""; |
20 | return ""; |
| 21 | } |
21 | } |
| 22 | 22 | ||
| 23 | var buttons = Storage_GetParameters(remote_storage_name); |
23 | var buttons = Storage_GetParameters(remote_storage_name); |
| 24 | 24 | ||
| 25 | for (var button_name in buttons) |
25 | for (var button_name in buttons) |
| 26 | { |
26 | { |
| 27 | var button_data = eval("(" + buttons[button_name]+ ")"); |
27 | var button_data = eval("(" + buttons[button_name]+ ")"); |
| 28 | 28 | ||
| 29 | Log(buttons[button_name]); |
29 | Log(buttons[button_name]); |
| 30 | 30 | ||
| 31 | if (button_data["data"] == (data + '') && button_data["protocol"] == protocol) |
31 | if (button_data["data"] == (data + '') && button_data["protocol"] == protocol) |
| 32 | { |
32 | { |
| 33 | return button_name; |
33 | return button_name; |
| 34 | } |
34 | } |
| 35 | } |
35 | } |
| 36 | 36 | ||
| 37 | Log("Found no matching button on remote " + remote_name); |
37 | Log("Found no matching button on remote " + remote_name); |
| 38 | return ""; |
38 | return ""; |
| 39 | } |
39 | } |
| 40 | 40 | ||
| 41 | function IRIn_Record(alias_name, remote_name) |
41 | function IRIn_Record(alias_name, remote_name) |
| 42 | { |
42 | { |
| 43 | if (arguments.length < 2) |
43 | if (arguments.length < 2) |
| 44 | { |
44 | { |
| 45 | Log("\033[31mNot 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[32mNo 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[31mAlias 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_RecordClientId = Console_GetClientId(); |
70 | IRIn_RecordClientId = Console_GetClientId(); |
| 71 | 71 | ||
| 72 | IRIn_RecordAliasData = aliases_data[name]; |
72 | IRIn_RecordAliasData = aliases_data[name]; |
| 73 | Log("Enter a single dot to finish.\n"); |
73 | Log("Enter a single dot to finish.\n"); |
| 74 | 74 | ||
| 75 | Log("\033[29mPress a button on you remote...\033[0m\n"); |
75 | Log("\033[29mPress a button on you remote...\033[0m\n"); |
| 76 | Console_PreventDefaultPrompt(); |
76 | Console_PreventDefaultPrompt(); |
| 77 | 77 | ||
| 78 | Module_RegisterToOnMessage(alias_name, IRIn_RecordOnIrMessage); |
78 | Module_RegisterToOnMessage(alias_name, IRIn_RecordOnIrMessage); |
| 79 | return true; |
79 | return true; |
| 80 | } |
80 | } |
| 81 | 81 | ||
| 82 | Log("\033[31mNo such alias name found, " + alias_name + ".\033[0m\n"); |
82 | Log("\033[31mNo such alias name found, " + alias_name + ".\033[0m\n"); |
| 83 | return false; |
83 | return false; |
| 84 | 84 | ||
| 85 | } |
85 | } |
| 86 | Console_RegisterCommand(IRIn_Record, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, IRIn_Aliases(), IRIn_Remotes()); }); |
86 | Console_RegisterCommand(IRIn_Record, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, IRIn_Aliases(), IRIn_Remotes()); }); |
| 87 | 87 | ||
| 88 | function IRIn_RecordOnResponse(response) |
88 | function IRIn_RecordOnResponse(response) |
| 89 | { |
89 | { |
| 90 | if (response == ".") |
90 | if (response == ".") |
| 91 | { |
91 | { |
| 92 | IRIn_RecordClientId = null; |
92 | IRIn_RecordClientId = null; |
| 93 | return true; |
93 | return true; |
| 94 | } |
94 | } |
| 95 | 95 | ||
| 96 | Storage_SetParameter(IRIn_RecordRemoteName, response, JSON.stringify(IRIn_RecordLast)); |
96 | Storage_SetParameter(IRIn_RecordRemoteName, response, JSON.stringify(IRIn_RecordLast)); |
| 97 | IRIn_RecordLast = null; |
97 | IRIn_RecordLast = null; |
| 98 | 98 | ||
| 99 | Log("\033[29mPress a button on you remote...\033[0m\n"); |
99 | Log("\033[29mPress a button on you remote...\033[0m\n"); |
| 100 | Console_PreventDefaultPrompt(); |
100 | Console_PreventDefaultPrompt(); |
| 101 | 101 | ||
| 102 | return true; |
102 | return true; |
| 103 | } |
103 | } |
| 104 | 104 | ||
| 105 | function IRIn_RecordOnIrMessage(alias_name, command, variables) |
105 | function IRIn_RecordOnIrMessage(alias_name, command, variables) |
| 106 | { |
106 | { |
| 107 | if (variables["Status"] != "Pressed" || IRIn_RecordLast != null) |
107 | if (variables["Status"] != "Pressed" || IRIn_RecordLast != null) |
| 108 | { |
108 | { |
| 109 | return; |
109 | return; |
| 110 | } |
110 | } |
| 111 | 111 | ||
| 112 | ConsoleExport_LogToClient(IRIn_RecordClientId, "\033[32mGot code " + variables["IRdata"] + " on protocol " + variables["Protocol"] + ".\033[0m\n"); |
112 | ConsoleExport_LogToClient(IRIn_RecordClientId, "\033[32mGot code " + variables["IRdata"] + " on protocol " + variables["Protocol"] + ".\033[0m\n"); |
| 113 | 113 | ||
| 114 | IRIn_RecordLast = { "protocol" : variables["Protocol"], "data" : variables["IRdata"] }; |
114 | IRIn_RecordLast = { "protocol" : variables["Protocol"], "data" : variables["IRdata"] }; |
| 115 | 115 | ||
| 116 | Console_PromptRequest("\033[29mEnter name: \033[0m", IRIn_RecordOnResponse); |
116 | Console_PromptRequest("\033[29mEnter name: \033[0m", IRIn_RecordOnResponse); |
| 117 | 117 | ||
| 118 | return true; |
118 | return true; |
| 119 | } |
119 | } |
| 120 | 120 | ||