src/haptic/SDL_haptic.c
author Edgar Simo <bobbens@gmail.com>
Thu, 31 Jul 2008 09:45:27 +0000
branchgsoc2008_force_feedback
changeset 2561 3696b9ce8a37
parent 2560 2274406ba792
child 2645 269ba4f28d0e
permissions -rw-r--r--
Correctness patch, it's up to the SDL_haptic.c to clean up effects, not SDL_syshaptic.c.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
     1
/*
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
     3
    Copyright (C) 2008 Edgar Simo
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
     4
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
     9
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    13
    Lesser General Public License for more details.
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    14
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    16
    License along with this library; if not, write to the Free Software
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    18
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    19
    Sam Lantinga
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    20
    slouken@libsdl.org
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    21
*/
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    22
#include "SDL_config.h"
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    23
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    24
#include "SDL_syshaptic.h"
2489
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
    25
#include "../joystick/SDL_joystick_c.h" /* For SDL_PrivateJoystickValid */
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    26
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    27
2512
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
    28
Uint8 SDL_numhaptics = 0;
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    29
SDL_Haptic **SDL_haptics = NULL;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    30
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    31
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    32
/*
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    33
 * Initializes the Haptic devices.
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    34
 */
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    35
int
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    36
SDL_HapticInit(void)
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    37
{  
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    38
   int arraylen;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    39
   int status;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    40
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    41
   SDL_numhaptics = 0;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    42
   status = SDL_SYS_HapticInit();
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    43
   if (status >= 0) {
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    44
      arraylen = (status + 1) * sizeof(*SDL_haptics);
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    45
      SDL_haptics = (SDL_Haptic **) SDL_malloc(arraylen);
2514
840e1b6325c0 Minor corrections.
Edgar Simo <bobbens@gmail.com>
parents: 2513
diff changeset
    46
      if (SDL_haptics == NULL) { /* Out of memory. */
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    47
         SDL_numhaptics = 0;
2514
840e1b6325c0 Minor corrections.
Edgar Simo <bobbens@gmail.com>
parents: 2513
diff changeset
    48
      }
840e1b6325c0 Minor corrections.
Edgar Simo <bobbens@gmail.com>
parents: 2513
diff changeset
    49
      else {
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    50
         SDL_memset(SDL_haptics, 0, arraylen);
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    51
         SDL_numhaptics = status;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    52
      }
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    53
      status = 0;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    54
   }
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    55
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    56
   return status;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    57
}
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    58
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    59
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    60
/*
2505
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
    61
 * Checks to see if the haptic device is valid
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
    62
 */
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
    63
static int
2560
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
    64
ValidHaptic(SDL_Haptic * haptic)
2505
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
    65
{
2560
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
    66
   int i;
2505
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
    67
   int valid;
2560
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
    68
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
    69
   valid = 0;
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
    70
   for (i=0; i<SDL_numhaptics; i++) {
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
    71
      if (SDL_haptics[i] == haptic) {
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
    72
         valid = 1;
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
    73
         break;
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
    74
      }
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
    75
   }
2505
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
    76
   
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
    77
   return valid;
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
    78
}
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
    79
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
    80
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
    81
