fix some minor ar-com bugs

This commit is contained in:
Shannon Sterz 2016-02-17 12:33:17 +01:00
parent a6c4c5d5ce
commit 263c2cc0be
2 changed files with 15 additions and 15 deletions

View file

@ -4,9 +4,21 @@ var events = require('events'),
var IR = function (arduino) { var IR = function (arduino) {
if(!arduino) {console.log("Arduino not set!");} if(!arduino) {console.log("Arduino not set!");}
this.arduino = arduino; 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) { IR.prototype.send = function(type, len, val) {
@ -20,18 +32,6 @@ IR.prototype.send = function(type, len, val) {
IR.prototype.receive = function() { 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')); this.arduino.write(new Buffer('Y0000000', 'ascii'));
}; };

View file

@ -6,7 +6,7 @@ var Sensor = function (arduino, pin) {
this.arduino = arduino; this.arduino = arduino;
this.pin = pin; this.pin = pin;
this.board.on('data', function (message) { this.arduino.on('data', function (message) {
var m = message.slice(0, -1).split('::'), var m = message.slice(0, -1).split('::'),
err = null; err = null;
@ -28,4 +28,4 @@ Sensor.prototype.trigger = function() {
}; };
module.exports = IR; module.exports = Sensor;