mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add B+ GPIO support to Pi Node
This commit is contained in:
parent
aa35484a30
commit
aaab0d0d0b
@ -16,11 +16,11 @@
|
||||
|
||||
<script type="text/x-red" data-template-name="rpi-gpio in">
|
||||
<div class="form-row">
|
||||
<label for="node-input-pin"><i class="icon-asterisk"></i> GPIO Pin</label>
|
||||
<select type="text" id="node-input-pin" style="width: 150px;">
|
||||
<label for="node-input-pin"><i class="fa fa-circle"></i> GPIO Pin</label>
|
||||
<select type="text" id="node-input-pin" style="width: 200px;">
|
||||
<option value="-" disabled>select pin </option>
|
||||
<option value="3">3 - SDA0 </option>
|
||||
<option value="5">5 - SCL0 </option>
|
||||
<option value="3">3 - SDA1 </option>
|
||||
<option value="5">5 - SCL1 </option>
|
||||
<option value="7">7 - GPIO7</option>
|
||||
<option value="8">8 - TxD </option>
|
||||
<option value="10">10 - RxD </option>
|
||||
@ -37,9 +37,10 @@
|
||||
<option value="24">24 - CE0 </option>
|
||||
<option value="26">26 - CE1 </option>
|
||||
</select>
|
||||
<span id="pitype"></span>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-intype"><i class=" icon-resize-full"></i> Resistor?</label>
|
||||
<label for="node-input-intype"><i class="fa fa-arrows-v"></i> Resistor?</label>
|
||||
<select type="text" id="node-input-intype" style="width: 150px;">
|
||||
<option value="tri">none</option>
|
||||
<option value="up">pullup</option>
|
||||
@ -48,7 +49,7 @@
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-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">
|
||||
</div>
|
||||
<div class="form-tips">Tip: Only Digital I/O is supported - input must be 0 or 1.</div>
|
||||
@ -80,6 +81,24 @@
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name?"node_label_italic":"";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
$.getJSON('rpi-gpio/'+this.id,function(data) {
|
||||
$('#pitype').text(data.type);
|
||||
if (data.type === "Model B+") {
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",27).text("27 - SDA0"));
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",28).text("28 - SCL0"));
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",29).text("29 - GPIO21"));
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",31).text("31 - GPIO22"));
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",32).text("32 - GPIO26"));
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",33).text("33 - GPIO23"));
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",35).text("35 - GPIO24"));
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",36).text("36 - GPIO27"));
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",37).text("37 - GPIO25"));
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",38).text("38 - GPIO28"));
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",40).text("40 - GPIO29"));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@ -87,11 +106,11 @@
|
||||
|
||||
<script type="text/x-red" data-template-name="rpi-gpio out">
|
||||
<div class="form-row">
|
||||
<label for="node-input-pin"><i class="icon-asterisk"></i> GPIO Pin</label>
|
||||
<select type="text" id="node-input-pin" style="width: 150px;">
|
||||
<label for="node-input-pin"><i class="fa fa-circle"></i> GPIO Pin</label>
|
||||
<select type="text" id="node-input-pin" style="width: 200px;">
|
||||
<option value="-">select pin </option>
|
||||
<option value="3">3 - SDA0 </option>
|
||||
<option value="5">5 - SCL0 </option>
|
||||
<option value="3">3 - SDA1 </option>
|
||||
<option value="5">5 - SCL1 </option>
|
||||
<option value="7">7 - GPIO7</option>
|
||||
<option value="8">8 - TxD </option>
|
||||
<option value="10">10 - RxD </option>
|
||||
@ -108,9 +127,10 @@
|
||||
<option value="24">24 - CE0 </option>
|
||||
<option value="26">26 - CE1 </option>
|
||||
</select>
|
||||
<span id="pitype"></span>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-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">
|
||||
</div>
|
||||
<div class="form-tips">Tip: Only Digital I/O is supported - input must be 0 or 1.</div>
|
||||
@ -139,6 +159,25 @@
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name?"node_label_italic":"";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
$.getJSON('rpi-gpio/'+this.id,function(data) {
|
||||
$('#pitype').text(data.type);
|
||||
if (data.type === "Model B+") {
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",27).text("27 - SDA0"));
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",28).text("28 - SCL0"));
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",29).text("29 - GPIO21"));
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",31).text("31 - GPIO22"));
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",32).text("32 - GPIO26"));
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",33).text("33 - GPIO23"));
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",35).text("35 - GPIO24"));
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",36).text("36 - GPIO27"));
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",37).text("37 - GPIO25"));
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",38).text("38 - GPIO28"));
|
||||
$('#node-input-pin').append($("<option></option>").attr("value",40).text("40 - GPIO29"));
|
||||
}
|
||||
});
|
||||
$
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@ -47,7 +47,18 @@ module.exports = function(RED) {
|
||||
"21":"13",
|
||||
"23":"14",
|
||||
"8":"15",
|
||||
"10":"16"
|
||||
"10":"16",
|
||||
"27":"30",
|
||||
"28":"31",
|
||||
"29":"21",
|
||||
"31":"22",
|
||||
"32":"26",
|
||||
"33":"23",
|
||||
"35":"24",
|
||||
"36":"27",
|
||||
"37":"25",
|
||||
"38":"28",
|
||||
"40":"29"
|
||||
}
|
||||
var tablepin = {
|
||||
// WiringPi : Physical
|
||||
@ -67,7 +78,18 @@ module.exports = function(RED) {
|
||||
"13":"21",
|
||||
"14":"23",
|
||||
"15":"8",
|
||||
"16":"10"
|
||||
"16":"10",
|
||||
"30":"27",
|
||||
"31":"28",
|
||||
"21":"29",
|
||||
"22":"31",
|
||||
"26":"32",
|
||||
"23":"33",
|
||||
"24":"35",
|
||||
"27":"36",
|
||||
"25":"37",
|
||||
"28":"38",
|
||||
"29":"40"
|
||||
}
|
||||
|
||||
function GPIOInNode(n) {
|
||||
@ -77,13 +99,13 @@ module.exports = function(RED) {
|
||||
this.intype = n.intype;
|
||||
var node = this;
|
||||
|
||||
if (node.pin) {
|
||||
if (node.pin !== undefined) {
|
||||
exec("gpio mode "+node.pin+" "+node.intype, function(err,stdout,stderr) {
|
||||
if (err) node.error(err);
|
||||
if (err) { node.error(err); }
|
||||
else {
|
||||
node._interval = setInterval( function() {
|
||||
exec("gpio read "+node.pin, function(err,stdout,stderr) {
|
||||
if (err) node.error(err);
|
||||
if (err) { node.error(err); }
|
||||
else {
|
||||
if (node.buttonState !== Number(stdout)) {
|
||||
var previousState = node.buttonState;
|
||||
@ -113,21 +135,21 @@ module.exports = function(RED) {
|
||||
this.pin = pintable[n.pin];
|
||||
var node = this;
|
||||
|
||||
if (node.pin) {
|
||||
if (node.pin !== undefined) {
|
||||
process.nextTick(function() {
|
||||
exec("gpio mode "+node.pin+" out", function(err,stdout,stderr) {
|
||||
if (err) node.error(err);
|
||||
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;
|
||||
if (msg.payload === "true") { msg.payload = true; }
|
||||
if (msg.payload === "false") { msg.payload = false; }
|
||||
var out = Number(msg.payload);
|
||||
if ((out == 0)|(out == 1)) {
|
||||
if ((out === 0)|(out === 1)) {
|
||||
exec("gpio write "+node.pin+" "+out, function(err,stdout,stderr) {
|
||||
if (err) node.error(err);
|
||||
if (err) { node.error(err); }
|
||||
});
|
||||
}
|
||||
else node.warn("Invalid input - not 0 or 1");
|
||||
else { node.warn("Invalid input - not 0 or 1"); }
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -155,6 +177,22 @@ module.exports = function(RED) {
|
||||
// exec("gpio mode 7 in");
|
||||
//});
|
||||
|
||||
var pitype = { type:"" };
|
||||
exec("gpio -v | grep Type", function(err,stdout,stderr) {
|
||||
if (err) {
|
||||
util.log('[36-rpi-gpio.js] Error: "gpio -v" command failed for some reason.');
|
||||
}
|
||||
else {
|
||||
pitype = { type:(stdout.split(","))[0].split(": ")[1], rev:(stdout.split(","))[1].split(": ")[1] };
|
||||
}
|
||||
});
|
||||
|
||||
RED.nodes.registerType("rpi-gpio in",GPIOInNode);
|
||||
RED.nodes.registerType("rpi-gpio out",GPIOOutNode);
|
||||
|
||||
var querystring = require('querystring');
|
||||
RED.httpAdmin.get('/rpi-gpio/:id',function(req,res) {
|
||||
var credentials = RED.nodes.getCredentials(req.params.id);
|
||||
res.send( JSON.stringify(pitype) );
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user