Mercurial > sdl-ios-xcode
annotate src/haptic/linux/SDL_syshaptic.c @ 2510:e6ad7e678fca gsoc2008_force_feedback
Implemented SDL_HAPTIC_CARTESIAN on linux.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Wed, 09 Jul 2008 18:23:54 +0000 |
parents | 84a634009a83 |
children | f12ae0bae468 |
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 |
2493
6a2482d4af81
Fixed regex replace mistake.
Edgar Simo <bobbens@gmail.com>
parents:
2491
diff
changeset
|
24 #ifdef SDL_HAPTIC_LINUX |
2472
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_syshaptic.h" |
2489
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
28 #include "SDL_joystick.h" |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
29 #include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */ |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
30 #include "../../joystick/linux/SDL_sysjoystick_c.h" /* For joystick hwdata */ |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
31 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
32 #include <unistd.h> /* close */ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
33 #include <linux/input.h> |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
34 #include <sys/ioctl.h> |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
35 #include <sys/types.h> |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
36 #include <sys/stat.h> |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
37 #include <fcntl.h> |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
38 #include <linux/limits.h> |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
39 #include <string.h> |
2496
8f840a6cdf01
Using errno for more verbosity in errors.
Edgar Simo <bobbens@gmail.com>
parents:
2495
diff
changeset
|
40 #include <errno.h> |
2510
e6ad7e678fca
Implemented SDL_HAPTIC_CARTESIAN on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2503
diff
changeset
|
41 #include <math.h> |
e6ad7e678fca
Implemented SDL_HAPTIC_CARTESIAN on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2503
diff
changeset
|
42 |
e6ad7e678fca
Implemented SDL_HAPTIC_CARTESIAN on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2503
diff
changeset
|
43 #ifndef M_PI |
e6ad7e678fca
Implemented SDL_HAPTIC_CARTESIAN on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2503
diff
changeset
|
44 # define M_PI 3.14159265358979323846 |
e6ad7e678fca
Implemented SDL_HAPTIC_CARTESIAN on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2503
diff
changeset
|
45 #endif |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
46 |
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 #define MAX_HAPTICS 32 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
49 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
50 |
2475 | 51 /* |
52 * List of available haptic devices. | |
53 */ | |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
54 static struct |
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 char *fname; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
57 SDL_Haptic *haptic; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
58 } SDL_hapticlist[MAX_HAPTICS]; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
59 |
2475 | 60 |
61 /* | |
62 * Haptic system hardware data. | |
63 */ | |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
64 struct haptic_hwdata |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
65 { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
66 int fd; |
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 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
69 |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
70 /* |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
71 * Haptic system effect data. |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
72 */ |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
73 struct haptic_hweffect |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
74 { |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
75 struct ff_effect effect; |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
76 }; |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
77 |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
78 |
2475 | 79 |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
80 #define test_bit(nr, addr) \ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
81 (((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
|
82 #define EV_TEST(ev,f) \ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
83 if (test_bit((ev), features)) ret |= (f); |
2475 | 84 /* |
85 * Test whether a device has haptic properties. | |
86 * Returns available properties or 0 if there are none. | |
87 */ | |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
88 static int |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
89 EV_IsHaptic(int fd) |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
90 { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
91 unsigned int ret; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
92 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
|
93 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
94 ret = 0; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
95 |
2490 | 96 if (ioctl(fd, EVIOCGBIT(EV_FF, sizeof(unsigned long) * 4), features) < 0) { |
2496
8f840a6cdf01
Using errno for more verbosity in errors.
Edgar Simo <bobbens@gmail.com>
parents:
2495
diff
changeset
|
97 SDL_SetError("Unable to get device's haptic abilities: %s", strerror(errno)); |
2490 | 98 return -1; |
99 } | |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
100 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
101 EV_TEST(FF_CONSTANT, SDL_HAPTIC_CONSTANT); |
2487
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
102 EV_TEST(FF_PERIODIC, SDL_HAPTIC_SINE | |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
103 SDL_HAPTIC_SQUARE | |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
104 SDL_HAPTIC_TRIANGLE | |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
105 SDL_HAPTIC_SAWTOOTHUP | |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
106 SDL_HAPTIC_SAWTOOTHDOWN); |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
107 EV_TEST(FF_RAMP, SDL_HAPTIC_RAMP); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
108 EV_TEST(FF_SPRING, SDL_HAPTIC_SPRING); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
109 EV_TEST(FF_FRICTION, SDL_HAPTIC_FRICTION); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
110 EV_TEST(FF_DAMPER, SDL_HAPTIC_DAMPER); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
111 EV_TEST(FF_INERTIA, SDL_HAPTIC_INERTIA); |
2486
24dd8b8669fa
Added SDL_HAPTIC_CUSTOM (not supported on linux).
Edgar Simo <bobbens@gmail.com>
parents:
2485
diff
changeset
|
112 EV_TEST(FF_CUSTOM, SDL_HAPTIC_CUSTOM); |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
113 EV_TEST(FF_GAIN, SDL_HAPTIC_GAIN); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
114 EV_TEST(FF_AUTOCENTER, SDL_HAPTIC_AUTOCENTER); |
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 return ret; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
117 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
118 |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
119 /* |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
120 * Initializes the haptic subsystem by finding available devices. |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
121 */ |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
122 int |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
123 SDL_SYS_HapticInit(void) |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
124 { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
125 const char joydev_pattern[] = "/dev/input/event%d"; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
126 dev_t dev_nums[MAX_HAPTICS]; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
127 char path[PATH_MAX]; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
128 struct stat sb; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
129 int fd; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
130 int i, j, k; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
131 int duplicate; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
132 int numhaptics; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
133 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
134 numhaptics = 0; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
135 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
136 i = 0; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
137 for (j = 0; j < MAX_HAPTICS; ++j) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
138 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
139 snprintf(path, PATH_MAX, joydev_pattern, i++); |
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 /* check to see if file exists */ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
142 if (stat(path,&sb) != 0) |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
143 break; |
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 /* check for duplicates */ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
146 duplicate = 0; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
147 for (k = 0; (k < numhaptics) && !duplicate; ++k) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
148 if (sb.st_rdev == dev_nums[k]) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
149 duplicate = 1; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
150 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
151 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
152 if (duplicate) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
153 continue; |
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 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
156 /* try to open */ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
157 fd = open(path, O_RDWR, 0); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
158 if (fd < 0) continue; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
159 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
160 #ifdef DEBUG_INPUT_EVENTS |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
161 printf("Checking %s\n", path); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
162 #endif |
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 /* see if it works */ |
2490 | 165 if (EV_IsHaptic(fd) > 0) { |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
166 SDL_hapticlist[numhaptics].fname = SDL_strdup(path); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
167 SDL_hapticlist[numhaptics].haptic = NULL; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
168 dev_nums[numhaptics] = sb.st_rdev; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
169 ++numhaptics; |
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 close(fd); |
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 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
174 return numhaptics; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
175 } |
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 |
2475 | 178 /* |
179 * Return the name of a haptic device, does not need to be opened. | |
180 */ | |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
181 const char * |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
182 SDL_SYS_HapticName(int index) |
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 int fd; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
185 static char namebuf[128]; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
186 char *name; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
187 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
188 name = NULL; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
189 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
|
190 if (fd >= 0) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
191 if (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
192 name = SDL_hapticlist[index].fname; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
193 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
194 else { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
195 name = namebuf; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
196 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
197 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
198 close(fd); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
199 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
200 return name; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
201 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
202 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
203 |
2475 | 204 /* |
2490 | 205 * Opens the haptic device from the file descriptor. |
2475 | 206 */ |
2490 | 207 static int |
208 SDL_SYS_HapticOpenFromFD(SDL_Haptic * haptic, int fd) | |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
209 { |
2476
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
210 /* Allocate the hwdata */ |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
211 haptic->hwdata = (struct haptic_hwdata *) |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
212 SDL_malloc(sizeof(*haptic->hwdata)); |
2476
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
213 if (haptic->hwdata == NULL) { |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
214 SDL_OutOfMemory(); |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
215 goto open_err; |
2476
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
216 } |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
217 SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); |
2478
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
218 /* Set the data */ |
2476
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
219 haptic->hwdata->fd = fd; |
2478
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
220 haptic->supported = EV_IsHaptic(fd); |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
221 |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
222 /* Set the effects */ |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
223 if (ioctl(fd, EVIOCGEFFECTS, &haptic->neffects) < 0) { |
2496
8f840a6cdf01
Using errno for more verbosity in errors.
Edgar Simo <bobbens@gmail.com>
parents:
2495
diff
changeset
|
224 SDL_SetError("Unable to query haptic device memory: %s", strerror(errno)); |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
225 goto open_err; |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
226 } |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
227 haptic->effects = (struct haptic_effect *) |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
228 SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
229 if (haptic->effects == NULL) { |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
230 SDL_OutOfMemory(); |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
231 goto open_err; |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
232 } |
2483
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
233 /* Clear the memory */ |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
234 SDL_memset(haptic->effects, 0, |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
235 sizeof(struct haptic_effect) * haptic->neffects); |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
236 |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
237 return 0; |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
238 |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
239 /* Error handling */ |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
240 open_err: |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
241 close(fd); |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
242 if (haptic->hwdata != NULL) { |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
243 free(haptic->hwdata); |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
244 haptic->hwdata = NULL; |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
245 } |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
246 return -1; |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
247 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
248 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
249 |
2475 | 250 /* |
2490 | 251 * Opens a haptic device for usage. |
252 */ | |
253 int | |
254 SDL_SYS_HapticOpen(SDL_Haptic * haptic) | |
255 { | |
256 int fd; | |
257 | |
258 /* Open the character device */ | |
259 fd = open(SDL_hapticlist[haptic->index].fname, O_RDWR, 0); | |
260 if (fd < 0) { | |
2496
8f840a6cdf01
Using errno for more verbosity in errors.
Edgar Simo <bobbens@gmail.com>
parents:
2495
diff
changeset
|
261 SDL_SetError("Unable to open %s: %s", |
8f840a6cdf01
Using errno for more verbosity in errors.
Edgar Simo <bobbens@gmail.com>
parents:
2495
diff
changeset
|
262 SDL_hapticlist[haptic->index], strerror(errno)); |
2490 | 263 return -1; |
264 } | |
265 | |
266 return SDL_SYS_HapticOpenFromFD(haptic,fd); | |
267 } | |
268 | |
269 | |
270 /* | |
2489
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
271 * Checks to see if a joystick has haptic features. |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
272 */ |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
273 int |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
274 SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick) |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
275 { |
2490 | 276 return EV_IsHaptic(joystick->hwdata->fd); |
277 } | |
278 | |
279 | |
280 /* | |
281 * Checks to see if the haptic device and joystick and in reality the same. | |
282 */ | |
283 int | |
284 SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick) | |
285 { | |
286 if (SDL_strcmp(joystick->name,haptic->name)==0) { | |
2489
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
287 return 1; |
2490 | 288 } |
2489
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
289 return 0; |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
290 } |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
291 |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
292 |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
293 /* |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
294 * Opens a SDL_Haptic from a SDL_Joystick. |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
295 */ |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
296 int |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
297 SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick) |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
298 { |
2490 | 299 int fd; |
300 fd = open(joystick->hwdata->fname, O_RDWR, 0); | |
301 return SDL_SYS_HapticOpenFromFD(haptic,fd); | |
2489
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
302 } |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
303 |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
304 |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
305 /* |
2475 | 306 * Closes the haptic device. |
307 */ | |
308 void | |
309 SDL_SYS_HapticClose(SDL_Haptic * haptic) | |
310 { | |
2476
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
311 if (haptic->hwdata) { |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
312 |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
313 /* Clean up */ |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
314 close(haptic->hwdata->fd); |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
315 |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
316 /* Free */ |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
317 SDL_free(haptic->hwdata); |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
318 haptic->hwdata = NULL; |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
319 SDL_free(haptic->effects); |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
320 haptic->neffects = 0; |
2476
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
321 } |
2475 | 322 } |
323 | |
324 | |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
325 /* |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
326 * Clean up after system specific haptic stuff |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
327 */ |
2474
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
328 void |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
329 SDL_SYS_HapticQuit(void) |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
330 { |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
331 int i; |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
332 |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
333 for (i=0; SDL_hapticlist[i].fname != NULL; i++) { |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
334 SDL_free(SDL_hapticlist[i].fname); |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
335 } |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
336 SDL_hapticlist[0].fname = NULL; |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
337 } |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
338 |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
339 /* |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
340 * Returns the ff_effect usable direction from a SDL_HapticDirection. |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
341 */ |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
342 static Uint16 |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
343 SDL_SYS_ToDirection( SDL_HapticDirection * dir ) |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
344 { |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
345 Uint32 tmp; |
2510
e6ad7e678fca
Implemented SDL_HAPTIC_CARTESIAN on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2503
diff
changeset
|
346 float f; |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
347 |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
348 switch (dir->type) { |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
349 case SDL_HAPTIC_POLAR: |
2502
5356ca0c36a3
Fixed linux directions being inverted.
Edgar Simo <bobbens@gmail.com>
parents:
2500
diff
changeset
|
350 /* Linux directions are inverted. */ |
5356ca0c36a3
Fixed linux directions being inverted.
Edgar Simo <bobbens@gmail.com>
parents:
2500
diff
changeset
|
351 tmp = (((18000 + dir->dir[0]) % 36000) * 0xFFFF) / 36000; |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
352 return (Uint16) tmp; |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
353 break; |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
354 case SDL_HAPTIC_CARTESIAN: |
2510
e6ad7e678fca
Implemented SDL_HAPTIC_CARTESIAN on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2503
diff
changeset
|
355 f = atan2(dir->dir[0], dir->dir[1]); |
e6ad7e678fca
Implemented SDL_HAPTIC_CARTESIAN on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2503
diff
changeset
|
356 tmp = (int)(f*18000./M_PI) % 36000; |
e6ad7e678fca
Implemented SDL_HAPTIC_CARTESIAN on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2503
diff
changeset
|
357 tmp = (tmp * 0xFFFF) / 36000; |
e6ad7e678fca
Implemented SDL_HAPTIC_CARTESIAN on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2503
diff
changeset
|
358 return (Uint16) tmp; |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
359 break; |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
360 |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
361 default: |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
362 return -1; |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
363 } |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
364 |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
365 return 0; |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
366 } |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
367 |
2481 | 368 #define CLAMP(x) (((x) > 32767) ? 32767 : x) |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
369 /* |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
370 * Initializes the linux effect struct from a haptic_effect. |
2481 | 371 * Values above 32767 (for unsigned) are unspecified so we must clamp. |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
372 */ |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
373 static int |
2480 | 374 SDL_SYS_ToFFEffect( struct ff_effect * dest, SDL_HapticEffect * src ) |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
375 { |
2482
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
376 int i; |
2480 | 377 SDL_HapticConstant *constant; |
378 SDL_HapticPeriodic *periodic; | |
2482
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
379 SDL_HapticCondition *condition; |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
380 SDL_HapticRamp *ramp; |
2480 | 381 |
382 /* Clear up */ | |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
383 SDL_memset(dest, 0, sizeof(struct ff_effect)); |
2480 | 384 |
385 switch (src->type) { | |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
386 case SDL_HAPTIC_CONSTANT: |
2480 | 387 constant = &src->constant; |
388 | |
389 /* Header */ | |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
390 dest->type = FF_CONSTANT; |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
391 dest->direction = SDL_SYS_ToDirection(&constant->direction); |
2480 | 392 |
393 /* Replay */ | |
2481 | 394 dest->replay.length = CLAMP(constant->length); |
395 dest->replay.delay = CLAMP(constant->delay); | |
2480 | 396 |
397 /* Trigger */ | |
2481 | 398 dest->trigger.button = CLAMP(constant->button); |
399 dest->trigger.interval = CLAMP(constant->interval); | |
2480 | 400 |
401 /* Constant */ | |
402 dest->u.constant.level = constant->level; | |
403 | |
404 /* Envelope */ | |
2481 | 405 dest->u.constant.envelope.attack_length = CLAMP(constant->attack_length); |
406 dest->u.constant.envelope.attack_level = CLAMP(constant->attack_level); | |
407 dest->u.constant.envelope.fade_length = CLAMP(constant->fade_length); | |
408 dest->u.constant.envelope.fade_level = CLAMP(constant->fade_level); | |
2480 | 409 |
410 break; | |
411 | |
2487
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
412 case SDL_HAPTIC_SINE: |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
413 case SDL_HAPTIC_SQUARE: |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
414 case SDL_HAPTIC_TRIANGLE: |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
415 case SDL_HAPTIC_SAWTOOTHUP: |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
416 case SDL_HAPTIC_SAWTOOTHDOWN: |
2480 | 417 periodic = &src->periodic; |
418 | |
419 /* Header */ | |
420 dest->type = FF_PERIODIC; | |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
421 dest->direction = SDL_SYS_ToDirection(&periodic->direction); |
2480 | 422 |
423 /* Replay */ | |
2481 | 424 dest->replay.length = CLAMP(periodic->length); |
425 dest->replay.delay = CLAMP(periodic->delay); | |
2480 | 426 |
427 /* Trigger */ | |
2481 | 428 dest->trigger.button = CLAMP(periodic->button); |
429 dest->trigger.interval = CLAMP(periodic->interval); | |
2480 | 430 |
2487
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
431 /* Periodic */ |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
432 if (periodic->type == SDL_HAPTIC_SINE) |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
433 dest->u.periodic.waveform = FF_SINE; |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
434 else if (periodic->type == SDL_HAPTIC_SQUARE) |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
435 dest->u.periodic.waveform = FF_SQUARE; |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
436 else if (periodic->type == SDL_HAPTIC_TRIANGLE) |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
437 dest->u.periodic.waveform = FF_TRIANGLE; |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
438 else if (periodic->type == SDL_HAPTIC_SAWTOOTHUP) |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
439 dest->u.periodic.waveform = FF_SAW_UP; |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
440 else if (periodic->type == SDL_HAPTIC_SAWTOOTHDOWN) |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
441 dest->u.periodic.waveform = FF_SAW_DOWN; |
2481 | 442 dest->u.periodic.period = CLAMP(periodic->period); |
2480 | 443 dest->u.periodic.magnitude = periodic->magnitude; |
444 dest->u.periodic.offset = periodic->offset; | |
2481 | 445 dest->u.periodic.phase = CLAMP(periodic->phase); |
2480 | 446 |
447 /* Envelope */ | |
2481 | 448 dest->u.periodic.envelope.attack_length = CLAMP(periodic->attack_length); |
449 dest->u.periodic.envelope.attack_level = CLAMP(periodic->attack_level); | |
450 dest->u.periodic.envelope.fade_length = CLAMP(periodic->fade_length); | |
451 dest->u.periodic.envelope.fade_level = CLAMP(periodic->fade_level); | |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
452 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
453 break; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
454 |
2482
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
455 case SDL_HAPTIC_SPRING: |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
456 case SDL_HAPTIC_DAMPER: |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
457 case SDL_HAPTIC_INERTIA: |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
458 case SDL_HAPTIC_FRICTION: |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
459 condition = &src->condition; |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
460 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
461 /* Header */ |
2503
84a634009a83
Another important typo mistake.
Edgar Simo <bobbens@gmail.com>
parents:
2502
diff
changeset
|
462 if (condition->type == SDL_HAPTIC_SPRING) |
2482
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
463 dest->type = FF_SPRING; |
2503
84a634009a83
Another important typo mistake.
Edgar Simo <bobbens@gmail.com>
parents:
2502
diff
changeset
|
464 else if (condition->type == SDL_HAPTIC_DAMPER) |
2482
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
465 dest->type = FF_DAMPER; |
2503
84a634009a83
Another important typo mistake.
Edgar Simo <bobbens@gmail.com>
parents:
2502
diff
changeset
|
466 else if (condition->type == SDL_HAPTIC_INERTIA) |
2482
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
467 dest->type = FF_INERTIA; |
2503
84a634009a83
Another important typo mistake.
Edgar Simo <bobbens@gmail.com>
parents:
2502
diff
changeset
|
468 else if (condition->type == SDL_HAPTIC_FRICTION) |
2482
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
469 dest->type = FF_FRICTION; |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
470 dest->direction = 0; /* Handled by the condition-specifics. */ |
2482
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
471 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
472 /* Replay */ |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
473 dest->replay.length = CLAMP(condition->length); |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
474 dest->replay.delay = CLAMP(condition->delay); |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
475 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
476 /* Trigger */ |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
477 dest->trigger.button = CLAMP(condition->button); |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
478 dest->trigger.interval = CLAMP(condition->interval); |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
479 |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
480 /* Condition */ |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
481 /* X axis */ |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
482 dest->u.condition[0].right_saturation = CLAMP(condition->right_sat[0]); |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
483 dest->u.condition[0].left_saturation = CLAMP(condition->left_sat[0]); |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
484 dest->u.condition[0].right_coeff = condition->right_coeff[0]; |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
485 dest->u.condition[0].left_coeff = condition->left_coeff[0]; |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
486 dest->u.condition[0].deadband = CLAMP(condition->deadband[0]); |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
487 dest->u.condition[0].center = condition->center[0]; |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
488 /* Y axis */ |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
489 dest->u.condition[1].right_saturation = CLAMP(condition->right_sat[1]); |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
490 dest->u.condition[1].left_saturation = CLAMP(condition->left_sat[1]); |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
491 dest->u.condition[1].right_coeff = condition->right_coeff[1]; |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
492 dest->u.condition[1].left_coeff = condition->left_coeff[1]; |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
493 dest->u.condition[1].deadband = CLAMP(condition->deadband[1]); |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
494 dest->u.condition[1].center = condition->center[1]; |
2482
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
495 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
496 break; |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
497 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
498 case SDL_HAPTIC_RAMP: |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
499 ramp = &src->ramp; |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
500 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
501 /* Header */ |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
502 dest->type = FF_RAMP; |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
503 dest->direction = SDL_SYS_ToDirection(&ramp->direction); |
2482
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
504 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
505 /* Replay */ |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
506 dest->replay.length = CLAMP(ramp->length); |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
507 dest->replay.delay = CLAMP(ramp->delay); |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
508 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
509 /* Trigger */ |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
510 dest->trigger.button = CLAMP(ramp->button); |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
511 dest->trigger.interval = CLAMP(ramp->interval); |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
512 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
513 /* Ramp */ |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
514 dest->u.ramp.start_level = ramp->start; |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
515 dest->u.ramp.end_level = ramp->end; |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
516 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
517 /* Envelope */ |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
518 dest->u.ramp.envelope.attack_length = CLAMP(ramp->attack_length); |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
519 dest->u.ramp.envelope.attack_level = CLAMP(ramp->attack_level); |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
520 dest->u.ramp.envelope.fade_length = CLAMP(ramp->fade_length); |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
521 dest->u.ramp.envelope.fade_level = CLAMP(ramp->fade_level); |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
522 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
523 break; |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
524 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
525 |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
526 default: |
2496
8f840a6cdf01
Using errno for more verbosity in errors.
Edgar Simo <bobbens@gmail.com>
parents:
2495
diff
changeset
|
527 SDL_SetError("Unknown haptic effect type"); |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
528 return -1; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
529 } |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
530 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
531 return 0; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
532 } |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
533 |
2483
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
534 |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
535 /* |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
536 * Creates a new haptic effect. |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
537 */ |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
538 int |
2480 | 539 SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect * effect, |
540 SDL_HapticEffect * base) | |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
541 { |
2480 | 542 struct ff_effect * linux_effect; |
543 | |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
544 /* Allocate the hardware effect */ |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
545 effect->hweffect = (struct haptic_hweffect *) |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
546 SDL_malloc(sizeof(struct haptic_hweffect)); |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
547 if (effect->hweffect == NULL) { |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
548 SDL_OutOfMemory(); |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
549 return -1; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
550 } |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
551 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
552 /* Prepare the ff_effect */ |
2480 | 553 linux_effect = &effect->hweffect->effect; |
554 if (SDL_SYS_ToFFEffect( linux_effect, base ) != 0) { | |
2488
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
555 goto new_effect_err; |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
556 } |
2480 | 557 linux_effect->id = -1; /* Have the kernel give it an id */ |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
558 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
559 /* Upload the effect */ |
2480 | 560 if (ioctl(haptic->hwdata->fd, EVIOCSFF, linux_effect) < 0) { |
2496
8f840a6cdf01
Using errno for more verbosity in errors.
Edgar Simo <bobbens@gmail.com>
parents:
2495
diff
changeset
|
561 SDL_SetError("Error uploading effect to the haptic device: %s", strerror(errno)); |
2488
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
562 goto new_effect_err; |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
563 } |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
564 |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
565 return 0; |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
566 |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
567 new_effect_err: |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
568 free(effect->hweffect); |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
569 effect->hweffect = NULL; |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
570 return -1; |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
571 } |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
572 |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
573 |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
574 /* |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
575 * Updates an effect. |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
576 * |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
577 * Note: Dynamically updating the direction can in some cases force |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
578 * the effect to restart and run once. |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
579 */ |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
580 int SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic, |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
581 struct haptic_effect * effect, SDL_HapticEffect * data) |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
582 { |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
583 struct ff_effect linux_effect; |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
584 |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
585 /* Create the new effect */ |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
586 if (SDL_SYS_ToFFEffect( &linux_effect, data ) != 0) { |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
587 return -1; |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
588 } |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
589 linux_effect.id = effect->hweffect->effect.id; |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
590 |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
591 /* See if it can be uploaded. */ |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
592 if (ioctl(haptic->hwdata->fd, EVIOCSFF, &linux_effect) < 0) { |
2496
8f840a6cdf01
Using errno for more verbosity in errors.
Edgar Simo <bobbens@gmail.com>
parents:
2495
diff
changeset
|
593 SDL_SetError("Error updating the haptic effect: %s", strerror(errno)); |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
594 return -1; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
595 } |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
596 |
2488
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
597 /* Copy the new effect into memory. */ |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
598 SDL_memcpy( &effect->hweffect->effect, &linux_effect, sizeof(struct ff_effect) ); |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
599 |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
600 return effect->hweffect->effect.id; |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
601 } |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
602 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
603 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
604 /* |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
605 * Runs an effect. |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
606 */ |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
607 int |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
608 SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect) |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
609 { |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
610 struct input_event run; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
611 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
612 /* Prepare to run the effect */ |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
613 run.type = EV_FF; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
614 run.code = effect->hweffect->effect.id; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
615 run.value = 1; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
616 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
617 if (write(haptic->hwdata->fd, (const void*) &run, sizeof(run)) < 0) { |
2496
8f840a6cdf01
Using errno for more verbosity in errors.
Edgar Simo <bobbens@gmail.com>
parents:
2495
diff
changeset
|
618 SDL_SetError("Unable to run the haptic effect: %s", strerror(errno)); |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
619 return -1; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
620 } |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
621 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
622 return 0; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
623 } |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
624 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
625 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
626 /* |
2485
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
627 * Stops an effect. |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
628 */ |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
629 int |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
630 SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect * effect) |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
631 { |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
632 struct input_event stop; |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
633 |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
634 stop.type = EV_FF; |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
635 stop.code = effect->hweffect->effect.id; |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
636 stop.value = 0; |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
637 |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
638 if (write(haptic->hwdata->fd, (const void*) &stop, sizeof(stop)) < 0) { |
2496
8f840a6cdf01
Using errno for more verbosity in errors.
Edgar Simo <bobbens@gmail.com>
parents:
2495
diff
changeset
|
639 SDL_SetError("Unable to stop the haptic effect: %s", strerror(errno)); |
2485
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
640 return -1; |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
641 } |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
642 |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
643 return 0; |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
644 } |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
645 |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
646 |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
647 /* |
2487
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
648 * Frees the effect. |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
649 */ |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
650 void |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
651 SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect * effect) |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
652 { |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
653 if (ioctl(haptic->hwdata->fd, EVIOCRMFF, effect->hweffect->effect.id) < 0) { |
2496
8f840a6cdf01
Using errno for more verbosity in errors.
Edgar Simo <bobbens@gmail.com>
parents:
2495
diff
changeset
|
654 SDL_SetError("Error removing the effect from the haptic device: %s", |
8f840a6cdf01
Using errno for more verbosity in errors.
Edgar Simo <bobbens@gmail.com>
parents:
2495
diff
changeset
|
655 strerror(errno)); |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
656 } |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
657 SDL_free(effect->hweffect); |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
658 effect->hweffect = NULL; |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
659 } |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
660 |
2474
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
661 |
2483
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
662 /* |
2495
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
663 * Gets the status of a haptic effect. |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
664 */ |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
665 int |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
666 SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect * effect) |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
667 { |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
668 #if 0 /* Not supported atm. */ |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
669 struct input_event ie; |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
670 |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
671 ie.type = EV_FF; |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
672 ie.type = EV_FF_STATUS; |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
673 ie.code = effect->hweffect->effect.id; |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
674 |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
675 if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) { |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
676 SDL_SetError("Error getting haptic device status."); |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
677 return -1; |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
678 } |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
679 |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
680 return 0; |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
681 #endif |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
682 |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
683 return -1; |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
684 } |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
685 |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
686 |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
687 /* |
2483
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
688 * Sets the gain. |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
689 */ |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
690 int |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
691 SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain) |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
692 { |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
693 struct input_event ie; |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
694 |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
695 ie.type = EV_FF; |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
696 ie.code = FF_GAIN; |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
697 ie.value = (0xFFFFUL * gain) / 100; |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
698 |
2484
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
699 if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) { |
2496
8f840a6cdf01
Using errno for more verbosity in errors.
Edgar Simo <bobbens@gmail.com>
parents:
2495
diff
changeset
|
700 SDL_SetError("Error setting gain: %s", strerror(errno)); |
2484
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
701 return -1; |
2483
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
702 } |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
703 |
2484
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
704 return 0; |
2483
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
705 } |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
706 |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
707 |
2484
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
708 /* |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
709 * Sets the autocentering. |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
710 */ |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
711 int |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
712 SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter) |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
713 { |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
714 struct input_event ie; |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
715 |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
716 ie.type = EV_FF; |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
717 ie.code = FF_AUTOCENTER; |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
718 ie.value = (0xFFFFUL * autocenter) / 100; |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
719 |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
720 if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) { |
2496
8f840a6cdf01
Using errno for more verbosity in errors.
Edgar Simo <bobbens@gmail.com>
parents:
2495
diff
changeset
|
721 SDL_SetError("Error setting autocenter: %s", strerror(errno)); |
2484
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
722 return -1; |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
723 } |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
724 |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
725 return 0; |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
726 } |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
727 |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
728 |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
729 #endif /* SDL_HAPTIC_LINUX */ |