- add rcconsole key input (for now)
authorFelix Domke <tmbinc@elitedvb.net>
Thu, 27 Jan 2005 06:25:40 +0000 (06:25 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Thu, 27 Jan 2005 06:25:40 +0000 (06:25 +0000)
 - very basic method of delivering keys into python (will be changed, of course)

lib/driver/Makefile.am
lib/driver/rcconsole.cpp [new file with mode: 0644]
lib/driver/rcconsole.h [new file with mode: 0644]
lib/python/enigma_python.i
main/enigma.cpp
mytest.py
screens.py

index eff4486..a8a1f49 100644 (file)
@@ -4,4 +4,5 @@ INCLUDES = \
 noinst_LIBRARIES = libenigma_driver.a
 
 libenigma_driver_a_SOURCES = \
-       rc.cpp rcinput.cpp 
\ No newline at end of file
+       rc.cpp rcinput.cpp rcconsole.cpp
+       
\ No newline at end of file
diff --git a/lib/driver/rcconsole.cpp b/lib/driver/rcconsole.cpp
new file mode 100644 (file)
index 0000000..ec75916
--- /dev/null
@@ -0,0 +1,120 @@
+#include <lib/base/init.h>
+#include <lib/base/init_num.h>
+#include <lib/base/eerror.h>
+#include <lib/driver/rcconsole.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+eRCConsoleDriver::eRCConsoleDriver(const char *filename): eRCDriver(eRCInput::getInstance())
+{
+       handle=open(filename, O_RDONLY|O_NONBLOCK);
+       if (handle<0)
+       {
+               eDebug("failed to open %s", filename);
+               sn=0;
+       } else
+       {
+               sn=new eSocketNotifier(eApp, handle, eSocketNotifier::Read);
+               CONNECT(sn->activated, eRCConsoleDriver::keyPressed);
+               eRCInput::getInstance()->setFile(handle);
+       }
+       
+               /* set console mode */
+       struct termios t,ot;
+       tcgetattr(handle, &t);
+       t.c_lflag &= ~(ECHO | ICANON | ECHOK | ECHOE | ECHONL);
+       ot = t;
+       tcsetattr(handle, TCSANOW,&t);
+}
+
+eRCConsoleDriver::~eRCConsoleDriver()
+{
+       tcsetattr(handle,TCSANOW, &ot);
+       if (handle>=0)
+               close(handle);
+       if (sn)
+               delete sn;
+}
+
+void eRCConsoleDriver::keyPressed(int)
+{
+       char data[16];
+       char *d = data;
+       int num = read(handle, data, 16);
+       int code;
+#if 0  
+       int km = input->getKeyboardMode();
+
+       if (km == eRCInput::kmNone)
+               return;
+#endif
+       while (num--)
+       {
+#if 0
+               if (km == eRCInput::kmAll)
+#endif
+                       code = *d++;
+#if 0
+               else
+               {
+                       if (*d == 27) // escape code
+                       {
+                               while (num)
+                               {
+                                       num--;
+                                       if (*++d != '[')
+                                               break;
+                               }
+                               code = -1;
+                       } else
+                               code = *d;
+                       ++d;
+                       
+                       if (code < 32)                  /* control characters */
+                               code = -1;
+                       if (code == 0x7F)               /* delete */
+                               code = -1;
+               }
+#endif
+               if (code != -1)
+                       for (std::list<eRCDevice*>::iterator i(listeners.begin()); i!=listeners.end(); ++i)
+                               (*i)->handleCode(code);
+       }
+}
+
+void eRCConsole::handleCode(int code)
+{
+       input->keyPressed(eRCKey(this, code, 0));
+}
+
+eRCConsole::eRCConsole(eRCDriver *driver)
+                       : eRCDevice("Console", driver)
+{
+}
+
+const char *eRCConsole::getDescription() const
+{
+       return "Console";
+}
+
+const char *eRCConsole::getKeyDescription(const eRCKey &key) const
+{
+       return 0;
+}
+
+int eRCConsole::getKeyCompatibleCode(const eRCKey &key) const
+{
+       return key.code; // | KEY_ASCII;
+}
+
+class eRCConsoleInit
+{
+       eRCConsoleDriver driver;
+       eRCConsole device;
+public:
+       eRCConsoleInit(): driver("/dev/vc/0"), device(&driver)
+       {
+       }
+};
+
+eAutoInitP0<eRCConsoleInit> init_rcconsole(eAutoInitNumbers::rc+1, "Console RC Driver");
diff --git a/lib/driver/rcconsole.h b/lib/driver/rcconsole.h
new file mode 100644 (file)
index 0000000..0c1dd63
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef __lib_driver_rcconsole_h
+#define __lib_driver_rcconsole_h
+
+#include <termios.h>
+#include <lib/driver/rc.h>
+
+class eRCConsoleDriver: public eRCDriver
+{
+       struct termios ot;
+protected:
+       int handle;
+       eSocketNotifier *sn;
+       void keyPressed(int);
+public:
+       eRCConsoleDriver(const char *filename);
+       ~eRCConsoleDriver();
+       void flushBuffer() const
+       {
+               char data[16];
+               if (handle != -1)
+                       while ( ::read(handle, data, 16) == 16 );
+       }
+       void lock() const
+       {
+               if ( sn )
+                       sn->stop();
+       }
+       void unlock() const
+       {
+               if ( sn )
+                       sn->start();
+       }
+};
+
+class eRCConsole: public eRCDevice
+{
+public:
+       void handleCode(int code);
+       eRCConsole(eRCDriver *driver);
+       const char *getDescription() const;
+       const char *getKeyDescription(const eRCKey &key) const;
+       int getKeyCompatibleCode(const eRCKey &key) const;
+};
+
+#endif
index c621bb6..367d8f8 100644 (file)
@@ -53,6 +53,8 @@ is usually caused by not marking PSignals as immutable.
 #include <lib/python/connections.h>
 
 extern void runMainloop();
+
+extern PSignal1<void,int> &keyPressedSignal();
 %}
 
 #define DEBUG