/*
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    82
 * Returns the number of available devices.
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    83
 */
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    84
int
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    85
SDL_NumHaptics(void)
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    86
{
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    87
   return SDL_numhaptics;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    88
}
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    89
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    90
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    91
/*
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    92
 * Gets the name of a Haptic device by index.
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    93
 */
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    94
const char *
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    95
SDL_HapticName(int device_index)
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    96
{
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    97
   if ((device_index < 0) || (device_index >= SDL_numhaptics)) {
2513
55fd9103a330 Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents: 2512
diff changeset
    98
      SDL_SetError("Haptic: There are %d haptic devices available", SDL_numhaptics);
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
    99
      return NULL;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   100
   }
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   101
   return SDL_SYS_HapticName(device_index);
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   102
}
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   103
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   104
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   105
/*
2475
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
   106
 * Opens a Haptic device.
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   107
 */
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   108
SDL_Haptic *
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   109
SDL_HapticOpen(int device_index)
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   110
{
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   111
   int i;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   112
   SDL_Haptic *haptic;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   113
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   114
   if ((device_index < 0) || (device_index >= SDL_numhaptics)) {
2513
55fd9103a330 Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents: 2512
diff changeset
   115
      SDL_SetError("Haptic: There are %d haptic devices available", SDL_numhaptics);
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   116
      return NULL;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   117
   }
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   118
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   119
   /* If the haptic is already open, return it */
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   120
   for (i=0; SDL_haptics[i]; i++) {             
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   121
      if (device_index == SDL_haptics[i]->index) {
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   122
         haptic = SDL_haptics[i];
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   123
         ++haptic->ref_count;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   124
         return haptic;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   125
      }
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   126
   }
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   127
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   128
   /* Create the haptic device */
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   129
   haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   130
   if (haptic == NULL) {
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   131
      SDL_OutOfMemory();
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   132
      return NULL;
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   133
   }
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   134
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   135
   /* Initialize the haptic device */
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   136
   SDL_memset(haptic, 0, (sizeof *haptic));
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   137
   haptic->index = device_index;
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   138
   if (SDL_SYS_HapticOpen(haptic) < 0) {
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   139
      SDL_free(haptic);
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   140
      return NULL;
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   141
   }
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   142
2507
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   143
   /* Disable autocenter and set gain to max. */
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   144
   if (haptic->supported & SDL_HAPTIC_GAIN)
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   145
      SDL_HapticSetGain(haptic,100);
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   146
   if (haptic->supported & SDL_HAPTIC_AUTOCENTER)
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   147
      SDL_HapticSetAutocenter(haptic,0);
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   148
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   149
   /* Add haptic to list */
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   150
   ++haptic->ref_count;
2490
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   151
   for (i=0; SDL_haptics[i]; i++)
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   152
      /* Skip to next haptic */ ;
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   153
   SDL_haptics[i] = haptic;
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   154
2472
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   155
   return haptic;
3f73c88c9abb First commit of the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
   156
}
2474
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
   157
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
   158
2475
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
   159
/*
2506
ba8e99fe92c1 Added SDL_HapticOpened().
Edgar Simo <bobbens@gmail.com>
parents: 2505
diff changeset
   160
 * Returns 1 if the device has been opened.
ba8e99fe92c1 Added SDL_HapticOpened().
Edgar Simo <bobbens@gmail.com>
parents: 2505
diff changeset
   161
 */
ba8e99fe92c1 Added SDL_HapticOpened().
Edgar Simo <bobbens@gmail.com>
parents: 2505
diff changeset
   162
int
ba8e99fe92c1 Added SDL_HapticOpened().
Edgar Simo <bobbens@gmail.com>
parents: 2505
diff changeset
   163
SDL_HapticOpened(int device_index)
ba8e99fe92c1 Added SDL_HapticOpened().
Edgar Simo <bobbens@gmail.com>
parents: 2505
diff changeset
   164
{
ba8e99fe92c1 Added SDL_HapticOpened().
Edgar Simo <bobbens@gmail.com>
parents: 2505
diff changeset
   165
   int i, opened;
ba8e99fe92c1 Added SDL_HapticOpened().
Edgar Simo <bobbens@gmail.com>
parents: 2505
diff changeset
   166
ba8e99fe92c1 Added SDL_HapticOpened().
Edgar Simo <bobbens@gmail.com>
parents: 2505
diff changeset
   167
   opened = 0;
ba8e99fe92c1 Added SDL_HapticOpened().
Edgar Simo <bobbens@gmail.com>
parents: 2505
diff changeset
   168
   for (i=0; SDL_haptics[i]; i++) {
ba8e99fe92c1 Added SDL_HapticOpened().
Edgar Simo <bobbens@gmail.com>
parents: 2505
diff changeset
   169
      if (SDL_haptics[i]->index == (Uint8) device_index) {
ba8e99fe92c1 Added SDL_HapticOpened().
Edgar Simo <bobbens@gmail.com>
parents: 2505
diff changeset
   170
         opened = 1;
ba8e99fe92c1 Added SDL_HapticOpened().
Edgar Simo <bobbens@gmail.com>
parents: 2505
diff changeset
   171
         break;
ba8e99fe92c1 Added SDL_HapticOpened().
Edgar Simo <bobbens@gmail.com>
parents: 2505
diff changeset
   172
      }
ba8e99fe92c1 Added SDL_HapticOpened().
Edgar Simo <bobbens@gmail.com>
parents: 2505
diff changeset
   173
   }
ba8e99fe92c1 Added SDL_HapticOpened().
Edgar Simo <bobbens@gmail.com>
parents: 2505
diff changeset
   174
   return opened;
ba8e99fe92c1 Added SDL_HapticOpened().
Edgar Simo <bobbens@gmail.com>
parents: 2505
diff changeset
   175
}
ba8e99fe92c1 Added SDL_HapticOpened().
Edgar Simo <bobbens@gmail.com>
parents: 2505
diff changeset
   176
