add ir module
This commit is contained in:
parent
d69fcea212
commit
386ea0c2be
1 changed files with 39 additions and 0 deletions
39
nodejs/ar-com/ir.js
Normal file
39
nodejs/ar-com/ir.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
var events = require('events'),
|
||||
util = require('util');
|
||||
|
||||
var IR = function (arduino) {
|
||||
if(!arduino) {console.log("Arduino not set!");}
|
||||
this.arduino = arduino;
|
||||
}
|
||||
|
||||
util.inherits(Sensor, events.EventEmitter);
|
||||
|
||||
IR.prototype.send = function(type, len, val) {
|
||||
|
||||
type = String.fromCharCode(type);
|
||||
len = String.fromCharCode(len);
|
||||
val = this.arduino.valueToLastFour(val);
|
||||
|
||||
this.arduino.write(new Buffer('X0' + type + len + val,'ascii'));
|
||||
|
||||
};
|
||||
|
||||
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'));
|
||||
|
||||
};
|
||||
|
||||
module.exports = IR;
|
Reference in a new issue