Rev 1652 | Rev 1998 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1603 | runge | 1 | |
| 1647 | runge | 2 | IRIn_ModuleNames = [ "irReceive" ]; |
| 1646 | runge | 3 | IRIn_Channels = function() { return [ 0 ]; }; |
| 1647 | runge | 4 | IRIn_Aliases = function() { return Module_GetAliasNames(IRIn_ModuleNames); }; |
| 5 | IRIn_AvailableIds = function() { return Module_GetAvailableIds(IRIn_ModuleNames); }; |
||
| 6 | IRIn_Remotes = function() { return get_keys(Storage_GetParameters("RemoteList")); }; |
||
| 1646 | runge | 7 | |
| 1647 | runge | 8 | IRIn_RecordRemoteName = null; |
| 9 | IRIn_RecordAliasData = null; |
||
| 10 | IRIn_RecordLast = null; |
||
| 1657 | runge | 11 | IRIn_RecordClientId = null; |
| 1647 | runge | 12 | |
| 13 | function IRIn_CodeToName(data, protocol, remote_name) |
||
| 1646 | runge | 14 | { |
| 1647 | runge | 15 | var remote_storage_name = Storage_GetParameter("RemoteList", remote_name); |
| 1646 | runge | 16 | |
| 1647 | runge | 17 | if (!remote_storage_name) |
| 18 | { |
||
| 19 | Log("No such remote " + remote_name); |
||
| 20 | return ""; |
||
| 21 | } |
||
| 1646 | runge | 22 | |
| 1647 | runge | 23 | var buttons = Storage_GetParameters(remote_storage_name); |
| 1646 | runge | 24 | |
| 1647 | runge | 25 | for (var button_name in buttons) |
| 26 | { |
||
| 27 | var button_data = eval("(" + buttons[button_name]+ ")"); |
||
| 1646 | runge | 28 | |
| 1647 | runge | 29 | Log(buttons[button_name]); |
| 1646 | runge | 30 | |
| 1647 | runge | 31 | if (button_data["data"] == (data + '') && button_data["protocol"] == protocol) |
| 32 | { |
||
| 33 | return button_name; |
||
| 34 | } |
||
| 35 | } |
||
| 1646 | runge | 36 | |
| 1648 | runge | 37 | Log("Found no matching button on remote " + remote_name); |
| 1647 | runge | 38 | return ""; |
| 39 | } |
||
| 1646 | runge | 40 | |
| 1647 | runge | 41 | function IRIn_Record(alias_name, remote_name) |
| 42 | { |
||
| 43 | if (arguments.length < 2) |
||
| 44 | { |
||
| 1649 | runge | 45 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
| 1647 | runge | 46 | return false; |
| 47 | } |
||
| 48 | |||
| 49 | IRIn_RecordRemoteName = Storage_GetParameter("RemoteList", remote_name); |
||
| 50 | |||
| 51 | if (!IRIn_RecordRemoteName) |
||
| 52 | { |
||
| 53 | IRIn_RecordRemoteName = "Remote_" + remote_name; |
||
| 54 | |||
| 1649 | runge | 55 | Log("\033[32mNo such remote name in list, " + remote_name + ", creating...\033[0m\n"); |
| 1647 | runge | 56 | |
| 57 | Storage_SetParameter("RemoteList", remote_name, IRIn_RecordRemoteName); |
||
| 58 | } |
||
| 59 | |||
| 60 | var aliases_data = Module_ResolveAlias(alias_name, IRIn_ModuleNames); |
||
| 61 | |||
| 62 | for (var name in aliases_data) |
||
| 63 | { |
||
| 64 | if (aliases_data[name]["group"]) |
||
| 65 | { |
||
| 1649 | runge | 66 | Log("\033[31mAlias must not be an alias group.\033[0m\n"); |
| 1647 | runge | 67 | return false; |
| 68 | } |
||
| 69 | |||
| 1657 | runge | 70 | IRIn_RecordClientId = Console_GetClientId(); |
| 71 | |||
| 1647 | runge | 72 | IRIn_RecordAliasData = aliases_data[name]; |
| 73 | Log("Enter a single dot to finish.\n"); |
||
| 74 | |||
| 1649 | runge | 75 | Log("\033[29mPress a button on you remote...\033[0m\n"); |
| 1647 | runge | 76 | Console_PreventDefaultPrompt(); |
| 77 | |||
| 78 | Module_RegisterToOnMessage(alias_name, IRIn_RecordOnIrMessage); |
||
| 79 | return true; |
||
| 80 | } |
||
| 81 | |||
| 1649 | runge | 82 | Log("\033[31mNo such alias name found, " + alias_name + ".\033[0m\n"); |
| 1647 | runge | 83 | return false; |
| 84 | |||
| 85 | } |
||
| 86 | Console_RegisterCommand(IRIn_Record, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, IRIn_Aliases(), IRIn_Remotes()); }); |
||
| 1646 | runge | 87 | |
| 1647 | runge | 88 | function IRIn_RecordOnResponse(response) |
| 1603 | runge | 89 | { |
| 1647 | runge | 90 | if (response == ".") |
| 91 | { |
||
| 1657 | runge | 92 | IRIn_RecordClientId = null; |
| 1647 | runge | 93 | return true; |
| 94 | } |
||
| 95 | |||
| 96 | Storage_SetParameter(IRIn_RecordRemoteName, response, JSON.stringify(IRIn_RecordLast)); |
||
| 97 | IRIn_RecordLast = null; |
||
| 98 | |||
| 1649 | runge | 99 | Log("\033[29mPress a button on you remote...\033[0m\n"); |
| 1647 | runge | 100 | Console_PreventDefaultPrompt(); |
| 101 | |||
| 102 | return true; |
||
| 1603 | runge | 103 | } |
| 104 | |||
| 1647 | runge | 105 | function IRIn_RecordOnIrMessage(alias_name, command, variables) |
| 1603 | runge | 106 | { |
| 1647 | runge | 107 | if (variables["Status"] != "Pressed" || IRIn_RecordLast != null) |
| 1603 | runge | 108 | { |
| 1647 | runge | 109 | return; |
| 1603 | runge | 110 | } |
| 111 | |||
| 1657 | runge | 112 | ConsoleExport_LogToClient(IRIn_RecordClientId, "\033[32mGot code " + variables["IRdata"] + " on protocol " + variables["Protocol"] + ".\033[0m\n"); |
| 1647 | runge | 113 | |
| 114 | IRIn_RecordLast = { "protocol" : variables["Protocol"], "data" : variables["IRdata"] }; |
||
| 115 | |||
| 1649 | runge | 116 | Console_PromptRequest("\033[29mEnter name: \033[0m", IRIn_RecordOnResponse); |
| 1647 | runge | 117 | |
| 118 | return true; |
||
| 1603 | runge | 119 | } |