Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1603 | runge | 1 | |
| 1624 | runge | 2 | RequireModule("irReceive"); |
| 3 | RequireModule("irTransmit"); |
||
| 4 | RequireModule("Dimmer230"); |
||
| 5 | |||
| 1603 | runge | 6 | var dimmer_module = GetModule("Dimmer230"); |
| 7 | var ir_module = GetModule("irReceive"); |
||
| 8 | |||
| 9 | function test_press(event, id, channel, data, protocol) |
||
| 10 | { |
||
| 1619 | runge | 11 | Log("Pressed: protocol=" + protocol + ", channel=" + channel + ", data=" + data); |
| 12 | |||
| 1603 | runge | 13 | if (protocol == "NEC" && data == 3877174275) |
| 14 | { |
||
| 1609 | runge | 15 | Dimmer230_StartFade(2, 0, 135, "Increase"); |
| 16 | Dimmer230_StartFade(1, 0, 135, "Increase"); |
||
| 1603 | runge | 17 | } |
| 18 | else if (protocol == "NEC" && data == 3860462595) |
||
| 19 | { |
||
| 1609 | runge | 20 | Dimmer230_StartFade(2, 0, 135, "Decrease"); |
| 21 | Dimmer230_StartFade(1, 0, 135, "Decrease"); |
||
| 1603 | runge | 22 | } |
| 1619 | runge | 23 | else if (protocol == "NEC" && data == 4144561155) |
| 24 | { |
||
| 25 | irTransmit_SendCode(1, 0, "Burst", "NEC", 3843720570); |
||
| 26 | } |
||
| 27 | else if (protocol == "NEC" && data == 4211407875) |
||
| 28 | { |
||
| 29 | irTransmit_SendCode(1, 0, "Burst", "NEC", 3827008890); |
||
| 30 | } |
||
| 1603 | runge | 31 | } |
| 32 | |||
| 33 | function test_release(event, id, channel, data, protocol) |
||
| 34 | { |
||
| 1619 | runge | 35 | Log("Released: protocol=" + protocol + ", channel=" + channel + ", data=" + data); |
| 36 | |||
| 1603 | runge | 37 | if (protocol == "NEC" && (data == 3877174275 || data == 3860462595)) |
| 38 | { |
||
| 1609 | runge | 39 | Dimmer230_StopFade(2, 0); |
| 1619 | runge | 40 | Dimmer230_StopFade(1, 0); |
| 1603 | runge | 41 | } |
| 1619 | runge | 42 | else if (protocol == "NEC" && (data == 4144561155 || data == 4211407875)) |
| 43 | { |
||
| 44 | //irTransmit_SendCode(1, 0, "Released", "NEC", data); |
||
| 45 | } |
||
| 1603 | runge | 46 | } |
| 47 | |||
| 48 | function test_status(event, id, available) |
||
| 49 | { |
||
| 1610 | runge | 50 | //Log("status change!"); |
| 1603 | runge | 51 | } |
| 52 | |||
| 1624 | runge | 53 | ir_module.Bind("onStatusChange", test_status); |
| 54 | ir_module.Bind("onPressed", test_press); |
||
| 55 | ir_module.Bind("onReleased", test_release); |
||
| 1603 | runge | 56 | |
| 1608 | runge | 57 | |
| 1619 | runge | 58 | /*CreateModuleAlias("bardisk", "Dimmer230", 2, { "channel" : 0 }); |
| 1614 | runge | 59 | CreateModuleAlias("bokhylla", "Dimmer230", 1, { "channel" : 0 }); |
| 60 | CreateModuleAliasGroup("vardagsrum", [ "bokhylla", "bardisk" ]); |
||
| 1619 | runge | 61 | */ |
| 1608 | runge | 62 | |
| 1614 | runge | 63 | function fadeto(alias, level, speed) |
| 64 | { |
||
| 1619 | runge | 65 | var alias_data = resolvealias(alias); |
| 66 | |||
| 67 | if (alias_data == null) |
||
| 1614 | runge | 68 | { |
| 69 | return "No such module name found"; |
||
| 70 | } |
||
| 71 | |||
| 1619 | runge | 72 | if (alias_data["is_group"]) |
| 1614 | runge | 73 | { |
| 74 | var result = ""; |
||
| 75 | |||
| 1619 | runge | 76 | for (var n = 0; n < alias_data["aliases"].length; n++) |
| 1614 | runge | 77 | { |
| 1619 | runge | 78 | result += fadeto(alias_data["aliases"][n], level, speed) + "\n"; |
| 1614 | runge | 79 | } |
| 80 | |||
| 81 | return result; |
||
| 82 | } |
||
| 83 | |||
| 1619 | runge | 84 | if (alias_data["module_name"] != "Dimmer230") |
| 1614 | runge | 85 | { |
| 1619 | runge | 86 | return "Module type " + alias_data["module_name"] + " is not valid for this action, valid are Dimmer230"; |
| 1614 | runge | 87 | } |
| 88 | |||
| 89 | if (!speed) |
||
| 90 | { |
||
| 91 | speed = 135; |
||
| 92 | } |
||
| 93 | |||
| 1619 | runge | 94 | return Dimmer230_AbsoluteFade(alias_data["module_id"], alias_data["extra"], speed, level); |
| 1614 | runge | 95 | } |
| 96 | RegisterConsoleCommand(fadeto, function(args) { return StandardAutocomplete(args, Dimmer230.instance_.GetAvailableNames(), [ 0, 50, 100, 150, 200, 255 ], [ 50, 135, 200, 255 ]); }); |
||
| 1620 | runge | 97 | |
| 1624 | runge | 98 | function irsend_autocomplete(args) |
| 1620 | runge | 99 | { |
| 1624 | runge | 100 | // args[0] == command name |
| 101 | var arg_index = args.length - 2; |
||
| 102 | |||
| 103 | if (arg_index == 0) |
||
| 104 | { |
||
| 105 | return irTransmit.instance_.GetAvailableNames(); |
||
| 106 | } |
||
| 107 | else if (arg_index == 1) |
||
| 108 | { |
||
| 109 | var remotes = Storage_GetParameters("RemoteList"); |
||
| 110 | |||
| 111 | var result = new Array(); |
||
| 112 | |||
| 113 | for (var name in remotes) |
||
| 114 | { |
||
| 115 | result.push(name); |
||
| 116 | } |
||
| 117 | |||
| 118 | return result; |
||
| 119 | } |
||
| 120 | else if (arg_index == 2) |
||
| 121 | { |
||
| 122 | var remote_storage_name = Storage_GetParameter("RemoteList", args[arg_index]); |
||
| 123 | |||
| 124 | var buttons = Storage_GetParameters(remote_storage_name); |
||
| 125 | |||
| 126 | var result = new Array(); |
||
| 127 | |||
| 128 | for (var name in buttons) |
||
| 129 | { |
||
| 130 | result.push(name); |
||
| 131 | } |
||
| 132 | |||
| 133 | return result; |
||
| 134 | } |
||
| 135 | |||
| 136 | return new Array(); |
||
| 1620 | runge | 137 | } |
| 138 | |||
| 1624 | runge | 139 | |
| 140 | function irsend(alias, remote, button) |
||
| 1620 | runge | 141 | { |
| 1624 | runge | 142 | var alias_data = resolvealias(alias); |
| 143 | |||
| 144 | if (alias_data == null) |
||
| 145 | { |
||
| 146 | return "No such module name found"; |
||
| 147 | } |
||
| 148 | |||
| 149 | if (alias_data["is_group"]) |
||
| 150 | { |
||
| 151 | var result = ""; |
||
| 152 | |||
| 153 | for (var n = 0; n < alias_data["aliases"].length; n++) |
||
| 154 | { |
||
| 155 | result += irsend(alias_data["aliases"][n], remote, button) + "\n"; |
||
| 156 | } |
||
| 157 | |||
| 158 | return result; |
||
| 159 | } |
||
| 160 | |||
| 161 | if (alias_data["module_name"] != "irTransmit") |
||
| 162 | { |
||
| 163 | return "Module type " + alias_data["module_name"] + " is not valid for this action, valid are irTransmit"; |
||
| 164 | } |
||
| 165 | |||
| 166 | var remote_storage_name = Storage_GetParameter("RemoteList", remote); |
||
| 1625 | runge | 167 | |
| 168 | if (!remote_storage_name) |
||
| 169 | { |
||
| 170 | return "No such remote name in list, " + remote; |
||
| 171 | } |
||
| 172 | |||
| 173 | var button_string = Storage_GetParameter(remote_storage_name, button); |
||
| 174 | |||
| 175 | if (!button_string) |
||
| 176 | { |
||
| 177 | return "No such button " + button + " found on remote " + remote; |
||
| 178 | } |
||
| 179 | |||
| 180 | var button = eval("(" + button_string + ")"); |
||
| 181 | |||
| 1624 | runge | 182 | Log(JSON.stringify(button)); |
| 183 | Log(alias_data["module_id"]); |
||
| 184 | Log(alias_data["extra"]); |
||
| 185 | Log(button["protocol"]); |
||
| 186 | Log(button["data"]); |
||
| 187 | |||
| 188 | return irTransmit_SendCode(alias_data["module_id"], alias_data["extra"], "Burst", button["protocol"], button["data"]); |
||
| 1620 | runge | 189 | } |
| 1624 | runge | 190 | RegisterConsoleCommand(irsend, irsend_autocomplete); |
| 1625 | runge | 191 | |
| 192 | |||
| 193 | function media(mode) |
||
| 194 | { |
||
| 195 | if (!mode) |
||
| 196 | { |
||
| 197 | return "You must specify a mode"; |
||
| 198 | } |
||
| 199 | |||
| 200 | if (mode == "movie") |
||
| 201 | { |
||
| 202 | irsend("tvbankut", "Yamaha_RAV34", "POWER"); |
||
| 203 | |||
| 204 | fadeto("bokhylla", 100, 135); |
||
| 205 | fadeto("bardisk", 0, 135); |
||
| 206 | |||
| 207 | sleep(1000); |
||
| 208 | irsend("tvbankut", "Yamaha_RAV34", "CD"); |
||
| 209 | } |
||
| 210 | else if (mode == "tv") |
||
| 211 | { |
||
| 212 | irsend("tvbankut", "Yamaha_RAV34", "POWER"); |
||
| 213 | |||
| 214 | fadeto("bokhylla", 150, 135); |
||
| 215 | fadeto("bardisk", 150, 135); |
||
| 216 | |||
| 217 | sleep(1000); |
||
| 218 | irsend("tvbankut", "Yamaha_RAV34", "DTV_CBL"); |
||
| 219 | } |
||
| 220 | else if (mode == "off") |
||
| 221 | { |
||
| 222 | irsend("tvbankut", "Yamaha_RAV34", "STANDBY"); |
||
| 223 | |||
| 224 | fadeto("bokhylla", 0, 135); |
||
| 225 | fadeto("bardisk", 0, 135); |
||
| 226 | } |
||
| 227 | |||
| 228 | return "OK"; |
||
| 229 | } |
||
| 230 | RegisterConsoleCommand(media, function(args) { return StandardAutocomplete(args, [ "off", "tv", "movie" ]); }); |