ba8e99fe92c1 Added SDL_HapticOpened().
Edgar Simo <bobbens@gmail.com>
parents: 2505
diff changeset
   177
ba8e99fe92c1 Added SDL_HapticOpened().
Edgar Simo <bobbens@gmail.com>
parents: 2505
diff changeset
   178
/*
2505
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
   179
 * Returns the index to a haptic device.
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
   180
 */
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
   181
int
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
   182
SDL_HapticIndex(SDL_Haptic * haptic)
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
   183
{
2560
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
   184
   if (!ValidHaptic(haptic)) {
2505
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
   185
      return -1;
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
   186
   }
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
   187
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
   188
   return haptic->index;
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
   189
}
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
   190
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
   191
abfcba0f3bd1 Added SDL_HapticIndex.
Edgar Simo <bobbens@gmail.com>
parents: 2497
diff changeset
   192
/*
2512
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   193
 * Returns SDL_TRUE if mouse is haptic, SDL_FALSE if it isn't.
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   194
 */
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   195
int
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   196
SDL_MouseIsHaptic(void)
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   197
{
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   198
   if (SDL_SYS_HapticMouse() < 0)
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   199
      return SDL_FALSE;
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   200
   return SDL_TRUE;
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   201
}
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   202
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   203
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   204
/*
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   205
 * Returns the haptic device if mouse is haptic or NULL elsewise.
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   206
 */
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   207
SDL_Haptic *
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   208
SDL_HapticOpenFromMouse(void)
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   209
{
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   210
   int device_index;
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   211
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   212
   device_index = SDL_SYS_HapticMouse();
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   213
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   214
   if (device_index < 0) {
2513
55fd9103a330 Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents: 2512
diff changeset
   215
      SDL_SetError("Haptic: Mouse isn't a haptic device.");
2512
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   216
      return NULL;
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   217
   }
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   218
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   219
   return SDL_HapticOpen(device_index);
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   220
}
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   221
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   222
ef147ee4896c Improved some ioctl handling.
Edgar Simo <bobbens@gmail.com>
parents: 2507
diff changeset
   223
/*
2489
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   224
 * Returns SDL_TRUE if joystick has haptic features.
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   225
 */
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   226
int
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   227
SDL_JoystickIsHaptic(SDL_Joystick * joystick)
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   228
{
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   229
   int ret;
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   230
2490
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   231
   /* Must be a valid joystick */
2489
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   232
   if (!SDL_PrivateJoystickValid(&joystick)) {
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   233
      return -1;
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   234
   }
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   235
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   236
   ret = SDL_SYS_JoystickIsHaptic(joystick);
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   237
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   238
   if (ret > 0) return SDL_TRUE;
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   239
   else if (ret == 0) return SDL_FALSE;
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   240
   else return -1;
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   241
}
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   242
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   243
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   244
/*
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   245
 * Opens a haptic device from a joystick.
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   246
 */
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   247
SDL_Haptic *
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   248
SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   249
{
2490
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   250
   int i;
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   251
   SDL_Haptic *haptic;
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   252
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   253
   /* Must be a valid joystick */
2489
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   254
   if (!SDL_PrivateJoystickValid(&joystick)) {
2490
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   255
      return NULL;
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   256
   }
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   257
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   258
   /* Joystick must be haptic */
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   259
   if (SDL_SYS_JoystickIsHaptic(joystick) <= 0) {
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   260
      return NULL;
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   261
   }
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   262
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   263
   /* Check to see if joystick's haptic is already open */
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   264
   for (i=0; SDL_haptics[i]; i++) {
2491
10bc7aaf5114 Commented SDL_syshaptic.h.
Edgar Simo <bobbens@gmail.com>
parents: 2490
diff changeset
   265
      if (SDL_SYS_JoystickSameHaptic(SDL_haptics[i],joystick)) {
2490
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   266
         haptic = SDL_haptics[i];
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   267
         ++haptic->ref_count;
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   268
         return haptic;
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   269
      }
2489
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   270
   }
2490
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   271
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   272
   /* Create the haptic device */
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   273
   haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   274
   if (haptic == NULL) {
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   275
      SDL_OutOfMemory();
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   276
      return NULL;
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   277
   }
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   278
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   279
   /* Initialize the haptic device */
2524
1a55848ce198 Better handling of opening haptics from joysticks.
Edgar Simo <bobbens@gmail.com>
parents: 2523
diff changeset
   280
   SDL_memset(haptic, 0, sizeof(SDL_Haptic));
2490
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   281
   if (SDL_SYS_HapticOpenFromJoystick(haptic,joystick) < 0) {
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   282
      SDL_free(haptic);
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   283
      return NULL;
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   284
   }
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   285
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   286
   /* Add haptic to list */
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   287
   ++haptic->ref_count;
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   288
   for (i=0; SDL_haptics[i]; i++)
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   289
      /* Skip to next haptic */ ;
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   290
   SDL_haptics[i] = haptic;
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   291
be9b206d44af Some more error checking.
Edgar Simo <bobbens@gmail.com>
parents: 2489
diff changeset
   292
   return haptic;
2489
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   293
}
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   294
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   295
96adc8025331 Exposed some of the joystick stuff to the haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2488
diff changeset
   296
