comparison src/haptic/linux/SDL_syshaptic.c @ 2481:5d0ea4576f20 gsoc2008_force_feedback

More comments. Clamped values in struct ff_effect. Added waveforms.
author Edgar Simo <bobbens@gmail.com>
date Tue, 01 Jul 2008 10:44:42 +0000
parents b883974445fc
children b51ad78812d5
comparison
equal deleted inserted replaced
2480:b883974445fc 2481:5d0ea4576f20
269 SDL_free(SDL_hapticlist[i].fname); 269 SDL_free(SDL_hapticlist[i].fname);
270 } 270 }
271 SDL_hapticlist[0].fname = NULL; 271 SDL_hapticlist[0].fname = NULL;
272 } 272 }
273 273
274 #define CLAMP(x) (((x) > 32767) ? 32767 : x)
274 /* 275 /*
275 * Initializes the linux effect struct from a haptic_effect. 276 * Initializes the linux effect struct from a haptic_effect.
277 * Values above 32767 (for unsigned) are unspecified so we must clamp.
276 */ 278 */
277 static int 279 static int
278 SDL_SYS_ToFFEffect( struct ff_effect * dest, SDL_HapticEffect * src ) 280 SDL_SYS_ToFFEffect( struct ff_effect * dest, SDL_HapticEffect * src )
279 { 281 {
280 SDL_HapticConstant *constant; 282 SDL_HapticConstant *constant;
287 case SDL_HAPTIC_CONSTANT: 289 case SDL_HAPTIC_CONSTANT:
288 constant = &src->constant; 290 constant = &src->constant;
289 291
290 /* Header */ 292 /* Header */
291 dest->type = FF_CONSTANT; 293 dest->type = FF_CONSTANT;
292 dest->direction = constant->direction; 294 dest->direction = CLAMP(constant->direction);
293 295
294 /* Replay */ 296 /* Replay */
295 dest->replay.length = constant->length; 297 dest->replay.length = CLAMP(constant->length);
296 dest->replay.delay = constant->delay; 298 dest->replay.delay = CLAMP(constant->delay);
297 299
298 /* Trigger */ 300 /* Trigger */
299 dest->trigger.button = constant->button; 301 dest->trigger.button = CLAMP(constant->button);
300 dest->trigger.interval = constant->interval; 302 dest->trigger.interval = CLAMP(constant->interval);
301 303
302 /* Constant */ 304 /* Constant */
303 dest->u.constant.level = constant->level; 305 dest->u.constant.level = constant->level;
304 306
305 /* Envelope */ 307 /* Envelope */
306 dest->u.constant.envelope.attack_length = constant->attack_length; 308 dest->u.constant.envelope.attack_length = CLAMP(constant->attack_length);
307 dest->u.constant.envelope.attack_level = constant->attack_level; 309 dest->u.constant.envelope.attack_level = CLAMP(constant->attack_level);
308 dest->u.constant.envelope.fade_length = constant->fade_length; 310 dest->u.constant.envelope.fade_length = CLAMP(constant->fade_length);
309 dest->u.constant.envelope.fade_level = constant->fade_level; 311 dest->u.constant.envelope.fade_level = CLAMP(constant->fade_level);
310 312
311 break; 313 break;
312 314
313 case SDL_HAPTIC_PERIODIC: 315 case SDL_HAPTIC_PERIODIC:
314 periodic = &src->periodic; 316 periodic = &src->periodic;
315 317
316 /* Header */ 318 /* Header */
317 dest->type = FF_PERIODIC; 319 dest->type = FF_PERIODIC;
318 dest->direction = periodic->direction; 320 dest->direction = CLAMP(periodic->direction);
319 321
320 /* Replay */ 322 /* Replay */
321 dest->replay.length = periodic->length; 323 dest->replay.length = CLAMP(periodic->length);
322 dest->replay.delay = periodic->delay; 324 dest->replay.delay = CLAMP(periodic->delay);
323 325
324 /* Trigger */ 326 /* Trigger */
325 dest->trigger.button = periodic->button; 327 dest->trigger.button = CLAMP(periodic->button);
326 dest->trigger.interval = periodic->interval; 328 dest->trigger.interval = CLAMP(periodic->interval);
327 329
328 /* Constant */ 330 /* Constant */
329 dest->u.periodic.waveform = periodic->waveform; 331 switch (periodic->waveform) {
330 dest->u.periodic.period = periodic->period; 332 case SDL_WAVEFORM_SINE:
333 dest->u.periodic.waveform = FF_SINE;
334 break;
335 case SDL_WAVEFORM_SQUARE:
336 dest->u.periodic.waveform = FF_SQUARE;
337 break;
338 case SDL_WAVEFORM_TRIANGLE:
339 dest->u.periodic.waveform = FF_TRIANGLE;
340 break;
341 case SDL_WAVEFORM_SAWTOOTHUP:
342 dest->u.periodic.waveform = FF_SAW_UP;
343 break;
344 case SDL_WAVEFORM_SAWTOOTHDOWN:
345 dest->u.periodic.waveform = FF_SAW_DOWN;
346 break;
347
348 default:
349 SDL_SetError("Unknown waveform.");
350 return -1;
351 }
352 dest->u.periodic.period = CLAMP(periodic->period);
331 dest->u.periodic.magnitude = periodic->magnitude; 353 dest->u.periodic.magnitude = periodic->magnitude;
332 dest->u.periodic.offset = periodic->offset; 354 dest->u.periodic.offset = periodic->offset;
333 dest->u.periodic.phase = periodic->phase; 355 dest->u.periodic.phase = CLAMP(periodic->phase);
334 356
335 /* Envelope */ 357 /* Envelope */
336 dest->u.periodic.envelope.attack_length = periodic->attack_length; 358 dest->u.periodic.envelope.attack_length = CLAMP(periodic->attack_length);
337 dest->u.periodic.envelope.attack_level = periodic->attack_level; 359 dest->u.periodic.envelope.attack_level = CLAMP(periodic->attack_level);
338 dest->u.periodic.envelope.fade_length = periodic->fade_length; 360 dest->u.periodic.envelope.fade_length = CLAMP(periodic->fade_length);
339 dest->u.periodic.envelope.fade_level = periodic->fade_level; 361 dest->u.periodic.envelope.fade_level = CLAMP(periodic->fade_level);
340 362
341 break; 363 break;
342 364
343 default: 365 default:
344 SDL_SetError("Unknown haptic effect type."); 366 SDL_SetError("Unknown haptic effect type.");