Was wir brauchen: 1 RJ 11 KAbel
1 Raspberry
1 SD Karte passend zum Raspberry.
Die Tastatur/maus Kombi, die wir benutzen wollen.
Schritt 1. Man besorge sich ein normales raspian mit cc compiler und compiliere dann auf dem Raspberry folgenden Code:
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <linux/input.h>
#include <termios.h>
int main(int argc,char *argv[])
{
int i,j,code,lb=0,rb=0,mv=0,msdevnr=-1,kbddevnr = -1,serdevnr = -1;
struct input_event *ereignis,puffer[100];
struct termios seropt;
unsigned char serout[3];
char scancodes[] = {
0, // (Nothing)
1, // Esc
2, // 1
3, // 2
4, // 3
5, // 4
6, // 5
7, // 6
8, // 7
9, // 8
10, // 9
11, // 0
12, // - (ß)
13, // `
14, // Backspace
15, // Tab
16, // q
17, // w
18, // e
19, // r
20, // t
21, // y (z)
22, // u
23, // i
24, // o
25, // p
26, // [ (ü)
27, // ] (+)
28, // Enter
29, // Control
30, // a
31, // s
32, // d
33, // f
34, // g
35, // h
36, // j
37, // k
38, // l
39, // ; (ö)
40, // ' (ä)
43, // ~ (Mapped to ~) PC:^
42, // Lshift
41, // #
44, // z (y)
45, // x
46, // c
47, // v
48, // b
49, // n
50, // m
51, // ,
52, // .
53, // / (-)
54, // Rshift
102, // N* (PC:55)
56, // Alternate (left)
57, // Space
58, // CapsLock
59, // F1
60, // F2
61, // F3
62, // F4
63, // F5
64, // F6
65, // F7
66, // F8
67, // F9
68, // F10
0, // Num (PC:69)
0, // Rollen (PC:70)
103, // N7 (PC:71)
104, // N8 (PC:72)
105, // N9 (PC:73)
74, // N-
106, // N4 (PC:75)
107, // N5 (PC:76)
108, // N6 (PC:77)
78, // N+
109, // N1 (PC:79)
110, // N2 (PC:80)
111, // N3 (PC:81)
112, // N0 (PC:82)
113, // N. (PC:83)
0, // (Not used)
0, // (Not used)
96, // < (PC:86)
99, // F11 (PC:87) mapped to NUM (
100, // F12 (PC:88) mapped to NUM )
0, // (Not used)
0, // (Not used)
0, // (Not used)
0, // (Not used)
0, // (Not used)
0, // (Not used)
0, // (Not used)
114, // NEnter (PC:96)
29, // Control (PC:97 right CTRL)
101, // N/ (PC:98)
0, // Druck (PC:99)
56, // Alt (PC:100 Alt GR right)
0, // (Not used)
71, // Pos1 (Clr/Home) (PC:102)
72, // Arrow up (PC:103)
98, // Pg up (PC:104) mapped to Help
75, // Arrow left (PC:105)
77, // Arrow right (PC:106)
0, // Ende (PC:107)
80, // Arrow down (PC:108)
97, // Pg down (PC:109) mapped to Undo
82, // Insert (PC:110)
83, // Delete: (PC:111)
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
};
if ( argc != 3 ) {printf ("usage: ikbdemu kbddevfilename mousedevfilename\n");return(99);}
kbddevnr = open(argv[1],O_RDONLY | O_NONBLOCK);
msdevnr = open(argv[2],O_RDONLY | O_NONBLOCK);
serdevnr = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY | O_NDELAY);
if (ioctl(kbddevnr, EVIOCGRAB, 1) != 0) return(98);
if (ioctl(msdevnr, EVIOCGRAB, 1) != 0) return(97);
if((kbddevnr == -1) || (msdevnr == -1) || (serdevnr == -1)) return(96);
tcgetattr(serdevnr,&seropt);
seropt.c_cflag = B9600 | CS8 | CLOCAL | CREAD;
seropt.c_iflag = IGNPAR;
seropt.c_oflag=0;
seropt.c_lflag=0;
tcflush(serdevnr,TCIFLUSH);
tcsetattr(serdevnr,TCSANOW,&seropt);
while(1)
{
j = read(msdevnr,puffer,sizeof(puffer)) / 16;
for (i=0;i<j;i++)
{
ereignis = &puffer[i];
if(ereignis->type == 1
&& ereignis->code < 274) {if (ereignis->code == 272) lb=2*ereignis->value;
if (ereignis->code == 273) rb=ereignis->value;
//printf("Mouse code: %d %d %d\n",248+lb+rb,0,0);
serout[0]=248+lb+rb;
serout[1]=0;serout[2]=0;
write(serdevnr,&serout[0],3);
}
if(ereignis->type == 2
&& ereignis->code < 2) { mv=ereignis->value;
while (mv < -100)
{serout[0]=248+lb+rb;serout[1]=0;serout[2]=0;
if (ereignis->code == 0)
{//printf("Mouse code: %d %d %d\n",248+lb+rb,156,0);
serout[1]=156;}
else {//printf("Mouse code: %d %d %d\n",248+lb+rb,0,156);
serout[2]=156;}
mv=mv+100;
write(serdevnr,&serout[0],3);
}
while (mv > 100)
{serout[0]=248+lb+rb;serout[1]=0;serout[2]=0;
if (ereignis->code == 0)
{//printf("Mouse code: %d %d %d\n",248+lb+rb,100,0);
serout[1]=100;}
else {//printf("Mouse code: %d %d %d\n",248+lb+rb,0,100);
serout[2]=100;}
mv=mv-100;
write(serdevnr,&serout[0],3);
}
if (mv < 0)
{serout[0]=248+lb+rb;serout[1]=0;serout[2]=0;
if (ereignis->code == 0)
{//printf("Mouse code: %d %d %d\n",248+lb+rb,256+mv,0);
serout[1]=256+mv;}
else {//printf("Mouse code: %d %d %d\n",248+lb+rb,0,256+mv);
serout[2]=256+mv;}
write(serdevnr,&serout[0],3);
}
if (mv > 0)
{serout[0]=248+lb+rb;serout[1]=0;serout[2]=0;
if (ereignis->code == 0)
{//printf("Mouse code: %d %d %d\n",248+lb+rb,mv,0);
serout[1]=mv;}
else {//printf("Mouse code: %d %d %d\n",248+lb+rb,0,mv);
serout[2]=mv;}
write(serdevnr,&serout[0],3);
}
}
}
j = read(kbddevnr,puffer,sizeof(puffer)) / 16;
for (i=0;i<j;i++)
{
ereignis = &puffer[i];
if(ereignis->type == 1 && ereignis->code < 128) {code=0;
if (ereignis->value == 1) code=scancodes[ereignis->code];
if (ereignis->value == 0) code=scancodes[ereignis->code]+128;
serout[0]=code;
if (code != 0 && code != 128){printf("KBD Code: %d \n",code);write(serdevnr,&serout[0],1);}}
}
}
}