Skip to content

Commit

Permalink
Expander: PCF8574 ensure that pin state byte is tracked
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Jun 18, 2015
1 parent 1499ad5 commit b70eebc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 48 deletions.
5 changes: 4 additions & 1 deletion lib/expander.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ var Controllers = {

state.port = 0x00;
state.ddr = 0x00;
state.pins = 0xEF;
state.pins = 0x00;

this.address = opts.address || this.REGISTER.ADDRESS;

Expand Down Expand Up @@ -441,6 +441,7 @@ var Controllers = {
},
digitalRead: {
value: function(pin, callback) {
var state = priv.get(this);
var pinIndex = pin;

this.pins[pinIndex].report = 1;
Expand All @@ -451,6 +452,8 @@ var Controllers = {
var byte = data[0];
var value = byte >> pin & 0x01;

state.pins = byte;

this.pins[pinIndex].value = value;

this.emit("digital-read-" + pin, value);
Expand Down
94 changes: 47 additions & 47 deletions test/expander.js
Original file line number Diff line number Diff line change
Expand Up @@ -839,28 +839,27 @@ exports["Expander - PCF8574"] = {
// 1 initialization call + (8 * (pinMode + digitalWrite))
test.equal(this.i2cWrite.callCount, 16);

test.deepEqual(this.i2cWrite.getCall(0).args, [ 32, 238 ]);
test.deepEqual(this.i2cWrite.getCall(0).args, [ 32, 0 ]);

test.deepEqual(this.i2cWrite.args, [
[ 32, 238 ],
[ 32, 238 ],
[ 32, 236 ],
[ 32, 236 ],
[ 32, 232 ],
[ 32, 232 ],
[ 32, 224 ],
[ 32, 224 ],
[ 32, 224 ],
[ 32, 224 ],
[ 32, 192 ],
[ 32, 192 ],
[ 32, 128 ],
[ 32, 128 ],
[ 32, 0 ],
[ 32, 0 ],
[ 32, 0 ],
[ 32, 0 ],
[ 32, 0 ],
[ 32, 0 ],
[ 32, 0 ],
[ 32, 0 ],
[ 32, 0 ],
[ 32, 0 ],
[ 32, 0 ],
[ 32, 0 ],
[ 32, 0 ],
[ 32, 0 ],
[ 32, 0 ],
[ 32, 0 ]
]);


test.done();
},

Expand All @@ -884,14 +883,14 @@ exports["Expander - PCF8574"] = {
}

var expects = [
[ 32, 1 ],
[ 32, 3 ],
[ 32, 7 ],
[ 32, 15 ],
[ 32, 15 ],
[ 32, 47 ],
[ 32, 111 ],
[ 32, 239 ],
[ 32, 0 ],
[ 32, 0 ],
[ 32, 0 ],
[ 32, 0 ],
[ 32, 0 ],
[ 32, 0 ],
[ 32, 0 ],
[ 32, 0 ],
];

test.deepEqual(this.i2cWrite.args, expects);
Expand Down Expand Up @@ -919,6 +918,7 @@ exports["Expander - PCF8574"] = {
[ 32, 0 ],
];


test.deepEqual(this.i2cWrite.args, expects);

test.done();
Expand Down Expand Up @@ -1068,23 +1068,23 @@ exports["Expander - PCF8574A"] = {
// 1 initialization call + (8 * (pinMode + digitalWrite))
test.equal(this.i2cWrite.callCount, 16);

test.deepEqual(this.i2cWrite.getCall(0).args, [ 56, 238 ]);
test.deepEqual(this.i2cWrite.getCall(0).args, [ 56, 0 ]);

test.deepEqual(this.i2cWrite.args, [
[ 56, 238 ],
[ 56, 238 ],
[ 56, 236 ],
[ 56, 236 ],
[ 56, 232 ],
[ 56, 232 ],
[ 56, 224 ],
[ 56, 224 ],
[ 56, 224 ],
[ 56, 224 ],
[ 56, 192 ],
[ 56, 192 ],
[ 56, 128 ],
[ 56, 128 ],
[ 56, 0 ],
[ 56, 0 ],
[ 56, 0 ],
[ 56, 0 ],
[ 56, 0 ],
[ 56, 0 ],
[ 56, 0 ],
[ 56, 0 ],
[ 56, 0 ],
[ 56, 0 ],
[ 56, 0 ],
[ 56, 0 ],
[ 56, 0 ],
[ 56, 0 ],
[ 56, 0 ],
[ 56, 0 ]
]);
Expand Down Expand Up @@ -1113,14 +1113,14 @@ exports["Expander - PCF8574A"] = {
}

var expects = [
[ 56, 1 ],
[ 56, 3 ],
[ 56, 7 ],
[ 56, 15 ],
[ 56, 15 ],
[ 56, 47 ],
[ 56, 111 ],
[ 56, 239 ],
[ 56, 0 ],
[ 56, 0 ],
[ 56, 0 ],
[ 56, 0 ],
[ 56, 0 ],
[ 56, 0 ],
[ 56, 0 ],
[ 56, 0 ],
];

test.deepEqual(this.i2cWrite.args, expects);
Expand Down

0 comments on commit b70eebc

Please sign in to comment.