Skip to content

Commit

Permalink
Merge pull request tessel#66 from rwaldron/65
Browse files Browse the repository at this point in the history
Make Port a subclass of EventEmitter. Fixes tesselgh-65
  • Loading branch information
rwaldron committed Jul 14, 2015
2 parents 0227298 + 69c8258 commit a77c98f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
4 changes: 3 additions & 1 deletion node/tessel.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ Tessel.Port = function(name, socketPath, board) {
} else if (byte >= REPLY.MIN_ASYNC) {
if (byte >= REPLY.ASYNC_PIN_CHANGE_N && byte < REPLY.ASYNC_PIN_CHANGE_N + 8) {
var pin = this.pin[byte - REPLY.ASYNC_PIN_CHANGE_N];

var mode = pin.interruptMode;

if (mode === 'low' || mode === 'high') {
pin.interruptMode = null;
}
Expand Down Expand Up @@ -176,6 +176,8 @@ Tessel.Port = function(name, socketPath, board) {
};
};

util.inherits(Tessel.Port, EventEmitter);

Tessel.Port.prototype.cork = function() {
this.sock.cork();
};
Expand Down
34 changes: 20 additions & 14 deletions node/test/unit/tessel.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ exports['Tessel.Port'] = {
done();
},

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

var port = new Tessel.Port('foo', '/foo/bar/baz', this.tessel);

test.ok(port instanceof EventEmitter);

test.done();
},

instanceProperties: function(test) {
test.expect(14);

Expand Down Expand Up @@ -580,22 +590,18 @@ exports['Tessel.Port Commands (handling incoming socket stream)'] = {

test.done();
},
//
//
// // According to the 'readable' handler, this should work.
// // It currently does not work because Port is not a
// // subclass of Emitter.
// replyminasync: function(test) {
// test.expect(1);

// this.port.once('async-event', function(data) {
// test.equal(data, REPLY.MIN_ASYNC);
// test.done();
// });
replyminasync: function(test) {
test.expect(1);

// this.port.sock.read.returns(new Buffer([REPLY.MIN_ASYNC]));
// this.port.sock.emit('readable');
// },
this.port.on('async-event', function(data) {
test.equal(data, REPLY.MIN_ASYNC);
test.done();
});

this.port.sock.read.returns(new Buffer([REPLY.MIN_ASYNC]));
this.port.sock.emit('readable');
},
};

exports['Tessel.I2C'] = {
Expand Down
15 changes: 15 additions & 0 deletions node/tests/interrupt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var tessel = require('tessel');
var portA = tessel.port.A;
var portB = tessel.port.B;

[2, 5, 6, 7].forEach(function(index) {
portA.pin[index].low();
portA.pin[index].once('high', function() {
console.log('(A) Pin: %d went high!', index);
});

portB.pin[index].low();
portB.pin[index].once('high', function() {
console.log('(B) Pin: %d went high!', index);
});
});

0 comments on commit a77c98f

Please sign in to comment.