mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Let Pi GPIO node show pins in use to help avoid clashes.
This commit is contained in:
parent
2dd572f5bd
commit
07c8c4bb45
@ -57,6 +57,7 @@
|
|||||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||||
<input type="text" id="node-input-name" placeholder="Name">
|
<input type="text" id="node-input-name" placeholder="Name">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-tips" id="pin-tip"><b>Pins in Use</b>: </div>
|
||||||
<div class="form-tips">Tip: Only Digital Input is supported - input must be 0 or 1.</div>
|
<div class="form-tips">Tip: Only Digital Input is supported - input must be 0 or 1.</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -69,6 +70,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
var pinsInUse = {};
|
||||||
RED.nodes.registerType('rpi-gpio in',{
|
RED.nodes.registerType('rpi-gpio in',{
|
||||||
category: 'Raspberry Pi',
|
category: 'Raspberry Pi',
|
||||||
color:"#c6dbef",
|
color:"#c6dbef",
|
||||||
@ -81,6 +83,12 @@
|
|||||||
inputs:0,
|
inputs:0,
|
||||||
outputs:1,
|
outputs:1,
|
||||||
icon: "rpi.png",
|
icon: "rpi.png",
|
||||||
|
info: function() {
|
||||||
|
if ( Object.keys(pinsInUse).length !== 0 ) {
|
||||||
|
return "**Pins in use** : "+Object.keys(pinsInUse);
|
||||||
|
}
|
||||||
|
else { return ""; }
|
||||||
|
},
|
||||||
label: function() {
|
label: function() {
|
||||||
return this.name||"Pin: "+this.pin ;
|
return this.name||"Pin: "+this.pin ;
|
||||||
},
|
},
|
||||||
@ -89,7 +97,6 @@
|
|||||||
},
|
},
|
||||||
oneditprepare: function() {
|
oneditprepare: function() {
|
||||||
var pinnow = this.pin;
|
var pinnow = this.pin;
|
||||||
var pinsInUse = {};
|
|
||||||
$.getJSON('rpi-gpio/'+this.id,function(data) {
|
$.getJSON('rpi-gpio/'+this.id,function(data) {
|
||||||
$('#pitype').text(data.type);
|
$('#pitype').text(data.type);
|
||||||
if ((data.type === "Model B+") || (data.type === "Model A+")) {
|
if ((data.type === "Model B+") || (data.type === "Model A+")) {
|
||||||
@ -110,13 +117,14 @@
|
|||||||
|
|
||||||
$.getJSON('rpi-pins/'+this.id,function(data) {
|
$.getJSON('rpi-pins/'+this.id,function(data) {
|
||||||
pinsInUse = data || {};
|
pinsInUse = data || {};
|
||||||
|
$('#pin-tip').html("<b>Pins in Use</b>: "+Object.keys(data));
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#node-input-pin").change(function() {
|
$("#node-input-pin").change(function() {
|
||||||
var pinnew = $("#node-input-pin").val();
|
var pinnew = $("#node-input-pin").val();
|
||||||
if ((pinnew) && (pinnew !== pinnow)) {
|
if ((pinnew) && (pinnew !== pinnow)) {
|
||||||
if (pinsInUse.hasOwnProperty(pinnew)) {
|
if (pinsInUse.hasOwnProperty(pinnew)) {
|
||||||
RED.notify("Pin "+pinnew+" already in use.","info");
|
RED.notify("Pin "+pinnew+" already in use.","warn");
|
||||||
}
|
}
|
||||||
pinnow = pinnew;
|
pinnow = pinnew;
|
||||||
}
|
}
|
||||||
@ -181,6 +189,7 @@
|
|||||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||||
<input type="text" id="node-input-name" placeholder="Name">
|
<input type="text" id="node-input-name" placeholder="Name">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-tips" id="pin-tip"><b>Pins in Use</b>: </div>
|
||||||
<div class="form-tips" id="dig-tip"><b>Tip</b>: For digital output - input must be 0 or 1.</div>
|
<div class="form-tips" id="dig-tip"><b>Tip</b>: For digital output - input must be 0 or 1.</div>
|
||||||
<div class="form-tips" id="pwm-tip"><b>Tip</b>: For PWM output - input must be between 0 to 1023.</div>
|
<div class="form-tips" id="pwm-tip"><b>Tip</b>: For PWM output - input must be between 0 to 1023.</div>
|
||||||
</script>
|
</script>
|
||||||
@ -195,6 +204,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
var pinsInUse = {};
|
||||||
RED.nodes.registerType('rpi-gpio out',{
|
RED.nodes.registerType('rpi-gpio out',{
|
||||||
category: 'Raspberry Pi',
|
category: 'Raspberry Pi',
|
||||||
color:"#c6dbef",
|
color:"#c6dbef",
|
||||||
@ -208,6 +218,12 @@
|
|||||||
inputs:1,
|
inputs:1,
|
||||||
outputs:0,
|
outputs:0,
|
||||||
icon: "rpi.png",
|
icon: "rpi.png",
|
||||||
|
info: function() {
|
||||||
|
if ( Object.keys(pinsInUse).length !== 0 ) {
|
||||||
|
return "**Pins in use** : "+Object.keys(pinsInUse);
|
||||||
|
}
|
||||||
|
else { return ""; }
|
||||||
|
},
|
||||||
align: "right",
|
align: "right",
|
||||||
label: function() {
|
label: function() {
|
||||||
if (this.out === "pwm") { return this.name || "PWM: "+this.pin; }
|
if (this.out === "pwm") { return this.name || "PWM: "+this.pin; }
|
||||||
@ -218,7 +234,6 @@
|
|||||||
},
|
},
|
||||||
oneditprepare: function() {
|
oneditprepare: function() {
|
||||||
var pinnow = this.pin;
|
var pinnow = this.pin;
|
||||||
var pinsInUse = {};
|
|
||||||
if (!$("#node-input-out").val()) { $("#node-input-out").val("out"); }
|
if (!$("#node-input-out").val()) { $("#node-input-out").val("out"); }
|
||||||
$.getJSON('rpi-gpio/'+this.id,function(data) {
|
$.getJSON('rpi-gpio/'+this.id,function(data) {
|
||||||
$('#pitype').text(data.type);
|
$('#pitype').text(data.type);
|
||||||
@ -240,13 +255,14 @@
|
|||||||
|
|
||||||
$.getJSON('rpi-pins/'+this.id,function(data) {
|
$.getJSON('rpi-pins/'+this.id,function(data) {
|
||||||
pinsInUse = data || {};
|
pinsInUse = data || {};
|
||||||
|
$('#pin-tip').html("<b>Pins in Use</b>: "+Object.keys(data));
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#node-input-pin").change(function() {
|
$("#node-input-pin").change(function() {
|
||||||
var pinnew = $("#node-input-pin").val();
|
var pinnew = $("#node-input-pin").val();
|
||||||
if ((pinnew) && (pinnew !== pinnow)) {
|
if ((pinnew) && (pinnew !== pinnow)) {
|
||||||
if (pinsInUse.hasOwnProperty(pinnew)) {
|
if (pinsInUse.hasOwnProperty(pinnew)) {
|
||||||
RED.notify("Pin "+pinnew+" already in use.","info");
|
RED.notify("Pin "+pinnew+" already in use.","warn");
|
||||||
}
|
}
|
||||||
pinnow = pinnew;
|
pinnow = pinnew;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user