-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhdmi.js
61 lines (48 loc) · 1.17 KB
/
hdmi.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
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 -- ');
}
function tv_standby() {
console.log(' -- TV_STANDBY -- ');
}
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' );