- very basic method of delivering keys into python (will be changed, of course)
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
--- /dev/null
+#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");
--- /dev/null
+#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
#include <lib/python/connections.h>
extern void runMainloop();
+
+extern PSignal1<void,int> &keyPressedSignal();
%}
#define DEBUG
/************** debug **************/
void runMainloop();
+%immutable keyPressed;
+PSignal1<void,int> &keyPressedSignal();
#include <lib/python/python.h>
#include <lib/python/connections.h>
+#include <lib/driver/rc.h>
+
#ifdef OBJECT_DEBUG
int object_total_remaining;
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
/* 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");
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
else:
self.currentWindow = None
+ def keyEvent(self, code):
+ self.currentDialog.data["okbutton"]["instance"].push()
+
def close(self):
self.delayTimer.start(0, 1)
# 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()
# 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: