diff --git a/README.md b/README.md index 723af5e..e5e05c8 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ These are the available configuration options: 5. ``blacklists`` - a way to hide unused commands from your remotes. 6. ``server`` - server configuration settings (ports, [SSL](http://serverfault.com/a/366374)). 7. ``socket`` - to specify the lircd socket for irsend. +8. ``simulators`` - a list of remotes that should use the 'simulate' command. This list can contain any remote inside of the lircd.conf file. #### Example config.json: @@ -108,7 +109,11 @@ These are the available configuration options: "AUX3" ] }, - "socket": "/run/lirc/lircd1" + "socket": "/run/lirc/lircd1", + "simulators":[ + "Outlets", + "Plugs" + ] } Please see the `example_configs/` directory. @@ -207,4 +212,4 @@ permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. +included in all copies or substantial portions of the Software. \ No newline at end of file diff --git a/app.js b/app.js index b884830..cfb395f 100644 --- a/app.js +++ b/app.js @@ -117,6 +117,8 @@ labelFor = labels(config.remoteLabels, config.commandLabels); // Index app.get('/', function (req, res) { var refinedRemotes = refineRemotes(lircNode.remotes); + + console.log(refinedRemotes); res.send(JST.index({ remotes: refinedRemotes, macros: config.macros, @@ -170,7 +172,15 @@ app.get('/macros/:macro.json', function (req, res) { // Send :remote/:command one time app.post('/remotes/:remote/:command', function (req, res) { - lircNode.irsend.send_once(req.params.remote, req.params.command, function () {}); + + if(config.simulators.includes(req.params.remote)) + { + console.log("This is a remote that should be simulated"); + lircNode.irsend.simulate("0000000000000000 00 " + req.params.command + " " + req.params.remote); + } + else + lircNode.irsend.send_once(req.params.remote, req.params.command, function () {}); + res.setHeader('Cache-Control', 'no-cache'); res.sendStatus(200); }); @@ -193,7 +203,7 @@ app.post('/remotes/:remote/:command/send_stop', function (req, res) { app.post('/macros/:macro', function (req, res) { // If the macro exists, execute it if (config.macros && config.macros[req.params.macro]) { - macros.exec(config.macros[req.params.macro], lircNode); + macros.exec(config.macros[req.params.macro], lircNode, config.simulators); res.setHeader('Cache-Control', 'no-cache'); res.sendStatus(200); } else { diff --git a/lib/macros.js b/lib/macros.js index 4a04c65..9359f66 100644 --- a/lib/macros.js +++ b/lib/macros.js @@ -1,36 +1,32 @@ -function exec(macro, lircNode, iter) { +function exec(macro, lircNode, simulators, iter) { var i = iter || 0; + var callback = function() + { + setTimeout(function () { + exec(macro, lircNode, simulators, i); + }, 100); + } + // select the command from the sequence var command = macro[i]; - i = i + 1; - if (!command) { return false; } + i = i + 1; + // if the command is delay, wait N msec and then execute next command if (command[0] === 'delay') { - setTimeout(function () { - exec(macro, lircNode, i); - }, command[1]); - } else if (Array.isArray(command[1])) { - // send_start hold command and set timeout for hold time to call send_stop - lircNode.irsend.send_start(command[0], command[1][0], function () { - setTimeout(function () { - lircNode.irsend.send_stop(command[0], command[1][0], function () { - setTimeout(function () { - exec(macro, lircNode, i); - }, 100); - }); - }, command[1][1]); - }); + setTimeout(callback, command[1]); } else { // By default, wait 100msec before calling next command - lircNode.irsend.send_once(command[0], command[1], function () { - setTimeout(function () { - exec(macro, lircNode, i); - }, 100); - }); + if(simulators.includes(command[0])) + { + console.log("This is a remote that should be simulated"); + lircNode.irsend.simulate("0000000000000000 00 " + command[1] + " " + command[0], callback); + } + else + lircNode.irsend.send_once(command[0], command[1], callback) } return true;