Skip to content

Latest commit

 

History

History
100 lines (76 loc) · 5.05 KB

README.md

File metadata and controls

100 lines (76 loc) · 5.05 KB

NPM

Description

node-lirc_client provides a lirc_client object so your nodejs application can receive lirc command.

It is based on the lirc_client example

Installation

npm install lirc_client

Requirements

  • node.js -- v0.10.0+
  • lirc -- v0.9.0
    • lirc-devel(Fedora based), liblircclient-dev(raspbian), liblircclient-dev(Ubuntu) package is required for lirc_client.h header file.
  • Compile tools like make and gcc.

Example

var lirc_client = require('lirc_client');

try {
	lirc_client.connect("testone", true, "test1.lircrc",function(type, data, configFile){
		console.log("Type:", type);
		console.log("Data:", data);
		switch (type) {
			case "rawdata":
				console.log("Rawdata received:",data);
				break;
			case "data":
				console.log("Data received '%s' from configFile '%s'",data, configFile);
				break;
			case "closed":
				console.log("Lircd closed connection to us.");
				break;
		}
	});

	console.log("lirc_client.isConnected:", lirc_client.isConnected);
	console.log("lirc_client.mode:", lirc_client.mode);
	console.log("lirc_client.configFiles:", lirc_client.configFiles);

	console.close();
	console.log("lirc_client.isConnected:", lirc_client.isConnected);
}
catch (err) {
	console.log("Error on connect:",err);
}

See examples folder for more detailed example.

API Documentation

Module Functions

  • connect(< String >programName, [< Boolean >verbose], [< String >configFiles], < Function >callback(< String >type[, < String >data[, < String >configFile]])) - Should be called to connect to lircd.

  • connect(< String >programName, [< Boolean >verbose], [< Array >configFiles], < Function >callback(< String >type[, < String >data[, < String >configFile]])) - Should be called to connect to lircd.

    • < String >programName - Is the program name used to select right button in lircrc config files. Will be matched by lirc against the "prog" attribute. (.lircrc file format)
    • < Boolean >verbose - Will put the lirc library in verbose mode or not.
    • < String >configFiles - Specify full or relative path to an existing lircrc file. (.lircrc file format). When undefined then the lirc default config files /etc/lirc/lircrc and ~/.lircrc will be loaded.
    • < Array >configFiles - Array of < String > values. Each strings is a full or relative path to an existing lircrc file. (.lircrc file format). When undefined then the lirc default config files /etc/lirc/lircrc and ~/.lircrc will be loaded.
    • < Function >callback(< String >type[, < String >data[, < String >configFile]]) - Callback function which gets called when data is available or connection to lircd was closed outside of our control.
      • < String >type - Specifies why the callback function was called. Following values are possible:
        • "rawdata" - Means data argument contains raw data from lircd.conf file.
        • "data" - Means data argument contains config attribute from lircrc button which matches received ir button and prog attribute from lirrc file(s) and configFile will contain name of configFile as specified in connect or addConfig.
        • "closed" - Means connection to lircd was closed outside of our control.
      • Will throw errors when something fails.
  • close() - Closes the connection to lircd for this object.

  • reConnect() - Reconnects a closed connection to the lircd for this object. It will reuse arguments from connect call.

    • Will throw errors when something fails.
  • addConfig(< String >configFile | < Array >configFiles) - Add one or more lircrc config files.

    • < String >configFile - Must contain the full or relative path to an existing lircrc file.
    • < Array >configFiles - Is an array of String values. Each string must contain the full or relative path to an existing lircrc file.
  • clearConfig() - Will remove all lircrc config files from object. No more "data" events will be emited until at least one config has been added again.

Module properties

  • < Boolean >isConnected (read only) - When true is returned there is a connection to the lircd and the object will receive events. When false is returned the object is not connected to lircd and it will not receive events.

  • < String >mode (read/write) - Will perform lirc_getmode and lirc_setmode. Are not described on lirc website but were found in lirc_client.h file and on following page

  • < Array >configFiles (read only) - Will contain a list with config filenames currently active. When array is empty the lirc default lircrc config files are used.