Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
494 giacomo 1
/*
2
 * $Id: joydump.c,v 1.1 2004-03-08 18:47:38 giacomo Exp $
3
 *
4
 *  Copyright (c) 1996-2001 Vojtech Pavlik
5
 */
6
 
7
/*
8
 * This is just a very simple driver that can dump the data
9
 * out of the joystick port into the syslog ...
10
 */
11
 
12
/*
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
 *
27
 * Should you need to contact me, the author, you can do so either by
28
 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
29
 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
30
 */
31
 
32
#include <linuxcomp.h>
33
 
34
#include <linux/module.h>
35
#include <linux/gameport.h>
36
#include <linux/kernel.h>
37
#include <linux/delay.h>
38
#include <linux/init.h>
39
 
40
MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
41
MODULE_DESCRIPTION("Gameport data dumper module");
42
MODULE_LICENSE("GPL");
43
 
44
#define BUF_SIZE 256
45
 
46
struct joydump {
47
        unsigned int time;
48
        unsigned char data;
49
};
50
 
51
static void __devinit joydump_connect(struct gameport *gameport, struct gameport_dev *dev)
52
{
53
        struct joydump buf[BUF_SIZE];
54
        int axes[4], buttons;
55
        int i, j, t, timeout;
56
        unsigned long flags;
57
        unsigned char u;
58
 
59
        printk(KERN_INFO "joydump: ,------------------- START ------------------.\n");
60
        printk(KERN_INFO "joydump: | Dumping gameport%s.\n", gameport->phys);
61
        printk(KERN_INFO "joydump: | Speed: %4d kHz.                            |\n", gameport->speed);
62
 
63
        if (gameport_open(gameport, dev, GAMEPORT_MODE_RAW)) {
64
 
65
                printk(KERN_INFO "joydump: | Raw mode not available - trying cooked.    |\n");
66
 
67
                if (gameport_open(gameport, dev, GAMEPORT_MODE_COOKED)) {
68
 
69
                        printk(KERN_INFO "joydump: | Cooked not available either. Failing.      |\n");
70
                        printk(KERN_INFO "joydump: `-------------------- END -------------------'\n");
71
                        return;
72
                }
73
 
74
                gameport_cooked_read(gameport, axes, &buttons);
75
 
76
                for (i = 0; i < 4; i++)
77
                        printk(KERN_INFO "joydump: | Axis %d: %4d.                              |\n", i, axes[i]);
78
                printk(KERN_INFO "joydump: | Buttons %02x.                                |\n", buttons);
79
                printk(KERN_INFO "joydump: `-------------------- END -------------------'\n");
80
        }
81
 
82
        timeout = gameport_time(gameport, 10000); /* 10 ms */
83
        t = 0;
84
        i = 1;
85
 
86
        local_irq_save(flags);
87
 
88
        u = gameport_read(gameport);
89
 
90
        buf[0].data = u;
91
        buf[0].time = t;
92
 
93
        gameport_trigger(gameport);
94
 
95
        while (i < BUF_SIZE && t < timeout) {
96
 
97
                buf[i].data = gameport_read(gameport);
98
 
99
                if (buf[i].data ^ u) {
100
                        u = buf[i].data;
101
                        buf[i].time = t;
102
                        i++;
103
                }
104
                t++;
105
        }
106
 
107
        local_irq_restore(flags);
108
 
109
/*
110
 * Dump data.
111
 */
112
 
113
        t = i;
114
 
115
        printk(KERN_INFO "joydump: >------------------- DATA -------------------<\n");
116
        printk(KERN_INFO "joydump: | index: %3d delta: %3d.%02d us data: ", 0, 0, 0);
117
        for (j = 7; j >= 0; j--)
118
                printk("%d",(buf[0].data >> j) & 1);
119
        printk(" |\n");
120
        for (i = 1; i < t; i++) {
121
                printk(KERN_INFO "joydump: | index: %3d delta: %3d us data: ",
122
                        i, buf[i].time - buf[i-1].time);
123
                for (j = 7; j >= 0; j--)
124
                        printk("%d",(buf[i].data >> j) & 1);
125
                printk("    |\n");
126
        }
127
 
128
        printk(KERN_INFO "joydump: `-------------------- END -------------------'\n");
129
}
130
 
131
static void __devexit joydump_disconnect(struct gameport *gameport)
132
{
133
        gameport_close(gameport);
134
}
135
 
136
static struct gameport_dev joydump_dev = {
137
        .connect =      joydump_connect,
138
        .disconnect =   joydump_disconnect,
139
};
140
 
141
/*static*/ int __init joydump_init(void)
142
{
143
        gameport_register_device(&joydump_dev);
144
        return 0;
145
}
146
 
147
/*static*/ void __exit joydump_exit(void)
148
{
149
        gameport_unregister_device(&joydump_dev);
150
}
151
 
152
module_init(joydump_init);
153
module_exit(joydump_exit);