Rev 1625 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1625 | Rev 1626 | ||
|---|---|---|---|
| 1 | 1 | ||
| 2 | RequireModule("irReceive"); |
2 | RequireModule("irReceive"); |
| 3 | RequireModule("irTransmit"); |
3 | RequireModule("irTransmit"); |
| 4 | RequireModule("Dimmer230"); |
4 | RequireModule("Dimmer230"); |
| 5 | 5 | ||
| 6 | var dimmer_module = GetModule("Dimmer230"); |
6 | var dimmer_module = GetModule("Dimmer230"); |
| 7 | var ir_module = GetModule("irReceive"); |
7 | var ir_module = GetModule("irReceive"); |
| 8 | 8 | ||
| 9 | function test_press(event, id, channel, data, protocol) |
9 | function test_press(event, id, channel, data, protocol) |
| 10 | { |
10 | { |
| 11 | Log("Pressed: protocol=" + protocol + ", channel=" + channel + ", data=" + data); |
11 | Log("Pressed: protocol=" + protocol + ", channel=" + channel + ", data=" + data); |
| 12 | 12 | ||
| 13 | if (protocol == "NEC" && data == 3877174275) |
13 | if (protocol == "NEC" && data == 3877174275) |
| 14 | { |
14 | { |
| 15 | Dimmer230_StartFade(2, 0, 135, "Increase"); |
15 | Dimmer230_StartFade(2, 0, 135, "Increase"); |
| 16 | Dimmer230_StartFade(1, 0, 135, "Increase"); |
16 | Dimmer230_StartFade(1, 0, 135, "Increase"); |
| 17 | } |
17 | } |
| 18 | else if (protocol == "NEC" && data == 3860462595) |
18 | else if (protocol == "NEC" && data == 3860462595) |
| 19 | { |
19 | { |
| 20 | Dimmer230_StartFade(2, 0, 135, "Decrease"); |
20 | Dimmer230_StartFade(2, 0, 135, "Decrease"); |
| 21 | Dimmer230_StartFade(1, 0, 135, "Decrease"); |
21 | Dimmer230_StartFade(1, 0, 135, "Decrease"); |
| 22 | } |
22 | } |
| 23 | else if (protocol == "NEC" && data == 4144561155) |
23 | else if (protocol == "NEC" && data == 4144561155) |
| 24 | { |
24 | { |
| 25 | irTransmit_SendCode(1, 0, "Burst", "NEC", 3843720570); |
25 | irTransmit_SendCode(1, 0, "Burst", "NEC", 3843720570); |
| 26 | } |
26 | } |
| 27 | else if (protocol == "NEC" && data == 4211407875) |
27 | else if (protocol == "NEC" && data == 4211407875) |
| 28 | { |
28 | { |
| 29 | irTransmit_SendCode(1, 0, "Burst", "NEC", 3827008890); |
29 | irTransmit_SendCode(1, 0, "Burst", "NEC", 3827008890); |
| 30 | } |
30 | } |
| 31 | } |
31 | } |
| 32 | 32 | ||
| 33 | function test_release(event, id, channel, data, protocol) |
33 | function test_release(event, id, channel, data, protocol) |
| 34 | { |
34 | { |
| 35 | Log("Released: protocol=" + protocol + ", channel=" + channel + ", data=" + data); |
35 | Log("Released: protocol=" + protocol + ", channel=" + channel + ", data=" + data); |
| 36 | 36 | ||
| 37 | if (protocol == "NEC" && (data == 3877174275 || data == 3860462595)) |
37 | if (protocol == "NEC" && (data == 3877174275 || data == 3860462595)) |
| 38 | { |
38 | { |
| 39 | Dimmer230_StopFade(2, 0); |
39 | Dimmer230_StopFade(2, 0); |
| 40 | Dimmer230_StopFade(1, 0); |
40 | Dimmer230_StopFade(1, 0); |
| 41 | } |
41 | } |
| 42 | else if (protocol == "NEC" && (data == 4144561155 || data == 4211407875)) |
42 | else if (protocol == "NEC" && (data == 4144561155 || data == 4211407875)) |
| 43 | { |
43 | { |
| 44 | //irTransmit_SendCode(1, 0, "Released", "NEC", data); |
44 | //irTransmit_SendCode(1, 0, "Released", "NEC", data); |
| 45 | } |
45 | } |
| 46 | } |
46 | } |
| 47 | 47 | ||
| 48 | function test_status(event, id, available) |
48 | function test_status(event, id, available) |
| 49 | { |
49 | { |
| 50 | //Log("status change!"); |
50 | //Log("status change!"); |
| 51 | } |
51 | } |
| 52 | 52 | ||
| 53 | ir_module.Bind("onStatusChange", test_status); |
53 | ir_module.Bind("onStatusChange", test_status); |
| 54 | ir_module.Bind("onPressed", test_press); |
54 | ir_module.Bind("onPressed", test_press); |
| 55 | ir_module.Bind("onReleased", test_release); |
55 | ir_module.Bind("onReleased", test_release); |
| 56 | 56 | ||
| 57 | 57 | ||
| 58 | /*CreateModuleAlias("bardisk", "Dimmer230", 2, { "channel" : 0 }); |
- | |
| 59 | CreateModuleAlias("bokhylla", "Dimmer230", 1, { "channel" : 0 }); |
- | |
| 60 | CreateModuleAliasGroup("vardagsrum", [ "bokhylla", "bardisk" ]); |
- | |
| 61 | */ |
- | |
| 62 | 58 | ||
| 63 | function fadeto(alias, level, speed) |
- | |
| 64 | { |
- | |
| 65 | var alias_data = resolvealias(alias); |
- | |
| 66 | - | ||
| 67 | if (alias_data == null) |
- | |
| 68 | { |
- | |
| 69 | return "No such module name found"; |
- | |
| 70 | } |
- | |
| 71 | - | ||
| 72 | if (alias_data["is_group"]) |
- | |
| 73 | { |
- | |
| 74 | var result = ""; |
- | |
| 75 | - | ||
| 76 | for (var n = 0; n < alias_data["aliases"].length; n++) |
- | |
| 77 | { |
- | |
| 78 | result += fadeto(alias_data["aliases"][n], level, speed) + "\n"; |
- | |
| 79 | } |
- | |
| 80 | - | ||
| 81 | return result; |
- | |
| 82 | } |
- | |
| 83 | - | ||
| 84 | if (alias_data["module_name"] != "Dimmer230") |
- | |
| 85 | { |
- | |
| 86 | return "Module type " + alias_data["module_name"] + " is not valid for this action, valid are Dimmer230"; |
- | |
| 87 | } |
- | |
| 88 | - | ||
| 89 | if (!speed) |
- | |
| 90 | { |
- | |
| 91 | speed = 135; |
- | |
| 92 | } |
- | |
| 93 | - | ||
| 94 | return Dimmer230_AbsoluteFade(alias_data["module_id"], alias_data["extra"], speed, level); |
- | |
| 95 | } |
- | |
| 96 | RegisterConsoleCommand(fadeto, function(args) { return StandardAutocomplete(args, Dimmer230.instance_.GetAvailableNames(), [ 0, 50, 100, 150, 200, 255 ], [ 50, 135, 200, 255 ]); }); |
- | |
| 97 | - | ||
| 98 | function irsend_autocomplete(args) |
- | |
| 99 | { |
- | |
| 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(); |
- | |
| 137 | } |
- | |
| 138 | - | ||
| 139 | - | ||
| 140 | function irsend(alias, remote, button) |
- | |
| 141 | { |
- | |
| 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); |
- | |
| 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 | - | ||
| 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"]); |
- | |
| 189 | } |
- | |
| 190 | RegisterConsoleCommand(irsend, irsend_autocomplete); |
- | |
| 191 | 59 | ||
| 192 | 60 | ||
| 193 | function media(mode) |
61 | function media(mode) |
| 194 | { |
62 | { |
| 195 | if (!mode) |
63 | if (!mode) |
| 196 | { |
64 | { |
| 197 | return "You must specify a mode"; |
65 | return "You must specify a mode"; |
| 198 | } |
66 | } |
| 199 | 67 | ||
| 200 | if (mode == "movie") |
68 | if (mode == "movie") |
| 201 | { |
69 | { |
| 202 | irsend("tvbankut", "Yamaha_RAV34", "POWER"); |
70 | irsend("tvbankut", "Yamaha_RAV34", "POWER"); |
| 203 | 71 | ||
| 204 | fadeto("bokhylla", 100, 135); |
72 | fadeto("bokhylla", 100, 135); |
| 205 | fadeto("bardisk", 0, 135); |
73 | fadeto("bardisk", 0, 135); |
| 206 | 74 | ||
| 207 | sleep(1000); |
75 | sleep(1000); |
| 208 | irsend("tvbankut", "Yamaha_RAV34", "CD"); |
76 | irsend("tvbankut", "Yamaha_RAV34", "CD"); |
| 209 | } |
77 | } |
| 210 | else if (mode == "tv") |
78 | else if (mode == "tv") |
| 211 | { |
79 | { |
| 212 | irsend("tvbankut", "Yamaha_RAV34", "POWER"); |
80 | irsend("tvbankut", "Yamaha_RAV34", "POWER"); |
| 213 | 81 | ||
| 214 | fadeto("bokhylla", 150, 135); |
82 | fadeto("bokhylla", 150, 135); |
| 215 | fadeto("bardisk", 150, 135); |
83 | fadeto("bardisk", 150, 135); |
| 216 | 84 | ||
| 217 | sleep(1000); |
85 | sleep(1000); |
| 218 | irsend("tvbankut", "Yamaha_RAV34", "DTV_CBL"); |
86 | irsend("tvbankut", "Yamaha_RAV34", "DTV_CBL"); |
| 219 | } |
87 | } |
| 220 | else if (mode == "off") |
88 | else if (mode == "off") |
| 221 | { |
89 | { |
| 222 | irsend("tvbankut", "Yamaha_RAV34", "STANDBY"); |
90 | irsend("tvbankut", "Yamaha_RAV34", "STANDBY"); |
| 223 | 91 | ||
| 224 | fadeto("bokhylla", 0, 135); |
92 | fadeto("bokhylla", 0, 135); |
| 225 | fadeto("bardisk", 0, 135); |
93 | fadeto("bardisk", 0, 135); |
| 226 | } |
94 | } |
| 227 | 95 | ||
| 228 | return "OK"; |
96 | return "OK"; |
| 229 | } |
97 | } |
| 230 | RegisterConsoleCommand(media, function(args) { return StandardAutocomplete(args, [ "off", "tv", "movie" ]); }); |
98 | RegisterConsoleCommand(media, function(args) { return StandardAutocomplete(args, [ "off", "tv", "movie" ]); }); |
| 231 | 99 | ||