diff options
| author | Felix Domke <tmbinc@elitedvb.net> | 2005-01-27 06:25:40 +0000 |
|---|---|---|
| committer | Felix Domke <tmbinc@elitedvb.net> | 2005-01-27 06:25:40 +0000 |
| commit | 84670d3dc9c9dc29fd3af42b2f25092b3b6c2a09 (patch) | |
| tree | 2b6dd112784a6958665dcd54aeaa42ef9ea94472 /lib/driver | |
| parent | f9723e7fbf7669f063151eaf53bb1ee9f4189289 (diff) | |
| download | enigma2-84670d3dc9c9dc29fd3af42b2f25092b3b6c2a09.tar.gz enigma2-84670d3dc9c9dc29fd3af42b2f25092b3b6c2a09.zip | |
- add rcconsole key input (for now)
- very basic method of delivering keys into python (will be changed, of course)
Diffstat (limited to 'lib/driver')
| -rw-r--r-- | lib/driver/Makefile.am | 3 | ||||
| -rw-r--r-- | lib/driver/rcconsole.cpp | 120 | ||||
| -rw-r--r-- | lib/driver/rcconsole.h | 45 |
3 files changed, 167 insertions, 1 deletions
diff --git a/lib/driver/Makefile.am b/lib/driver/Makefile.am index eff4486f..a8a1f49b 100644 --- a/lib/driver/Makefile.am +++ b/lib/driver/Makefile.am @@ -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 index 00000000..ec759164 --- /dev/null +++ b/lib/driver/rcconsole.cpp @@ -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 index 00000000..0c1dd636 --- /dev/null +++ b/lib/driver/rcconsole.h @@ -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 |
