annotate src/haptic/darwin/SDL_syshaptic.c @ 2530:22ce87690b41 gsoc2008_force_feedback

More comments. Added support for condition effects on darwin.
author Edgar Simo <bobbens@gmail.com>
date Fri, 18 Jul 2008 18:52:06 +0000
parents e1d5d16e88a8
children 7f2a4c387292
rev   line source
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
1 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
3 Copyright (C) 2008 Edgar Simo
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
4
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
9
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
13 Lesser General Public License for more details.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
14
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
18
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
19 Sam Lantinga
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
20 slouken@libsdl.org
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
21 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
22 #include "SDL_config.h"
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
23
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
24 #ifdef SDL_HAPTIC_IOKIT
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
25
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
26 #include "SDL_haptic.h"
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
27 #include "../SDL_syshaptic.h"
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
28 #include "SDL_joystick.h"
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
29 #include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
30 /*#include "../../joystick/dawrin/SDL_sysjoystick_c.h"*/ /* For joystick hwdata */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
31
2522
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
32 #include <IOKit/IOKitLib.h>
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
33 #include <IOKit/hid/IOHIDKeys.h>
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
34 #include <ForceFeedback/ForceFeedback.h>
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
35 #include <ForceFeedback/ForceFeedbackConstants.h>
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
36
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
37
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
38 #define MAX_HAPTICS 32
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
39
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
40
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
41 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
42 * List of available haptic devices.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
43 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
44 static struct
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
45 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
46 io_service_t dev;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
47 SDL_Haptic *haptic;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
48 } SDL_hapticlist[MAX_HAPTICS];
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
49
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
50
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
51 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
52 * Haptic system hardware data.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
53 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
54 struct haptic_hwdata
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
55 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
56 FFDeviceObjectReference device; /* Hardware device. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
57 };
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
58
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
59
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
60 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
61 * Haptic system effect data.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
62 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
63 struct haptic_hweffect
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
64 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
65 FFEffectObjectReference ref; /* Reference. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
66 struct FFEFFECT effect; /* Hardware effect. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
67 };
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
68
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
69
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
70 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
71 * Initializes the haptic subsystem.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
72 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
73 int
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
74 SDL_SYS_HapticInit(void)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
75 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
76 int numhaptics;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
77 IOReturn result;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
78 io_iterator_t iter;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
79 CFDictionaryRef match;
2521
7aa91c21ce5f Many typo and silly mistake fixes.
Edgar Simo <bobbens@gmail.com>
parents: 2520
diff changeset
80 io_service_t device;
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
81
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
82 /* Get HID devices. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
83 match = IOServiceMatching(kIOHIDDeviceKey);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
84 if (match == NULL) {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
85 SDL_SetError("Haptic: Failed to get IOServiceMatching.");
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
86 return -1;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
87 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
88
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
89 /* Now search I/O Registry for matching devices. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
90 result = IOServiceGetMatchingServices(kIOMasterPortDefault, match, &iter);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
91 if (result != kIOReturnSuccess) {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
92 SDL_SetError("Haptic: Couldn't create a HID object iterator.");
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
93 return -1;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
94 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
95 /* IOServiceGetMatchingServices consumes dictionary. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
96
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
97 numhaptics = 0;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
98 while ((device = IOIteratorNext(iter)) != IO_OBJECT_NULL) {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
99
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
100 /* Check for force feedback. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
101 if (FFIsForceFeedback(device) == FF_OK) {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
102 SDL_hapticlist[numhaptics].dev = device;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
103 SDL_hapticlist[numhaptics].haptic = NULL;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
104 numhaptics++;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
105 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
106
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
107 /* Reached haptic limit. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
108 if (numhaptics >= MAX_HAPTICS)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
109 break;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
110 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
111 IOObjectRelease(iter);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
112
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
113 return numhaptics;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
114 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
115
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
116
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
117 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
118 * Return the name of a haptic device, does not need to be opened.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
119 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
120 const char *
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
121 SDL_SYS_HapticName(int index)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
122 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
123 return NULL;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
124 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
125
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
126
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
127 #define FF_TEST(ff, s) \
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
128 if (features.supportedEffects & ff) supported |= s
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
129 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
130 * Gets supported features.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
131 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
132 static unsigned int
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
133 GetSupportedFeatures(FFDeviceObjectReference device,
2527
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
134 int *neffects, int *nplaying, int *naxes)
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
135 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
136 HRESULT ret;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
137 FFCAPABILITIES features;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
138 unsigned int supported;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
139 Uint32 val;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
140
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
141 ret = FFDeviceGetForceFeedbackCapabilities(device, &features);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
142 if (ret != FF_OK) {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
143 SDL_SetError("Haptic: Unable to get device's supported features.");
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
144 return 0;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
145 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
146
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
147 supported = 0;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
148
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
149 /* Get maximum effects. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
150 *neffects = features.storageCapacity;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
151 *nplaying = features.playbackCapacity;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
152
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
153 /* Test for effects. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
154 FF_TEST(FFCAP_ET_CONSTANTFORCE, SDL_HAPTIC_CONSTANT);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
155 FF_TEST(FFCAP_ET_RAMPFORCE, SDL_HAPTIC_RAMP);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
156 FF_TEST(FFCAP_ET_SQUARE, SDL_HAPTIC_SQUARE);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
157 FF_TEST(FFCAP_ET_SINE, SDL_HAPTIC_SINE);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
158 FF_TEST(FFCAP_ET_TRIANGLE, SDL_HAPTIC_TRIANGLE);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
159 FF_TEST(FFCAP_ET_SAWTOOTHUP, SDL_HAPTIC_SAWTOOTHUP);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
160 FF_TEST(FFCAP_ET_SAWTOOTHDOWN, SDL_HAPTIC_SAWTOOTHDOWN);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
161 FF_TEST(FFCAP_ET_SPRING, SDL_HAPTIC_SPRING);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
162 FF_TEST(FFCAP_ET_DAMPER, SDL_HAPTIC_DAMPER);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
163 FF_TEST(FFCAP_ET_INERTIA, SDL_HAPTIC_INERTIA);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
164 FF_TEST(FFCAP_ET_FRICTION, SDL_HAPTIC_FRICTION);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
165 FF_TEST(FFCAP_ET_CUSTOMFORCE, SDL_HAPTIC_CUSTOM);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
166
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
167 /* Check if supports gain. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
168 ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_FFGAIN,
2522
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
169 &val, sizeof(val));
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
170 if (ret == FF_OK) supported |= SDL_HAPTIC_GAIN;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
171 else if (ret != FFERR_UNSUPPORTED) {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
172 SDL_SetError("Haptic: Unable to get if device supports gain.");
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
173 return 0;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
174 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
175
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
176 /* Checks if supports autocenter. */
2521
7aa91c21ce5f Many typo and silly mistake fixes.
Edgar Simo <bobbens@gmail.com>
parents: 2520
diff changeset
177 ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_AUTOCENTER,
2522
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
178 &val, sizeof(val));
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
179 if (ret == FF_OK) supported |= SDL_HAPTIC_AUTOCENTER;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
180 else if (ret != FFERR_UNSUPPORTED) {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
181 SDL_SetError("Haptic: Unable to get if device supports autocenter.");
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
182 return 0;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
183 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
184
2527
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
185 /* Check for axes, we have an artificial limit on axes */
2528
50414589501e Fixed some typos.
Edgar Simo <bobbens@gmail.com>
parents: 2527
diff changeset
186 *naxes = ((features.numFfAxes) > 3) ?
2527
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
187 3 : features.numFfAxes;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
188
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
189 /* Always supported features. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
190 supported |= SDL_HAPTIC_STATUS;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
191 return supported;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
192 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
193
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
194
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
195 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
196 * Opens the haptic device from the file descriptor.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
197 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
198 static int
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
199 SDL_SYS_HapticOpenFromService(SDL_Haptic * haptic, io_service_t service)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
200 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
201 /* Allocate the hwdata */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
202 haptic->hwdata = (struct haptic_hwdata *)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
203 SDL_malloc(sizeof(*haptic->hwdata));
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
204 if (haptic->hwdata == NULL) {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
205 SDL_OutOfMemory();
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
206 goto creat_err;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
207 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
208 SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
209
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
210 /* Open the device */
2522
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
211 if (FFCreateDevice( service, &haptic->hwdata->device ) != FF_OK) {
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
212 SDL_SetError("Haptic: Unable to create device from service.");
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
213 goto creat_err;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
214 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
215
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
216 /* Get supported features. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
217 haptic->supported = GetSupportedFeatures(haptic->hwdata->device,
2527
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
218 &haptic->neffects, &haptic->nplaying,
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
219 &haptic->naxes);
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
220 if (haptic->supported == 0) { /* Error since device supports nothing. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
221 goto open_err;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
222 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
223 haptic->effects = (struct haptic_effect *)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
224 SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
225 if (haptic->effects == NULL) {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
226 SDL_OutOfMemory();
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
227 goto open_err;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
228 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
229 /* Clear the memory */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
230 SDL_memset(haptic->effects, 0,
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
231 sizeof(struct haptic_effect) * haptic->neffects);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
232
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
233 return 0;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
234
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
235 /* Error handling */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
236 open_err:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
237 FFReleaseDevice(haptic->hwdata->device);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
238 creat_err:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
239 if (haptic->hwdata != NULL) {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
240 free(haptic->hwdata);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
241 haptic->hwdata = NULL;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
242 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
243 return -1;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
244
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
245 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
246
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
247
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
248 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
249 * Opens a haptic device for usage.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
250 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
251 int
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
252 SDL_SYS_HapticOpen(SDL_Haptic * haptic)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
253 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
254 return SDL_SYS_HapticOpenFromService(haptic,
2522
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
255 SDL_hapticlist[haptic->index].dev);
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
256 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
257
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
258
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
259 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
260 * Opens a haptic device from first mouse it finds for usage.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
261 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
262 int
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
263 SDL_SYS_HapticMouse(void)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
264 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
265 return -1;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
266 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
267
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
268
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
269 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
270 * Checks to see if a joystick has haptic features.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
271 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
272 int
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
273 SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
274 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
275 return SDL_FALSE;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
276 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
277
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
278
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
279 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
280 * Checks to see if the haptic device and joystick and in reality the same.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
281 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
282 int
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
283 SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
284 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
285 return 0;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
286 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
287
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
288
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
289 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
290 * Opens a SDL_Haptic from a SDL_Joystick.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
291 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
292 int
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
293 SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
294 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
295 return -1;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
296 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
297
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
298
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
299 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
300 * Closes the haptic device.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
301 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
302 void
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
303 SDL_SYS_HapticClose(SDL_Haptic * haptic)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
304 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
305 int i;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
306
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
307 if (haptic->hwdata) {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
308
2530
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
309 /* Free the effects. */
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
310 for (i=0; i<haptic->neffects; i++) {
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
311 if (haptic->effects[i].hweffect != NULL) {
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
312 SDL_SYS_HapticFreeFFEFFECT(&haptic->effects[i].hweffect->effect);
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
313 SDL_free(haptic->effects[i].hweffect);
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
314 }
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
315 }
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
316 SDL_free(haptic->effects);
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
317 haptic->neffects = 0;
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
318
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
319 /* Clean up */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
320 FFReleaseDevice(haptic->hwdata->device);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
321
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
322 /* Free */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
323 SDL_free(haptic->hwdata);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
324 haptic->hwdata = NULL;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
325 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
326 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
327
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
328
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
329 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
330 * Clean up after system specific haptic stuff
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
331 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
332 void
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
333 SDL_SYS_HapticQuit(void)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
334 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
335 int i;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
336
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
337 for (i=0; i < SDL_numhaptics; i++) {
2530
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
338 /* Opened and not closed haptics are leaked, this is on purpose.
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
339 * Close your haptic devices after usage. */
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
340
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
341 /* Free the io_service_t */
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
342 IOObjectRelease(SDL_hapticlist[i].dev);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
343 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
344 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
345
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
346
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
347 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
348 * Sets the direction.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
349 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
350 static int
2529
e1d5d16e88a8 Can't believe I missed this typo.
Edgar Simo <bobbens@gmail.com>
parents: 2528
diff changeset
351 SDL_SYS_SetDirection( FFEFFECT * effect, SDL_HapticDirection *dir, int naxes )
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
352 {
2521
7aa91c21ce5f Many typo and silly mistake fixes.
Edgar Simo <bobbens@gmail.com>
parents: 2520
diff changeset
353 LONG *rglDir;
2527
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
354
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
355 /* Handle no axes a part. */
2528
50414589501e Fixed some typos.
Edgar Simo <bobbens@gmail.com>
parents: 2527
diff changeset
356 if (naxes == 0) {
2527
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
357 effect->rglDirection = NULL;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
358 return 0;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
359 }
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
360
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
361 /* Has axes. */
2529
e1d5d16e88a8 Can't believe I missed this typo.
Edgar Simo <bobbens@gmail.com>
parents: 2528
diff changeset
362 rglDir = SDL_malloc( sizeof(LONG) * naxes );
2527
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
363 if (rglDir == NULL) {
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
364 SDL_OutOfMemory();
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
365 return -1;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
366 }
2529
e1d5d16e88a8 Can't believe I missed this typo.
Edgar Simo <bobbens@gmail.com>
parents: 2528
diff changeset
367 SDL_memset( rglDir, 0, sizeof(LONG) * naxes );
2521
7aa91c21ce5f Many typo and silly mistake fixes.
Edgar Simo <bobbens@gmail.com>
parents: 2520
diff changeset
368 effect->rglDirection = rglDir;
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
369
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
370 switch (dir->type) {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
371 case SDL_HAPTIC_POLAR:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
372 effect->dwFlags |= FFEFF_POLAR;
2521
7aa91c21ce5f Many typo and silly mistake fixes.
Edgar Simo <bobbens@gmail.com>
parents: 2520
diff changeset
373 rglDir[0] = dir->dir[0];
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
374 return 0;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
375 case SDL_HAPTIC_CARTESIAN:
2522
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
376 effect->dwFlags |= FFEFF_CARTESIAN;
2521
7aa91c21ce5f Many typo and silly mistake fixes.
Edgar Simo <bobbens@gmail.com>
parents: 2520
diff changeset
377 rglDir[0] = dir->dir[0];
7aa91c21ce5f Many typo and silly mistake fixes.
Edgar Simo <bobbens@gmail.com>
parents: 2520
diff changeset
378 rglDir[1] = dir->dir[1];
7aa91c21ce5f Many typo and silly mistake fixes.
Edgar Simo <bobbens@gmail.com>
parents: 2520
diff changeset
379 rglDir[2] = dir->dir[2];
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
380 return 0;
2521
7aa91c21ce5f Many typo and silly mistake fixes.
Edgar Simo <bobbens@gmail.com>
parents: 2520
diff changeset
381 case SDL_HAPTIC_SPHERICAL:
2522
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
382 effect->dwFlags |= FFEFF_SPHERICAL;
2521
7aa91c21ce5f Many typo and silly mistake fixes.
Edgar Simo <bobbens@gmail.com>
parents: 2520
diff changeset
383 rglDir[0] = dir->dir[0];
7aa91c21ce5f Many typo and silly mistake fixes.
Edgar Simo <bobbens@gmail.com>
parents: 2520
diff changeset
384 rglDir[1] = dir->dir[1];
7aa91c21ce5f Many typo and silly mistake fixes.
Edgar Simo <bobbens@gmail.com>
parents: 2520
diff changeset
385 rglDir[2] = dir->dir[2];
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
386 return 0;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
387
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
388 default:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
389 SDL_SetError("Haptic: Unknown direction type.");
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
390 return -1;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
391 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
392 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
393
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
394 #define CONVERT(x) (((x)*10000) / 0xFFFF )
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
395 /*
2527
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
396 * Creates the FFEFFECT from a SDL_HapticEffect.
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
397 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
398 static int
2527
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
399 SDL_SYS_ToFFEFFECT( SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src )
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
400 {
2530
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
401 int i;
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
402 FFCONSTANTFORCE *constant;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
403 FFPERIODIC *periodic;
2530
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
404 FFCONDITION *condition; /* Actually an array of conditions - one per axis. */
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
405 FFRAMPFORCE *ramp;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
406 FFCUSTOMFORCE *custom;
2522
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
407 FFENVELOPE *envelope;
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
408 SDL_HapticConstant *hap_constant;
2521
7aa91c21ce5f Many typo and silly mistake fixes.
Edgar Simo <bobbens@gmail.com>
parents: 2520
diff changeset
409 SDL_HapticPeriodic *hap_periodic;
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
410 SDL_HapticCondition *hap_condition;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
411 SDL_HapticRamp *hap_ramp;
2527
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
412 DWORD *axes;
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
413
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
414 /* Set global stuff. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
415 SDL_memset(dest, 0, sizeof(FFEFFECT));
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
416 dest->dwSize = sizeof(FFEFFECT); /* Set the structure size. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
417 dest->dwSamplePeriod = 0; /* Not used by us. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
418 dest->dwGain = 10000; /* Gain is set globally, not locally. */
2522
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
419
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
420 /* Envelope. */
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
421 envelope = SDL_malloc( sizeof(FFENVELOPE) );
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
422 if (envelope == NULL) {
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
423 SDL_OutOfMemory();
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
424 return -1;
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
425 }
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
426 SDL_memset(envelope, 0, sizeof(FFENVELOPE));
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
427 dest->lpEnvelope = envelope;
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
428 envelope->dwSize = sizeof(FFENVELOPE); /* Always should be this. */
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
429
2527
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
430 /* Axes. */
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
431 dest->cAxes = haptic->naxes;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
432 if (dest->cAxes > 0) {
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
433 axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
434 if (axes == NULL) {
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
435 SDL_OutOfMemory();
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
436 return -1;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
437 }
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
438 axes[0] = FFJOFS_X; /* Always at least one axis. */
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
439 if (dest->cAxes > 1) {
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
440 axes[1] = FFJOFS_Y;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
441 }
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
442 if (dest->cAxes > 2) {
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
443 axes[2] = FFJOFS_Z;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
444 }
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
445 dest->rgdwAxes = axes;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
446 }
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
447
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
448
2530
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
449 /* The big type handling switch, even bigger then linux's version. */
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
450 switch (src->type) {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
451 case SDL_HAPTIC_CONSTANT:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
452 hap_constant = &src->constant;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
453 constant = SDL_malloc( sizeof(FFCONSTANTFORCE) );
2527
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
454 if (constant == NULL) {
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
455 SDL_OutOfMemory();
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
456 return -1;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
457 }
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
458
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
459 /* Specifics */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
460 constant->lMagnitude = CONVERT(hap_constant->level);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
461 dest->cbTypeSpecificParams = sizeof(FFCONSTANTFORCE);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
462 dest->lpvTypeSpecificParams = constant;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
463
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
464 /* Generics */
2521
7aa91c21ce5f Many typo and silly mistake fixes.
Edgar Simo <bobbens@gmail.com>
parents: 2520
diff changeset
465 dest->dwDuration = hap_constant->length * 1000; /* In microseconds. */
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
466 dest->dwTriggerButton = FFJOFS_BUTTON(hap_constant->button);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
467 dest->dwTriggerRepeatInterval = hap_constant->interval;
2521
7aa91c21ce5f Many typo and silly mistake fixes.
Edgar Simo <bobbens@gmail.com>
parents: 2520
diff changeset
468 dest->dwStartDelay = hap_constant->delay * 1000; /* In microseconds. */
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
469
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
470 /* Direction. */
2522
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
471 if (SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes) < 0) {
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
472 return -1;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
473 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
474
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
475 /* Envelope */
2522
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
476 envelope->dwAttackLevel = CONVERT(hap_constant->attack_level);
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
477 envelope->dwAttackTime = hap_constant->attack_length * 1000;
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
478 envelope->dwFadeLevel = CONVERT(hap_constant->fade_level);
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
479 envelope->dwFadeTime = hap_constant->fade_length * 1000;
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
480
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
481 break;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
482
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
483 case SDL_HAPTIC_SINE:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
484 case SDL_HAPTIC_SQUARE:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
485 case SDL_HAPTIC_TRIANGLE:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
486 case SDL_HAPTIC_SAWTOOTHUP:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
487 case SDL_HAPTIC_SAWTOOTHDOWN:
2522
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
488 hap_periodic = &src->periodic;
2527
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
489 periodic = SDL_malloc(sizeof(FFPERIODIC));
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
490 if (periodic == NULL) {
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
491 SDL_OutOfMemory();
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
492 return -1;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
493 }
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
494
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
495 /* Specifics */
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
496 periodic->dwMagnitude = CONVERT(hap_periodic->magnitude);
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
497 periodic->lOffset = CONVERT(hap_periodic->offset);
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
498 periodic->dwPhase = hap_periodic->phase;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
499 periodic->dwPeriod = hap_periodic->period * 1000;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
500 dest->cbTypeSpecificParams = sizeof(FFPERIODIC);
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
501 dest->lpvTypeSpecificParams = periodic;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
502
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
503 /* Generics */
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
504 dest->dwDuration = hap_periodic->length * 1000; /* In microseconds. */
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
505 dest->dwTriggerButton = FFJOFS_BUTTON(hap_periodic->button);
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
506 dest->dwTriggerRepeatInterval = hap_periodic->interval;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
507 dest->dwStartDelay = hap_periodic->delay * 1000; /* In microseconds. */
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
508
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
509 /* Direction. */
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
510 if (SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes) < 0) {
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
511 return -1;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
512 }
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
513
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
514 /* Envelope */
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
515 envelope->dwAttackLevel = CONVERT(hap_periodic->attack_level);
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
516 envelope->dwAttackTime = hap_periodic->attack_length * 1000;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
517 envelope->dwFadeLevel = CONVERT(hap_periodic->fade_level);
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
518 envelope->dwFadeTime = hap_periodic->fade_length * 1000;
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
519
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
520 break;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
521
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
522 case SDL_HAPTIC_SPRING:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
523 case SDL_HAPTIC_DAMPER:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
524 case SDL_HAPTIC_INERTIA:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
525 case SDL_HAPTIC_FRICTION:
2522
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
526 hap_condition = &src->condition;
2530
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
527 condition = SDL_malloc(sizeof(FFCONDITION) * dest->cAxes);
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
528 if (condition == NULL) {
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
529 SDL_OutOfMemory();
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
530 return -1;
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
531 }
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
532
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
533 /* Specifics */
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
534 for (i=0; i<dest->cAxes; i++) {
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
535 condition[i].lOffset = CONVERT(hap_constant->center[i]);
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
536 condition[i].lPositiveCoefficient = CONVERT(hap_constant->right_coeff[i]);
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
537 condition[i].lNegativeCoefficient = CONVERT(hap_constant->left_coeff[i]);
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
538 condition[i].dwPositiveSaturation = CONVERT(hap_constant->right_sat[i]);
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
539 condition[i].dwNegativeSaturation = CONVERT(hap_constant->left_sat[i]);
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
540 condition[i].lDeadBand = CONVERT(hap_constant->deadband[i]);
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
541 }
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
542 dest->cbTypeSpecificParams = sizeof(FFCONDITION) * dest->cAxes;
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
543 dest->lpvTypeSpecificParams = condition;
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
544
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
545 /* Generics */
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
546 dest->dwDuration = hap_constant->length * 1000; /* In microseconds. */
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
547 dest->dwTriggerButton = FFJOFS_BUTTON(hap_constant->button);
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
548 dest->dwTriggerRepeatInterval = hap_constant->interval;
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
549 dest->dwStartDelay = hap_constant->delay * 1000; /* In microseconds. */
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
550
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
551 /* Direction. */
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
552 if (SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes) < 0) {
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
553 return -1;
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
554 }
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
555
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
556 /* Envelope */
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
557 envelope->dwAttackLevel = CONVERT(hap_constant->attack_level);
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
558 envelope->dwAttackTime = hap_constant->attack_length * 1000;
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
559 envelope->dwFadeLevel = CONVERT(hap_constant->fade_level);
22ce87690b41 More comments.
Edgar Simo <bobbens@gmail.com>
parents: 2529
diff changeset
560 envelope->dwFadeTime = hap_constant->fade_length * 1000;
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
561
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
562 break;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
563
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
564 case SDL_HAPTIC_RAMP:
2522
0877146be013 Now compiles cleanly (has yet to work though).
Edgar Simo <bobbens@gmail.com>
parents: 2521
diff changeset
565 hap_ramp = &src->ramp;
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
566
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
567 break;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
568
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
569
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
570 default:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
571 SDL_SetError("Haptic: Unknown effect type.");
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
572 return -1;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
573 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
574
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
575 return 0;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
576 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
577
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
578
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
579 /*
2527
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
580 * Frees an FFEFFECT allocated by SDL_SYS_ToFFEFFECT.
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
581 */
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
582 void SDL_SYS_HapticFreeFFEFFECT( FFEFFECT * effect )
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
583 {
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
584 if (effect->lpEnvelope != NULL) {
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
585 SDL_free(effect->lpEnvelope);
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
586 effect->lpEnvelope = NULL;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
587 }
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
588 if (effect->rgdwAxes != NULL) {
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
589 SDL_free(effect->rgdwAxes);
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
590 effect->rgdwAxes = NULL;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
591 }
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
592 if (effect->lpvTypeSpecificParams != NULL) {
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
593 SDL_free(effect->lpvTypeSpecificParams);
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
594 effect->lpvTypeSpecificParams = NULL;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
595 }
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
596 if (effect->rglDirection != NULL) {
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
597 SDL_free(effect->rglDirection);
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
598 effect->rglDirection = NULL;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
599 }
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
600 }
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
601
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
602
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
603 /*
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
604 * Gets the effect type from the generic SDL haptic effect wrapper.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
605 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
606 CFUUIDRef SDL_SYS_HapticEffectType(struct haptic_effect * effect)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
607 {
2521
7aa91c21ce5f Many typo and silly mistake fixes.
Edgar Simo <bobbens@gmail.com>
parents: 2520
diff changeset
608 switch (effect->effect.type) {
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
609 case SDL_HAPTIC_CONSTANT:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
610 return kFFEffectType_ConstantForce_ID;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
611
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
612 case SDL_HAPTIC_RAMP:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
613 return kFFEffectType_RampForce_ID;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
614
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
615 case SDL_HAPTIC_SQUARE:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
616 return kFFEffectType_Square_ID;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
617
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
618 case SDL_HAPTIC_SINE:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
619 return kFFEffectType_Sine_ID;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
620
2521
7aa91c21ce5f Many typo and silly mistake fixes.
Edgar Simo <bobbens@gmail.com>
parents: 2520
diff changeset
621 case SDL_HAPTIC_TRIANGLE:
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
622 return kFFEffectType_Triangle_ID;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
623
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
624 case SDL_HAPTIC_SAWTOOTHUP:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
625 return kFFEffectType_SawtoothUp_ID;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
626
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
627 case SDL_HAPTIC_SAWTOOTHDOWN:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
628 return kFFEffectType_SawtoothDown_ID;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
629
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
630 case SDL_HAPTIC_SPRING:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
631 return kFFEffectType_Spring_ID;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
632
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
633 case SDL_HAPTIC_DAMPER:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
634 return kFFEffectType_Damper_ID;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
635
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
636 case SDL_HAPTIC_INERTIA:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
637 return kFFEffectType_Inertia_ID;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
638
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
639 case SDL_HAPTIC_FRICTION:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
640 return kFFEffectType_Friction_ID;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
641
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
642 case SDL_HAPTIC_CUSTOM:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
643 return kFFEffectType_CustomForce_ID;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
644
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
645 default:
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
646 SDL_SetError("Haptic: Unknown effect type.");
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
647 return NULL;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
648 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
649 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
650
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
651
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
652 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
653 * Creates a new haptic effect.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
654 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
655 int
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
656 SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect * effect,
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
657 SDL_HapticEffect * base)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
658 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
659 HRESULT ret;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
660 CFUUIDRef type;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
661
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
662 /* Alloc the effect. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
663 effect->hweffect = (struct haptic_hweffect *)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
664 SDL_malloc(sizeof(struct haptic_hweffect));
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
665 if (effect->hweffect == NULL) {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
666 SDL_OutOfMemory();
2527
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
667 goto err_hweffect;
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
668 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
669
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
670 /* Get the type. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
671 type = SDL_SYS_HapticEffectType(effect);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
672 if (type == NULL) {
2527
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
673 goto err_hweffect;
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
674 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
675
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
676 /* Get the effect. */
2527
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
677 if (SDL_SYS_ToFFEFFECT(haptic, &effect->hweffect->effect, &effect->effect ) < 0) {
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
678 goto err_effectdone;
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
679 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
680
2527
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
681 /* Create the actual effect. */
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
682 ret = FFDeviceCreateEffect( haptic->hwdata->device, type,
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
683 &effect->hweffect->effect, &effect->hweffect->ref );
2527
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
684
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
685 if (ret != FF_OK) {
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
686 SDL_SetError("Haptic: Unable to create effect.");
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
687 goto err_effectdone;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
688 }
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
689
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
690 return 0;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
691
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
692 err_effectdone:
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
693 SDL_SYS_HapticFreeFFEFFECT(&effect->hweffect->effect);
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
694 err_hweffect:
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
695 if (effect->hweffect != NULL) {
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
696 SDL_free(effect->hweffect);
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
697 effect->hweffect = NULL;
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
698 }
924a32719b6f Handle axes for darwin now.
Edgar Simo <bobbens@gmail.com>
parents: 2522
diff changeset
699 return -1;
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
700 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
701
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
702
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
703 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
704 * Updates an effect.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
705 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
706 int SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
707 struct haptic_effect * effect, SDL_HapticEffect * data)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
708 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
709 /* TODO */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
710 return -1;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
711 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
712
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
713
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
714 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
715 * Runs an effect.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
716 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
717 int
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
718 SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect,
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
719 Uint32 iterations)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
720 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
721 HRESULT ret;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
722 Uint32 iter;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
723
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
724 /* Check if it's infinite. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
725 if (iterations == SDL_HAPTIC_INFINITY) {
2521
7aa91c21ce5f Many typo and silly mistake fixes.
Edgar Simo <bobbens@gmail.com>
parents: 2520
diff changeset
726 iter = FF_INFINITE;
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
727 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
728 else
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
729 iter = iterations;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
730
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
731 /* Run the effect. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
732 ret = FFEffectStart(effect->hweffect->ref, iter, 0);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
733 if (ret != FF_OK) {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
734 SDL_SetError("Haptic: Unable to run the effect.");
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
735 return -1;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
736 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
737
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
738 return 0;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
739 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
740
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
741
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
742 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
743 * Stops an effect.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
744 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
745 int
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
746 SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
747 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
748 HRESULT ret;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
749
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
750 ret = FFEffectStop(effect->hweffect->ref);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
751 if (ret != FF_OK) {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
752 SDL_SetError("Haptic: Unable to stop the effect.");
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
753 return -1;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
754 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
755
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
756 return 0;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
757 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
758
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
759
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
760 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
761 * Frees the effect.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
762 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
763 void
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
764 SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
765 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
766 HRESULT ret;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
767
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
768 ret = FFDeviceReleaseEffect(haptic->hwdata->device, effect->hweffect->ref);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
769 if (ret != FF_OK) {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
770 SDL_SetError("Haptic: Error removing the effect from the device.");
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
771 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
772 SDL_free(effect->hweffect->effect.lpvTypeSpecificParams);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
773 effect->hweffect->effect.lpvTypeSpecificParams = NULL;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
774 SDL_free(effect->hweffect);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
775 effect->hweffect = NULL;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
776 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
777
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
778
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
779 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
780 * Gets the status of a haptic effect.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
781 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
782 int
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
783 SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect * effect)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
784 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
785 HRESULT ret;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
786 FFEffectStatusFlag status;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
787
2521
7aa91c21ce5f Many typo and silly mistake fixes.
Edgar Simo <bobbens@gmail.com>
parents: 2520
diff changeset
788 ret = FFEffectGetEffectStatus(effect->hweffect->ref, &status);
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
789 if (ret != FF_OK) {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
790 SDL_SetError("Haptic: Unable to get effect status.");
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
791 return -1;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
792 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
793
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
794 if (status == 0) return SDL_FALSE;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
795 return SDL_TRUE; /* Assume it's playing or emulated. */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
796 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
797
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
798
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
799 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
800 * Sets the gain.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
801 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
802 int
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
803 SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
804 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
805 HRESULT ret;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
806 Uint32 val;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
807
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
808 val = gain * 100; /* Mac OS X uses 0 to 10,000 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
809 ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device, FFPROP_FFGAIN, &val);
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
810 if (ret != FF_OK) {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
811 SDL_SetError("Haptic: Error setting gain.");
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
812 return -1;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
813 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
814
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
815 return 0;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
816 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
817
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
818
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
819 /*
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
820 * Sets the autocentering.
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
821 */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
822 int
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
823 SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
824 {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
825 HRESULT ret;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
826 Uint32 val;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
827
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
828 /* Mac OS X only has 0 (off) and 1 (on) */
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
829 if (autocenter == 0) val = 0;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
830 else val = 1;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
831
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
832 ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device,
2521
7aa91c21ce5f Many typo and silly mistake fixes.
Edgar Simo <bobbens@gmail.com>
parents: 2520
diff changeset
833 FFPROP_AUTOCENTER, &val);
2520
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
834 if (ret != FF_OK) {
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
835 SDL_SetError("Haptic: Error setting autocenter.");
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
836 return -1;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
837 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
838
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
839 return 0;
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
840
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
841 }
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
842
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
843
6aee9eb4fc6d Adding initial darwin port of haptic subsystem - broken atm.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
844 #endif /* SDL_HAPTIC_LINUX */