1 #include <lib/system/init.h>
2 #include <lib/system/init_num.h>
3 #include <lib/driver/rcconsole.h>
7 eRCConsoleDriver::eRCConsoleDriver(const char *filename
): eRCDriver(eRCInput::getInstance())
9 handle
=open(filename
, O_RDONLY
|O_NONBLOCK
);
12 eDebug("failed to open %s", filename
);
16 sn
=new eSocketNotifier(eApp
, handle
, eSocketNotifier::Read
);
17 CONNECT(sn
->activated
, eRCConsoleDriver::keyPressed
);
18 eRCInput::getInstance()->setFile(handle
);
21 /* set console mode */
23 tcgetattr(handle
, &t
);
24 t
.c_lflag
&= ~(ECHO
| ICANON
| ECHOK
| ECHOE
| ECHONL
);
26 tcsetattr(handle
, TCSANOW
,&t
);
29 eRCConsoleDriver::~eRCConsoleDriver()
31 tcsetattr(handle
,TCSANOW
, &ot
);
38 void eRCConsoleDriver::keyPressed(int)
40 unsigned char data
[16];
41 unsigned char *d
= data
;
42 int num
= read(handle
, data
, 16);
45 int km
= input
->getKeyboardMode();
47 if (km
== eRCInput::kmNone
)
52 if (km
== eRCInput::kmAll
)
56 if (*d
== 27) // escape code
69 if (code
< 32) /* control characters */
71 if (code
== 0x7F) /* delete */
76 for (std::list
<eRCDevice
*>::iterator
i(listeners
.begin()); i
!=listeners
.end(); ++i
)
77 (*i
)->handleCode(code
);
81 void eRCConsole::handleCode(int code
)
83 // eDebug("console code is %d", code);
84 input
->keyPressed(eRCKey(this, code
, 0));
87 eRCConsole::eRCConsole(eRCDriver
*driver
)
88 : eRCDevice("Console", driver
)
92 const char *eRCConsole::getDescription() const
97 const char *eRCConsole::getKeyDescription(const eRCKey
&key
) const
102 int eRCConsole::getKeyCompatibleCode(const eRCKey
&key
) const
104 return key
.code
| KEY_ASCII
;
109 eRCConsoleDriver driver
;
112 eRCConsoleInit(): driver("/dev/vc/0"), device(&driver
)
117 eAutoInitP0
<eRCConsoleInit
> init_rcconsole(eAutoInitNumbers::rc
+1, "Console RC Driver");