X-Git-Url: http://git.jankratochvil.net/?a=blobdiff_plain;ds=sidebyside;f=terminal.c;h=b3c460eb5331d59ade3ab53c44ce2f77a4e22ce8;hb=a5f79a5362f7a39266a4ba33abf76eec004cf805;hp=5de10a8f0fc80e6ac092b2583fe9d3d241493753;hpb=2665bb5e2a4bf30c7e68813f6ee07ca4d8f1d15e;p=lptgpib.git diff --git a/terminal.c b/terminal.c index 5de10a8..b3c460e 100644 --- a/terminal.c +++ b/terminal.c @@ -5,6 +5,9 @@ #include #include #include +#include + +static const int zdroj_adresa=20; // lptgpib.c #define get_control() (inb(lpt_base+2) ^ 0x04) @@ -12,13 +15,26 @@ #define TRI 0x20 /* tristate data lines */ #define NDAC 0x04 /* LPT pin 16 */ #define DAV 0x01 /* LPT pin 1 */ +#define NRFD 0x02 /* LPT pin 14 */ extern int lpt_base; int main(int argc,char **argv) { lptgpib_init(0x378); + int init=1; for (;;) { + + // GPIB -> obrazovka + if (init) { + fprintf(stderr,"Inicializuji port... "); + lptgpib_command(UNL); + lptgpib_command(MLA+0); + lptgpib_command(MTA+zdroj_adresa); + fprintf(stderr,"hotovo.\n"); + init=0; + } put_control(TRI | NDAC); /* clear NRFD */ + usleep(1000000/10); if (get_control()&DAV) { /* wait for DAV */ fprintf(stderr,"ctu znak...\n"); char flags,val=lptgpib_read_byte(&flags); @@ -27,6 +43,10 @@ int main(int argc,char **argv) { else fprintf(stderr,"precten znak: %02x (%c)\n",val,val); } + put_control(TRI | NDAC | NRFD ); /* back to default state */ + usleep(1000000/10); /* chvili pockat, asi zbytecne, jen aby to bylo videt na portu */ + + // klavesnice -> GPIB struct pollfd pollfd; memset(&pollfd,0,sizeof pollfd); pollfd.fd=0; @@ -34,12 +54,17 @@ int main(int argc,char **argv) { int i=poll(&pollfd,1,0); assert(i==0||i==1); if (i==1) { - char val; - i=read(0,&val,1); - assert(i==1); - fprintf(stderr,"zapisuji znak... %02x (%c)\n",val,val); - lptgpib_write_byte(val,0); - fprintf(stderr,"zapsan znak.\n"); + char str[LINE_MAX],*s=fgets(str,sizeof(str),stdin); + assert(s==str); + s=strchr(str,'\n'); + assert(s); + assert(s[1]==0); + *s=0; + fprintf(stderr,"zapisuji radek: %s\n",str); + lptgpib_write(zdroj_adresa,str); + fprintf(stderr,"zapsan radek.\n"); + init=1; } + } }