From ae4b6bb0bfedda8145affae51c09c1ad7f4c730d Mon Sep 17 00:00:00 2001 From: CD2468 <87912608+CD2468@users.noreply.github.com> Date: Wed, 27 Oct 2021 14:46:00 +0200 Subject: [PATCH] Problems with more than one MCP3008 (#823) * Add files via upload * Update pimcp3008.js implementation of the discussion * Update pimcp3008.js Co-authored-by: Dave Conway-Jones --- hardware/mcp3008/pimcp3008.html | 3 ++- hardware/mcp3008/pimcp3008.js | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/hardware/mcp3008/pimcp3008.html b/hardware/mcp3008/pimcp3008.html index e6e9894f..4ed013dc 100644 --- a/hardware/mcp3008/pimcp3008.html +++ b/hardware/mcp3008/pimcp3008.html @@ -32,6 +32,7 @@
@@ -77,7 +78,7 @@ outputs: 1, icon: "rpi.png", label: function() { - return this.name || "mcp"+this.dev+" "+((this.pin==="M")?"":this.pin); + return this.name || "mcp:"+this.dev+" "+" bus:"+this.bus+" CS:"+this.dnum+" pin:"+((this.pin==="M")?"":this.pin); }, labelStyle: function() { return this.name?"node_label_italic":""; diff --git a/hardware/mcp3008/pimcp3008.js b/hardware/mcp3008/pimcp3008.js index e6125695..ebb0066a 100644 --- a/hardware/mcp3008/pimcp3008.js +++ b/hardware/mcp3008/pimcp3008.js @@ -19,7 +19,7 @@ module.exports = function(RED) { RED.log.warn("Info : mcp3xxx : Not running on a Pi - Ignoring node"); } - var mcp3xxx = []; + //var mcp3xxx = []; function PiMcpNode(n) { RED.nodes.createNode(this,n); @@ -28,15 +28,17 @@ module.exports = function(RED) { this.dnum = parseInt(n.dnum || 0); this.bus = parseInt(n.bus || 0); this.dev = n.dev || "3008"; + this.mcp3xxx = []; var node = this; - var cb = function (err) { if (err) { node.error("Error: "+err); } }; - var opt = { speedHz:20000, deviceNumber:node.dnum, busNumber:node.bus }; + this.cb = function (err) { if (err) { node.error("Error: "+err); } }; + this.opt = { speedHz:20000, deviceNumber:node.dnum, busNumber:node.bus }; var chans = parseInt(this.dev.substr(3)); + var node = this; if (allOK === true) { try { fs.statSync("/dev/spidev"+node.bus+"."+node.dnum); - if (mcp3xxx.length === 0) { + if (node.mcp3xxx.length === 0) { for (var i=0; i