Subversion Repositories shark

Rev

Rev 547 | Rev 549 | Go to most recent revision | 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
 
548 mauro 19
//#define __JOY_DEBUG__
538 mauro 20
//#define __JOY_DUMP__
21
 
22
#include <kernel/kern.h>
23
 
24
#include "../include/drivers/shark_input26.h"
25
#include "../include/drivers/shark_joy26.h"
26
 
27
#include <kernel/func.h>
28
 
29
/* Devices */
30
extern int ns558_init(void);
31
extern int ns558_exit(void);
32
 
33
extern int analog_init(void);
34
extern int analog_exit(void);
35
 
36
extern int joydump_init(void);
37
extern int joydump_exit(void);
38
 
39
/* Handler */
40
extern int joystick_init(void);
41
extern int joystick_exit(void);
42
 
547 mauro 43
/* Functions */
44
extern int joystick_get(int *type, int *number, int *value);
45
 
538 mauro 46
extern int input_installed;
47
 
547 mauro 48
#define JS_EVENT_BUTTON         0x01    /* button pressed/released */
49
#define JS_EVENT_AXIS           0x02    /* joystick moved */
50
#define JS_EVENT_INIT           0x80    /* initial state of device */
51
 
52
/* joystick driver currently installed */
53
static int joystick_installed = FALSE;
548 mauro 54
static int joystick_enabled = FALSE;
55
 
547 mauro 56
static int axis[4], button;
57
 
58
/* Called by handler */
59
void shark_joy_exec(void) {
60
        int type, number, value;
548 mauro 61
 
62
        if (joystick_enabled == FALSE)
63
                return;
64
 
547 mauro 65
        if (joystick_get(&type, &number, &value))
66
                return;
67
 
548 mauro 68
        switch (type) {                                 /* TODO */
547 mauro 69
                case JS_EVENT_BUTTON:
548 mauro 70
                        if (value)
71
                                button |= 1 << number;
72
                        else
73
                                button &= ~(1 << number);
547 mauro 74
                        break;
75
                case JS_EVENT_AXIS:
548 mauro 76
                        axis[number] = value;
547 mauro 77
                        break;
78
                default:
79
                        return;
80
        }
81
#ifdef __JOY_DEBUG__
548 mauro 82
        printk(KERN_DEBUG "shark_joy.c: (%4d,%4d) (%4d,%4d) %4x\n", axis[0], axis[1], axis[2], axis[3], button);
547 mauro 83
#endif
84
}
85
 
538 mauro 86
/* User Functions */
548 mauro 87
void joy_getstatus(int *axe0, int *axe1, int *axe2, int *axe3, int *buttons)
88
{
89
        if (axe0)
90
                *axe0 = axis[0];
91
        if (axe1)
92
                *axe1 = axis[1];
93
        if (axe2)
94
                *axe2 = axis[2];
95
        if (axe3)
96
                *axe3 = axis[3];
97
        if (buttons)
98
                *buttons = button;
99
}
100
 
101
void joy_setstatus(int axe0, int axe1, int axe2, int axe3, int buttons)
102
{
103
        if ((axe0 > -32767) && (axe0 < 32767))
104
                axis[0] = axe0;
105
        if ((axe1 > -32767) && (axe1 < 32767))
106
                axis[1] = axe1;
107
        if ((axe2 > -32767) && (axe2 < 32767))
108
                axis[2] = axe2;
109
        if ((axe3 > -32767) && (axe3 < 32767))
110
                axis[3] = axe3;
111
        button = buttons;
112
}
113
 
547 mauro 114
void joy_enable(void)
115
{
548 mauro 116
        joystick_enabled = TRUE;
117
#ifdef __JOY_DEBUG__
118
        printk("shark_joy.c: Joystick Enabled.\n");
119
#endif
547 mauro 120
}
538 mauro 121
 
547 mauro 122
void joy_disable(void)
123
{
548 mauro 124
        joystick_enabled = FALSE;
125
#ifdef __JOY_DEBUG__
126
        printk("shark_joy.c: Joystick Disabled.\n");
127
#endif
547 mauro 128
}
129
 
130
 
538 mauro 131
/* Init the Linux Joystick Driver */
132
int JOY26_init() {
133
 
134
        int ret;
135
 
136
        if (input_installed == FALSE)
137
                if (INPUT26_init()) {
138
                        printk(KERN_ERR "Unable to open Input SubSystem.\n");
139
                        return -1;
140
                }
141
 
142
        ret = ns558_init();
143
        if (ret) {
144
                printk(KERN_ERR "Gameport_Init return: %d\n", ret);
145
                return -1;
146
        }
147
 
148
#ifdef __JOY_DUMP__
149
        ret = joydump_init();
150
#else
151
        ret = analog_init();
152
#endif
153
        if (ret) {
154
                printk(KERN_ERR "Joystick_Device_Init return: %d\n", ret);
155
                return -1;
156
        }
157
 
158
        ret = joystick_init();
159
        if (ret) {
160
                printk(KERN_ERR "Joystick_Handler_Init return: %d\n", ret);
161
                return -1;
162
        }
548 mauro 163
 
547 mauro 164
        joystick_installed = TRUE;
548 mauro 165
        joystick_enabled = TRUE;
166
 
538 mauro 167
        return 0;
168
}
169
 
170
int JOY26_close() {
547 mauro 171
        if (!joystick_installed)
172
                return -1;
538 mauro 173
 
548 mauro 174
        joystick_enabled = FALSE;
538 mauro 175
        joystick_exit();
176
#ifdef __JOY_DUMP__
177
        joydump_exit();
178
#else
179
        analog_exit();
180
#endif
181
        ns558_exit();
547 mauro 182
 
183
        joystick_installed = FALSE;
538 mauro 184
        return 0;
185
}