63
62
unsigned int supported;
64
/* Enable standard application logging */
65
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
69
71
if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) {
70
printf("USAGE: %s [device]\n"
72
SDL_Log("USAGE: %s [device]\n"
71
73
"If device is a two-digit number it'll use it as an index, otherwise\n"
72
74
"it'll use it as if it were part of the device's name.\n",
84
86
/* Initialize the force feedbackness */
85
87
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK |
87
printf("%d Haptic devices detected.\n", SDL_NumHaptics());
89
SDL_Log("%d Haptic devices detected.\n", SDL_NumHaptics());
88
90
if (SDL_NumHaptics() > 0) {
89
91
/* We'll just use index or the first force feedback device found */
90
92
if (name == NULL) {
100
102
if (i >= SDL_NumHaptics()) {
101
printf("Unable to find device matching '%s', aborting.\n",
103
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n",
107
109
haptic = SDL_HapticOpen(i);
108
110
if (haptic == NULL) {
109
printf("Unable to create the haptic device: %s\n",
111
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n",
113
printf("Device: %s\n", SDL_HapticName(i));
115
SDL_Log("Device: %s\n", SDL_HapticName(i));
114
116
HapticPrintSupported(haptic);
116
printf("No Haptic devices found!\n");
118
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n");
126
128
supported = SDL_HapticQuery(haptic);
128
printf("\nUploading effects\n");
130
SDL_Log("\nUploading effects\n");
129
131
/* First we'll try a SINE effect. */
130
132
if (supported & SDL_HAPTIC_SINE) {
131
printf(" effect %d: Sine Wave\n", nefx);
133
SDL_Log(" effect %d: Sine Wave\n", nefx);
132
134
efx[nefx].type = SDL_HAPTIC_SINE;
133
135
efx[nefx].periodic.period = 1000;
134
136
efx[nefx].periodic.magnitude = 0x4000;
137
139
efx[nefx].periodic.fade_length = 1000;
138
140
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
139
141
if (id[nefx] < 0) {
140
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
142
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
141
143
abort_execution();
145
147
/* Now we'll try a SAWTOOTHUP */
146
148
if (supported & SDL_HAPTIC_SAWTOOTHUP) {
147
printf(" effect %d: Sawtooth Up\n", nefx);
149
SDL_Log(" effect %d: Sawtooth Up\n", nefx);
148
150
efx[nefx].type = SDL_HAPTIC_SAWTOOTHUP;
149
151
efx[nefx].periodic.period = 500;
150
152
efx[nefx].periodic.magnitude = 0x5000;
153
155
efx[nefx].periodic.fade_length = 1000;
154
156
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
155
157
if (id[nefx] < 0) {
156
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
158
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
157
159
abort_execution();
161
163
/* Now the classical constant effect. */
162
164
if (supported & SDL_HAPTIC_CONSTANT) {
163
printf(" effect %d: Constant Force\n", nefx);
165
SDL_Log(" effect %d: Constant Force\n", nefx);
164
166
efx[nefx].type = SDL_HAPTIC_CONSTANT;
165
167
efx[nefx].constant.direction.type = SDL_HAPTIC_POLAR;
166
168
efx[nefx].constant.direction.dir[0] = 20000; /* Force comes from the south-west. */
170
172
efx[nefx].constant.fade_length = 1000;
171
173
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
172
174
if (id[nefx] < 0) {
173
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
175
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
174
176
abort_execution();
178
180
/* The cute spring effect. */
179
181
if (supported & SDL_HAPTIC_SPRING) {
180
printf(" effect %d: Condition Spring\n", nefx);
182
SDL_Log(" effect %d: Condition Spring\n", nefx);
181
183
efx[nefx].type = SDL_HAPTIC_SPRING;
182
184
efx[nefx].condition.length = 5000;
183
185
for (i = 0; i < SDL_HapticNumAxes(haptic); i++) {
190
192
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
191
193
if (id[nefx] < 0) {
192
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
194
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
193
195
abort_execution();
197
199
/* The pretty awesome inertia effect. */
198
200
if (supported & SDL_HAPTIC_INERTIA) {
199
printf(" effect %d: Condition Inertia\n", nefx);
201
SDL_Log(" effect %d: Condition Inertia\n", nefx);
200
202
efx[nefx].type = SDL_HAPTIC_SPRING;
201
203
efx[nefx].condition.length = 5000;
202
204
for (i = 0; i < SDL_HapticNumAxes(haptic); i++) {
208
210
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
209
211
if (id[nefx] < 0) {
210
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
212
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
211
213
abort_execution();
216
218
/* Finally we'll try a left/right effect. */
217
219
if (supported & SDL_HAPTIC_LEFTRIGHT) {
218
printf(" effect %d: Left/Right\n", nefx);
220
SDL_Log(" effect %d: Left/Right\n", nefx);
219
221
efx[nefx].type = SDL_HAPTIC_LEFTRIGHT;
220
222
efx[nefx].leftright.length = 5000;
221
223
efx[nefx].leftright.large_magnitude = 0x3000;
222
224
efx[nefx].leftright.small_magnitude = 0xFFFF;
223
225
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
224
226
if (id[nefx] < 0) {
225
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
227
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
226
228
abort_execution();
233
235
("\nNow playing effects for 5 seconds each with 1 second delay between\n");
234
236
for (i = 0; i < nefx; i++) {
235
printf(" Playing effect %d\n", i);
237
SDL_Log(" Playing effect %d\n", i);
236
238
SDL_HapticRunEffect(haptic, id[i], 1);
237
239
SDL_Delay(6000); /* Effects only have length 5000 */
270
272
unsigned int supported;
272
274
supported = SDL_HapticQuery(haptic);
273
printf(" Supported effects [%d effects, %d playing]:\n",
275
SDL_Log(" Supported effects [%d effects, %d playing]:\n",
274
276
SDL_HapticNumEffects(haptic), SDL_HapticNumEffectsPlaying(haptic));
275
277
if (supported & SDL_HAPTIC_CONSTANT)
276
printf(" constant\n");
278
SDL_Log(" constant\n");
277
279
if (supported & SDL_HAPTIC_SINE)
279
281
/* !!! FIXME: put this back when we have more bits in 2.1 */
280
/*if (supported & SDL_HAPTIC_SQUARE)
281
printf(" square\n");*/
282
/* if (supported & SDL_HAPTIC_SQUARE)
283
SDL_Log(" square\n"); */
282
284
if (supported & SDL_HAPTIC_TRIANGLE)
283
printf(" triangle\n");
285
SDL_Log(" triangle\n");
284
286
if (supported & SDL_HAPTIC_SAWTOOTHUP)
285
printf(" sawtoothup\n");
287
SDL_Log(" sawtoothup\n");
286
288
if (supported & SDL_HAPTIC_SAWTOOTHDOWN)
287
printf(" sawtoothdown\n");
289
SDL_Log(" sawtoothdown\n");
288
290
if (supported & SDL_HAPTIC_RAMP)
290
292
if (supported & SDL_HAPTIC_FRICTION)
291
printf(" friction\n");
293
SDL_Log(" friction\n");
292
294
if (supported & SDL_HAPTIC_SPRING)
295
SDL_Log(" spring\n");
294
296
if (supported & SDL_HAPTIC_DAMPER)
297
SDL_Log(" damper\n");
296
298
if (supported & SDL_HAPTIC_INERTIA)
297
printf(" intertia\n");
299
SDL_Log(" inertia\n");
298
300
if (supported & SDL_HAPTIC_CUSTOM)
301
SDL_Log(" custom\n");
300
302
if (supported & SDL_HAPTIC_LEFTRIGHT)
301
printf(" left/right\n");
302
printf(" Supported capabilities:\n");
303
SDL_Log(" left/right\n");
304
SDL_Log(" Supported capabilities:\n");
303
305
if (supported & SDL_HAPTIC_GAIN)
305
307
if (supported & SDL_HAPTIC_AUTOCENTER)
306
printf(" autocenter\n");
308
SDL_Log(" autocenter\n");
307
309
if (supported & SDL_HAPTIC_STATUS)
310
SDL_Log(" status\n");
314
316
main(int argc, char *argv[])
316
fprintf(stderr, "SDL compiled without Haptic support.\n");
318
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Haptic support.\n");