Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
14 changes: 12 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
});
Expand All @@ -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 {
Expand Down
40 changes: 18 additions & 22 deletions lib/macros.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down