mirror of https://github.com/node-red/node-red.git
Allow Raspberry Pi node to set initial output level.
Fix for #443 Also allow (optional) initial read of input pins on deploy. Moved to Category Raspberry Pi (other Pi related nodes will be updated to match soon).pull/449/head
parent
28a4ba1aad
commit
472fdc65a9
|
@ -40,7 +40,7 @@
|
|||
<span id="pitype"></span>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-intype"><i class="fa fa-long-arrow-up"></i> Resistor?</label>
|
||||
<label for="node-input-intype"><i class="fa fa-long-arrow-up"></i> Resistor ?</label>
|
||||
<select type="text" id="node-input-intype" style="width: 150px;">
|
||||
<option value="tri">none</option>
|
||||
<option value="up">pullup</option>
|
||||
|
@ -48,6 +48,11 @@
|
|||
<!--<option value="tri">tristate</option>-->
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label> </label>
|
||||
<input type="checkbox" id="node-input-read" style="display: inline-block; width: auto; vertical-align: top;">
|
||||
<label for="node-input-read" style="width: 70%;">Read initial state of pin on deploy ?</label>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
|
@ -60,18 +65,18 @@
|
|||
<p>You may also enable the input pullup resitor or the pulldown resistor.</p>
|
||||
<p>The <b>msg.topic</b> is set to <i>pi/{the pin number}</i></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, and will be rewritten shortly to try to use interrupts.</p>
|
||||
|
||||
<p><b>Note:</b> This node currently polls the pin every 250mS. This is not ideal as it loads the cpu, and should be rewritten to try to use interrupts.</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('rpi-gpio in',{
|
||||
category: 'advanced-input',
|
||||
category: 'Raspberry Pi',
|
||||
color:"#c6dbef",
|
||||
defaults: {
|
||||
name: { value:"" },
|
||||
intype: { value: "in" },
|
||||
pin: { value:"",required:true,validate:RED.validators.number() },
|
||||
intype: { value: "in" },
|
||||
read: { value:false }
|
||||
},
|
||||
inputs:0,
|
||||
outputs:1,
|
||||
|
@ -129,6 +134,18 @@
|
|||
</select>
|
||||
<span id="pitype"></span>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label> </label>
|
||||
<input type="checkbox" id="node-input-set" style="display: inline-block; width: auto; vertical-align: top;">
|
||||
<label for="node-input-set" style="width: 70%;">Initialise pin state ?</label>
|
||||
</div>
|
||||
<div class="form-row" id="node-set-state">
|
||||
<label for="node-input-level"> </label>
|
||||
<select id="node-input-level" style="width: 300px;">
|
||||
<option value="0">initial level of pin - low (0)</option>
|
||||
<option value="1">initial level of pin - high (1)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
|
@ -139,16 +156,19 @@
|
|||
<script type="text/x-red" data-help-name="rpi-gpio out">
|
||||
<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><b>Note:</b> we are using the actual physical pin numbers on connector P1 as they are easier to locate.</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('rpi-gpio out',{
|
||||
category: 'advanced-output',
|
||||
category: 'Raspberry Pi',
|
||||
color:"#c6dbef",
|
||||
defaults: {
|
||||
name: { value:"" },
|
||||
pin: { value:"",required:true,validate:RED.validators.number() },
|
||||
set: { value:false },
|
||||
level: { value:"0" }
|
||||
},
|
||||
inputs:1,
|
||||
outputs:0,
|
||||
|
@ -177,6 +197,14 @@
|
|||
$('#node-input-pin').append($("<option></option>").attr("value",40).text("40 - GPIO29"));
|
||||
}
|
||||
});
|
||||
|
||||
$("#node-input-set").change(function() {
|
||||
if ($('#node-input-set').is(":checked")) {
|
||||
$("#node-set-state").show();
|
||||
} else {
|
||||
$("#node-set-state").hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright 2013 IBM Corp.
|
||||
* Copyright 2013,2014 IBM Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -99,6 +99,8 @@ module.exports = function(RED) {
|
|||
this.buttonState = -1;
|
||||
this.pin = pintable[n.pin];
|
||||
this.intype = n.intype;
|
||||
this.read = n.read || false;
|
||||
if (this.read) { this.buttonState = -2; }
|
||||
var node = this;
|
||||
|
||||
if (node.pin !== undefined) {
|
||||
|
@ -135,26 +137,31 @@ module.exports = function(RED) {
|
|||
function GPIOOutNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.pin = pintable[n.pin];
|
||||
this.set = n.set || false;
|
||||
this.level = n.level || 0;
|
||||
var node = this;
|
||||
|
||||
if (node.pin !== undefined) {
|
||||
process.nextTick(function() {
|
||||
exec(gpioCommand+" mode "+node.pin+" out", function(err,stdout,stderr) {
|
||||
if (err) { node.error(err); }
|
||||
else {
|
||||
node.on("input", function(msg) {
|
||||
if (msg.payload === "true") { msg.payload = true; }
|
||||
if (msg.payload === "false") { msg.payload = false; }
|
||||
var out = Number(msg.payload);
|
||||
if ((out === 0)|(out === 1)) {
|
||||
exec(gpioCommand+" write "+node.pin+" "+out, function(err,stdout,stderr) {
|
||||
if (err) { node.error(err); }
|
||||
});
|
||||
}
|
||||
else { node.warn("Invalid input - not 0 or 1"); }
|
||||
exec(gpioCommand+" mode "+node.pin+" out", function(err,stdout,stderr) {
|
||||
if (err) { node.error(err); }
|
||||
else {
|
||||
if (node.set) {
|
||||
exec(gpioCommand+" write "+node.pin+" "+node.level, function(err,stdout,stderr) {
|
||||
if (err) { node.error(err); }
|
||||
});
|
||||
}
|
||||
});
|
||||
node.on("input", function(msg) {
|
||||
if (msg.payload === "true") { msg.payload = true; }
|
||||
if (msg.payload === "false") { msg.payload = false; }
|
||||
var out = Number(msg.payload);
|
||||
if ((out === 0)|(out === 1)) {
|
||||
exec(gpioCommand+" write "+node.pin+" "+out, function(err,stdout,stderr) {
|
||||
if (err) { node.error(err); }
|
||||
});
|
||||
}
|
||||
else { node.warn("Invalid input - not 0 or 1"); }
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Reference in New Issue