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