New Pi GPIO node based on RPI.GPIO library.

Adds PWM support of outputs and easier access to interrupts for inputs.
This commit is contained in:
dceejay
2014-12-27 13:11:44 +00:00
parent b4dc66944a
commit 9e4187d6a8
4 changed files with 327 additions and 132 deletions

View File

@@ -45,7 +45,6 @@
<option value="tri">none</option>
<option value="up">pullup</option>
<option value="down">pulldown</option>
<!--<option value="tri">tristate</option>-->
</select>
</div>
<div class="form-row">
@@ -63,11 +62,11 @@
<script type="text/x-red" data-help-name="rpi-gpio in">
<p>Raspberry Pi input node. Generates a <b>msg.payload</b> with either a 0 or 1 depending on the state of the input pin. Requires the gpio command to work.</p>
<p>You may also enable the input pullup resitor or the pulldown resistor.</p>
<p>You may also enable the input pullup resistor or the pulldown resistor.</p>
<p>The <b>msg.topic</b> is set to <i>pi/{the pin number}</i></p>
<p>Requires the RPi.GPIO python library version 0.5.8 (or better) in order to work.</p>
<p><b>Note:</b> we are using the actual physical pin numbers on connector P1 as they are easier to locate.</p>
<p><b>Note:</b> This node currently polls the pin every 250mS. This is not ideal as it loads the cpu.</p>
</script>
</script>
<script type="text/javascript">
RED.nodes.registerType('rpi-gpio in',{
@@ -90,6 +89,7 @@
},
oneditprepare: function() {
var pinnow = this.pin;
var pinsInUse = {};
$.getJSON('rpi-gpio/'+this.id,function(data) {
$('#pitype').text(data.type);
if ((data.type === "Model B+") || (data.type === "Model A+")) {
@@ -107,11 +107,31 @@
$('#node-input-pin').val(pinnow);
}
});
$.getJSON('rpi-pins/'+this.id,function(data) {
pinsInUse = data || {};
});
$("#node-input-pin").change(function() {
var pinnew = $("#node-input-pin").val();
if ((pinnew) && (pinnew !== pinnow)) {
if (pinsInUse.hasOwnProperty(pinnew)) {
RED.notify("Pin "+pinnew+" already in use.","info");
}
pinnow = pinnew;
}
});
$("#node-input-intype").change(function() {
var newtype = $("#node-input-intype option:selected").val();
if ((pinsInUse.hasOwnProperty(pinnow)) && (pinsInUse[pinnow] !== newtype)) {
RED.notify("Pin "+pinnow+" already set as "+pinsInUse[pinnow],"error");
}
});
}
});
</script>
<script type="text/x-red" data-template-name="rpi-gpio out">
<div class="form-row">
<label for="node-input-pin"><i class="fa fa-circle"></i> GPIO Pin</label>
@@ -123,7 +143,7 @@
<option value="8">8 - TxD </option>
<option value="10">10 - RxD </option>
<option value="11">11 - GPIO0</option>
<option value="12">12 - GPIO1 (PWM)</option>
<option value="12">12 - GPIO1</option>
<option value="13">13 - GPIO2</option>
<option value="15">15 - GPIO3</option>
<option value="16">16 - GPIO4</option>
@@ -169,7 +189,8 @@
<p>Raspberry Pi output node. Expects a <b>msg.payload</b> with either a 0 or 1 (or true or false). Requires the gpio command to work.</p>
<p>Will set the selected physical pin high or low depending on the value passed in.</p>
<p>The initial value of the pin at deploy time can also be set to 0 or 1.</p>
<p>Use of PWM on Pin 12 - GPIO1 will interfere with any other audio playback.</p>
<p>When using PWM mode - expects an input value of a number 0 - 100.</p>
<p>Requires the RPi.GPIO python library version 0.5.8 (or better) in order to work.</p>
<p><b>Note:</b> we are using the actual physical pin numbers on connector P1 as they are easier to locate.</p>
</script>
@@ -189,7 +210,7 @@
icon: "rpi.png",
align: "right",
label: function() {
if ((this.pin == 12) && (this.out === "pwm")) { return this.name || "PWM: 12"; }
if (this.out === "pwm") { return this.name || "PWM: "+this.pin; }
else { return this.name||"Pin: "+this.pin ; }
},
labelStyle: function() {
@@ -197,6 +218,7 @@
},
oneditprepare: function() {
var pinnow = this.pin;
var pinsInUse = {};
if (!$("#node-input-out").val()) { $("#node-input-out").val("out"); }
$.getJSON('rpi-gpio/'+this.id,function(data) {
$('#pitype').text(data.type);
@@ -216,17 +238,26 @@
}
});
var hidepwm = function() {
if ($('#node-input-pin').val() == 12) {
$('#node-set-pwm').show();
$.getJSON('rpi-pins/'+this.id,function(data) {
pinsInUse = data || {};
});
$("#node-input-pin").change(function() {
var pinnew = $("#node-input-pin").val();
if ((pinnew) && (pinnew !== pinnow)) {
if (pinsInUse.hasOwnProperty(pinnew)) {
RED.notify("Pin "+pinnew+" already in use.","info");
}
pinnow = pinnew;
}
else {
$('#node-set-pwm').hide();
$('#node-input-out').val("out");
});
$("#node-input-out").change(function() {
var newtype = $("#node-input-out option:selected").val();
if ((pinsInUse.hasOwnProperty(pinnow)) && (pinsInUse[pinnow] !== newtype)) {
RED.notify("Pin "+pinnow+" already set as "+pinsInUse[pinnow],"error");
}
};
$("#node-input-pin").change(function () { hidepwm(); });
hidepwm();
});
var hidestate = function () {
if ($("#node-input-out").val() === "pwm") {