From 386ea0c2beee4d6288e5e15d237552c94339ea68 Mon Sep 17 00:00:00 2001 From: Stefan Sterz Date: Fri, 29 Jan 2016 21:33:17 +0100 Subject: [PATCH] add ir module --- nodejs/ar-com/ir.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 nodejs/ar-com/ir.js diff --git a/nodejs/ar-com/ir.js b/nodejs/ar-com/ir.js new file mode 100644 index 0000000..d563715 --- /dev/null +++ b/nodejs/ar-com/ir.js @@ -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; \ No newline at end of file