/*
2475
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
   297
 * Closes a SDL_Haptic device.
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
   298
 */
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
   299
void
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
   300
SDL_HapticClose(SDL_Haptic * haptic)
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
   301
{
2476
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   302
   int i;
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   303
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   304
   /* Must be valid */
2560
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
   305
   if (!ValidHaptic(haptic)) {
2476
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   306
      return;
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   307
   }
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   308
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   309
   /* Check if it's still in use */
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   310
   if (--haptic->ref_count < 0) {
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   311
      return;
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   312
   }
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   313
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   314
   /* Close it, properly removing effects if needed */
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   315
   for (i=0; i<haptic->neffects; i++) {
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   316
      if (haptic->effects[i].hweffect != NULL) {
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   317
         SDL_HapticDestroyEffect(haptic,i);
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   318
      }
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   319
   }
2476
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   320
   SDL_SYS_HapticClose(haptic);
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   321
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   322
   /* Remove from the list */
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   323
   for (i = 0; SDL_haptics[i]; ++i) {
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   324
      if (haptic == SDL_haptics[i]) {
2561
3696b9ce8a37 Correctness patch, it's up to the SDL_haptic.c to clean up effects, not SDL_syshaptic.c.
Edgar Simo <bobbens@gmail.com>
parents: 2560
diff changeset
   325
         SDL_haptics[i] = NULL;
2476
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   326
         SDL_memcpy(&SDL_haptics[i], &SDL_haptics[i + 1],
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   327
               (SDL_numhaptics - i) * sizeof(haptic));
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   328
         break;
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   329
      }
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   330
   }
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   331
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   332
   /* Free */
242d8a668ebb * Implemented opening and closing of haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2475
diff changeset
   333
   SDL_free(haptic);
2475
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
   334
}
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
   335
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
   336
/*
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
   337
 * Cleans up after the subsystem.
4b874e3a3a2c Some code cleanup.
Edgar Simo <bobbens@gmail.com>
parents: 2474
diff changeset
   338
 */
2474
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
   339
void
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
   340
SDL_HapticQuit(void)
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
   341
{
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
   342
   SDL_SYS_HapticQuit();
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
   343
   if (SDL_haptics != NULL) {
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
   344
      SDL_free(SDL_haptics);
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
   345
      SDL_haptics = NULL;
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
   346
   }
2514
840e1b6325c0 Minor corrections.
Edgar Simo <bobbens@gmail.com>
parents: 2513
diff changeset
   347
   SDL_numhaptics = 0;
2474
3f80bf1528b4 Properly quit the SDL_haptic subsystem.
Edgar Simo <bobbens@gmail.com>
parents: 2472
diff changeset
   348
}
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   349
2478
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   350
/*
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   351
 * Returns the number of effects a haptic device has.
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   352
 */
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   353
int
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   354
SDL_HapticNumEffects(SDL_Haptic * haptic)
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   355
{
2560
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
   356
   if (!ValidHaptic(haptic)) {
2478
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   357
      return -1;
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   358
   }
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   359
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   360
   return haptic->neffects;
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   361
}
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   362
2515
030fc4375e63 Added SDL_HapticNumEffectsPlaying().
Edgar Simo <bobbens@gmail.com>
parents: 2514
diff changeset
   363
030fc4375e63 Added SDL_HapticNumEffectsPlaying().
Edgar Simo <bobbens@gmail.com>
parents: 2514
diff changeset
   364
/*
030fc4375e63 Added SDL_HapticNumEffectsPlaying().
Edgar Simo <bobbens@gmail.com>
parents: 2514
diff changeset
   365
 * Returns the number of effects a haptic device can play.
030fc4375e63 Added SDL_HapticNumEffectsPlaying().
Edgar Simo <bobbens@gmail.com>
parents: 2514
diff changeset
   366
 */
