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