110 lines
2.9 KiB
C++
110 lines
2.9 KiB
C++
#include "pikbdlistener.h"
|
|
#include "piconnection.h"
|
|
#include "piconfig.h"
|
|
#include "piscreentiles.h"
|
|
#include "piscreen.h"
|
|
#include "piethernet.h"
|
|
#include "piintrospection.h"
|
|
#include "pifile.h"
|
|
#include "piterminal.h"
|
|
#include "piserial.h"
|
|
|
|
|
|
PIScreen screen;
|
|
PIConnection conn;
|
|
|
|
|
|
const char conn_config[] =
|
|
"[connection]\n\
|
|
device.test = ser://COM54:115200 #s\n\
|
|
device.test.disconnectTimeout = 3.00000000 #f\n\
|
|
[]\n";
|
|
|
|
private:
|
|
void drawEvent(PIScreenDrawer * d) {
|
|
//piCout << "draw" << visible;
|
|
if (!term) return;
|
|
PIVector<PIVector<PIScreenTypes::Cell> > c = term->content();
|
|
d->fillRect(x_, y_, x_ + width_, y_ + height_, c);
|
|
}
|
|
bool keyEvent(PIKbdListener::KeyEvent key) {
|
|
//piCout << "key";
|
|
//return false;
|
|
if (!term) return false;
|
|
if (PITerminal::isSpecialKey(key.key)) term->write((PIKbdListener::SpecialKey)key.key, key.modifiers);
|
|
else {
|
|
PIByteArray ba;
|
|
//ba << PIChar(key.key).toConcole1Byte();
|
|
//piCout << key.key;
|
|
ba = PIString(PIChar(key.key)).toUTF8();
|
|
term->write(ba);
|
|
}
|
|
EVENT_HANDLER1(void, keyEv, PIKbdListener::KeyEvent, k) {
|
|
piCoutObj << k.key;
|
|
if (k.key == -20) {
|
|
PIKbdListener::exiting = true;
|
|
|
|
}
|
|
if (k.key == 's') {
|
|
PISerial * ser = (PISerial *)conn.deviceByName("test");
|
|
if (ser) {
|
|
PIByteArray ba;
|
|
ba << uchar(31) << uchar(230) << uchar(0xd) << uchar(0xa);
|
|
piCoutObj << "send";
|
|
ser->writeThreaded(ba);
|
|
}
|
|
}
|
|
}
|
|
|
|
EVENT_HANDLER2(void, recv, const PIString &, from, const PIByteArray &, data) {
|
|
piCoutObj << from << PIString(data) << PICoutManipulators::Hex << data;
|
|
}
|
|
};
|
|
|
|
int main (int argc, char * argv[]) {
|
|
/*const char cs[] = "this is text\e";
|
|
PIByteArray ba(cs, sizeof(cs) - 1);
|
|
PIString s(ba);
|
|
piCout << ba;
|
|
piCout << s;
|
|
piCout << s.toByteArray();
|
|
return 0;*/
|
|
PIScreen * screen = 0;
|
|
if (argc > 1) screen = new PIScreen();
|
|
PITerminal term;
|
|
TileTerminal tt(&term);
|
|
if (screen) {
|
|
screen->rootTile()->addTile(&tt);
|
|
screen->rootTile()->addTile(new TilePICout());
|
|
screen->enableExitCapture();
|
|
}
|
|
tt.setFocus();
|
|
term.initialize();
|
|
piMSleep(100);
|
|
//term.write(PIString("ls -l /etc/\n").toByteArray());
|
|
//term.write(PIString("mc\n").toByteArray());
|
|
//term.write(PIString("aptitude\n").toByteArray());
|
|
if (screen) {
|
|
screen->start();
|
|
piMSleep(100);
|
|
//piCout << tt.width() << tt.height();
|
|
term.resize(tt.width(), tt.height());
|
|
screen->waitForFinish();
|
|
} else {
|
|
piMSleep(4000);
|
|
term.write(PIKbdListener::KeyEvent(PIKbdListener::Tab));
|
|
piMSleep(1000);
|
|
term.write(PIKbdListener::KeyEvent(PIKbdListener::Tab));
|
|
//term.write(PIKbdListener::KeyEvent(PIKbdListener::Space));
|
|
//term.write(PIString("exit\n").toByteArray());
|
|
term.write(PIString("Q\n").toByteArray());
|
|
piMSleep(1000);
|
|
}
|
|
if (screen) {
|
|
screen->rootTile()->takeTile(&tt);
|
|
delete screen;
|
|
}
|
|
return 0;
|
|
}
|
|
|