030fc4375e63 Added SDL_HapticNumEffectsPlaying().
Edgar Simo <bobbens@gmail.com>
parents: 2514
diff changeset
   367
int
030fc4375e63 Added SDL_HapticNumEffectsPlaying().
Edgar Simo <bobbens@gmail.com>
parents: 2514
diff changeset
   368
SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic)
030fc4375e63 Added SDL_HapticNumEffectsPlaying().
Edgar Simo <bobbens@gmail.com>
parents: 2514
diff changeset
   369
{
2560
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
   370
   if (!ValidHaptic(haptic)) {
2515
030fc4375e63 Added SDL_HapticNumEffectsPlaying().
Edgar Simo <bobbens@gmail.com>
parents: 2514
diff changeset
   371
      return -1;
030fc4375e63 Added SDL_HapticNumEffectsPlaying().
Edgar Simo <bobbens@gmail.com>
parents: 2514
diff changeset
   372
   }
030fc4375e63 Added SDL_HapticNumEffectsPlaying().
Edgar Simo <bobbens@gmail.com>
parents: 2514
diff changeset
   373
030fc4375e63 Added SDL_HapticNumEffectsPlaying().
Edgar Simo <bobbens@gmail.com>
parents: 2514
diff changeset
   374
   return haptic->nplaying;
030fc4375e63 Added SDL_HapticNumEffectsPlaying().
Edgar Simo <bobbens@gmail.com>
parents: 2514
diff changeset
   375
}
030fc4375e63 Added SDL_HapticNumEffectsPlaying().
Edgar Simo <bobbens@gmail.com>
parents: 2514
diff changeset
   376
030fc4375e63 Added SDL_HapticNumEffectsPlaying().
Edgar Simo <bobbens@gmail.com>
parents: 2514
diff changeset
   377
2478
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   378
/*
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   379
 * Returns supported effects by the device.
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   380
 */
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   381
unsigned int
2497
0893fbf73b3d Renamed SDL_HapticQueryEffects to SDL_HapticQuery.
Edgar Simo <bobbens@gmail.com>
parents: 2495
diff changeset
   382
SDL_HapticQuery(SDL_Haptic * haptic)
2478
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   383
{
2560
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
   384
   if (!ValidHaptic(haptic)) {
2478
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   385
      return -1;
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   386
   }
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   387
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   388
   return haptic->supported;
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   389
}
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   390
2523
366d84fdf8d1 Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents: 2519
diff changeset
   391
366d84fdf8d1 Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents: 2519
diff changeset
   392
/*
366d84fdf8d1 Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents: 2519
diff changeset
   393
 * Returns the number of axis on the device.
366d84fdf8d1 Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents: 2519
diff changeset
   394
 */
366d84fdf8d1 Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents: 2519
diff changeset
   395
int
366d84fdf8d1 Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents: 2519
diff changeset
   396
SDL_HapticNumAxes(SDL_Haptic * haptic)
366d84fdf8d1 Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents: 2519
diff changeset
   397
{
2560
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
   398
   if (!ValidHaptic(haptic)) {
2523
366d84fdf8d1 Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents: 2519
diff changeset
   399
      return -1;
366d84fdf8d1 Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents: 2519
diff changeset
   400
   }
366d84fdf8d1 Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents: 2519
diff changeset
   401
366d84fdf8d1 Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents: 2519
diff changeset
   402
   return haptic->naxes;
366d84fdf8d1 Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents: 2519
diff changeset
   403
}
366d84fdf8d1 Haptic subsystem handles haptic axes now.
Edgar Simo <bobbens@gmail.com>
parents: 2519
diff changeset
   404
2486
24dd8b8669fa Added SDL_HAPTIC_CUSTOM (not supported on linux).
Edgar Simo <bobbens@gmail.com>
parents: 2485
diff changeset
   405
/*
24dd8b8669fa Added SDL_HAPTIC_CUSTOM (not supported on linux).
Edgar Simo <bobbens@gmail.com>
parents: 2485
diff changeset
   406
 * Checks to see if the device can support the effect.
24dd8b8669fa Added SDL_HAPTIC_CUSTOM (not supported on linux).
Edgar Simo <bobbens@gmail.com>
parents: 2485
diff changeset
   407
 */
