cec-controller
Requires CEC capable device (e.g. Raspberry Pi or USB-CEC adapter).
Additionally cec-client
must be installed. On Raspbian it is included in cec-utils package.
Controller scans devices on startup. It takes a while (scan is done async and result is returned in "ready" event).
Usage Examples
var CecController = ;var cecCtl = ; cecCtl;cecCtl; /*{ dev0: { name: 'TV', logicalAddress: '0', address: '0.0.0.0', activeSource: 'no', vendor: 'Samsung', osdString: 'TV', cecVersion: '1.4', powerStatus: 'on', language: 'eng', turnOn: [Function: bound changePower], // Turn on dev0 (TV) turnOff: [Function: bound changePower], // Turn off dev0 (TV) togglePower: [Function: bound togglePower], // Transition to power "on" from "standby" and vice versa changeSource: [Function], // Switch HDMI input (optional arg is port number) sendKey: [Function] // Send key press to this device }, dev4: { name: 'Playback 1', logicalAddress: '4', address: '3.0.0.0', activeSource: 'no', vendor: 'Pulse Eight', osdString: 'CEC-Control', cecVersion: '1.4', powerStatus: 'on', language: 'eng', turnOn: [Function: bound changePower], turnOff: [Function: bound changePower], togglePower: [Function: bound togglePower] }, setActive: [Function: bound changeActive], // Send source active signal (switches TV input) setInactive: [Function: bound changeActive], // Send source inactive signal volumeUp: [Function: bound command], // Increase amplifier volume volumeDown: [Function: bound command], // Decrease amplifier volume mute: [Function: bound command], // Mute amplifier getKeyNames: [Function: bound getNamesArray], // Returns array of supported keys (for use with sendKey()) command: [Function: command] // Send custom signal (arg is send as input to cec-client)}*/
Send TV remote key presses
Send key press to your TV, player or receiver. Get the list of available key names with cecCtl.getKeyNames()
.
var CecController = ;var cecCtl = ; cecCtl;cecCtl; { /* In this example dev1 is a satellite decoder */ controllerdev1;}
Receive TV remote input
Use keypress
, keydown
or keyup
events to implement code logic that depends on the pressed TV remote button.
var CecController = ;var cecCtl = ; cecCtl;cecCtl; { console; controllerdev0; cecCtl;}
Asynchronous execution
Each function returns a Promise. They are executed asynchronously by default.
controllerdev0;console; ;console;
Synchronous execution
Synchronous execution can be achieved by using await inside async function.
{ await controllerdev0; console; await controller; console;} { whilecount-- await controller;} ;; // Increase volume 3 times
Additional pre-made runnable scripts can be found inside "test" folder.
Donation
If you like my work please support it by buying me a cup of coffee :-)