Mercurial > sdl-ios-xcode
annotate src/haptic/linux/SDL_syshaptic.c @ 2472:3f73c88c9abb gsoc2008_force_feedback
First commit of the SDL_haptic subsystem.
Code compiles and works, very limited functionality (linux only).
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Sun, 01 Jun 2008 11:44:25 +0000 |
parents | |
children | 3f80bf1528b4 |
rev | line source |
---|---|
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
1 /* |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
3 Copyright (C) 2008 Edgar Simo |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
4 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
9 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
14 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
18 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
19 Sam Lantinga |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
20 slouken@libsdl.org |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
21 */ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
22 #include "SDL_config.h" |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
23 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
24 #ifdef SDL_JOYSTICK_LINUX |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
25 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
26 #include "SDL_haptic.h" |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
27 #include "../SDL_haptic_c.h" |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
28 #include "../SDL_syshaptic.h" |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
29 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
30 #include <unistd.h> /* close */ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
31 #include <linux/input.h> |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
32 #include <sys/ioctl.h> |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
33 #include <sys/types.h> |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
34 #include <sys/stat.h> |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
35 #include <fcntl.h> |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
36 #include <linux/limits.h> |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
37 #include <string.h> |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
38 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
39 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
40 #include <stdio.h> |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
41 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
42 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
43 #define MAX_HAPTICS 32 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
44 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
45 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
46 static struct |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
47 { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
48 char *fname; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
49 SDL_Haptic *haptic; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
50 } SDL_hapticlist[MAX_HAPTICS]; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
51 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
52 struct haptic_hwdata |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
53 { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
54 int fd; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
55 }; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
56 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
57 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
58 #define test_bit(nr, addr) \ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
59 (((1UL << ((nr) & 31)) & (((const unsigned int *) addr)[(nr) >> 5])) != 0) |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
60 #define EV_TEST(ev,f) \ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
61 if (test_bit((ev), features)) ret |= (f); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
62 static int |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
63 EV_IsHaptic(int fd) |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
64 { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
65 unsigned int ret; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
66 unsigned long features[1 + FF_MAX/sizeof(unsigned long)]; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
67 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
68 ret = 0; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
69 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
70 ioctl(fd, EVIOCGBIT(EV_FF, sizeof(unsigned long) * 4), features); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
71 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
72 EV_TEST(FF_CONSTANT, SDL_HAPTIC_CONSTANT); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
73 EV_TEST(FF_PERIODIC, SDL_HAPTIC_PERIODIC); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
74 EV_TEST(FF_RAMP, SDL_HAPTIC_RAMP); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
75 EV_TEST(FF_SPRING, SDL_HAPTIC_SPRING); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
76 EV_TEST(FF_FRICTION, SDL_HAPTIC_FRICTION); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
77 EV_TEST(FF_DAMPER, SDL_HAPTIC_DAMPER); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
78 EV_TEST(FF_RUMBLE, SDL_HAPTIC_RUMBLE); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
79 EV_TEST(FF_INERTIA, SDL_HAPTIC_INERTIA); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
80 EV_TEST(FF_GAIN, SDL_HAPTIC_GAIN); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
81 EV_TEST(FF_AUTOCENTER, SDL_HAPTIC_AUTOCENTER); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
82 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
83 return ret; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
84 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
85 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
86 int |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
87 SDL_SYS_HapticInit(void) |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
88 { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
89 const char joydev_pattern[] = "/dev/input/event%d"; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
90 dev_t dev_nums[MAX_HAPTICS]; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
91 char path[PATH_MAX]; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
92 struct stat sb; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
93 int fd; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
94 int i, j, k; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
95 int duplicate; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
96 int numhaptics; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
97 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
98 numhaptics = 0; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
99 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
100 i = 0; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
101 for (j = 0; j < MAX_HAPTICS; ++j) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
102 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
103 snprintf(path, PATH_MAX, joydev_pattern, i++); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
104 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
105 /* check to see if file exists */ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
106 if (stat(path,&sb) != 0) |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
107 break; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
108 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
109 /* check for duplicates */ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
110 duplicate = 0; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
111 for (k = 0; (k < numhaptics) && !duplicate; ++k) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
112 if (sb.st_rdev == dev_nums[k]) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
113 duplicate = 1; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
114 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
115 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
116 if (duplicate) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
117 continue; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
118 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
119 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
120 /* try to open */ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
121 fd = open(path, O_RDWR, 0); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
122 if (fd < 0) continue; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
123 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
124 #ifdef DEBUG_INPUT_EVENTS |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
125 printf("Checking %s\n", path); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
126 #endif |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
127 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
128 /* see if it works */ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
129 if (EV_IsHaptic(fd)!=0) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
130 SDL_hapticlist[numhaptics].fname = SDL_strdup(path); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
131 SDL_hapticlist[numhaptics].haptic = NULL; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
132 dev_nums[numhaptics] = sb.st_rdev; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
133 ++numhaptics; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
134 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
135 close(fd); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
136 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
137 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
138 return numhaptics; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
139 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
140 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
141 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
142 const char * |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
143 SDL_SYS_HapticName(int index) |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
144 { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
145 int fd; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
146 static char namebuf[128]; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
147 char *name; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
148 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
149 name = NULL; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
150 fd = open(SDL_hapticlist[index].fname, O_RDONLY, 0); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
151 if (fd >= 0) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
152 if (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
153 name = SDL_hapticlist[index].fname; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
154 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
155 else { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
156 name = namebuf; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
157 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
158 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
159 close(fd); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
160 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
161 return name; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
162 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
163 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
164 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
165 int |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
166 SDL_SYS_HapticOpen(SDL_Haptic * haptic) |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
167 { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
168 /* TODO finish |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
169 int fd; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
170 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
171 fd = open(SDL_hapticlist[haptic->index].fname, O_RDWR, 0); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
172 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
173 if (fd < 0) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
174 SDL_SetError("Unable to open %s\n", SDL_hapticlist[haptic->index]); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
175 return (-1); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
176 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
177 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
178 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
179 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
180 return 0; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
181 */ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
182 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
183 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
184 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
185 #endif /* SDL_HAPTIC_LINUX */ |