Subversion Repositories shark

Rev

Rev 847 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
538 mauro 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Mauro Marinoni      <mauro.marinoni@unipv.it>
10
 *
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
1063 tullio 19
/*
20
 * This program is free software; you can redistribute it and/or modify
21
 * it under the terms of the GNU General Public License as published by
22
 * the Free Software Foundation; either version 2 of the License, or
23
 * (at your option) any later version.
24
 *
25
 * This program is distributed in the hope that it will be useful,
26
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
 * GNU General Public License for more details.
29
 *
30
 * You should have received a copy of the GNU General Public License
31
 * along with this program; if not, write to the Free Software
32
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
33
 *
34
 */
35
 
548 mauro 36
//#define __JOY_DEBUG__
538 mauro 37
//#define __JOY_DUMP__
38
 
39
#include <kernel/kern.h>
40
 
41
#include "../include/drivers/shark_input26.h"
42
#include "../include/drivers/shark_joy26.h"
43
 
44
#include <kernel/func.h>
45
 
46
/* Devices */
47
extern int ns558_init(void);
48
extern int ns558_exit(void);
49
 
50
extern int analog_init(void);
51
extern int analog_exit(void);
52
 
53
extern int joydump_init(void);
54
extern int joydump_exit(void);
55
 
56
/* Handler */
57
extern int joystick_init(void);
58
extern int joystick_exit(void);
59
 
547 mauro 60
/* Functions */
61
extern int joystick_get(int *type, int *number, int *value);
62
 
63
#define JS_EVENT_BUTTON         0x01    /* button pressed/released */
64
#define JS_EVENT_AXIS           0x02    /* joystick moved */
65
#define JS_EVENT_INIT           0x80    /* initial state of device */
66
 
67
/* joystick driver currently installed */
68
static int joystick_installed = FALSE;
548 mauro 69
static int joystick_enabled = FALSE;
70
 
547 mauro 71
static int axis[4], button;
72
 
73
/* Called by handler */
74
void shark_joy_exec(void) {
75
        int type, number, value;
548 mauro 76
 
77
        if (joystick_enabled == FALSE)
78
                return;
79
 
547 mauro 80
        if (joystick_get(&type, &number, &value))
81
                return;
82
 
548 mauro 83
        switch (type) {                                 /* TODO */
547 mauro 84
                case JS_EVENT_BUTTON:
548 mauro 85
                        if (value)
86
                                button |= 1 << number;
87
                        else
88
                                button &= ~(1 << number);
547 mauro 89
                        break;
90
                case JS_EVENT_AXIS:
548 mauro 91
                        axis[number] = value;
547 mauro 92
                        break;
93
                default:
94
                        return;
95
        }
96
#ifdef __JOY_DEBUG__
548 mauro 97
        printk(KERN_DEBUG "shark_joy.c: (%4d,%4d) (%4d,%4d) %4x\n", axis[0], axis[1], axis[2], axis[3], button);
547 mauro 98
#endif
99
}
100
 
538 mauro 101
/* User Functions */
548 mauro 102
void joy_getstatus(int *axe0, int *axe1, int *axe2, int *axe3, int *buttons)
103
{
104
        if (axe0)
105
                *axe0 = axis[0];
106
        if (axe1)
107
                *axe1 = axis[1];
108
        if (axe2)
109
                *axe2 = axis[2];
110
        if (axe3)
111
                *axe3 = axis[3];
112
        if (buttons)
113
                *buttons = button;
114
}
115
 
116
void joy_setstatus(int axe0, int axe1, int axe2, int axe3, int buttons)
117
{
118
        if ((axe0 > -32767) && (axe0 < 32767))
119
                axis[0] = axe0;
120
        if ((axe1 > -32767) && (axe1 < 32767))
121
                axis[1] = axe1;
122
        if ((axe2 > -32767) && (axe2 < 32767))
123
                axis[2] = axe2;
124
        if ((axe3 > -32767) && (axe3 < 32767))
125
                axis[3] = axe3;
126
        button = buttons;
127
}
128
 
547 mauro 129
void joy_enable(void)
130
{
548 mauro 131
        joystick_enabled = TRUE;
132
#ifdef __JOY_DEBUG__
133
        printk("shark_joy.c: Joystick Enabled.\n");
134
#endif
547 mauro 135
}
538 mauro 136
 
547 mauro 137
void joy_disable(void)
138
{
548 mauro 139
        joystick_enabled = FALSE;
140
#ifdef __JOY_DEBUG__
141
        printk("shark_joy.c: Joystick Disabled.\n");
142
#endif
547 mauro 143
}
144
 
145
 
538 mauro 146
/* Init the Linux Joystick Driver */
549 mauro 147
int JOY26_installed(void) {
148
        return joystick_installed;
149
}
538 mauro 150
 
549 mauro 151
int JOY26_init(void) {
152
 
538 mauro 153
        int ret;
154
 
549 mauro 155
        if (INPUT26_installed() == FALSE)
538 mauro 156
                if (INPUT26_init()) {
157
                        printk(KERN_ERR "Unable to open Input SubSystem.\n");
158
                        return -1;
159
                }
160
 
161
        ret = ns558_init();
847 giacomo 162
        //if (ret) {
163
        //      printk(KERN_ERR "Gameport_Init return: %d\n", ret);
164
        //      return -1;
165
        //}
538 mauro 166
 
167
#ifdef __JOY_DUMP__
168
        ret = joydump_init();
169
#else
170
        ret = analog_init();
171
#endif
172
        if (ret) {
173
                printk(KERN_ERR "Joystick_Device_Init return: %d\n", ret);
174
                return -1;
175
        }
176
 
177
        ret = joystick_init();
178
        if (ret) {
179
                printk(KERN_ERR "Joystick_Handler_Init return: %d\n", ret);
180
                return -1;
181
        }
548 mauro 182
 
547 mauro 183
        joystick_installed = TRUE;
548 mauro 184
        joystick_enabled = TRUE;
185
 
538 mauro 186
        return 0;
187
}
188
 
549 mauro 189
int JOY26_close(void) {
547 mauro 190
        if (!joystick_installed)
191
                return -1;
538 mauro 192
 
548 mauro 193
        joystick_enabled = FALSE;
538 mauro 194
        joystick_exit();
195
#ifdef __JOY_DUMP__
196
        joydump_exit();
197
#else
198
        analog_exit();
199
#endif
200
        ns558_exit();
547 mauro 201
 
202
        joystick_installed = FALSE;
538 mauro 203
        return 0;
204
}