Rev 2123 | Rev 2125 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1619 | runge | 1 | |
| 1997 | arune | 2 | IROut_ModuleNames = [ "irTransmit", "rfTransceive" ]; |
| 1644 | runge | 3 | IROut_Channels = function() { return [ 0 ]; }; |
| 4 | IROut_Statuses = function() { return [ "Pressed", "Released", "Burst" ]; }; |
||
| 2072 | arune | 5 | IROut_Protocols = function() { return [ "RC5", "RC6", "RCMM", "SIRC", "Sharp", "NEC", "Samsung", "Marantz", "Panasonic", "Sky", "Nexa2", "Nexa" ]; }; |
| 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 | |
| 2072 | arune | 68 | function IROut_Send_Raw(alias_name, protocol, data, status) |
| 1644 | runge | 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 | |||
| 1647 | runge | 76 | var aliases_data = Module_ResolveAlias(alias_name, IROut_ModuleNames); |
| 1644 | runge | 77 | |
| 78 | for (var name in aliases_data) |
||
| 79 | { |
||
| 80 | var variables = { |
||
| 1647 | runge | 81 | "Channel" : aliases_data[name]["specific"]["Channel"], |
| 2072 | arune | 82 | "Protocol" : protocol, |
| 83 | "IRdata" : data, |
||
| 1647 | runge | 84 | "Status" : status }; |
| 2116 | linlun | 85 | Log("will send data to: "+aliases_data[name]["module_name"]+":"+aliases_data[name]["module_id"]+" Data: "+ data + " Prot: "+protocol+" Sts: "+status+"\n"); |
| 1647 | runge | 86 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "IR", variables)) |
| 87 | { |
||
| 1649 | runge | 88 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
| 1647 | runge | 89 | } |
| 90 | else |
||
| 91 | { |
||
| 1649 | runge | 92 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
| 1647 | runge | 93 | } |
| 94 | |||
| 95 | found = true; |
||
| 1644 | runge | 96 | } |
| 97 | |||
| 1647 | runge | 98 | if (!found) |
| 1644 | runge | 99 | { |
| 1649 | runge | 100 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
| 1647 | runge | 101 | return false; |
| 1644 | runge | 102 | } |
| 103 | |||
| 1647 | runge | 104 | return true; |
| 1644 | runge | 105 | } |
| 2116 | linlun | 106 | Console_RegisterCommand(IROut_SendBurst, IROut_StartSendAutoComplete); |
| 1644 | runge | 107 | |
| 2072 | arune | 108 | function IROut_Send(alias_name, remote_name, button_name, status) |
| 109 | { |
||
| 110 | if (arguments.length < 4) |
||
| 111 | { |
||
| 112 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 113 | return false; |
||
| 114 | } |
||
| 115 | |||
| 116 | var remote_storage_name = Storage_GetParameter("RemoteList", remote_name); |
||
| 117 | |||
| 118 | if (!remote_storage_name) |
||
| 119 | { |
||
| 120 | Log("\033[31mNo such remote name in list, " + remote_name + ".\033[0m\n"); |
||
| 121 | return false; |
||
| 122 | } |
||
| 123 | |||
| 124 | var button_string = Storage_GetParameter(remote_storage_name, button_name); |
||
| 125 | |||
| 126 | if (!button_string) |
||
| 127 | { |
||
| 128 | Log("\033[31mNo such button " + button_name + " found on remote " + remote + ".\033[0m\n"); |
||
| 129 | return false; |
||
| 130 | } |
||
| 131 | |||
| 132 | var button_data = eval("(" + button_string + ")"); |
||
| 133 | |||
| 134 | if (typeof button_data["protocol"] == 'undefined' || typeof button_data["data"] == 'undefined') |
||
| 135 | { |
||
| 136 | Log("\033[31mButton data is corrupt.\033[0m\n"); |
||
| 137 | return false; |
||
| 138 | } |
||
| 139 | |||
| 140 | return IROut_Send_Raw(alias_name, button_data["protocol"], button_data["data"], status); |
||
| 141 | } |
||
| 142 | |||
| 1644 | runge | 143 | function IROut_StartSend(alias_name, remote_name, button_name) |
| 144 | { |
||
| 145 | return IROut_Send(alias_name, remote_name, button_name, "Pressed"); |
||
| 146 | } |
||
| 147 | Console_RegisterCommand(IROut_StartSend, IROut_StartSendAutoComplete); |
||
| 148 | |||
| 149 | function IROut_SendBurst(alias_name, remote_name, button_name) |
||
| 150 | { |
||
| 151 | return IROut_Send(alias_name, remote_name, button_name, "Burst"); |
||
| 152 | } |
||
| 153 | Console_RegisterCommand(IROut_SendBurst, IROut_StartSendAutoComplete); |
||
| 154 | |||
| 2117 | linlun | 155 | function IROut_SendBurst_Raw(alias_name, protocol, data) |
| 2116 | linlun | 156 | { |
| 2117 | linlun | 157 | return IROut_Send_Raw(alias_name, protocol, data, "Burst"); |
| 2116 | linlun | 158 | } |
| 2117 | linlun | 159 | Console_RegisterCommand(IROut_SendBurst_Raw, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, IROut_Aliases(), IROut_Protocols()); }); |
| 2116 | linlun | 160 | |
| 2123 | linlun | 161 | function IROut_SendDimmer(alias_name, remote_name, button_name, level) |
| 162 | { |
||
| 163 | if (arguments.length < 4) |
||
| 164 | { |
||
| 165 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 166 | return false; |
||
| 167 | } |
||
| 168 | |||
| 169 | var remote_storage_name = Storage_GetParameter("RemoteList", remote_name); |
||
| 170 | |||
| 171 | if (!remote_storage_name) |
||
| 172 | { |
||
| 173 | Log("\033[31mNo such remote name in list, " + remote_name + ".\033[0m\n"); |
||
| 174 | return false; |
||
| 175 | } |
||
| 176 | |||
| 177 | var button_string = Storage_GetParameter(remote_storage_name, button_name); |
||
| 178 | |||
| 179 | if (!button_string) |
||
| 180 | { |
||
| 2124 | runge | 181 | Log("\033[31mNo such button " + button_name + " found on remote " + remote_name + ".\033[0m\n"); |
| 2123 | linlun | 182 | return false; |
| 183 | } |
||
| 184 | |||
| 185 | var button_data = eval("(" + button_string + ")"); |
||
| 186 | |||
| 187 | if (typeof button_data["protocol"] == 'undefined' || typeof button_data["data"] == 'undefined') |
||
| 188 | { |
||
| 189 | Log("\033[31mButton data is corrupt.\033[0m\n"); |
||
| 190 | return false; |
||
| 191 | } |
||
| 192 | levelInt = parseInt(level); |
||
| 193 | dataInt = parseInt(button_data["data"]); |
||
| 194 | if (levelInt >= 0 && levelInt <= 15) { |
||
| 195 | switch(levelInt) { |
||
| 196 | case 0: |
||
| 197 | levelInt = 15; |
||
| 198 | break; |
||
| 199 | case 1: |
||
| 200 | levelInt = 7; |
||
| 201 | break; |
||
| 202 | case 2: |
||
| 203 | levelInt = 11; |
||
| 204 | break; |
||
| 205 | case 3: |
||
| 206 | levelInt = 3; |
||
| 207 | break; |
||
| 208 | case 4: |
||
| 209 | levelInt = 13; |
||
| 210 | break; |
||
| 211 | case 5: |
||
| 212 | levelInt = 5; |
||
| 213 | break; |
||
| 214 | case 6: |
||
| 215 | levelInt = 9; |
||
| 216 | break; |
||
| 217 | case 7: |
||
| 218 | levelInt = 1; |
||
| 219 | break; |
||
| 220 | case 8: |
||
| 221 | levelInt = 14; |
||
| 222 | break; |
||
| 223 | case 9: |
||
| 224 | levelInt = 6; |
||
| 225 | break; |
||
| 226 | case 10: |
||
| 227 | levelInt = 10; |
||
| 228 | break; |
||
| 229 | case 11: |
||
| 230 | levelInt = 2; |
||
| 231 | break; |
||
| 232 | case 12: |
||
| 233 | levelInt = 12; |
||
| 234 | break; |
||
| 235 | case 13: |
||
| 236 | levelInt = 4; |
||
| 237 | break; |
||
| 238 | case 14: |
||
| 239 | levelInt = 8; |
||
| 240 | break; |
||
| 241 | case 15: |
||
| 242 | levelInt = 0; |
||
| 243 | break; |
||
| 244 | } |
||
| 245 | dataInt += 549755813888; //Set MSB |
||
| 246 | dataInt += levelInt*4294967296//Add dimmer level |
||
| 2124 | runge | 247 | Log("button_data[protocol]=" + button_data["protocol"] + "\n"); |
| 2123 | linlun | 248 | return IROut_Send_Raw(alias_name, button_data["protocol"], dataInt.toString(), "Burst"); |
| 249 | } else { |
||
| 250 | Log("\033[31mDimmer level out of range [0 -> 16].\033[0m\n"); |
||
| 251 | return false; |
||
| 252 | } |
||
| 253 | } |
||
| 254 | Console_RegisterCommand(IROut_SendDimmer, IROut_StartSendAutoComplete); |
||
| 255 | |||
| 256 | |||
| 257 | |||
| 2114 | arune | 258 | function IROut_SendDuration(alias_name, remote_name, button_name, duration_ms) |
| 259 | { |
||
| 260 | IROut_Send(alias_name, remote_name, button_name, "Pressed"); |
||
| 261 | Timer_SetTimer(function(timer) {IROut_StopSend(alias_name);}, duration_ms, false); |
||
| 262 | } |
||
| 263 | Console_RegisterCommand(IROut_SendDuration, IROut_StartSendAutoComplete); |
||
| 264 |