diff --git a/nodejs/ar-com/ir.js b/nodejs/ar-com/ir.js index d563715..3db4d14 100644 --- a/nodejs/ar-com/ir.js +++ b/nodejs/ar-com/ir.js @@ -4,9 +4,21 @@ var events = require('events'), var IR = function (arduino) { if(!arduino) {console.log("Arduino not set!");} this.arduino = arduino; + + this.arduino.on('data', function (message) { + var m = message.slice(0, -1).split('::'), + err = null; + + if (m.length != 3) { + return; + } + + this.emit('read', err, m); + + }.bind(this)); } -util.inherits(Sensor, events.EventEmitter); +util.inherits(IR, events.EventEmitter); IR.prototype.send = function(type, len, val) { @@ -20,18 +32,6 @@ IR.prototype.send = function(type, len, val) { IR.prototype.receive = function() { - this.board.on('data', function (message) { - var m = message.slice(0, -1).split('::'), - err = null; - - if (m.length != 3) { - return; - } - - this.emit('read', err, m); - - }.bind(this)); - this.arduino.write(new Buffer('Y0000000', 'ascii')); }; diff --git a/nodejs/ar-com/sensor.js b/nodejs/ar-com/sensor.js index ee74a8e..4f8d680 100644 --- a/nodejs/ar-com/sensor.js +++ b/nodejs/ar-com/sensor.js @@ -6,7 +6,7 @@ var Sensor = function (arduino, pin) { this.arduino = arduino; this.pin = pin; - this.board.on('data', function (message) { + this.arduino.on('data', function (message) { var m = message.slice(0, -1).split('::'), err = null; @@ -28,4 +28,4 @@ Sensor.prototype.trigger = function() { }; -module.exports = IR; \ No newline at end of file +module.exports = Sensor; \ No newline at end of file