2478
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   408
int
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   409
SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect)
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   410
{
2560
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
   411
   if (!ValidHaptic(haptic)) {
2478
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   412
      return -1;
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   413
   }
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   414
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   415
   if ((haptic->supported & effect->type) != 0)
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   416
      return SDL_TRUE;
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   417
   return SDL_FALSE;
4fd783e0f34b Added query functions for haptic devices.
Edgar Simo <bobbens@gmail.com>
parents: 2477
diff changeset
   418
}
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   419
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   420
/*
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   421
 * Creates a new haptic effect.
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   422
 */
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   423
int
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   424
SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect)
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   425
{
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   426
   int i;
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   427
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   428
   /* Check for device validity. */
2560
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
   429
   if (!ValidHaptic(haptic)) {
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   430
      return -1;
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   431
   }
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   432
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   433
   /* Check to see if effect is supported */
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   434
   if (SDL_HapticEffectSupported(haptic,effect)==SDL_FALSE) {
2513
55fd9103a330 Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents: 2512
diff changeset
   435
      SDL_SetError("Haptic: Effect not supported by haptic device.");
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   436
      return -1;
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   437
   }
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   438
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   439
   /* See if there's a free slot */
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   440
   for (i=0; i<haptic->neffects; i++) {
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   441
      if (haptic->effects[i].hweffect == NULL) {
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   442
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   443
         /* Now let the backend create the real effect */
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   444
         if (SDL_SYS_HapticNewEffect(haptic,&haptic->effects[i],effect) != 0) {
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   445
            return -1; /* Backend failed to create effect */
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   446
         }
2526
2d88b82ce781 More documentation.
Edgar Simo <bobbens@gmail.com>
parents: 2524
diff changeset
   447
2d88b82ce781 More documentation.
Edgar Simo <bobbens@gmail.com>
parents: 2524
diff changeset
   448
         SDL_memcpy(&haptic->effects[i].effect, effect, sizeof(SDL_HapticEffect));
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   449
         return i;
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   450
      }
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   451
   }
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   452
2513
55fd9103a330 Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents: 2512
diff changeset
   453
   SDL_SetError("Haptic: Device has no free space left.");
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   454
   return -1;
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   455
}
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   456
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   457
/*
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   458
 * Checks to see if an effect is valid.
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   459
 */
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   460
static int
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   461
ValidEffect(SDL_Haptic * haptic, int effect)
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   462
{
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   463
   if ((effect < 0) || (effect >= haptic->neffects)) {
2513
55fd9103a330 Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents: 2512
diff changeset
   464
      SDL_SetError("Haptic: Invalid effect identifier.");
2480
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   465
      return 0;
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   466
   }
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   467
   return 1;
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   468
}
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   469
b883974445fc Some more error reporting.
Edgar Simo <bobbens@gmail.com>
parents: 2479
diff changeset
   470
/*
2488
8e2bdbccf7ff Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2486
diff changeset
   471
 * Updates an effect.
8e2bdbccf7ff Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2486
diff changeset
   472
 */
8e2bdbccf7ff Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2486
diff changeset
   473
int
8e2bdbccf7ff Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2486
diff changeset
   474
SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, SDL_HapticEffect * data)
8e2bdbccf7ff Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2486
diff changeset
   475
{
2560
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
   476
   if (!ValidHaptic(haptic) || !ValidEffect(haptic,effect)) {
2488
8e2bdbccf7ff Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2486
diff changeset
   477
      return -1;
8e2bdbccf7ff Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2486
diff changeset
   478
   }
8e2bdbccf7ff Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2486
diff changeset
   479
2526
2d88b82ce781 More documentation.
Edgar Simo <bobbens@gmail.com>
parents: 2524
diff changeset
   480
   /* Can't change type dynamically. */
2d88b82ce781 More documentation.
Edgar Simo <bobbens@gmail.com>
parents: 2524
diff changeset
   481
   if (data->type != haptic->effects[effect].effect.type) {
2d88b82ce781 More documentation.
Edgar Simo <bobbens@gmail.com>
parents: 2524
diff changeset
   482
      SDL_SetError("Haptic: Updating effect type is illegal.");
2d88b82ce781 More documentation.
Edgar Simo <bobbens@gmail.com>
parents: 2524
diff changeset
   483
      return -1;
2d88b82ce781 More documentation.
Edgar Simo <bobbens@gmail.com>
parents: 2524
diff changeset
   484
   }
2d88b82ce781 More documentation.
Edgar Simo <bobbens@gmail.com>
parents: 2524
diff changeset
   485
2488
8e2bdbccf7ff Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2486
diff changeset
   486
   /* Updates the effect */
8e2bdbccf7ff Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2486
diff changeset
   487
   if (SDL_SYS_HapticUpdateEffect(haptic,&haptic->effects[effect],data) < 0) {
8e2bdbccf7ff Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2486
diff changeset
   488
      return -1;
8e2bdbccf7ff Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2486
diff changeset
   489
   }
8e2bdbccf7ff Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2486
diff changeset
   490
2526
2d88b82ce781 More documentation.
Edgar Simo <bobbens@gmail.com>
parents: 2524
diff changeset
   491
   SDL_memcpy(&haptic->effects[effect].effect, data, sizeof(SDL_HapticEffect));
2488
8e2bdbccf7ff Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2486
diff changeset
   492
   return 0;
8e2bdbccf7ff Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2486
diff changeset
   493
}
8e2bdbccf7ff Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2486
diff changeset
   494
