-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode-ir.js
executable file
·38 lines (32 loc) · 908 Bytes
/
node-ir.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var spawn = require('child_process').spawn;
var events = require('events');
var util = require('util');
function IR (config) {
events.EventEmitter.call(this);
this.config = config || require('./config/binding.json');
this.showAll = false;
this.ir_process = spawn(__dirname+'/lib/IR', ['/dev/input/event0']);
this.ir_process.stdout.on('data', this.sendEvent.bind(this));
}
util.inherits(IR, events.EventEmitter);
IR.prototype.sendEvent = function (buffer) {
var key = buffer.toString(),
ev = this.config[key];
if (ev) {
if (ev.type) {
this.emit(ev.type, ev.value);
} else {
this.emit(ev);
}
}
if (this.showAll) {
this.emit('key', key);
}
}
IR.prototype.displayEvents = function () {
this.showAll = true;
}
IR.prototype.hideEvents = function () {
this.showAll = false;
}
module.exports = IR;