[mythtv] [PATCH] MythTV LIRC KeyPress Spawn External App
Dan Morphis
dan at milkcarton.com
Sat Mar 27 14:05:29 EST 2004
I saw a bunch of commits this morning, but I didn't see this one go
through. Don't know if it fell off the radar or what not. Let me know.
-dan
Dan Morphis wrote:
> This patch allows mythtv to spawn an external app when lirc receives a
> key. Why would you want this? Well, some people on the lists have
> expressed interest in knowing when the system has received their
> button presses. One could use it to toggle a parallel port driven
> LED. Or as I do with Enrique Vidal's improved transmitter circuit
> (which has a led in it); send a lirc command which causes no action on
> the cable box, but causes lirc to pulse dtr thereby lighting up my ir
> and regular led.
>
> The patch of course defaults to doing nothing if the user hasn't
> specified/doesn't want said action to happen. I've attached the
> sample script I use to cause the LED in my transmitter circuit to
> function. Alternatly, people could build the circuit described in
> "Re: [mythtv-users] LED Recording feature" and pulse the parallel port.
>
> Enjoy!
>
> -dan
-------------- next part --------------
#!/bin/sh
REMOTE_NAME=GI #DVD-Panasonic-0490
KEY=EXIT
irsend SEND_ONCE $REMOTE_NAME $KEY
-------------- next part --------------
Index: libs/libmyth/lirc.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/lirc.cpp,v
retrieving revision 1.6
diff -u -d -r1.6 lirc.cpp
--- libs/libmyth/lirc.cpp 25 Jan 2004 08:27:42 -0000 1.6
+++ libs/libmyth/lirc.cpp 20 Mar 2004 02:41:41 -0000
@@ -3,6 +3,9 @@
#include <qkeysequence.h>
#include <cstdio>
#include <cerrno>
+#include "mythcontext.h"
+
+#include <sys/wait.h>
#include <iostream>
using namespace std;
@@ -83,6 +86,39 @@
QApplication::postEvent(mainWindow, new LircKeycodeEvent(code,
keycode, false));
}
+
+ //Spawn app to thwap led (or what ever the user has picked if
+ // anything) to give positive feedback that a key was received
+ QString external_app = gContext->GetSetting("LircKeyPressedApp") + " &";
+ if(external_app != " &")
+ {
+ pid_t child = fork();
+ if (child < 0)
+ {
+ perror("fork");
+ }
+ else if (child == 0)
+ {
+ for(int i = 3; i < sysconf(_SC_OPEN_MAX) - 1; ++i)
+ close(i);
+ execl("/bin/sh", "sh", "-c", external_app.ascii(), NULL);
+ perror("exec");
+ _exit(1);
+ }
+ else
+ {
+ int status;
+ if (waitpid(child, &status, 0) < 0)
+ {
+ perror("waitpid");
+ }
+ else if (status != 0)
+ {
+ cerr << "External key pressed command exited with status "
+ << status << endl;
+ }
+ }
+ }
}
free(ir);
Index: programs/mythfrontend/globalsettings.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfrontend/globalsettings.cpp,v
retrieving revision 1.147
diff -u -d -r1.147 globalsettings.cpp
--- programs/mythfrontend/globalsettings.cpp 14 Mar 2004 07:35:33 -0000 1.147
+++ programs/mythfrontend/globalsettings.cpp 20 Mar 2004 02:41:44 -0000
@@ -958,6 +958,17 @@
};
};
+class LircKeyPressedApp: public LineEditSetting, public GlobalSetting {
+public:
+ LircKeyPressedApp():
+ GlobalSetting("LircKeyPressedApp") {
+ setLabel(QObject::tr("Keypress Application"));
+ setValue("");
+ setHelpText(QObject::tr("External application or script to run when "
+ "a keypress is received by lirc"));
+ };
+};
+
class SetupPinCode: public LineEditSetting, public GlobalSetting {
public:
SetupPinCode():
@@ -1937,6 +1948,7 @@
general->addChild(new AllowQuitShutdown());
general->addChild(new NoPromptOnExit());
general->addChild(new HaltCommand());
+ general->addChild(new LircKeyPressedApp());
general->addChild(new SetupPinCodeRequired());
general->addChild(new SetupPinCode());
general->addChild(new EnableMediaMon());
More information about the mythtv-dev
mailing list