-
Notifications
You must be signed in to change notification settings - Fork 3
/
bpi-ir-node.js
41 lines (41 loc) · 1.31 KB
/
bpi-ir-node.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
39
40
41
module.exports = function(RED) {
var IR = require('bpi-ir');
function BpiIrOutNode(config) {
var ir = new IR();
RED.nodes.createNode(this,config);
this.debug = config.debug || false;
this.keyMap = config.keymap || {};
var node = this;
this.on('close', function() {
if (ir !== undefined && ir.stop !== undefined) {
ir.stop();
}
});
ir.start();
var lastKey = null;
var mappKey = function(key) {
var mappedKey = node.keyMap[key];
if (mappedKey == undefined) {
mappedKey = key;
}
return mappedKey;
}
ir.on('down', function(key) {
var mappedKey = mappKey(key);
var msg = { payload: mappedKey };
if (node.debug) {
node.status({fill:"green",shape:"ring",text:"Key: " + mappedKey});
}
node.send([msg, null]);
});
ir.on('up', function(key) {
var mappedKey = mappKey(key);
var msg = { payload: mappedKey };
node.send([null, msg]);
if (node.debug) {
node.status({fill:"red",shape:"ring",text:"Key: " + mappedKey});
}
});
}
RED.nodes.registerType("banana-ir in", BpiIrOutNode);
}