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