npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cec-controller

v1.4.0

Published

Easy to use cec-client wrapper

Downloads

134

Readme

cec-controller

License npm Downloads Donate Donate

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 = require('cec-controller');
var cecCtl = new CecController();

cecCtl.on('ready', (controller) => console.log(controller));
cecCtl.on('error', console.error);

/*
{
  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 = require('cec-controller');
var cecCtl = new CecController();

cecCtl.on('ready', readyHandler);
cecCtl.on('error', console.error);

function readyHandler(controller)
{
	/* In this example dev1 is a satellite decoder */
	controller.dev1.sendKey('up').then((success) =>
	{
		if(success)
			console.log('Successfully send "up" key to decoder');
		else
			console.error('Could not send input key!');
	});
}

Receive TV remote input

Use keypress, keydown or keyup events to implement code logic that depends on the pressed TV remote button.

var CecController = require('cec-controller');
var cecCtl = new CecController();

cecCtl.on('ready', readyHandler);
cecCtl.on('error', console.error);

function readyHandler(controller)
{
	console.log('Turning ON TV...');

	controller.dev0.turnOn().then(() =>
	{
		controller.setActive();
		console.log('Press any button on TV remote');
	});

	cecCtl.on('keypress', (keyName) => console.log(`User pressed: ${keyName}`));
}

Asynchronous execution

Each function returns a Promise. They are executed asynchronously by default.

controller.dev0.turnOn();
console.log('Sending turn on signal to TV');

setTimeout(() => controller.setActive(), 5000);
console.log('Changing TV input source in 5 sec...');

Synchronous execution

Synchronous execution can be achieved by using await inside async function.

async function controlTv()
{
	await controller.dev0.turnOn();
	console.log('Turned on TV');

	await controller.setActive();
	console.log('Changed TV input source');
}

async function increaseVolume(count)
{
	while(count--) await controller.volumeUp();
}

controlTv();
increaseVolume(3); // 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 :-)

PayPal