Skip to content

Commit

Permalink
Expander: don't require an address when unnecessary. Fixes gh-1291
Browse files Browse the repository at this point in the history
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Mar 30, 2017
1 parent 23a9526 commit cc85c69
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/expander.js
Original file line number Diff line number Diff line change
Expand Up @@ -1812,6 +1812,10 @@ Object.keys(Controllers).forEach(function(name) {
});
});

var nonAddressable = [
"74HC595"
];

function Expander(opts) {
if (!(this instanceof Expander)) {
return new Expander(opts);
Expand All @@ -1836,6 +1840,11 @@ function Expander(opts) {
}
);

if (nonAddressable.includes(opts.controller) &&
typeof this.address === "undefined") {
this.address = Fn.uid();
}

expander = active.get(this.address);

if (expander) {
Expand Down
26 changes: 26 additions & 0 deletions test/expander.js
Original file line number Diff line number Diff line change
Expand Up @@ -2905,6 +2905,32 @@ exports["Expander - 74HC595"] = {
test.done();
},

multipleInstancesOfNonAddressableExpanders: function(test) {
test.expect(1);

test.doesNotThrow(function() {
var a = new five.Expander({
controller: "74HC595",
pins: {
data: 6,
clock: 7,
latch: 8,
}
});

var b = new five.Expander({
controller: "74HC595",
pins: {
data: 9,
clock: 10,
latch: 11,
}
});
});

test.done();
},

normalize: function(test) {
test.expect(8);

Expand Down

0 comments on commit cc85c69

Please sign in to comment.