Mercurial > sdl-ios-xcode
annotate src/haptic/linux/SDL_syshaptic.c @ 2646:9408be170bff gsoc2008_force_feedback
Added SDL_HapticStopAll.
Cleaned up the dummy haptic driver a bit.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Sun, 24 Aug 2008 17:32:50 +0000 |
parents | 269ba4f28d0e |
children | e871cff1e3d2 |
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 */ |
2644 | 33 #include <linux/input.h> /* Force feedback linux stuff. */ |
34 #include <fcntl.h> /* O_RDWR */ | |
2517
37c13c12c878
Broke API by introducing iterations to SDL_HapticRunEffects().
Edgar Simo <bobbens@gmail.com>
parents:
2515
diff
changeset
|
35 #include <limits.h> /* INT_MAX */ |
2644 | 36 #include <errno.h> /* errno, strerror */ |
37 #include <math.h> /* atan2 */ | |
2510
e6ad7e678fca
Implemented SDL_HAPTIC_CARTESIAN on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2503
diff
changeset
|
38 |
2644 | 39 /* Just in case. */ |
2510
e6ad7e678fca
Implemented SDL_HAPTIC_CARTESIAN on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2503
diff
changeset
|
40 #ifndef M_PI |
e6ad7e678fca
Implemented SDL_HAPTIC_CARTESIAN on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2503
diff
changeset
|
41 # define M_PI 3.14159265358979323846 |
e6ad7e678fca
Implemented SDL_HAPTIC_CARTESIAN on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2503
diff
changeset
|
42 #endif |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
43 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
44 |
2644 | 45 #define MAX_HAPTICS 32 /* It's doubtful someone has more then 32 evdev */ |
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 |
2475 | 48 /* |
49 * List of available haptic devices. | |
50 */ | |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
51 static struct |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
52 { |
2644 | 53 char *fname; /* Dev path name (like /dev/input/event1) */ |
54 SDL_Haptic *haptic; /* Assosciated haptic. */ | |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
55 } SDL_hapticlist[MAX_HAPTICS]; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
56 |
2475 | 57 |
58 /* | |
59 * Haptic system hardware data. | |
60 */ | |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
61 struct haptic_hwdata |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
62 { |
2644 | 63 int fd; /* File descriptor of the device. */ |
2524
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
64 char *fname; /* Points to the name in SDL_hapticlist. */ |
2472
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 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
67 |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
68 /* |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
69 * Haptic system effect data. |
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 struct haptic_hweffect |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
72 { |
2511
f12ae0bae468
Fixed bugs in documentation.
Edgar Simo <bobbens@gmail.com>
parents:
2510
diff
changeset
|
73 struct ff_effect effect; /* The linux kernel effect structure. */ |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
74 }; |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
75 |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
76 |
2475 | 77 |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
78 #define test_bit(nr, addr) \ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
79 (((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
|
80 #define EV_TEST(ev,f) \ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
81 if (test_bit((ev), features)) ret |= (f); |
2475 | 82 /* |
83 * Test whether a device has haptic properties. | |
84 * Returns available properties or 0 if there are none. | |
85 */ | |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
86 static int |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
87 EV_IsHaptic(int fd) |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
88 { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
89 unsigned int ret; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
90 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
|
91 |
2512
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
92 /* Ask device for what it has. */ |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
93 ret = 0; |
2512
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
94 if (ioctl(fd, EVIOCGBIT(EV_FF, sizeof(features)), features) < 0) { |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
95 SDL_SetError("Haptic: Unable to get device's features: %s", strerror(errno)); |
2490 | 96 return -1; |
97 } | |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
98 |
2512
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
99 /* Convert supported features to SDL_HAPTIC platform-neutral features. */ |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
100 EV_TEST(FF_CONSTANT, SDL_HAPTIC_CONSTANT); |
2635
318e67011ad9
Linux documentation was off, periodic does not imply all the individual effects.
Edgar Simo <bobbens@gmail.com>
parents:
2634
diff
changeset
|
101 EV_TEST(FF_SINE, SDL_HAPTIC_SINE); |
318e67011ad9
Linux documentation was off, periodic does not imply all the individual effects.
Edgar Simo <bobbens@gmail.com>
parents:
2634
diff
changeset
|
102 EV_TEST(FF_SQUARE, SDL_HAPTIC_SQUARE); |
318e67011ad9
Linux documentation was off, periodic does not imply all the individual effects.
Edgar Simo <bobbens@gmail.com>
parents:
2634
diff
changeset
|
103 EV_TEST(FF_TRIANGLE, SDL_HAPTIC_TRIANGLE); |
318e67011ad9
Linux documentation was off, periodic does not imply all the individual effects.
Edgar Simo <bobbens@gmail.com>
parents:
2634
diff
changeset
|
104 EV_TEST(FF_SAW_UP, SDL_HAPTIC_SAWTOOTHUP); |
318e67011ad9
Linux documentation was off, periodic does not imply all the individual effects.
Edgar Simo <bobbens@gmail.com>
parents:
2634
diff
changeset
|
105 EV_TEST(FF_SAW_DOWN, SDL_HAPTIC_SAWTOOTHDOWN); |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
106 EV_TEST(FF_RAMP, SDL_HAPTIC_RAMP); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
107 EV_TEST(FF_SPRING, SDL_HAPTIC_SPRING); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
108 EV_TEST(FF_FRICTION, SDL_HAPTIC_FRICTION); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
109 EV_TEST(FF_DAMPER, SDL_HAPTIC_DAMPER); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
110 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
|
111 EV_TEST(FF_CUSTOM, SDL_HAPTIC_CUSTOM); |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
112 EV_TEST(FF_GAIN, SDL_HAPTIC_GAIN); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
113 EV_TEST(FF_AUTOCENTER, SDL_HAPTIC_AUTOCENTER); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
114 |
2512
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
115 /* Return what it supports. */ |
2472
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 |
2512
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
119 |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
120 /* |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
121 * Tests whether a device is a mouse or not. |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
122 */ |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
123 static int |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
124 EV_IsMouse(int fd) |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
125 { |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
126 unsigned long argp[40]; |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
127 |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
128 /* Ask for supported features. */ |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
129 if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(argp)), argp) < 0) { |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
130 return -1; |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
131 } |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
132 |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
133 /* Currently we only test for BTN_MOUSE which can give fake positives. */ |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
134 if (test_bit(BTN_MOUSE,argp) != 0) { |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
135 return 1; |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
136 } |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
137 |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
138 return 0; |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
139 } |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
140 |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
141 /* |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
142 * Initializes the haptic subsystem by finding available devices. |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
143 */ |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
144 int |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
145 SDL_SYS_HapticInit(void) |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
146 { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
147 const char joydev_pattern[] = "/dev/input/event%d"; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
148 dev_t dev_nums[MAX_HAPTICS]; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
149 char path[PATH_MAX]; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
150 struct stat sb; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
151 int fd; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
152 int i, j, k; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
153 int duplicate; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
154 int numhaptics; |
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 numhaptics = 0; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
157 |
2512
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
158 /* |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
159 * Limit amount of checks to MAX_HAPTICS since we may or may not have |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
160 * permission to some or all devices. |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
161 */ |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
162 i = 0; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
163 for (j = 0; j < MAX_HAPTICS; ++j) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
164 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
165 snprintf(path, PATH_MAX, joydev_pattern, i++); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
166 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
167 /* check to see if file exists */ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
168 if (stat(path,&sb) != 0) |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
169 break; |
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 /* check for duplicates */ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
172 duplicate = 0; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
173 for (k = 0; (k < numhaptics) && !duplicate; ++k) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
174 if (sb.st_rdev == dev_nums[k]) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
175 duplicate = 1; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
176 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
177 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
178 if (duplicate) { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
179 continue; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
180 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
181 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
182 /* try to open */ |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
183 fd = open(path, O_RDWR, 0); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
184 if (fd < 0) continue; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
185 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
186 #ifdef DEBUG_INPUT_EVENTS |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
187 printf("Checking %s\n", path); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
188 #endif |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
189 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
190 /* see if it works */ |
2490 | 191 if (EV_IsHaptic(fd) > 0) { |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
192 SDL_hapticlist[numhaptics].fname = SDL_strdup(path); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
193 SDL_hapticlist[numhaptics].haptic = NULL; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
194 dev_nums[numhaptics] = sb.st_rdev; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
195 ++numhaptics; |
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 close(fd); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
198 } |
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 numhaptics; |
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 /* |
2524
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
205 * Gets the name from a file descriptor. |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
206 */ |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
207 static const char * |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
208 SDL_SYS_HapticNameFromFD(int fd) |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
209 { |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
210 static char namebuf[128]; |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
211 |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
212 /* We use the evdev name ioctl. */ |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
213 if (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) { |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
214 return NULL; |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
215 } |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
216 |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
217 return namebuf; |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
218 } |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
219 |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
220 |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
221 /* |
2475 | 222 * Return the name of a haptic device, does not need to be opened. |
223 */ | |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
224 const char * |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
225 SDL_SYS_HapticName(int index) |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
226 { |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
227 int fd; |
2524
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
228 const char *name; |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
229 |
2512
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
230 /* Open the haptic device. */ |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
231 name = NULL; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
232 fd = open(SDL_hapticlist[index].fname, O_RDONLY, 0); |
2512
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
233 |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
234 if (fd >= 0) { |
2512
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
235 |
2524
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
236 name = SDL_SYS_HapticNameFromFD(fd); |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
237 if (name==NULL) { |
2512
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
238 /* No name found, return device character device */ |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
239 name = SDL_hapticlist[index].fname; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
240 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
241 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
242 close(fd); |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
243 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
244 return name; |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
245 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
246 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
247 |
2475 | 248 /* |
2490 | 249 * Opens the haptic device from the file descriptor. |
2475 | 250 */ |
2490 | 251 static int |
252 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
|
253 { |
2524
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
254 const char *name; |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
255 |
2476
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
256 /* Allocate the hwdata */ |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
257 haptic->hwdata = (struct haptic_hwdata *) |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
258 SDL_malloc(sizeof(*haptic->hwdata)); |
2476
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
259 if (haptic->hwdata == NULL) { |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
260 SDL_OutOfMemory(); |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
261 goto open_err; |
2476
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
262 } |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
263 SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); |
2512
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
264 |
2524
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
265 /* Set the data. */ |
2476
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
266 haptic->hwdata->fd = fd; |
2478
4fd783e0f34b
Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2477
diff
changeset
|
267 haptic->supported = EV_IsHaptic(fd); |
2523
366d84fdf8d1
Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents:
2519
diff
changeset
|
268 haptic->naxes = 2; /* Hardcoded for now, not sure if it's possible to find out. */ |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
269 |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
270 /* Set the effects */ |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
271 if (ioctl(fd, EVIOCGEFFECTS, &haptic->neffects) < 0) { |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
272 SDL_SetError("Haptic: Unable to query device memory: %s", strerror(errno)); |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
273 goto open_err; |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
274 } |
2515
030fc4375e63
Added SDL_HapticNumEffectsPlaying().
Edgar Simo <bobbens@gmail.com>
parents:
2513
diff
changeset
|
275 haptic->nplaying = haptic->neffects; /* Linux makes no distinction. */ |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
276 haptic->effects = (struct haptic_effect *) |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
277 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
|
278 if (haptic->effects == NULL) { |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
279 SDL_OutOfMemory(); |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
280 goto open_err; |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
281 } |
2483
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
282 /* Clear the memory */ |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
283 SDL_memset(haptic->effects, 0, |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
284 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
|
285 |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
286 return 0; |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
287 |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
288 /* Error handling */ |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
289 open_err: |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
290 close(fd); |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
291 if (haptic->hwdata != NULL) { |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
292 free(haptic->hwdata); |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
293 haptic->hwdata = NULL; |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
294 } |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
295 return -1; |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
296 } |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
297 |
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
298 |
2475 | 299 /* |
2490 | 300 * Opens a haptic device for usage. |
301 */ | |
302 int | |
303 SDL_SYS_HapticOpen(SDL_Haptic * haptic) | |
304 { | |
305 int fd; | |
2524
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
306 int ret; |
2490 | 307 |
308 /* Open the character device */ | |
309 fd = open(SDL_hapticlist[haptic->index].fname, O_RDWR, 0); | |
310 if (fd < 0) { | |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
311 SDL_SetError("Haptic: Unable to open %s: %s", |
2496
8f840a6cdf01
Using errno for more verbosity in errors.
Edgar Simo <bobbens@gmail.com>
parents:
2495
diff
changeset
|
312 SDL_hapticlist[haptic->index], strerror(errno)); |
2490 | 313 return -1; |
314 } | |
2524
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
315 |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
316 /* Try to create the haptic. */ |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
317 ret = SDL_SYS_HapticOpenFromFD(haptic,fd); /* Already closes on error. */ |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
318 if (ret < 0) { |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
319 return -1; |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
320 } |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
321 |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
322 /* Set the fname. */ |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
323 haptic->hwdata->fname = SDL_hapticlist[haptic->index].fname; |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
324 return 0; |
2512
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
325 } |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
326 |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
327 |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
328 /* |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
329 * Opens a haptic device from first mouse it finds for usage. |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
330 */ |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
331 int |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
332 SDL_SYS_HapticMouse(void) |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
333 { |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
334 int fd; |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
335 int i; |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
336 |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
337 for (i=0; i<SDL_numhaptics; i++) { |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
338 |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
339 /* Open the device. */ |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
340 fd = open(SDL_hapticlist[i].fname, O_RDWR, 0); |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
341 if (fd < 0) { |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
342 SDL_SetError("Haptic: Unable to open %s: %s", |
2512
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
343 SDL_hapticlist[i], strerror(errno)); |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
344 return -1; |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
345 } |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
346 |
2644 | 347 /* Is it a mouse? */ |
2512
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
348 if (EV_IsMouse(fd)) { |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
349 close(fd); |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
350 return i; |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
351 } |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
352 |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
353 close(fd); |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
354 } |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
355 |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
356 return -1; |
ef147ee4896c
Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents:
2511
diff
changeset
|
357 } |
2490 | 358 |
359 | |
360 /* | |
2489
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
361 * 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
|
362 */ |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
363 int |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
364 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
|
365 { |
2490 | 366 return EV_IsHaptic(joystick->hwdata->fd); |
367 } | |
368 | |
369 | |
370 /* | |
371 * Checks to see if the haptic device and joystick and in reality the same. | |
372 */ | |
373 int | |
374 SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick) | |
375 { | |
2524
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
376 /* We are assuming linux is using evdev which should trump the old |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
377 * joystick methods. */ |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
378 if (SDL_strcmp(joystick->hwdata->fname,haptic->hwdata->fname)==0) { |
2489
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
379 return 1; |
2490 | 380 } |
2489
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
381 return 0; |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
382 } |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
383 |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
384 |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
385 /* |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
386 * 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
|
387 */ |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
388 int |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
389 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
|
390 { |
2524
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
391 int i; |
2490 | 392 int fd; |
2524
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
393 int ret; |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
394 |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
395 /* Find the joystick in the haptic list. */ |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
396 for (i=0; i<MAX_HAPTICS; i++) { |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
397 if (SDL_hapticlist[i].fname != NULL) { |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
398 if (SDL_strcmp(SDL_hapticlist[i].fname, joystick->hwdata->fname)==0) { |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
399 haptic->index = i; |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
400 } |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
401 } |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
402 } |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
403 |
2490 | 404 fd = open(joystick->hwdata->fname, O_RDWR, 0); |
2524
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
405 ret = SDL_SYS_HapticOpenFromFD(haptic,fd); /* Already closes on error. */ |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
406 if (ret < 0) { |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
407 return -1; |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
408 } |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
409 |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
410 haptic->hwdata->fname = SDL_hapticlist[haptic->index].fname; |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
411 return 0; |
2489
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
412 } |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
413 |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
414 |
96adc8025331
Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2488
diff
changeset
|
415 /* |
2475 | 416 * Closes the haptic device. |
417 */ | |
418 void | |
419 SDL_SYS_HapticClose(SDL_Haptic * haptic) | |
420 { | |
2476
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
421 if (haptic->hwdata) { |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
422 |
2561
3696b9ce8a37
Correctness patch, it's up to the SDL_haptic.c to clean up effects, not SDL_syshaptic.c.
Edgar Simo <bobbens@gmail.com>
parents:
2556
diff
changeset
|
423 /* Free effects. */ |
3696b9ce8a37
Correctness patch, it's up to the SDL_haptic.c to clean up effects, not SDL_syshaptic.c.
Edgar Simo <bobbens@gmail.com>
parents:
2556
diff
changeset
|
424 SDL_free(haptic->effects); |
3696b9ce8a37
Correctness patch, it's up to the SDL_haptic.c to clean up effects, not SDL_syshaptic.c.
Edgar Simo <bobbens@gmail.com>
parents:
2556
diff
changeset
|
425 haptic->effects = NULL; |
3696b9ce8a37
Correctness patch, it's up to the SDL_haptic.c to clean up effects, not SDL_syshaptic.c.
Edgar Simo <bobbens@gmail.com>
parents:
2556
diff
changeset
|
426 haptic->neffects = 0; |
3696b9ce8a37
Correctness patch, it's up to the SDL_haptic.c to clean up effects, not SDL_syshaptic.c.
Edgar Simo <bobbens@gmail.com>
parents:
2556
diff
changeset
|
427 |
2476
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
428 /* Clean up */ |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
429 close(haptic->hwdata->fd); |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
430 |
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
431 /* Free */ |
2561
3696b9ce8a37
Correctness patch, it's up to the SDL_haptic.c to clean up effects, not SDL_syshaptic.c.
Edgar Simo <bobbens@gmail.com>
parents:
2556
diff
changeset
|
432 SDL_free(haptic->hwdata); |
3696b9ce8a37
Correctness patch, it's up to the SDL_haptic.c to clean up effects, not SDL_syshaptic.c.
Edgar Simo <bobbens@gmail.com>
parents:
2556
diff
changeset
|
433 haptic->hwdata = NULL; |
2476
242d8a668ebb
* Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2475
diff
changeset
|
434 } |
2524
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
435 |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
436 /* Clear the rest. */ |
1a55848ce198
Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents:
2523
diff
changeset
|
437 SDL_memset(haptic, 0, sizeof(SDL_Haptic)); |
2475 | 438 } |
439 | |
440 | |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
441 /* |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
442 * 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
|
443 */ |
2474
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
444 void |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
445 SDL_SYS_HapticQuit(void) |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
446 { |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
447 int i; |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
448 |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
449 for (i=0; SDL_hapticlist[i].fname != NULL; i++) { |
2530 | 450 /* Opened and not closed haptics are leaked, this is on purpose. |
451 * Close your haptic devices after usage. */ | |
452 | |
2474
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
453 SDL_free(SDL_hapticlist[i].fname); |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
454 } |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
455 SDL_hapticlist[0].fname = NULL; |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
456 } |
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
457 |
2556
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
458 |
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
459 /* |
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
460 * Converts an SDL button to a ff_trigger button. |
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
461 */ |
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
462 static Uint16 |
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
463 SDL_SYS_ToButton( Uint16 button ) |
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
464 { |
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
465 Uint16 ff_button; |
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
466 |
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
467 ff_button = 0; |
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
468 |
2644 | 469 /* |
470 * Not sure what the proper syntax is because this actually isn't implemented | |
471 * in the current kernel from what I've seen (2.6.26). | |
472 */ | |
2556
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
473 if (button != 0) { |
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
474 ff_button = BTN_GAMEPAD + button - 1; |
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
475 } |
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
476 |
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
477 return ff_button; |
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
478 } |
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
479 |
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
480 |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
481 /* |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
482 * 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
|
483 */ |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
484 static Uint16 |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
485 SDL_SYS_ToDirection( SDL_HapticDirection * dir ) |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
486 { |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
487 Uint32 tmp; |
2511
f12ae0bae468
Fixed bugs in documentation.
Edgar Simo <bobbens@gmail.com>
parents:
2510
diff
changeset
|
488 float f; /* Ideally we'd use fixed point math instead of floats... */ |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
489 |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
490 switch (dir->type) { |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
491 case SDL_HAPTIC_POLAR: |
2502
5356ca0c36a3
Fixed linux directions being inverted.
Edgar Simo <bobbens@gmail.com>
parents:
2500
diff
changeset
|
492 /* Linux directions are inverted. */ |
5356ca0c36a3
Fixed linux directions being inverted.
Edgar Simo <bobbens@gmail.com>
parents:
2500
diff
changeset
|
493 tmp = (((18000 + dir->dir[0]) % 36000) * 0xFFFF) / 36000; |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
494 return (Uint16) tmp; |
2523
366d84fdf8d1
Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents:
2519
diff
changeset
|
495 |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
496 case SDL_HAPTIC_CARTESIAN: |
2511
f12ae0bae468
Fixed bugs in documentation.
Edgar Simo <bobbens@gmail.com>
parents:
2510
diff
changeset
|
497 /* We must invert "x" and "y" to go clockwise. */ |
2510
e6ad7e678fca
Implemented SDL_HAPTIC_CARTESIAN on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2503
diff
changeset
|
498 f = atan2(dir->dir[0], dir->dir[1]); |
e6ad7e678fca
Implemented SDL_HAPTIC_CARTESIAN on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2503
diff
changeset
|
499 tmp = (int)(f*18000./M_PI) % 36000; |
e6ad7e678fca
Implemented SDL_HAPTIC_CARTESIAN on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2503
diff
changeset
|
500 tmp = (tmp * 0xFFFF) / 36000; |
e6ad7e678fca
Implemented SDL_HAPTIC_CARTESIAN on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2503
diff
changeset
|
501 return (Uint16) tmp; |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
502 |
2523
366d84fdf8d1
Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents:
2519
diff
changeset
|
503 case SDL_HAPTIC_SPHERICAL: |
366d84fdf8d1
Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents:
2519
diff
changeset
|
504 tmp = (36000 - dir->dir[0]) + 27000; /* Convert to polars */ |
366d84fdf8d1
Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents:
2519
diff
changeset
|
505 tmp = (((18000 + tmp) % 36000) * 0xFFFF) / 36000; |
366d84fdf8d1
Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents:
2519
diff
changeset
|
506 return (Uint16) tmp; |
366d84fdf8d1
Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents:
2519
diff
changeset
|
507 |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
508 default: |
2523
366d84fdf8d1
Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents:
2519
diff
changeset
|
509 SDL_SetError("Haptic: Unsupported direction type."); |
2634 | 510 return (Uint16)-1; |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
511 } |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
512 |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
513 return 0; |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
514 } |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
515 |
2556
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
516 |
2481 | 517 #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
|
518 /* |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
519 * Initializes the linux effect struct from a haptic_effect. |
2481 | 520 * 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
|
521 */ |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
522 static int |
2480 | 523 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
|
524 { |
2526 | 525 Uint32 tmp; |
2480 | 526 SDL_HapticConstant *constant; |
527 SDL_HapticPeriodic *periodic; | |
2482
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
528 SDL_HapticCondition *condition; |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
529 SDL_HapticRamp *ramp; |
2480 | 530 |
531 /* Clear up */ | |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
532 SDL_memset(dest, 0, sizeof(struct ff_effect)); |
2480 | 533 |
534 switch (src->type) { | |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
535 case SDL_HAPTIC_CONSTANT: |
2480 | 536 constant = &src->constant; |
537 | |
538 /* Header */ | |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
539 dest->type = FF_CONSTANT; |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
540 dest->direction = SDL_SYS_ToDirection(&constant->direction); |
2634 | 541 if (dest->direction == (Uint16)-1) return -1; |
2480 | 542 |
543 /* Replay */ | |
2539
b4c41a7eea04
Properly support INFINITY length haptic effects on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2530
diff
changeset
|
544 dest->replay.length = (constant->length == SDL_HAPTIC_INFINITY) ? |
b4c41a7eea04
Properly support INFINITY length haptic effects on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2530
diff
changeset
|
545 0 : CLAMP(constant->length); |
2481 | 546 dest->replay.delay = CLAMP(constant->delay); |
2480 | 547 |
548 /* Trigger */ | |
2556
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
549 dest->trigger.button = SDL_SYS_ToButton(constant->button); |
2481 | 550 dest->trigger.interval = CLAMP(constant->interval); |
2480 | 551 |
552 /* Constant */ | |
553 dest->u.constant.level = constant->level; | |
554 | |
555 /* Envelope */ | |
2481 | 556 dest->u.constant.envelope.attack_length = CLAMP(constant->attack_length); |
557 dest->u.constant.envelope.attack_level = CLAMP(constant->attack_level); | |
558 dest->u.constant.envelope.fade_length = CLAMP(constant->fade_length); | |
559 dest->u.constant.envelope.fade_level = CLAMP(constant->fade_level); | |
2480 | 560 |
561 break; | |
562 | |
2487
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
563 case SDL_HAPTIC_SINE: |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
564 case SDL_HAPTIC_SQUARE: |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
565 case SDL_HAPTIC_TRIANGLE: |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
566 case SDL_HAPTIC_SAWTOOTHUP: |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
567 case SDL_HAPTIC_SAWTOOTHDOWN: |
2480 | 568 periodic = &src->periodic; |
569 | |
570 /* Header */ | |
571 dest->type = FF_PERIODIC; | |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
572 dest->direction = SDL_SYS_ToDirection(&periodic->direction); |
2634 | 573 if (dest->direction == (Uint16)-1) return -1; |
2480 | 574 |
575 /* Replay */ | |
2539
b4c41a7eea04
Properly support INFINITY length haptic effects on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2530
diff
changeset
|
576 dest->replay.length = (periodic->length == SDL_HAPTIC_INFINITY) ? |
b4c41a7eea04
Properly support INFINITY length haptic effects on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2530
diff
changeset
|
577 0 : CLAMP(periodic->length); |
2481 | 578 dest->replay.delay = CLAMP(periodic->delay); |
2480 | 579 |
580 /* Trigger */ | |
2556
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
581 dest->trigger.button = SDL_SYS_ToButton(periodic->button); |
2481 | 582 dest->trigger.interval = CLAMP(periodic->interval); |
2480 | 583 |
2487
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
584 /* Periodic */ |
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
585 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
|
586 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
|
587 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
|
588 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
|
589 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
|
590 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
|
591 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
|
592 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
|
593 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
|
594 dest->u.periodic.waveform = FF_SAW_DOWN; |
2481 | 595 dest->u.periodic.period = CLAMP(periodic->period); |
2480 | 596 dest->u.periodic.magnitude = periodic->magnitude; |
597 dest->u.periodic.offset = periodic->offset; | |
2526 | 598 /* Phase is calculated based of offset from period and then clamped. */ |
599 tmp = ((periodic->phase % 36000) * dest->u.periodic.period) / 36000; | |
600 dest->u.periodic.phase = CLAMP(tmp); | |
2480 | 601 |
602 /* Envelope */ | |
2481 | 603 dest->u.periodic.envelope.attack_length = CLAMP(periodic->attack_length); |
604 dest->u.periodic.envelope.attack_level = CLAMP(periodic->attack_level); | |
605 dest->u.periodic.envelope.fade_length = CLAMP(periodic->fade_length); | |
606 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
|
607 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
608 break; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
609 |
2482
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
610 case SDL_HAPTIC_SPRING: |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
611 case SDL_HAPTIC_DAMPER: |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
612 case SDL_HAPTIC_INERTIA: |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
613 case SDL_HAPTIC_FRICTION: |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
614 condition = &src->condition; |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
615 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
616 /* Header */ |
2503
84a634009a83
Another important typo mistake.
Edgar Simo <bobbens@gmail.com>
parents:
2502
diff
changeset
|
617 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
|
618 dest->type = FF_SPRING; |
2503
84a634009a83
Another important typo mistake.
Edgar Simo <bobbens@gmail.com>
parents:
2502
diff
changeset
|
619 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
|
620 dest->type = FF_DAMPER; |
2503
84a634009a83
Another important typo mistake.
Edgar Simo <bobbens@gmail.com>
parents:
2502
diff
changeset
|
621 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
|
622 dest->type = FF_INERTIA; |
2503
84a634009a83
Another important typo mistake.
Edgar Simo <bobbens@gmail.com>
parents:
2502
diff
changeset
|
623 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
|
624 dest->type = FF_FRICTION; |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
625 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
|
626 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
627 /* Replay */ |
2539
b4c41a7eea04
Properly support INFINITY length haptic effects on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2530
diff
changeset
|
628 dest->replay.length = (condition->length == SDL_HAPTIC_INFINITY) ? |
b4c41a7eea04
Properly support INFINITY length haptic effects on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2530
diff
changeset
|
629 0 : CLAMP(condition->length); |
2482
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
630 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
|
631 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
632 /* Trigger */ |
2556
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
633 dest->trigger.button = SDL_SYS_ToButton(condition->button); |
2482
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
634 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
|
635 |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
636 /* Condition */ |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
637 /* X axis */ |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
638 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
|
639 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
|
640 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
|
641 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
|
642 dest->u.condition[0].deadband = CLAMP(condition->deadband[0]); |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
643 dest->u.condition[0].center = condition->center[0]; |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
644 /* Y axis */ |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
645 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
|
646 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
|
647 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
|
648 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
|
649 dest->u.condition[1].deadband = CLAMP(condition->deadband[1]); |
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
650 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
|
651 |
2644 | 652 /* |
653 * There is no envelope in the linux force feedback api for conditions. | |
654 */ | |
655 | |
2482
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
656 break; |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
657 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
658 case SDL_HAPTIC_RAMP: |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
659 ramp = &src->ramp; |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
660 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
661 /* Header */ |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
662 dest->type = FF_RAMP; |
2500
5251d0510b7e
Implemented polar coordinates in linux.
Edgar Simo <bobbens@gmail.com>
parents:
2496
diff
changeset
|
663 dest->direction = SDL_SYS_ToDirection(&ramp->direction); |
2634 | 664 if (dest->direction == (Uint16)-1) return -1; |
2482
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
665 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
666 /* Replay */ |
2539
b4c41a7eea04
Properly support INFINITY length haptic effects on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2530
diff
changeset
|
667 dest->replay.length = (ramp->length == SDL_HAPTIC_INFINITY) ? |
b4c41a7eea04
Properly support INFINITY length haptic effects on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2530
diff
changeset
|
668 0 : CLAMP(ramp->length); |
2482
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
669 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
|
670 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
671 /* Trigger */ |
2556
fe346eddd3fb
Updated button trigger stuff.
Edgar Simo <bobbens@gmail.com>
parents:
2539
diff
changeset
|
672 dest->trigger.button = SDL_SYS_ToButton(ramp->button); |
2482
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
673 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
|
674 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
675 /* Ramp */ |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
676 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
|
677 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
|
678 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
679 /* Envelope */ |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
680 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
|
681 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
|
682 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
|
683 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
|
684 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
685 break; |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
686 |
b51ad78812d5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents:
2481
diff
changeset
|
687 |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
688 default: |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
689 SDL_SetError("Haptic: Unknown effect type."); |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
690 return -1; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
691 } |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
692 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
693 return 0; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
694 } |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
695 |
2483
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
696 |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
697 /* |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
698 * Creates a new haptic effect. |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
699 */ |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
700 int |
2480 | 701 SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect * effect, |
702 SDL_HapticEffect * base) | |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
703 { |
2480 | 704 struct ff_effect * linux_effect; |
705 | |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
706 /* Allocate the hardware effect */ |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
707 effect->hweffect = (struct haptic_hweffect *) |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
708 SDL_malloc(sizeof(struct haptic_hweffect)); |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
709 if (effect->hweffect == NULL) { |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
710 SDL_OutOfMemory(); |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
711 return -1; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
712 } |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
713 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
714 /* Prepare the ff_effect */ |
2480 | 715 linux_effect = &effect->hweffect->effect; |
716 if (SDL_SYS_ToFFEffect( linux_effect, base ) != 0) { | |
2488
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
717 goto new_effect_err; |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
718 } |
2480 | 719 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
|
720 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
721 /* Upload the effect */ |
2480 | 722 if (ioctl(haptic->hwdata->fd, EVIOCSFF, linux_effect) < 0) { |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
723 SDL_SetError("Haptic: Error uploading effect to the device: %s", strerror(errno)); |
2488
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
724 goto new_effect_err; |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
725 } |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
726 |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
727 return 0; |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
728 |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
729 new_effect_err: |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
730 free(effect->hweffect); |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
731 effect->hweffect = NULL; |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
732 return -1; |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
733 } |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
734 |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
735 |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
736 /* |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
737 * Updates an effect. |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
738 * |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
739 * Note: Dynamically updating the direction can in some cases force |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
740 * the effect to restart and run once. |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
741 */ |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
742 int SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic, |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
743 struct haptic_effect * effect, SDL_HapticEffect * data) |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
744 { |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
745 struct ff_effect linux_effect; |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
746 |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
747 /* Create the new effect */ |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
748 if (SDL_SYS_ToFFEffect( &linux_effect, data ) != 0) { |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
749 return -1; |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
750 } |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
751 linux_effect.id = effect->hweffect->effect.id; |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
752 |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
753 /* See if it can be uploaded. */ |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
754 if (ioctl(haptic->hwdata->fd, EVIOCSFF, &linux_effect) < 0) { |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
755 SDL_SetError("Haptic: Error updating the effect: %s", strerror(errno)); |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
756 return -1; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
757 } |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
758 |
2488
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
759 /* Copy the new effect into memory. */ |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
760 SDL_memcpy( &effect->hweffect->effect, &linux_effect, sizeof(struct ff_effect) ); |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
761 |
8e2bdbccf7ff
Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2487
diff
changeset
|
762 return effect->hweffect->effect.id; |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
763 } |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
764 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
765 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
766 /* |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
767 * Runs an effect. |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
768 */ |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
769 int |
2519
af9df9662807
More explicit with iterations and length.
Edgar Simo <bobbens@gmail.com>
parents:
2518
diff
changeset
|
770 SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect, |
af9df9662807
More explicit with iterations and length.
Edgar Simo <bobbens@gmail.com>
parents:
2518
diff
changeset
|
771 Uint32 iterations) |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
772 { |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
773 struct input_event run; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
774 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
775 /* Prepare to run the effect */ |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
776 run.type = EV_FF; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
777 run.code = effect->hweffect->effect.id; |
2539
b4c41a7eea04
Properly support INFINITY length haptic effects on linux.
Edgar Simo <bobbens@gmail.com>
parents:
2530
diff
changeset
|
778 /* We don't actually have infinity here, so we just do INT_MAX which is pretty damn close. */ |
2519
af9df9662807
More explicit with iterations and length.
Edgar Simo <bobbens@gmail.com>
parents:
2518
diff
changeset
|
779 run.value = (iterations > INT_MAX) ? INT_MAX : iterations; |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
780 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
781 if (write(haptic->hwdata->fd, (const void*) &run, sizeof(run)) < 0) { |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
782 SDL_SetError("Haptic: Unable to run the effect: %s", strerror(errno)); |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
783 return -1; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
784 } |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
785 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
786 return 0; |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
787 } |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
788 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
789 |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
790 /* |
2485
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
791 * Stops an effect. |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
792 */ |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
793 int |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
794 SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect * effect) |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
795 { |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
796 struct input_event stop; |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
797 |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
798 stop.type = EV_FF; |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
799 stop.code = effect->hweffect->effect.id; |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
800 stop.value = 0; |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
801 |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
802 if (write(haptic->hwdata->fd, (const void*) &stop, sizeof(stop)) < 0) { |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
803 SDL_SetError("Haptic: Unable to stop the effect: %s", strerror(errno)); |
2485
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
804 return -1; |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
805 } |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
806 |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
807 return 0; |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
808 } |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
809 |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
810 |
67978eea6d10
Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents:
2484
diff
changeset
|
811 /* |
2487
4c8e25ef2d97
Merged seperate waveforms into types to be more compatible.
Edgar Simo <bobbens@gmail.com>
parents:
2486
diff
changeset
|
812 * Frees the effect. |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
813 */ |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
814 void |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
815 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
|
816 { |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
817 if (ioctl(haptic->hwdata->fd, EVIOCRMFF, effect->hweffect->effect.id) < 0) { |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
818 SDL_SetError("Haptic: Error removing the effect from the device: %s", |
2496
8f840a6cdf01
Using errno for more verbosity in errors.
Edgar Simo <bobbens@gmail.com>
parents:
2495
diff
changeset
|
819 strerror(errno)); |
2479
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
820 } |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
821 SDL_free(effect->hweffect); |
b9eb2cfe16cd
Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents:
2478
diff
changeset
|
822 effect->hweffect = NULL; |
2477
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
823 } |
97f75ea43a93
Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents:
2476
diff
changeset
|
824 |
2474
3f80bf1528b4
Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
2472
diff
changeset
|
825 |
2483
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
826 /* |
2495
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
827 * Gets the status of a haptic effect. |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
828 */ |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
829 int |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
830 SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect * effect) |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
831 { |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
832 #if 0 /* Not supported atm. */ |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
833 struct input_event ie; |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
834 |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
835 ie.type = EV_FF; |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
836 ie.type = EV_FF_STATUS; |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
837 ie.code = effect->hweffect->effect.id; |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
838 |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
839 if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) { |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
840 SDL_SetError("Haptic: Error getting device status."); |
2495
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
841 return -1; |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
842 } |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
843 |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
844 return 0; |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
845 #endif |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
846 |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
847 return -1; |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
848 } |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
849 |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
850 |
66c02abeef0e
Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents:
2493
diff
changeset
|
851 /* |
2483
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
852 * Sets the gain. |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
853 */ |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
854 int |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
855 SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain) |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
856 { |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
857 struct input_event ie; |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
858 |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
859 ie.type = EV_FF; |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
860 ie.code = FF_GAIN; |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
861 ie.value = (0xFFFFUL * gain) / 100; |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
862 |
2484
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
863 if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) { |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
864 SDL_SetError("Haptic: 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
|
865 return -1; |
2483
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
866 } |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
867 |
2484
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
868 return 0; |
2483
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
869 } |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
870 |
9d52368ebcf5
Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents:
2482
diff
changeset
|
871 |
2484
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
872 /* |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
873 * Sets the autocentering. |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
874 */ |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
875 int |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
876 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
|
877 { |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
878 struct input_event ie; |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
879 |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
880 ie.type = EV_FF; |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
881 ie.code = FF_AUTOCENTER; |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
882 ie.value = (0xFFFFUL * autocenter) / 100; |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
883 |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
884 if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) { |
2513
55fd9103a330
Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents:
2512
diff
changeset
|
885 SDL_SetError("Haptic: 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
|
886 return -1; |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
887 } |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
888 |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
889 return 0; |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
890 } |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
891 |
666472fd4cb0
HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents:
2483
diff
changeset
|
892 |
2645
269ba4f28d0e
Added support for pausing/unpausing haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2644
diff
changeset
|
893 /* |
269ba4f28d0e
Added support for pausing/unpausing haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2644
diff
changeset
|
894 * Pausing is not supported atm by linux. |
269ba4f28d0e
Added support for pausing/unpausing haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2644
diff
changeset
|
895 */ |
269ba4f28d0e
Added support for pausing/unpausing haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2644
diff
changeset
|
896 int |
269ba4f28d0e
Added support for pausing/unpausing haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2644
diff
changeset
|
897 SDL_SYS_HapticPause(SDL_Haptic * haptic) |
269ba4f28d0e
Added support for pausing/unpausing haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2644
diff
changeset
|
898 { |
269ba4f28d0e
Added support for pausing/unpausing haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2644
diff
changeset
|
899 return -1; |
269ba4f28d0e
Added support for pausing/unpausing haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2644
diff
changeset
|
900 } |
269ba4f28d0e
Added support for pausing/unpausing haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2644
diff
changeset
|
901 |
269ba4f28d0e
Added support for pausing/unpausing haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2644
diff
changeset
|
902 |
269ba4f28d0e
Added support for pausing/unpausing haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2644
diff
changeset
|
903 /* |
269ba4f28d0e
Added support for pausing/unpausing haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2644
diff
changeset
|
904 * Unpausing is not supported atm by linux. |
269ba4f28d0e
Added support for pausing/unpausing haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2644
diff
changeset
|
905 */ |
269ba4f28d0e
Added support for pausing/unpausing haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2644
diff
changeset
|
906 int |
269ba4f28d0e
Added support for pausing/unpausing haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2644
diff
changeset
|
907 SDL_SYS_HapticUnpause(SDL_Haptic * haptic) |
269ba4f28d0e
Added support for pausing/unpausing haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2644
diff
changeset
|
908 { |
269ba4f28d0e
Added support for pausing/unpausing haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2644
diff
changeset
|
909 return -1; |
269ba4f28d0e
Added support for pausing/unpausing haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2644
diff
changeset
|
910 } |
269ba4f28d0e
Added support for pausing/unpausing haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2644
diff
changeset
|
911 |
269ba4f28d0e
Added support for pausing/unpausing haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
2644
diff
changeset
|
912 |
2646 | 913 /* |
914 * Stops all the currently playing effects. | |
915 */ | |
916 int | |
917 SDL_SYS_HapticStopAll(SDL_Haptic * haptic) | |
918 { | |
919 int i, ret;; | |
920 | |
921 for (i=0; i<haptic->neffects; i++) { | |
922 ret = SDL_SYS_HapticStopEffect(haptic, &haptic->effects[i]); | |
923 if (ret < 0) { | |
924 SDL_SetError("Haptic: Error while trying to stop all playing effects."); | |
925 return -1; | |
926 } | |
927 } | |
928 | |
929 return 0; | |
930 } | |
931 | |
932 | |
2472
3f73c88c9abb
First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff
changeset
|
933 #endif /* SDL_HAPTIC_LINUX */ |