annotate test/testhaptic.c @ 2636:57ac1594164e gsoc2008_force_feedback

Added testhaptic to test haptic devices.
author Edgar Simo <bobbens@gmail.com>
date Wed, 06 Aug 2008 17:14:54 +0000
parents
children
rev   line source
2636
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
1 /*
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
2 Copyright (c) 2008, Edgar Simo Serra
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
3 All rights reserved.
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
4
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
6
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
7 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
8 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
9 * Neither the name of the Simple Directmedia Layer (SDL) nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
10
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
11 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
12 */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
13
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
14 /*
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
15 * includes
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
16 */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
17 #include "SDL.h"
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
18 #include "SDL_haptic.h"
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
19
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
20 #include <stdio.h> /* printf */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
21 #include <string.h> /* strstr */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
22
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
23
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
24
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
25 static SDL_Haptic *haptic;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
26
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
27
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
28 /*
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
29 * prototypes
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
30 */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
31 static void abort_execution (void);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
32 static void HapticPrintSupported( SDL_Haptic * haptic );
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
33
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
34
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
35 /**
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
36 * @brief The entry point of this force feedback demo.
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
37 * @param[in] argc Number of arguments.
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
38 * @param[in] argv Array of argc arguments.
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
39 */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
40 int main( int argc, char** argv )
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
41 {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
42 int i;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
43 char *name;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
44 SDL_HapticEffect efx[5];
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
45 int id[5];
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
46 int nefx;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
47 unsigned int supported;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
48
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
49 name = NULL;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
50 if (argc > 1) {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
51 name = argv[1];
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
52 if ((strcmp(name,"--help")==0) || (strcmp(name,"-h")==0)) {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
53 printf("USAGE: %s [device name]\n"
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
54 "If device name is specified, it will try to find a device whose name\n"
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
55 "contains device name for testing.\n", argv[0]);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
56 return 0;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
57 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
58 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
59
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
60 /* Initialize the force feedbackness */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
61 SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
62 printf("%d Haptic devices detected.\n", SDL_NumHaptics());
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
63 if (SDL_NumHaptics() > 0) {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
64 /* We'll just use the first force feedback device found */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
65 if (name == NULL) {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
66 i = 0;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
67 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
68 /* Try to find matching device */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
69 else {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
70 for (i=0; i<SDL_NumHaptics(); i++) {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
71 if (strstr(SDL_HapticName(i), name)!=NULL)
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
72 break;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
73 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
74
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
75 if (i >= SDL_NumHaptics()) {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
76 printf("Unable to find device matching '%s', aborting.\n", name);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
77 return 1;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
78 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
79 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
80
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
81 haptic = SDL_HapticOpen(i);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
82 if (haptic==NULL) {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
83 perror("Unable to create the haptic device");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
84 return 1;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
85 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
86 printf("Device: %s\n",SDL_HapticName(i));
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
87 HapticPrintSupported(haptic);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
88 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
89 else {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
90 printf("No Haptic devices found!\n");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
91 return 1;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
92 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
93
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
94 /* We only want force feedback errors. */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
95 SDL_ClearError();
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
96
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
97 /* Create effects. */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
98 memset(&efx,0,sizeof(efx));
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
99 nefx = 0;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
100 supported = SDL_HapticQuery(haptic);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
101
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
102 printf("\nUploading effects\n");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
103 /* First we'll try a SINE effect. */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
104 if (supported & SDL_HAPTIC_SINE) {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
105 printf(" effect %d: Sine Wave\n",nefx);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
106 efx[nefx].type = SDL_HAPTIC_SINE;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
107 efx[nefx].periodic.period = 1000;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
108 efx[nefx].periodic.magnitude = 0x4000;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
109 efx[nefx].periodic.length = 5000;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
110 efx[nefx].periodic.attack_length = 1000;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
111 efx[nefx].periodic.fade_length = 1000;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
112 id[nefx] = SDL_HapticNewEffect(haptic,&efx[nefx]);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
113 if (id[nefx] < 0) {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
114 printf("UPLOADING EFFECT ERROR: %s\n",SDL_GetError());
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
115 abort_execution();
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
116 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
117 nefx++;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
118 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
119 /* Now we'll try a SAWTOOTHUP */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
120 if (supported & SDL_HAPTIC_SAWTOOTHUP) {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
121 printf(" effect %d: Sawtooth Up\n",nefx);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
122 efx[nefx].type = SDL_HAPTIC_SQUARE;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
123 efx[nefx].periodic.period = 500;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
124 efx[nefx].periodic.magnitude = 0x5000;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
125 efx[nefx].periodic.length = 5000;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
126 efx[nefx].periodic.attack_length = 1000;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
127 efx[nefx].periodic.fade_length = 1000;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
128 id[nefx] = SDL_HapticNewEffect(haptic,&efx[nefx]);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
129 if (id[nefx] < 0) {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
130 printf("UPLOADING EFFECT ERROR: %s\n",SDL_GetError());
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
131 abort_execution();
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
132 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
133 nefx++;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
134 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
135 /* Now the classical constant effect. */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
136 if (supported & SDL_HAPTIC_CONSTANT) {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
137 printf(" effect %d: Constant Force\n",nefx);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
138 efx[nefx].type = SDL_HAPTIC_CONSTANT;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
139 efx[nefx].constant.direction.type = SDL_HAPTIC_POLAR;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
140 efx[nefx].constant.direction.dir[0] = 20000; /* Force comes from the south-west. */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
141 efx[nefx].constant.length = 5000;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
142 efx[nefx].constant.level = 0x6000;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
143 efx[nefx].constant.attack_length = 1000;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
144 efx[nefx].constant.fade_length = 1000;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
145 id[nefx] = SDL_HapticNewEffect(haptic,&efx[nefx]);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
146 if (id[nefx] < 0) {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
147 printf("UPLOADING EFFECT ERROR: %s\n",SDL_GetError());
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
148 abort_execution();
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
149 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
150 nefx++;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
151 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
152 /* The cute spring effect. */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
153 if (supported & SDL_HAPTIC_SPRING) {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
154 printf(" effect %d: Condition Spring\n",nefx);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
155 efx[nefx].type = SDL_HAPTIC_SPRING;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
156 efx[nefx].condition.length = 5000;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
157 for (i=0; i<SDL_HapticNumAxes(haptic); i++) {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
158 efx[nefx].condition.right_sat[i] = 0x7FFF;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
159 efx[nefx].condition.left_sat[i] = 0x7FFF;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
160 efx[nefx].condition.right_coeff[i] = 0x2000;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
161 efx[nefx].condition.left_coeff[i] = 0x2000;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
162 efx[nefx].condition.center[i] = 0x1000; /* Displace the center for it to move. */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
163 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
164 id[nefx] = SDL_HapticNewEffect(haptic,&efx[nefx]);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
165 if (id[nefx] < 0) {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
166 printf("UPLOADING EFFECT ERROR: %s\n",SDL_GetError());
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
167 abort_execution();
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
168 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
169 nefx++;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
170 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
171 /* The pretty awesome inertia effect. */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
172 if (supported & SDL_HAPTIC_INERTIA) {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
173 printf(" effect %d: Condition Inertia\n",nefx);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
174 efx[nefx].type = SDL_HAPTIC_SPRING;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
175 efx[nefx].condition.length = 5000;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
176 for (i=0; i<SDL_HapticNumAxes(haptic); i++) {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
177 efx[nefx].condition.right_sat[i] = 0x7FFF;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
178 efx[nefx].condition.left_sat[i] = 0x7FFF;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
179 efx[nefx].condition.right_coeff[i] = 0x2000;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
180 efx[nefx].condition.left_coeff[i] = 0x2000;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
181 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
182 id[nefx] = SDL_HapticNewEffect(haptic,&efx[nefx]);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
183 if (id[nefx] < 0) {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
184 printf("UPLOADING EFFECT ERROR: %s\n",SDL_GetError());
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
185 abort_execution();
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
186 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
187 nefx++;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
188 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
189
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
190 printf("\nNow playing effects for 5 seconds each with 1 second delay between\n");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
191 for (i=0; i<nefx; i++) {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
192 printf(" Playing effect %d\n",i);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
193 SDL_HapticRunEffect(haptic, id[i], 1);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
194 SDL_Delay(6000); /* Effects only have length 5000 */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
195 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
196
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
197 /* Quit */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
198 if (haptic != NULL)
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
199 SDL_HapticClose(haptic);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
200 SDL_Quit();
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
201
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
202 return 0;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
203 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
204
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
205
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
206 /*
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
207 * Cleans up a bit.
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
208 */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
209 static void abort_execution (void)
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
210 {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
211 printf("\nAborting program execution.\n");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
212
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
213 SDL_HapticClose(haptic);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
214 SDL_Quit();
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
215
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
216 exit(1);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
217 }
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
218
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
219
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
220 /*
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
221 * Displays information about the haptic device.
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
222 */
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
223 static void HapticPrintSupported( SDL_Haptic * haptic )
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
224 {
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
225 unsigned int supported;
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
226
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
227 supported = SDL_HapticQuery(haptic);
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
228 printf(" Supported effects [%d effects, %d playing]:\n",
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
229 SDL_HapticNumEffects(haptic),
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
230 SDL_HapticNumEffectsPlaying(haptic));
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
231 if (supported & SDL_HAPTIC_CONSTANT) printf(" constant\n");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
232 if (supported & SDL_HAPTIC_SINE) printf(" sine\n");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
233 if (supported & SDL_HAPTIC_SQUARE) printf(" square\n");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
234 if (supported & SDL_HAPTIC_TRIANGLE) printf(" triangle\n");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
235 if (supported & SDL_HAPTIC_SAWTOOTHUP) printf(" sawtoothup\n");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
236 if (supported & SDL_HAPTIC_SAWTOOTHDOWN) printf(" sawtoothdown\n");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
237 if (supported & SDL_HAPTIC_RAMP) printf(" ramp\n");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
238 if (supported & SDL_HAPTIC_FRICTION) printf(" friction\n");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
239 if (supported & SDL_HAPTIC_SPRING) printf(" spring\n");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
240 if (supported & SDL_HAPTIC_DAMPER) printf(" damper\n");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
241 if (supported & SDL_HAPTIC_INERTIA) printf(" intertia\n");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
242 if (supported & SDL_HAPTIC_CUSTOM) printf(" custom\n");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
243 printf(" Supported capabilities:\n");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
244 if (supported & SDL_HAPTIC_GAIN) printf(" gain\n");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
245 if (supported & SDL_HAPTIC_AUTOCENTER) printf(" autocenter\n");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
246 if (supported & SDL_HAPTIC_STATUS) printf(" status\n");
57ac1594164e Added testhaptic to test haptic devices.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
247 }