Rev 1649 | Rev 2072 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1619 | runge | 1 | |
| 1647 | runge | 2 | IROut_ModuleNames = [ "irTransmit" ]; |
| 1644 | runge | 3 | IROut_Channels = function() { return [ 0 ]; }; |
| 4 | IROut_Statuses = function() { return [ "Pressed", "Released", "Burst" ]; }; |
||
| 5 | IROut_Protocols = function() { return [ "RC5", "RC6", "RCMM", "SIRC", "Sharp", "NEC", "Samsung", "Marantz", "Panasonic", "Sky", "Nexa2" ]; }; |
||
| 1647 | runge | 6 | IROut_Aliases = function() { return Module_GetAliasNames(IROut_ModuleNames); }; |
| 7 | IROut_AvailableIds = function() { return Module_GetAvailableIds(IROut_ModuleNames); }; |
||
| 1644 | runge | 8 | |
| 9 | function IROut_StopSend(alias_name) |
||
| 10 | { |
||
| 1646 | runge | 11 | if (arguments.length < 1) |
| 1644 | runge | 12 | { |
| 1649 | runge | 13 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
| 1647 | runge | 14 | return false; |
| 1644 | runge | 15 | } |
| 16 | |||
| 1647 | runge | 17 | var aliases_data = Module_ResolveAlias(alias_name, IROut_ModuleNames); |
| 18 | var found = false; |
||
| 1644 | runge | 19 | |
| 20 | for (var name in aliases_data) |
||
| 21 | { |
||
| 22 | var variables = { |
||
| 1647 | runge | 23 | "Channel" : aliases_data[name]["specific"]["Channel"], |
| 24 | "Status" : "Released" }; |
||
| 1644 | runge | 25 | |
| 26 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "IR", variables)) |
||
| 27 | { |
||
| 1649 | runge | 28 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
| 1644 | runge | 29 | } |
| 30 | else |
||
| 31 | { |
||
| 1649 | runge | 32 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
| 1644 | runge | 33 | } |
| 1647 | runge | 34 | |
| 35 | found = true; |
||
| 1644 | runge | 36 | } |
| 37 | |||
| 1647 | runge | 38 | if (!found) |
| 1644 | runge | 39 | { |
| 1649 | runge | 40 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
| 1647 | runge | 41 | return false; |
| 1644 | runge | 42 | } |
| 43 | |||
| 1647 | runge | 44 | return true; |
| 1644 | runge | 45 | } |
| 1647 | runge | 46 | Console_RegisterCommand(IROut_StopSend, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, IROut_Aliases()); }); |
| 1619 | runge | 47 | |
| 1647 | runge | 48 | function IROut_StartSendAutoComplete(arg_index, args) |
| 1619 | runge | 49 | { |
| 1644 | runge | 50 | if (arg_index == 0) |
| 51 | { |
||
| 52 | return IROut_Aliases(); |
||
| 53 | } |
||
| 54 | else if (arg_index == 1) |
||
| 55 | { |
||
| 1647 | runge | 56 | return get_keys(Storage_GetParameters("RemoteList")); |
| 1644 | runge | 57 | } |
| 58 | else if (arg_index == 2) |
||
| 59 | { |
||
| 1647 | runge | 60 | var remote_storage_name = Storage_GetParameter("RemoteList", args[arg_index - 1]); |
| 61 | |||
| 62 | return get_keys(Storage_GetParameters(remote_storage_name)); |
||
| 1644 | runge | 63 | } |
| 64 | |||
| 65 | return []; |
||
| 1619 | runge | 66 | } |
| 1644 | runge | 67 | |
| 68 | function IROut_Send(alias_name, remote_name, button_name, status) |
||
| 69 | { |
||
| 70 | if (arguments.length < 4) |
||
| 71 | { |
||
| 1649 | runge | 72 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
| 1647 | runge | 73 | return false; |
| 1644 | runge | 74 | } |
| 75 | |||
| 76 | var result_text = ""; |
||
| 1647 | runge | 77 | var aliases_data = Module_ResolveAlias(alias_name, IROut_ModuleNames); |
| 1644 | runge | 78 | |
| 79 | var remote_storage_name = Storage_GetParameter("RemoteList", remote_name); |
||
| 80 | |||
| 81 | if (!remote_storage_name) |
||
| 82 | { |
||
| 1649 | runge | 83 | Log("\033[31mNo such remote name in list, " + remote_name + ".\033[0m\n"); |
| 1647 | runge | 84 | return false; |
| 1644 | runge | 85 | } |
| 86 | |||
| 87 | var button_string = Storage_GetParameter(remote_storage_name, button_name); |
||
| 88 | |||
| 89 | if (!button_string) |
||
| 90 | { |
||
| 1649 | runge | 91 | Log("\033[31mNo such button " + button_name + " found on remote " + remote + ".\033[0m\n"); |
| 1647 | runge | 92 | return false; |
| 1644 | runge | 93 | } |
| 94 | |||
| 95 | var button_data = eval("(" + button_string + ")"); |
||
| 96 | |||
| 97 | if (typeof button_data["protocol"] == 'undefined' || typeof button_data["data"] == 'undefined') |
||
| 98 | { |
||
| 1649 | runge | 99 | Log("\033[31mButton data is corrupt.\033[0m\n"); |
| 1647 | runge | 100 | return false; |
| 1644 | runge | 101 | } |
| 102 | |||
| 103 | for (var name in aliases_data) |
||
| 104 | { |
||
| 105 | var variables = { |
||
| 1647 | runge | 106 | "Channel" : aliases_data[name]["specific"]["Channel"], |
| 107 | "Protocol" : button_data["protocol"], |
||
| 108 | "IRdata" : button_data["data"], |
||
| 109 | "Status" : status }; |
||
| 110 | |||
| 111 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "IR", variables)) |
||
| 112 | { |
||
| 1649 | runge | 113 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
| 1647 | runge | 114 | } |
| 115 | else |
||
| 116 | { |
||
| 1649 | runge | 117 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
| 1647 | runge | 118 | } |
| 119 | |||
| 120 | found = true; |
||
| 1644 | runge | 121 | } |
| 122 | |||
| 1647 | runge | 123 | if (!found) |
| 1644 | runge | 124 | { |
| 1649 | runge | 125 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
| 1647 | runge | 126 | return false; |
| 1644 | runge | 127 | } |
| 128 | |||
| 1647 | runge | 129 | return true; |
| 1644 | runge | 130 | } |
| 131 | |||
| 132 | function IROut_StartSend(alias_name, remote_name, button_name) |
||
| 133 | { |
||
| 134 | return IROut_Send(alias_name, remote_name, button_name, "Pressed"); |
||
| 135 | } |
||
| 136 | Console_RegisterCommand(IROut_StartSend, IROut_StartSendAutoComplete); |
||
| 137 | |||
| 138 | function IROut_SendBurst(alias_name, remote_name, button_name) |
||
| 139 | { |
||
| 140 | return IROut_Send(alias_name, remote_name, button_name, "Burst"); |
||
| 141 | } |
||
| 142 | Console_RegisterCommand(IROut_SendBurst, IROut_StartSendAutoComplete); |
||
| 143 |