-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrelay.html
136 lines (128 loc) · 6.03 KB
/
relay.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
<script type="text/javascript">
RED.nodes.registerType('ppRelay', {
category: 'Pi_Plates',
color: '#87A980',
defaults: {
config_plate: { value: '', type: "pi_plate"},
name: { value: ''},
relay: { value: "1", required: true}
},
inputs: 1,
outputs: 1,
align:'right',
icon: 'relay.svg',
paletteLabel: 'RELAY',
label: function () {
return (this.name || 'RELAY ' + this.relay);
},
outputLabels: function(index) {
let tinker_labels = ['Relay 1', 'Relay 2'];
let relay_labels = ['K1', 'K2', 'K3', 'K4', 'K5', 'K6', 'K7'];
let relay2_labels = ['K1', 'K2', 'K3', 'K4', 'K5', 'K6', 'K7', 'K8'];
let node = this;
if (node.plate_model && node.relay) {
let relay_index = parseInt(node.relay, 10) - 1;
if (node.plate_model == "TINKERplate") {
return(tinker_labels[relay_index]);
} else if (node.plate_model == "RELAYplate") {
return(relay_labels[relay_index]);
} else if (node.plate_model == "RELAYplate2") {
return(relay2_labels[relay_index]);
} else if (node.plate_model == "POWERplate24") {
return('Fan');
} else {
return('');
}
} else {
return('');
}
},
oneditprepare: function () {
var node = this;
node.prev_config_id = $("#node-input-config_plate").val();
node.plate_model = 'unknown';
function draw_form() {
$("#invalid_plate_section").hide();
$("#relay_section").hide();
$("#node-input-relay").empty()
var config_id = $("#node-input-config_plate").val();
if (config_id == "_ADD_") {
// no config node yet
} else {
node.config_node = RED.nodes.node(config_id)
node.plate_model = node.config_node.model;
if (node.plate_model == "RELAYplate" || node.plate_model == "RELAYplate2") {
var relay_options = [
{name: "K1", value: 1},
{name: "K2", value: 2},
{name: "K3", value: 3},
{name: "K4", value: 4},
{name: "K5", value: 5},
{name: "K6", value: 6},
{name: "K7", value: 7}
]
for (var i = 0; i < relay_options.length; i++)
$('#node-input-relay').append('<option value="' + relay_options[i].value + '">' + relay_options[i].name + '</option>');
if (node.plate_model == "RELAYplate2")
$('#node-input-relay').append('<option value="8">K8</option>');
$("#relay_section").show()
} else if (node.plate_model == "TINKERplate") {
node.outputLabels = function(index) { return("bar " + index); };
var tink_options = [
{name: "Relay 1", value: 1},
{name: "Relay 2", value: 2}
]
for (var i = 0; i < tink_options.length; i++)
$('#node-input-relay').append('<option value="' + tink_options[i].value + '">' + tink_options[i].name + '</option>');
$("#relay_section").show()
} else if (node.plate_model == "POWERplate24") {
node.outputLabels = ["fan state"];
$('#node-input-relay').append('<option value="fan">Onboard Fan</option>');
$("#relay_section").show()
} else {
$("#invalid_plate_section").show();
$("#relay_section").hide();
node.input = null;
}
if (node.relay) {
$("#relay_section select").val(node.relay);
}
}
} // draw_form()
$("#node-input-config_plate").on('focus', function() {node.prev_config_id = this.value}).change(function() {
// if config node selection has changed, clear our form selection and redraw the form
if (node.prev_config_id !== this.value) {
node.plate_model = null;
}
draw_form()
});
} // oneditprepare()
});
</script>
<script type="text/x-red" data-template-name="ppRelay">
<div class="form-row">
<label for="node-input-config_plate"><i class="icon-tag"></i> Plate</label>
<input type="text" id="node-input-config_plate">
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row" id="relay_section">
<label for="node-input-relay"><i class="icon-tag"></i> Relay #</label>
<select id="node-input-relay">
</select>
</div>
<div class="form-row" id="invalid_plate_section">
<h3 style="color: red">Invalid plate selected</h2>
</div>
</script>
<script type="text/x-red" data-help-name="ppRelay">
<p>Relays are Normally Open switches that can be turned on, off, or toggled.</p>
<p>Send "off" to this node to open the contact (turn load off).</p>
<p>Send "on" to this node to close the contact (turn load on).</p>
<p>Send "toggle" to toggle the relay.</p>
<p>Send "state" to read the state of the relay.</p>
<p>The node will send the relay's new state to it's output (1 for "on", 0 for "off")</p>
<p>The POWERplate24 onboard fan is a special case: use "on", "off", or "state" to control fan.</p>
</script>