-
Notifications
You must be signed in to change notification settings - Fork 7
/
din.html
157 lines (149 loc) · 7.15 KB
/
din.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
<script type="text/javascript">
RED.nodes.registerType('ppDIN', {
category: 'Pi_Plates',
color: '#87A980',
defaults: {
config_plate: { value: '', type: "pi_plate"},
name: { value: ''},
input: { value: "0", required: true}
},
inputs: 1,
outputs: 1,
icon: 'serial.svg',
paletteLabel: 'DIN',
label: function () {
return (this.name || 'DIN' + this.input);
},
outputLabels: function(index) {
let daqc_labels = ['DIN0','DIN1','DIN2','DIN3','DIN4','DIN5','DIN6','DIN7'];
let adc_labels = ['DIN0','DIN1','DIN2','DIN3','TRIG'];
let digi_labels = ['DIN1','DIN2','DIN3','DIN4','DIN5','DIN6','DIN7','DIN8'];
let tinker_labels = ['DIO1','DIO2','DIO3','DIO4','DIO5','DIO6','DIO7','DIO8'];
let node = this;
if (node.plate_model && node.input) {
let input_index = parseInt(node.input, 10);
if (node.plate_model == "TINKERplate") {
input_index -= 1;
return(tinker_labels[input_index]);
} else if (node.plate_model == "DIGIplate") {
input_index -= 1;
return(digi_labels[input_index]);
} else if (node.plate_model == "DAQCplate" || node.plate_model == "DAQC2plate") {
return(daqc_labels[input_index]);
} else if (node.plate_model == "ADCplate") {
return(adc_labels[input_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();
$("#input_section").hide();
$("#node-input-input").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: "DIN0", value: 0},
{name: "DIN1", value: 1},
{name: "DIN2", value: 2},
{name: "DIN3", value: 3},
{name: "DIN4", value: 4},
{name: "DIN5", value: 5},
{name: "DIN6", value: 6},
{name: "DIN7", value: 7}
]
for (var i = 0; i < daqc_options.length; i++)
$('#node-input-input').append('<option value="' + daqc_options[i].value + '">' + daqc_options[i].name + '</option>');
$("#input_section").show()
} else if (node.plate_model == "ADCplate") {
var adc_options = [
{name: "DIN0", value: 0},
{name: "DIN1", value: 1},
{name: "DIN2", value: 2},
{name: "DIN3", value: 3},
{name: "TRIG", value: 4}
]
for (var i = 0; i < adc_options.length; i++)
$('#node-input-input').append('<option value="' + adc_options[i].value + '">' + adc_options[i].name + '</option>');
$("#input_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-input').append('<option value="' + tink_options[i].value + '">' + tink_options[i].name + '</option>');
$("#input_section").show()
} else if (node.plate_model == "DIGIplate") {
var digi_options = [
{name: "DIN1", value: 1},
{name: "DIN2", value: 2},
{name: "DIN3", value: 3},
{name: "DIN4", value: 4},
{name: "DIN5", value: 5},
{name: "DIN6", value: 6},
{name: "DIN7", value: 7},
{name: "DIN8", value: 8}
]
for (var i = 0; i < digi_options.length; i++)
$('#node-input-input').append('<option value="' + digi_options[i].value + '">' + digi_options[i].name + '</option>');
$("#input_section").show();
} else {
$("#invalid_plate_section").show();
$("#input_section").hide();
node.input = null;
}
if (node.input) {
$("#input_section select").val(node.input);
}
}
} // 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="ppDIN">
<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="input_section">
<label for="node-input-input"><i class="icon-tag"></i> Input #</label>
<select id="node-input-input">
</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="ppDIN">
<p>Digital Inputs read logic levels and output their (updated) status (1 == High, 0 == Low).</p>
</script>