mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
allow mcp node to be visible when not in Pi
mark as inactive status to close #718
This commit is contained in:
parent
2d5d553c4d
commit
91217d6e62
@ -1,9 +1,9 @@
|
||||
{
|
||||
"name" : "node-red-node-pi-mcp3008",
|
||||
"version" : "0.2.1",
|
||||
"version" : "0.3.0",
|
||||
"description" : "A Node-RED node to read from the MCP3008 Analogue to Digital Converter",
|
||||
"dependencies" : {
|
||||
"mcp-spi-adc": "^2.0.6"
|
||||
"mcp-spi-adc": "^3.1.0"
|
||||
},
|
||||
"repository" : {
|
||||
"type":"git",
|
||||
|
@ -2,16 +2,23 @@
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var fs = require('fs');
|
||||
var allOK = false;
|
||||
var mcpadc;
|
||||
// unlikely if not on a Pi
|
||||
try {
|
||||
var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString();
|
||||
if (cpuinfo.indexOf(": BCM") === -1) { throw "Info : "+RED._("rpi-gpio.errors.ignorenode"); }
|
||||
if (cpuinfo.indexOf(": BCM") === -1) {
|
||||
RED.log.warn("Info : mcp3xxx : Not running on a Pi - Ignoring node");
|
||||
}
|
||||
else {
|
||||
mcpadc = require('mcp-spi-adc');
|
||||
allOK = true;
|
||||
}
|
||||
}
|
||||
catch(err) {
|
||||
throw "Info : "+RED._("rpi-gpio.errors.ignorenode");
|
||||
RED.log.warn("Info : mcp3xxx : Not running on a Pi - Ignoring node");
|
||||
}
|
||||
|
||||
var mcpadc = require('mcp-spi-adc');
|
||||
var mcp3xxx = [];
|
||||
|
||||
function PiMcpNode(n) {
|
||||
@ -26,6 +33,7 @@ module.exports = function(RED) {
|
||||
var opt = { speedHz:20000, deviceNumber:node.dnum, busNumber:node.bus };
|
||||
var chans = parseInt(this.dev.substr(3));
|
||||
|
||||
if (allOK === true) {
|
||||
try {
|
||||
fs.statSync("/dev/spidev"+node.bus+"."+node.dnum);
|
||||
if (mcp3xxx.length === 0) {
|
||||
@ -70,6 +78,10 @@ module.exports = function(RED) {
|
||||
else { done(); }
|
||||
});
|
||||
}
|
||||
else {
|
||||
node.status({text:"node inactive."})
|
||||
}
|
||||
}
|
||||
|
||||
RED.nodes.registerType("pimcp3008",PiMcpNode);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user