-
Notifications
You must be signed in to change notification settings - Fork 1
/
hdmi-led.js
73 lines (57 loc) · 1.48 KB
/
hdmi-led.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var Gpio = require('onoff').Gpio;
var pin_red = 24;
var pin_green = 23;
var pin_blue = 22;
var emptyFunc = function(){};
var nodecec = require('node-cec');
var NodeCec = nodecec.NodeCec;
var CEC = nodecec.CEC;
var cec = new NodeCec('node-cec-monitor');
var tvOn = false;
process.on('SIGINT', function() {
if (cec != null) {
cec.stop();
}
process.exit();
});
function tv_on() {
console.log(' -- TV_ON -- ');
new Gpio(pin_red, 'out').write(0, emptyFunc);
new Gpio(pin_blue, 'out').write(1, emptyFunc);
}
function tv_standby() {
console.log(' -- TV_STANDBY -- ');
new Gpio(pin_red, 'out').write(1, emptyFunc);
new Gpio(pin_blue, 'out').write(0, emptyFunc);
}
cec.once('ready', function(client) {
console.log(' -- READY -- ');
client.sendCommand(0xf0, CEC.Opcode.GIVE_DEVICE_POWER_STATUS);
});
cec.on('REPORT_POWER_STATUS', function(packet, status) {
if (status == 0) {
tv_on();
tvOn = true;
} else if (status == 1) {
tv_standby();
tvOn = false;
}
});
cec.on('ACTIVE_SOURCE', function() {
if (!tvOn) {
cec.sendCommand(0xf0, CEC.Opcode.GIVE_DEVICE_POWER_STATUS);
}
});
cec.on('GIVE_PHYSICAL_ADDRESS', function() {
if (!tvOn) {
cec.sendCommand(0xf0, CEC.Opcode.GIVE_DEVICE_POWER_STATUS);
}
});
cec.on('STANDBY', function() {
tv_standby();
tvOn = false;
});
// -m = start in monitor-mode
// -d8 = set log level to 8 (=TRAFFIC) (-d 8)
// -br = logical address set to `recording device`
cec.start( 'cec-client', '-m', '-d', '8', '-b', 'r' );