-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathir.html
192 lines (160 loc) · 8.04 KB
/
ir.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<script type="text/javascript">
RED.nodes.registerType('ir-input',{
category: 'hapcan',
color: '#D3D3D3',
defaults: {
gateway: {type:"hapcan-gateway", required: true},
name: {value:""},
group: {value: 1, required: true, validate: function(val){return (val >= 0 && val < 256);} },
node: {value: 1, required: true, validate: function(val){return (val >= 0 && val < 256);}},
filter: {value: 0x00, required: true, validate: function(val) {return (val>=0 && val <0x03)}},
},
inputs:0,
outputs:1,
icon: "relay-output.png",
align: 'left',
label: function() {
return `${this.name||"IR input"} (${Number(this.node) === 0 ? 'any' : this.node}, ${Number(this.group) === 0 ? 'any' : this.group})`;
},
labelStyle: function() { return this.name?"node_label_italic":""; } ,
oneditprepare: async function() {
let config = this
var nodeOptions = '';
var groupOptions = '';
var devicesOptions = null
var gatewaySelect = $('#node-input-gateway')
var devicesSelect = $("#node-input-devices")
var nodeSelect = $("#node-input-node")
var groupSelect = $("#node-input-group")
var currentDevice = null
var deviceList = []
gatewaySelect.change(function()
{
devicesOptions = ''
currentDevice = null
var selectedGatewayId = gatewaySelect.children('option[selected]').first().val()
if(selectedGatewayId == null)
selectedGatewayId = gatewaySelect.children("option").first().val()
var gateway = RED.nodes.node(selectedGatewayId)
if(gateway != null )
{
deviceList = gateway.devices.filter((d) => d.applicationType === 5)
deviceList.forEach( (device) => {
var selected = '';
if(Number(config.node) === device.node && Number(config.group) === device.group)
{
selected = 'selected="selected"'
currentDevice = device
}
devicesOptions += `<option ${selected} value="${device.id}">${device.description} (${device.node},${device.group})</option>`
})
}
devicesOptions += `<option ${currentDevice === null ? 'selected="selected"' : ''} value="0">(set node, group manually)</option>`
devicesSelect.empty().append(devicesOptions).trigger('change')
})
devicesSelect.on('change', function() {
if(Number(this.value) === 0)
{
nodeSelect.removeAttr('disabled')
groupSelect.removeAttr('disabled')
}
currentDevice = deviceList.find(v=>v.id === this.value)
if(currentDevice !== undefined) {
nodeSelect.find('option').removeProp('selected').filter(`[value=${currentDevice.node}]`).prop('selected', true).trigger('change')
groupSelect.find('option').removeProp('selected').filter(`[value=${currentDevice.group}]`).prop('selected', true).trigger('change')
nodeSelect.attr('disabled', 'disabled')
groupSelect.attr('disabled', 'disabled')
}
})
for(var i = 0; i < 256; i++)
{
var selectedNode = '';
if((Number(this.node) === i))
selectedNode = 'selected="selected"';
let text = i === 0? 'any' : i
nodeOptions += `<option ${selectedNode} value="${i}">${text}</option>`
var selectedGroup = '';
if((Number(this.group) === i))
selectedGroup = 'selected="selected"';
groupOptions += `<option ${selectedGroup} value="${i}">${text}</option>`
}
nodeSelect.append(nodeOptions);
groupSelect.append(groupOptions);
},
oneditsave: function(){
}
});
</script>
<script type="text/x-red" data-template-name="ir-input">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Device name">
</div>
<div class="form-row">
<label for="node-input-gateway"><i class="fa fa-globe"></i> Gateway</label>
<input type="text" id="node-input-gateway" placeholder="Gateway">
</div>
<div class="form-row">
<label for="node-input-devices"><i class="fa fa-microchip"></i> Device</label>
<select id="node-input-devices"></select>
</div>
<div class="form-row">
<label for="node-input-node"><i class="fa fa-cube"></i> Node</label>
<select id="node-input-node"></select>
</div>
<div class="form-row">
<label for="node-input-group"><i class="fa fa-cubes"></i> Group</label>
<select id="node-input-group"></select>
</div>
<div class="form-row">
<label for="node-input-filter"><i class="fa fa-sign-out"></i> Filter</label>
<select id="node-input-filter">
<option selected="selected" value="0">Allow both start and stop messages</option>
<option value="1">Allow start message only</option>
<option value="2">Allow stop message only</option>
</select>
</div>
</script>
<script type="text/x-red" data-help-name="ir-input">
<p>Receives Hapcan Infrared receiver UNIV-3.5.X status messages.</p>
<p>The node emit IR status messages. It uses the Ethernet gateway to receive messages from Hapcan bus.</p>
<h3>Output</h3>
<dl class="message-properties">
<dt>payload <span class="property-type">object</span></dt>
<dd>Hapcan message object with IR module's state data.</dd>
</dl>
<h3>Details</h3>
<p>The <code>msg.payload</code> contains:
</p>
<dl class="message-properties">
<dt>frame <span class="property-type">Buffer[15]</span></dt>
<dd>15 bytes buffer containing raw Hapcan's CAN frame.</dd>
<dt>frameType <span class="property-type">number</span></dt>
<dd>Hapcan frame type number (decimal)</dd>
<dt>isAnswer <span class="property-type">bool</span></dt>
<dd><i>True</i> if message is an answer for request.</dd>
<dt>node <span class="property-type">number</span></dt>
<dd>Sender module node number.</dd>
<dt>group <span class="property-type">number</span></dt>
<dd>Sender module group number.</dd>
<dt>codeType <span class="property-type">string</span></dt>
<dd>Received code type. Possible values are: SIRC12, SIRC15, SIRC20, RC5, NEC16, NEC24</dd>
<dt>address <span class="property-type">number</span></dt>
<dd>Sender device address</dd>
<dt>command <span class="property-type">number</span></dt>
<dd>Sender command.</dd>
<dt>startMessage <span class="property-type">boolean</span></dt>
<dd>Start message is true, when receiver starts receiving and false when it stops receiving IR code.</dd>
<dt>channelName <span class="property-type">string</span></dt>
<dd>Device's channel name that has changed.</dd>
<dt>deviceName <span class="property-type">string</span></dt>
<dd>Device's name that emits the message.</dd>
</dl>
<p>
This node receives IR status messages of the selected module in group. The output is fired twice, on press and on release of the IR remote.
</p>
<h3>References</h3>
<ul>
<li><a href="http://hapcan.com/devices/universal/univ_3/univ_3-5-0-x/index.htm">Hapcan Infrared receiver and transmitter</a> - module firmware notes.</li>
</ul>
</script>