8e2bdbccf7ff Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2486
diff changeset
   495
8e2bdbccf7ff Added SDL_HapticUpdateEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2486
diff changeset
   496
/*
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   497
 * Runs the haptic effect on the device.
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   498
 */
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   499
int
2519
af9df9662807 More explicit with iterations and length.
Edgar Simo <bobbens@gmail.com>
parents: 2517
diff changeset
   500
SDL_HapticRunEffect(SDL_Haptic * haptic, int effect, Uint32 iterations)
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   501
{
2560
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
   502
   if (!ValidHaptic(haptic) || !ValidEffect(haptic,effect)) {
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   503
      return -1;
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   504
   }
2479
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
   505
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
   506
   /* Run the effect */
2517
37c13c12c878 Broke API by introducing iterations to SDL_HapticRunEffects().
Edgar Simo <bobbens@gmail.com>
parents: 2515
diff changeset
   507
   if (SDL_SYS_HapticRunEffect(haptic,&haptic->effects[effect], iterations) < 0) {
2479
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
   508
      return -1;
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
   509
   }
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
   510
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
   511
   return 0;
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   512
}
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   513
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   514
/*
2485
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
   515
 * Stops the haptic effect on the device.
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
   516
 */
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
   517
int
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
   518
SDL_HapticStopEffect(SDL_Haptic * haptic, int effect)
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
   519
{
2560
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
   520
   if (!ValidHaptic(haptic) || !ValidEffect(haptic,effect)) {
2485
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
   521
      return -1;
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
   522
   }
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
   523
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
   524
   /* Stop the effect */
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
   525
   if (SDL_SYS_HapticStopEffect(haptic,&haptic->effects[effect]) < 0) {
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
   526
      return -1;
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
   527
   }
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
   528
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
   529
   return 0;
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
   530
}
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
   531
67978eea6d10 Added SDL_HapticStopEffect().
Edgar Simo <bobbens@gmail.com>
parents: 2484
diff changeset
   532
/*
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   533
 * Gets rid of a haptic effect.
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   534
 */
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   535
void
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   536
SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect)
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   537
{
2560
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
   538
   if (!ValidHaptic(haptic) || !ValidEffect(haptic,effect)) {
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   539
      return;
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   540
   }
2479
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
   541
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
   542
   /* Not allocated */
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
   543
   if (haptic->effects[effect].hweffect == NULL) {
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
   544
      return;
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
   545
   }
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
   546
b9eb2cfe16cd Added some preliminary support for haptic effect control.
Edgar Simo <bobbens@gmail.com>
parents: 2478
diff changeset
   547
   SDL_SYS_HapticDestroyEffect(haptic, &haptic->effects[effect]);
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   548
}
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   549
2483
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
   550
/*
2495
66c02abeef0e Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents: 2491
diff changeset
   551
 * Gets the status of a haptic effect.
66c02abeef0e Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents: 2491
diff changeset
   552
 */
66c02abeef0e Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents: 2491
diff changeset
   553
int
66c02abeef0e Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents: 2491
diff changeset
   554
SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect)
66c02abeef0e Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents: 2491
diff changeset
   555
{
2560
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
   556
   if (!ValidHaptic(haptic) || !ValidEffect(haptic,effect)) {
2495
66c02abeef0e Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents: 2491
diff changeset
   557
      return -1;
66c02abeef0e Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents: 2491
diff changeset
   558
   }
66c02abeef0e Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents: 2491
diff changeset
   559
66c02abeef0e Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents: 2491
diff changeset
   560
   if ((haptic->supported & SDL_HAPTIC_STATUS) == 0) {
2513
55fd9103a330 Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents: 2512
diff changeset
   561
      SDL_SetError("Haptic: Device does not support status queries.");
2495
66c02abeef0e Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents: 2491
diff changeset
   562
      return -1;
66c02abeef0e Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents: 2491
diff changeset
   563
   }
66c02abeef0e Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents: 2491
diff changeset
   564
66c02abeef0e Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents: 2491
diff changeset
   565
   return SDL_SYS_HapticGetEffectStatus(haptic, &haptic->effects[effect]);
66c02abeef0e Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents: 2491
diff changeset
   566
}
66c02abeef0e Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents: 2491
diff changeset
   567