@@ -127,3 +129,5 @@ public:
 /**************  debug  **************/
 
 void runMainloop();
+%immutable keyPressed;
+PSignal1<void,int> &keyPressedSignal();
index 92982e5..df28bcd 100644 (file)
@@ -21,6 +21,8 @@
 #include <lib/python/python.h>
 #include <lib/python/connections.h>
 
+#include <lib/driver/rc.h>
+
 #ifdef OBJECT_DEBUG
 int object_total_remaining;
 
@@ -69,6 +71,19 @@ void print(int i)
        printf("C++ says: it's a %d!!!\n", i);
 }
 
+PSignal1<void,int> keyPressed;
+
+PSignal1<void,int> &keyPressedSignal()
+{
+       return keyPressed;
+}
+
+void keyEvent(const eRCKey &key)
+{
+       if (!key.flags)
+               keyPressed(key.code);
+}
+
 int main(int argc, char **argv)
 {
 #ifdef OBJECT_DEBUG
@@ -112,6 +127,8 @@ int main(int argc, char **argv)
                /* redrawing is done in an idle-timer, so we have to set the context */
        dsk.setRedrawTask(main);
        
+       eRCInput::getInstance()->keyEvent.connect(slot(keyEvent));
+       
        ePython python;
        
        printf("executing main\n");
index c0967d7..b3d1701 100644 (file)
--- a/mytest.py
+++ b/mytest.py
@@ -6,6 +6,13 @@ import time
 from screens import *
 from skin import applyGUIskin
 
+
+def CONNECT(slot, fnc):
+       slot.get().append(fnc)
+
+def DISCONNECT(slot, fnc):
+       slot.get().remove(fnc)
+
 # A screen is a function which instanciates all components of a screen into a temporary component.
 # Thus, the global stuff is a screen, too.
 # In a screen, components can either be instanciated from the class-tree, cloned (copied) or
@@ -92,6 +99,9 @@ class Session:
                else:
                        self.currentWindow = None
 
+       def keyEvent(self, code):
+               self.currentDialog.data["okbutton"]["instance"].push()
+
        def close(self):
                self.delayTimer.start(0, 1)
 
@@ -106,12 +116,15 @@ def runScreenTest():
        # active "okbutton", even when we changed the dialog
        #
        # more complicated reason: we don't want to hold a reference.
-       def blub():
-               session.currentDialog.data["okbutton"]["instance"].push()
-       
-       tmr = eTimer()
-       tmr.timeout.get().append(blub)
-       tmr.start(4000, 0)
+#      def blub():
+#              session.currentDialog.data["okbutton"]["instance"].push()       
+#              session.currentDialog["okbutton"].setText("hello!")
+#      
+#      tmr = eTimer()
+#      CONNECT(tmr.timeout, blub)
+#      tmr.start(4000, 0)
+#      
+       CONNECT(keyPressedSignal(), session.keyEvent)
        
        runMainloop()
        
index f0b06bd..a44f825 100644 (file)
@@ -14,7 +14,6 @@ class Screen(dict, HTMLSkin, GUISkin):
 # a test dialog
 class testDialog(Screen):
        def testDialogClick(self):
-               print "test dialog clicked!"
                if self.tries == 0:
                        self["title"].setText("Hihi - no, this doesn't work!")
                else: