-
Notifications
You must be signed in to change notification settings - Fork 7
/
dout.html
131 lines (125 loc) · 5.82 KB
/
dout.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
<script type="text/javascript">
RED.nodes.registerType('ppDOUT', {
category: 'Pi_Plates',
color: '#87A980',
defaults: {
config_plate: { value: '', type: "pi_plate"},
name: { value: ''},
output: { value: "0", required: true}
},
inputs: 1,
outputs: 1,
align:'right',
icon: 'serial.svg',
paletteLabel: 'DOUT',
label: function () {
return (this.name || 'DOUT' + this.output);
},
outputLabels: function(index) {
let daqc_labels = ['DOUT0','DOUT1','DOUT2','DOUT3','DOUT4','DOUT5','DOUT6'];
let daqc2_labels = ['DOUT0','DOUT1','DOUT2','DOUT3','DOUT4','DOUT5','DOUT6','DOUT7'];
let tinker_labels = ['DIO1','DIO2','DIO3','DIO4','DIO5','DIO6','DIO7','DIO8'];
let node = this;
if (node.plate_model && node.output) {
let output_index = parseInt(node.output, 10);
if (node.plate_model == "TINKERplate") {
output_index -= 1;
return(tinker_labels[output_index]);
} else if (node.plate_model == "DAQCplate") {
return(daqc_labels[output_index]);
} else if (node.plate_model == "DAQC2plate") {
return(daqc2_labels[output_index]);
} 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();
$("#output_section").hide();
$("#node-input-output").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 == "DAQCplate" || node.plate_model == "DAQC2plate") {
var daqc_options = [
{name: "DOUT0", value: 0},
{name: "DOUT1", value: 1},
{name: "DOUT2", value: 2},
{name: "DOUT3", value: 3},
{name: "DOUT4", value: 4},
{name: "DOUT5", value: 5},
{name: "DOUT6", value: 6}
]
for (var i = 0; i < daqc_options.length; i++)
$('#node-input-output').append('<option value="' + daqc_options[i].value + '">' + daqc_options[i].name + '</option>');
if (node.plate_model == "DAQC2plate")
$('#node-input-output').append('<option value="7">DOUT7</option>');
$("#output_section").show()
} else if (node.plate_model == "TINKERplate") {
var tink_options = [
{name: "DIO1", value: 1},
{name: "DIO2", value: 2},
{name: "DIO3", value: 3},
{name: "DIO4", value: 4},
{name: "DIO5", value: 5},
{name: "DIO6", value: 6},
{name: "DIO7", value: 7},
{name: "DIO8", value: 8}
]
for (var i = 0; i < tink_options.length; i++)
$('#node-input-output').append('<option value="' + tink_options[i].value + '">' + tink_options[i].name + '</option>');
$("#output_section").show()
} else {
$("#invalid_plate_section").show();
$("#output_section").hide();
node.output = null;
}
if (node.output) {
$("#output_section select").val(node.output);
}
}
} // 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="ppDOUT">
<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="output_section">
<label for="node-input-output"><i class="icon-tag"></i> Output #</label>
<select id="node-input-output">
</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="ppDOUT">
<p>Digital Outputs accept string input ("on", "off", or "toggle"). The associated
digital output is updated to the corresponding logic level. The updated state is
sent out (0 == "Low/Off", 1 == "High/On"). After a toggle operation, the node
doesn't know it's state and so it sends the string 'UNKNOWN'.</p>
</script>