66c02abeef0e Added SDL_HapticGetEffectStatus().
Edgar Simo <bobbens@gmail.com>
parents: 2491
diff changeset
   568
/*
2483
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
   569
 * Sets the global gain of the device.
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
   570
 */
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
   571
int
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
   572
SDL_HapticSetGain(SDL_Haptic * haptic, int gain )
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
   573
{
2507
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   574
   const char *env;
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   575
   int real_gain, max_gain;
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   576
2560
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
   577
   if (!ValidHaptic(haptic)) {
2483
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
   578
      return -1;
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
   579
   }
2477
97f75ea43a93 Starting to add infrastructure to handle haptic effects.
Edgar Simo <bobbens@gmail.com>
parents: 2476
diff changeset
   580
2484
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   581
   if ((haptic->supported & SDL_HAPTIC_GAIN) == 0) {
2513
55fd9103a330 Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents: 2512
diff changeset
   582
      SDL_SetError("Haptic: Device does not support setting gain.");
2484
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   583
      return -1;
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   584
   }
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   585
2483
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
   586
   if ((gain < 0) || (gain > 100)) {
2513
55fd9103a330 Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents: 2512
diff changeset
   587
      SDL_SetError("Haptic: Gain must be between 0 and 100.");
2483
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
   588
      return -1;
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
   589
   }
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
   590
2507
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   591
   /* We use the envvar to get the maximum gain. */
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   592
   env = SDL_getenv("SDL_HAPTIC_GAIN_MAX");
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   593
   if (env != NULL) {
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   594
      max_gain = SDL_atoi(env);
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   595
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   596
      /* Check for sanity. */
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   597
      if (max_gain < 0) max_gain = 0;
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   598
      else if (max_gain > 100) max_gain = 100;
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   599
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   600
      /* We'll scale it linearly with SDL_HAPTIC_GAIN_MAX */
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   601
      real_gain = (gain * max_gain) / 100;
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   602
   }
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   603
   else {
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   604
      real_gain = gain;
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   605
   }
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   606
8ef1d0f4d0c1 Gain is set to max on haptic device open.
Edgar Simo <bobbens@gmail.com>
parents: 2506
diff changeset
   607
   if (SDL_SYS_HapticSetGain(haptic,real_gain) < 0) {
2483
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
   608
      return -1;
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
   609
   }
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
   610
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
   611
   return 0;
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
   612
}
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
   613
2484
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   614
/*
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   615
 * Makes the device autocenter, 0 disables.
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   616
 */
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   617
int
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   618
SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter )
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   619
{
2560
2274406ba792 Made ValidHaptic cleaner.
Edgar Simo <bobbens@gmail.com>
parents: 2526
diff changeset
   620
   if (!ValidHaptic(haptic)) {
2484
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   621
      return -1;
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   622
   }
2483
9d52368ebcf5 Setting effects memory to 0.
Edgar Simo <bobbens@gmail.com>
parents: 2480
diff changeset
   623
2484
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   624
   if ((haptic->supported & SDL_HAPTIC_AUTOCENTER) == 0) {
2513
55fd9103a330 Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents: 2512
diff changeset
   625
      SDL_SetError("Haptic: Device does not support setting autocenter.");
2484
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   626
      return -1;
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   627
   }
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   628
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   629
   if ((autocenter < 0) || (autocenter > 100)) {
2513
55fd9103a330 Prefixed all haptic errors with "Haptic:" for easier readability.
Edgar Simo <bobbens@gmail.com>
parents: 2512
diff changeset
   630
      SDL_SetError("Haptic: Autocenter must be between 0 and 100.");
2484
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   631
      return -1;
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   632
   }                                           
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   633
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   634
   if (SDL_SYS_HapticSetAutocenter(haptic,autocenter) < 0) {
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   635
      return -1;
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   636
   }
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   637
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   638
   return 0;
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   639
}
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   640
666472fd4cb0 HapticSetGain checks to see if device supports it.
Edgar Simo <bobbens@gmail.com>
parents: 2483
diff changeset
   641