annotate src/haptic/linux/SDL_syshaptic.c @ 2486:24dd8b8669fa gsoc2008_force_feedback

Added SDL_HAPTIC_CUSTOM (not supported on linux). Exposed SDL_HapticEffectSupported().
author Edgar Simo <bobbens@gmail.com>
date Tue, 01 Jul 2008 16:19:54 +0000
parents 67978eea6d10
children 4c8e25ef2d97
rev   line source
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
1 /*
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
3 Copyright (C) 2008 Edgar Simo
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
4
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
9
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
13 Lesser General Public License for more details.
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
14
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
18
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
19 Sam Lantinga
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
20 slouken@libsdl.org
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
21 */
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
22 #include "SDL_config.h"
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
23
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
24 #ifdef SDL_JOYSTICK_LINUX
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
25
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
26 #include "SDL_haptic.h"
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
27 #include "../SDL_haptic_c.h"
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
28 #include "../SDL_syshaptic.h"
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
29
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
30 #include <unistd.h> /* close */
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
31 #include <linux/input.h>
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
32 #include <sys/ioctl.h>
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
33 #include <sys/types.h>
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
34 #include <sys/stat.h>
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
35 #include <fcntl.h>
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
36 #include <linux/limits.h>
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
37 #include <string.h>
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
38
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
39
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
40 #define MAX_HAPTICS 32
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
41
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
42
2475
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
43 /*
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
44 * List of available haptic devices.
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
45 */
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
46 static struct
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
47 {
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
48 char *fname;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
49 SDL_Haptic *haptic;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
50 } SDL_hapticlist[MAX_HAPTICS];
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
51
2475
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
52
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
53 /*
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
54 * Haptic system hardware data.
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
55 */
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
56 struct haptic_hwdata
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
57 {
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
58 int fd;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
59 };
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
60
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
61
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
62 /*
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
63 * Haptic system effect data.
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
64 */
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
65 struct haptic_hweffect
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
66 {
2479
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
67 struct ff_effect effect;
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
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
70
2475
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
71
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
72 #define test_bit(nr, addr) \
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
73 (((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
74 #define EV_TEST(ev,f) \
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
75 if (test_bit((ev), features)) ret |= (f);
2475
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
76 /*
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
77 * Test whether a device has haptic properties.
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
78 * Returns available properties or 0 if there are none.
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
79 */
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
80 static int
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
81 EV_IsHaptic(int fd)
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
82 {
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
83 unsigned int ret;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
84 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
85
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
86 ret = 0;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
87
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
88 ioctl(fd, EVIOCGBIT(EV_FF, sizeof(unsigned long) * 4), features);
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
89
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
90 EV_TEST(FF_CONSTANT, SDL_HAPTIC_CONSTANT);
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
91 EV_TEST(FF_PERIODIC, SDL_HAPTIC_PERIODIC);
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
92 EV_TEST(FF_RAMP, SDL_HAPTIC_RAMP);
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
93 EV_TEST(FF_SPRING, SDL_HAPTIC_SPRING);
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
94 EV_TEST(FF_FRICTION, SDL_HAPTIC_FRICTION);
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
95 EV_TEST(FF_DAMPER, SDL_HAPTIC_DAMPER);
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
96 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
97 EV_TEST(FF_CUSTOM, SDL_HAPTIC_CUSTOM);
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
98 EV_TEST(FF_GAIN, SDL_HAPTIC_GAIN);
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
99 EV_TEST(FF_AUTOCENTER, SDL_HAPTIC_AUTOCENTER);
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
100
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
101 return ret;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
102 }
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
103
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
104 int
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
105 SDL_SYS_HapticInit(void)
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
106 {
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
107 const char joydev_pattern[] = "/dev/input/event%d";
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
108 dev_t dev_nums[MAX_HAPTICS];
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
109 char path[PATH_MAX];
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
110 struct stat sb;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
111 int fd;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
112 int i, j, k;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
113 int duplicate;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
114 int numhaptics;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
115
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
116 numhaptics = 0;
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 i = 0;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
119 for (j = 0; j < MAX_HAPTICS; ++j) {
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
120
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
121 snprintf(path, PATH_MAX, joydev_pattern, i++);
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
122
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
123 /* check to see if file exists */
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
124 if (stat(path,&sb) != 0)
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
125 break;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
126
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
127 /* check for duplicates */
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
128 duplicate = 0;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
129 for (k = 0; (k < numhaptics) && !duplicate; ++k) {
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
130 if (sb.st_rdev == dev_nums[k]) {
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
131 duplicate = 1;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
132 }
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
133 }
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
134 if (duplicate) {
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
135 continue;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
136 }
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
137
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
138 /* try to open */
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
139 fd = open(path, O_RDWR, 0);
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
140 if (fd < 0) continue;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
141
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
142 #ifdef DEBUG_INPUT_EVENTS
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
143 printf("Checking %s\n", path);
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
144 #endif
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
145
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
146 /* see if it works */
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
147 if (EV_IsHaptic(fd)!=0) {
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
148 SDL_hapticlist[numhaptics].fname = SDL_strdup(path);
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
149 SDL_hapticlist[numhaptics].haptic = NULL;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
150 dev_nums[numhaptics] = sb.st_rdev;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
151 ++numhaptics;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
152 }
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
153 close(fd);
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
154 }
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
155
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
156 return numhaptics;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
157 }
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
158
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
159
2475
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
160 /*
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
161 * Return the name of a haptic device, does not need to be opened.
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
162 */
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
163 const char *
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
164 SDL_SYS_HapticName(int index)
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
165 {
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
166 int fd;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
167 static char namebuf[128];
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
168 char *name;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
169
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
170 name = NULL;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
171 fd = open(SDL_hapticlist[index].fname, O_RDONLY, 0);
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
172 if (fd >= 0) {
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
173 if (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) {
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
174 name = SDL_hapticlist[index].fname;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
175 }
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
176 else {
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
177 name = namebuf;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
178 }
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
179 }
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
180 close(fd);
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 return name;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
183 }
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
184
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
185
2475
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
186 /*
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
187 * Opens a haptic device for usage.
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
188 */
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
189 int
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
190 SDL_SYS_HapticOpen(SDL_Haptic * haptic)
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
191 {
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
192 int i;
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
193 int fd;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
194
2476
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
195 /* Open the character device */
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
196 fd = open(SDL_hapticlist[haptic->index].fname, O_RDWR, 0);
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
197 if (fd < 0) {
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
198 SDL_SetError("Unable to open %s\n", SDL_hapticlist[haptic->index]);
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
199 return -1;
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
200 }
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
201
2476
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
202 /* Allocate the hwdata */
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
203 haptic->hwdata = (struct haptic_hwdata *)
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
204 SDL_malloc(sizeof(*haptic->hwdata));
2476
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
205 if (haptic->hwdata == NULL) {
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
206 SDL_OutOfMemory();
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
207 goto open_err;
2476
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
208 }
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
209 SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
2478
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
210 /* Set the data */
2476
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
211 haptic->hwdata->fd = fd;
2478
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
212 haptic->supported = EV_IsHaptic(fd);
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
213
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
214 /* Set the effects */
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
215 if (ioctl(fd, EVIOCGEFFECTS, &haptic->neffects) < 0) {
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
216 SDL_SetError("Unable to query haptic device memory.");
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
217 goto open_err;
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
218 }
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
219 haptic->effects = (struct haptic_effect *)
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
220 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
221 if (haptic->effects == NULL) {
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
222 SDL_OutOfMemory();
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
223 goto open_err;
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
224 }
2483
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
225 /* Clear the memory */
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
226 SDL_memset(haptic->effects, 0,
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
227 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
228
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
229 return 0;
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
230
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
231 /* Error handling */
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
232 open_err:
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
233 close(fd);
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
234 if (haptic->hwdata != NULL) {
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
235 free(haptic->hwdata);
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
236 haptic->hwdata = NULL;
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
237 }
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
238 return -1;
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
239 }
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
2475
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
242 /*
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
243 * Closes the haptic device.
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
244 */
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
245 void
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
246 SDL_SYS_HapticClose(SDL_Haptic * haptic)
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
247 {
2476
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
248 if (haptic->hwdata) {
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
249
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
250 /* Clean up */
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
251 close(haptic->hwdata->fd);
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
252
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
253 /* Free */
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
254 SDL_free(haptic->hwdata);
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
255 haptic->hwdata = NULL;
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
256 SDL_free(haptic->effects);
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
257 haptic->neffects = 0;
2476
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
258 }
2475
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
259 }
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
260
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
261
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
262 /*
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
263 * 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
264 */
2474
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
265 void
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
266 SDL_SYS_HapticQuit(void)
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
267 {
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
268 int i;
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
269
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
270 for (i=0; SDL_hapticlist[i].fname != NULL; i++) {
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
271 SDL_free(SDL_hapticlist[i].fname);
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
272 }
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
273 SDL_hapticlist[0].fname = NULL;
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
274 }
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
275
2481
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
276 #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
277 /*
2479
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
278 * Initializes the linux effect struct from a haptic_effect.
2481
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
279 * 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
280 */
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
281 static int
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
282 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
283 {
2482
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
284 int i;
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
285 SDL_HapticConstant *constant;
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
286 SDL_HapticPeriodic *periodic;
2482
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
287 SDL_HapticCondition *condition;
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
288 SDL_HapticRamp *ramp;
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
289
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
290 /* Clear up */
2479
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
291 SDL_memset(dest, 0, sizeof(struct ff_effect));
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
292
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
293 switch (src->type) {
2479
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
294 case SDL_HAPTIC_CONSTANT:
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
295 constant = &src->constant;
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
296
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
297 /* Header */
2479
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
298 dest->type = FF_CONSTANT;
2481
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
299 dest->direction = CLAMP(constant->direction);
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
300
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
301 /* Replay */
2481
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
302 dest->replay.length = CLAMP(constant->length);
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
303 dest->replay.delay = CLAMP(constant->delay);
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
304
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
305 /* Trigger */
2481
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
306 dest->trigger.button = CLAMP(constant->button);
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
307 dest->trigger.interval = CLAMP(constant->interval);
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
308
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
309 /* Constant */
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
310 dest->u.constant.level = constant->level;
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
311
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
312 /* Envelope */
2481
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
313 dest->u.constant.envelope.attack_length = CLAMP(constant->attack_length);
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
314 dest->u.constant.envelope.attack_level = CLAMP(constant->attack_level);
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
315 dest->u.constant.envelope.fade_length = CLAMP(constant->fade_length);
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
316 dest->u.constant.envelope.fade_level = CLAMP(constant->fade_level);
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
317
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
318 break;
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
319
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
320 case SDL_HAPTIC_PERIODIC:
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
321 periodic = &src->periodic;
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
322
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
323 /* Header */
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
324 dest->type = FF_PERIODIC;
2481
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
325 dest->direction = CLAMP(periodic->direction);
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
326
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
327 /* Replay */
2481
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
328 dest->replay.length = CLAMP(periodic->length);
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
329 dest->replay.delay = CLAMP(periodic->delay);
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
330
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
331 /* Trigger */
2481
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
332 dest->trigger.button = CLAMP(periodic->button);
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
333 dest->trigger.interval = CLAMP(periodic->interval);
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
334
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
335 /* Constant */
2481
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
336 switch (periodic->waveform) {
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
337 case SDL_WAVEFORM_SINE:
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
338 dest->u.periodic.waveform = FF_SINE;
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
339 break;
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
340 case SDL_WAVEFORM_SQUARE:
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
341 dest->u.periodic.waveform = FF_SQUARE;
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
342 break;
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
343 case SDL_WAVEFORM_TRIANGLE:
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
344 dest->u.periodic.waveform = FF_TRIANGLE;
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
345 break;
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
346 case SDL_WAVEFORM_SAWTOOTHUP:
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
347 dest->u.periodic.waveform = FF_SAW_UP;
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
348 break;
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
349 case SDL_WAVEFORM_SAWTOOTHDOWN:
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
350 dest->u.periodic.waveform = FF_SAW_DOWN;
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
351 break;
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
352
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
353 default:
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
354 SDL_SetError("Unknown waveform.");
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
355 return -1;
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
356 }
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
357 dest->u.periodic.period = CLAMP(periodic->period);
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
358 dest->u.periodic.magnitude = periodic->magnitude;
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
359 dest->u.periodic.offset = periodic->offset;
2481
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
360 dest->u.periodic.phase = CLAMP(periodic->phase);
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
361
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
362 /* Envelope */
2481
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
363 dest->u.periodic.envelope.attack_length = CLAMP(periodic->attack_length);
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
364 dest->u.periodic.envelope.attack_level = CLAMP(periodic->attack_level);
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
365 dest->u.periodic.envelope.fade_length = CLAMP(periodic->fade_length);
5d0ea4576f20 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
366 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
367
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
368 break;
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
369
2482
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
370 case SDL_HAPTIC_SPRING:
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
371 case SDL_HAPTIC_DAMPER:
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
372 case SDL_HAPTIC_INERTIA:
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
373 case SDL_HAPTIC_FRICTION:
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
374 condition = &src->condition;
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
375
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
376 /* Header */
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
377 if (dest->type == SDL_HAPTIC_SPRING)
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
378 dest->type = FF_SPRING;
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
379 else if (dest->type == SDL_HAPTIC_DAMPER)
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
380 dest->type = FF_DAMPER;
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
381 else if (dest->type == SDL_HAPTIC_INERTIA)
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
382 dest->type = FF_INERTIA;
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
383 else if (dest->type == SDL_HAPTIC_FRICTION)
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
384 dest->type = FF_FRICTION;
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
385 dest->direction = CLAMP(condition->direction);
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
386
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
387 /* Replay */
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
388 dest->replay.length = CLAMP(condition->length);
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
389 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
390
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
391 /* Trigger */
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
392 dest->trigger.button = CLAMP(condition->button);
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
393 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
394
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
395 /* Condition - TODO handle axes */
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
396 dest->u.condition[0].right_saturation = CLAMP(condition->right_sat);
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
397 dest->u.condition[0].left_saturation = CLAMP(condition->left_sat);
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
398 dest->u.condition[0].right_coeff = condition->right_coeff;
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
399 dest->u.condition[0].left_coeff = condition->left_coeff;
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
400 dest->u.condition[0].deadband = CLAMP(condition->deadband);
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
401 dest->u.condition[0].center = condition->center;
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
402
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
403 break;
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
404
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
405 case SDL_HAPTIC_RAMP:
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
406 ramp = &src->ramp;
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
407
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
408 /* Header */
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
409 dest->type = FF_RAMP;
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
410 dest->direction = CLAMP(ramp->direction);
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
411
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
412 /* Replay */
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
413 dest->replay.length = CLAMP(ramp->length);
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
414 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
415
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
416 /* Trigger */
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
417 dest->trigger.button = CLAMP(ramp->button);
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
418 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
419
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
420 /* Ramp */
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
421 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
422 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
423
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
424 /* Envelope */
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
425 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
426 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
427 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
428 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
429
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
430 break;
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
431
b51ad78812d5 Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Edgar Simo <bobbens@gmail.com>
parents: 2481
diff changeset
432
2479
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
433 default:
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
434 SDL_SetError("Unknown haptic effect type.");
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
435 return -1;
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
436 }
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
437
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
438 return 0;
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
439 }
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
440
2483
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
441
2479
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
442 /*
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
443 * Creates a new haptic effect.
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
444 */
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
445 int
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
446 SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect * effect,
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
447 SDL_HapticEffect * base)
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
448 {
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
449 struct ff_effect * linux_effect;
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
450
2479
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
451 /* Allocate the hardware effect */
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
452 effect->hweffect = (struct haptic_hweffect *)
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
453 SDL_malloc(sizeof(struct haptic_hweffect));
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
454 if (effect->hweffect == NULL) {
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
455 SDL_OutOfMemory();
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
456 return -1;
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
457 }
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
458
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
459 /* Prepare the ff_effect */
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
460 linux_effect = &effect->hweffect->effect;
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
461 if (SDL_SYS_ToFFEffect( linux_effect, base ) != 0) {
2479
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
462 return -1;
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
463 }
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
464 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
465
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
466 /* Upload the effect */
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
467 if (ioctl(haptic->hwdata->fd, EVIOCSFF, linux_effect) < 0) {
2483
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
468 SDL_SetError("Error uploading effect to the haptic device.");
2479
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
469 return -1;
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
470 }
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
471
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
472 return 0;
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
473 }
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
474
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
475
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
476 /*
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
477 * Runs an effect.
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
478 */
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
479 int
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
480 SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
481 {
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
482 struct input_event run;
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
483
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
484 /* Prepare to run the effect */
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
485 run.type = EV_FF;
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
486 run.code = effect->hweffect->effect.id;
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
487 run.value = 1;
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
488
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
489 if (write(haptic->hwdata->fd, (const void*) &run, sizeof(run)) < 0) {
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
490 SDL_SetError("Unable to run the haptic effect.");
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
491 return -1;
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
492 }
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
493
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
494 return 0;
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
495 }
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
496
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
497
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
498 /*
2485
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
499 * Stops an effect.
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
500 */
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
501 int
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
502 SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
503 {
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
504 struct input_event stop;
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
505
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
506 stop.type = EV_FF;
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
507 stop.code = effect->hweffect->effect.id;
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
508 stop.value = 0;
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
509
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
510 if (write(haptic->hwdata->fd, (const void*) &stop, sizeof(stop)) < 0) {
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
511 SDL_SetError("Unable to stop the haptic effect.");
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
512 return -1;
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
513 }
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
514
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
515 return 0;
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
516 }
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
517
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
518
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
519 /*
2479
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
520 * Frees the effect
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 void
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
523 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
524 {
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
525 if (ioctl(haptic->hwdata->fd, EVIOCRMFF, effect->hweffect->effect.id) < 0) {
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
526 SDL_SetError("Error removing the effect from the haptic device.");
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
527 }
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
528 SDL_free(effect->hweffect);
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
529 effect->hweffect = NULL;
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
530 }
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
531
2474
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
532
2483
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
533 /*
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
534 * Sets the gain.
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
535 */
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
536 int
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
537 SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
538 {
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
539 struct input_event ie;
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
540
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
541 ie.type = EV_FF;
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
542 ie.code = FF_GAIN;
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
543 ie.value = (0xFFFFUL * gain) / 100;
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
544
2484
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
545 if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
2483
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
546 SDL_SetError("Error setting gain.");
2484
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
547 return -1;
2483
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
548 }
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
549
2484
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
550 return 0;
2483
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
551 }
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
552
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2482
diff changeset
553
2484
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
554 /*
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
555 * Sets the autocentering.
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
556 */
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
557 int
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
558 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
559 {
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
560 struct input_event ie;
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
561
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
562 ie.type = EV_FF;
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
563 ie.code = FF_AUTOCENTER;
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
564 ie.value = (0xFFFFUL * autocenter) / 100;
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
565
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
566 if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
567 SDL_SetError("Error setting autocenter.");
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
568 return -1;
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
569 }
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
570
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
571 return 0;
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
572 }
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
573
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
574
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
575
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
576 #endif /* SDL_HAPTIC_LINUX */