This repository has been archived by the owner on Mar 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetps2.c
75 lines (66 loc) · 1.38 KB
/
setps2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <config.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <time.h>
#include <termios.h>
char readps2(int fd)
{
char ch;
while(read(fd,&ch,1) && (ch==(char)0xfa || ch==(char)0xaa))
{
fprintf(stderr,"<%02X>",ch&0xff);
fflush(stdout);
}
return(ch);
}
int main(int argc, char **argv)
{
int fd;
char ch,
getdevtype=0xF2,
enabledev=0xF4,
disabledev=0xF5,
resetps2=0xFF;
if(argc>1)
fd=open(argv[1],O_RDWR);
else
fd=open("/dev/mouse",O_RDWR);
fprintf(stderr,"disable\n");
write(fd,&disabledev,1);
fprintf(stderr,"flush\n");
tcflush(fd, TCIFLUSH);
fprintf(stderr,"getdev\n");
write(fd,&getdevtype,1);
fprintf(stderr,"sleep(1)\n");
sleep(1);
fprintf(stderr,"read\n");
ch=readps2(fd);
fprintf(stderr,"device type=%02X(%4d)\n",ch&0xff,ch);
fprintf(stderr,"reset ps2\n");
write(fd,&resetps2,1);
fprintf(stderr,"sleep(1)\n");
sleep(1);
fprintf(stderr,"read\n");
ch=readps2(fd);
fprintf(stderr,"reset response=%02X(%4d)\n",ch&0xff,ch);
fprintf(stderr,"flush\n");
tcflush(fd, TCIFLUSH);
fprintf(stderr,"getdev\n");
write(fd,&getdevtype,1);
fprintf(stderr,"sleep(1)\n");
sleep(1);
fprintf(stderr,"read\n");
ch=readps2(fd);
fprintf(stderr,"device type=%02X(%4d)\n",ch&0xff,ch);
close(fd);
return(0);
}