author | Sam Lantinga <slouken@libsdl.org> |
Sun, 02 Feb 2014 00:53:27 -0800 | |
changeset 8149 | 681eb46b8ac4 |
parent 7639 | 9406b7dd2f2d |
child 9356 | e87d6e1e812a |
permissions | -rw-r--r-- |
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5360
diff
changeset
|
1 |
/* |
8149
681eb46b8ac4
Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents:
7639
diff
changeset
|
2 |
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> |
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5360
diff
changeset
|
3 |
|
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5360
diff
changeset
|
4 |
This software is provided 'as-is', without any express or implied |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5360
diff
changeset
|
5 |
warranty. In no event will the authors be held liable for any damages |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5360
diff
changeset
|
6 |
arising from the use of this software. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5360
diff
changeset
|
7 |
|
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5360
diff
changeset
|
8 |
Permission is granted to anyone to use this software for any purpose, |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5360
diff
changeset
|
9 |
including commercial applications, and to alter it and redistribute it |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5360
diff
changeset
|
10 |
freely. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5360
diff
changeset
|
11 |
*/ |
5360 | 12 |
/* |
13 |
Copyright (c) 2011, Edgar Simo Serra |
|
14 |
All rights reserved. |
|
15 |
||
16 |
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: |
|
17 |
||
18 |
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. |
|
19 |
* 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. |
|
20 |
* 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. |
|
21 |
||
22 |
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. |
|
23 |
*/ |
|
24 |
||
25 |
/* |
|
26 |
* includes |
|
27 |
*/ |
|
28 |
#include <stdlib.h> |
|
29 |
#include <string.h> /* strstr */ |
|
30 |
#include <ctype.h> /* isdigit */ |
|
31 |
||
6771
55337ff4256f
Fix compiler warning; minor harness driver cleanup; fix test build for SDL versions compiled with --disable-joystick or --disable-haptic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
5535
diff
changeset
|
32 |
#include "SDL.h" |
55337ff4256f
Fix compiler warning; minor harness driver cleanup; fix test build for SDL versions compiled with --disable-joystick or --disable-haptic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
5535
diff
changeset
|
33 |
|
55337ff4256f
Fix compiler warning; minor harness driver cleanup; fix test build for SDL versions compiled with --disable-joystick or --disable-haptic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
5535
diff
changeset
|
34 |
#ifndef SDL_HAPTIC_DISABLED |
55337ff4256f
Fix compiler warning; minor harness driver cleanup; fix test build for SDL versions compiled with --disable-joystick or --disable-haptic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
5535
diff
changeset
|
35 |
|
55337ff4256f
Fix compiler warning; minor harness driver cleanup; fix test build for SDL versions compiled with --disable-joystick or --disable-haptic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
5535
diff
changeset
|
36 |
#include "SDL_haptic.h" |
5360 | 37 |
|
38 |
static SDL_Haptic *haptic; |
|
39 |
||
40 |
||
41 |
/** |
|
42 |
* @brief The entry point of this force feedback demo. |
|
43 |
* @param[in] argc Number of arguments. |
|
44 |
* @param[in] argv Array of argc arguments. |
|
45 |
*/ |
|
46 |
int |
|
47 |
main(int argc, char **argv) |
|
48 |
{ |
|
49 |
int i; |
|
50 |
char *name; |
|
51 |
int index; |
|
52 |
||
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
53 |
/* Enable standard application logging */ |
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
54 |
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); |
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
55 |
|
5360 | 56 |
name = NULL; |
57 |
index = -1; |
|
58 |
if (argc > 1) { |
|
59 |
name = argv[1]; |
|
60 |
if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) { |
|
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
61 |
SDL_Log("USAGE: %s [device]\n" |
5360 | 62 |
"If device is a two-digit number it'll use it as an index, otherwise\n" |
63 |
"it'll use it as if it were part of the device's name.\n", |
|
64 |
argv[0]); |
|
65 |
return 0; |
|
66 |
} |
|
67 |
||
68 |
i = strlen(name); |
|
69 |
if ((i < 3) && isdigit(name[0]) && ((i == 1) || isdigit(name[1]))) { |
|
70 |
index = atoi(name); |
|
71 |
name = NULL; |
|
72 |
} |
|
73 |
} |
|
74 |
||
75 |
/* Initialize the force feedbackness */ |
|
76 |
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK | |
|
77 |
SDL_INIT_HAPTIC); |
|
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
78 |
SDL_Log("%d Haptic devices detected.\n", SDL_NumHaptics()); |
5360 | 79 |
if (SDL_NumHaptics() > 0) { |
80 |
/* We'll just use index or the first force feedback device found */ |
|
81 |
if (name == NULL) { |
|
82 |
i = (index != -1) ? index : 0; |
|
83 |
} |
|
84 |
/* Try to find matching device */ |
|
85 |
else { |
|
86 |
for (i = 0; i < SDL_NumHaptics(); i++) { |
|
87 |
if (strstr(SDL_HapticName(i), name) != NULL) |
|
88 |
break; |
|
89 |
} |
|
90 |
||
91 |
if (i >= SDL_NumHaptics()) { |
|
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
92 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n", |
5360 | 93 |
name); |
94 |
return 1; |
|
95 |
} |
|
96 |
} |
|
97 |
||
98 |
haptic = SDL_HapticOpen(i); |
|
99 |
if (haptic == NULL) { |
|
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
100 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n", |
5360 | 101 |
SDL_GetError()); |
102 |
return 1; |
|
103 |
} |
|
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
104 |
SDL_Log("Device: %s\n", SDL_HapticName(i)); |
5360 | 105 |
} else { |
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
106 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n"); |
5360 | 107 |
return 1; |
108 |
} |
|
109 |
||
110 |
/* We only want force feedback errors. */ |
|
111 |
SDL_ClearError(); |
|
112 |
||
113 |
if (SDL_HapticRumbleSupported(haptic) == SDL_FALSE) { |
|
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
114 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Rumble not supported!\n"); |
5360 | 115 |
return 1; |
116 |
} |
|
117 |
if (SDL_HapticRumbleInit(haptic) != 0) { |
|
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
118 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to initialize rumble: %s\n", SDL_GetError()); |
5360 | 119 |
return 1; |
120 |
} |
|
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
121 |
SDL_Log("Playing 2 second rumble at 0.5 magnitude.\n"); |
5360 | 122 |
if (SDL_HapticRumblePlay(haptic, 0.5, 5000) != 0) { |
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
123 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError() ); |
5360 | 124 |
return 1; |
125 |
} |
|
126 |
SDL_Delay(2000); |
|
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
127 |
SDL_Log("Stopping rumble.\n"); |
5360 | 128 |
SDL_HapticRumbleStop(haptic); |
129 |
SDL_Delay(2000); |
|
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
130 |
SDL_Log("Playing 2 second rumble at 0.3 magnitude.\n"); |
7437
964e8876ad3b
Fixed compiler warnings in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
6771
diff
changeset
|
131 |
if (SDL_HapticRumblePlay(haptic, 0.3f, 5000) != 0) { |
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
132 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError() ); |
5360 | 133 |
return 1; |
134 |
} |
|
135 |
SDL_Delay(2000); |
|
136 |
||
137 |
/* Quit */ |
|
138 |
if (haptic != NULL) |
|
139 |
SDL_HapticClose(haptic); |
|
140 |
SDL_Quit(); |
|
141 |
||
142 |
return 0; |
|
143 |
} |
|
144 |
||
6771
55337ff4256f
Fix compiler warning; minor harness driver cleanup; fix test build for SDL versions compiled with --disable-joystick or --disable-haptic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
5535
diff
changeset
|
145 |
#else |
55337ff4256f
Fix compiler warning; minor harness driver cleanup; fix test build for SDL versions compiled with --disable-joystick or --disable-haptic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
5535
diff
changeset
|
146 |
|
55337ff4256f
Fix compiler warning; minor harness driver cleanup; fix test build for SDL versions compiled with --disable-joystick or --disable-haptic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
5535
diff
changeset
|
147 |
int |
55337ff4256f
Fix compiler warning; minor harness driver cleanup; fix test build for SDL versions compiled with --disable-joystick or --disable-haptic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
5535
diff
changeset
|
148 |
main(int argc, char *argv[]) |
55337ff4256f
Fix compiler warning; minor harness driver cleanup; fix test build for SDL versions compiled with --disable-joystick or --disable-haptic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
5535
diff
changeset
|
149 |
{ |
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
150 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Haptic support.\n"); |
6771
55337ff4256f
Fix compiler warning; minor harness driver cleanup; fix test build for SDL versions compiled with --disable-joystick or --disable-haptic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
5535
diff
changeset
|
151 |
exit(1); |
55337ff4256f
Fix compiler warning; minor harness driver cleanup; fix test build for SDL versions compiled with --disable-joystick or --disable-haptic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
5535
diff
changeset
|
152 |
} |
55337ff4256f
Fix compiler warning; minor harness driver cleanup; fix test build for SDL versions compiled with --disable-joystick or --disable-haptic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
5535
diff
changeset
|
153 |
|
55337ff4256f
Fix compiler warning; minor harness driver cleanup; fix test build for SDL versions compiled with --disable-joystick or --disable-haptic
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
5535
diff
changeset
|
154 |
#endif |