Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
This commit is contained in:
parent
a0bc602061
commit
16a40598f6
47 changed files with 616 additions and 505 deletions
|
@ -26,7 +26,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||
* includes
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h> /* printf */
|
||||
#include <string.h> /* strstr */
|
||||
#include <ctype.h> /* isdigit */
|
||||
|
||||
|
@ -62,12 +61,15 @@ main(int argc, char **argv)
|
|||
int nefx;
|
||||
unsigned int supported;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
name = NULL;
|
||||
index = -1;
|
||||
if (argc > 1) {
|
||||
name = argv[1];
|
||||
if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) {
|
||||
printf("USAGE: %s [device]\n"
|
||||
SDL_Log("USAGE: %s [device]\n"
|
||||
"If device is a two-digit number it'll use it as an index, otherwise\n"
|
||||
"it'll use it as if it were part of the device's name.\n",
|
||||
argv[0]);
|
||||
|
@ -84,7 +86,7 @@ main(int argc, char **argv)
|
|||
/* Initialize the force feedbackness */
|
||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK |
|
||||
SDL_INIT_HAPTIC);
|
||||
printf("%d Haptic devices detected.\n", SDL_NumHaptics());
|
||||
SDL_Log("%d Haptic devices detected.\n", SDL_NumHaptics());
|
||||
if (SDL_NumHaptics() > 0) {
|
||||
/* We'll just use index or the first force feedback device found */
|
||||
if (name == NULL) {
|
||||
|
@ -98,7 +100,7 @@ main(int argc, char **argv)
|
|||
}
|
||||
|
||||
if (i >= SDL_NumHaptics()) {
|
||||
printf("Unable to find device matching '%s', aborting.\n",
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n",
|
||||
name);
|
||||
return 1;
|
||||
}
|
||||
|
@ -106,14 +108,14 @@ main(int argc, char **argv)
|
|||
|
||||
haptic = SDL_HapticOpen(i);
|
||||
if (haptic == NULL) {
|
||||
printf("Unable to create the haptic device: %s\n",
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n",
|
||||
SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
printf("Device: %s\n", SDL_HapticName(i));
|
||||
SDL_Log("Device: %s\n", SDL_HapticName(i));
|
||||
HapticPrintSupported(haptic);
|
||||
} else {
|
||||
printf("No Haptic devices found!\n");
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -125,10 +127,10 @@ main(int argc, char **argv)
|
|||
nefx = 0;
|
||||
supported = SDL_HapticQuery(haptic);
|
||||
|
||||
printf("\nUploading effects\n");
|
||||
SDL_Log("\nUploading effects\n");
|
||||
/* First we'll try a SINE effect. */
|
||||
if (supported & SDL_HAPTIC_SINE) {
|
||||
printf(" effect %d: Sine Wave\n", nefx);
|
||||
SDL_Log(" effect %d: Sine Wave\n", nefx);
|
||||
efx[nefx].type = SDL_HAPTIC_SINE;
|
||||
efx[nefx].periodic.period = 1000;
|
||||
efx[nefx].periodic.magnitude = 0x4000;
|
||||
|
@ -137,14 +139,14 @@ main(int argc, char **argv)
|
|||
efx[nefx].periodic.fade_length = 1000;
|
||||
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
|
||||
if (id[nefx] < 0) {
|
||||
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
|
||||
abort_execution();
|
||||
}
|
||||
nefx++;
|
||||
}
|
||||
/* Now we'll try a SAWTOOTHUP */
|
||||
if (supported & SDL_HAPTIC_SAWTOOTHUP) {
|
||||
printf(" effect %d: Sawtooth Up\n", nefx);
|
||||
SDL_Log(" effect %d: Sawtooth Up\n", nefx);
|
||||
efx[nefx].type = SDL_HAPTIC_SAWTOOTHUP;
|
||||
efx[nefx].periodic.period = 500;
|
||||
efx[nefx].periodic.magnitude = 0x5000;
|
||||
|
@ -153,14 +155,14 @@ main(int argc, char **argv)
|
|||
efx[nefx].periodic.fade_length = 1000;
|
||||
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
|
||||
if (id[nefx] < 0) {
|
||||
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
|
||||
abort_execution();
|
||||
}
|
||||
nefx++;
|
||||
}
|
||||
/* Now the classical constant effect. */
|
||||
if (supported & SDL_HAPTIC_CONSTANT) {
|
||||
printf(" effect %d: Constant Force\n", nefx);
|
||||
SDL_Log(" effect %d: Constant Force\n", nefx);
|
||||
efx[nefx].type = SDL_HAPTIC_CONSTANT;
|
||||
efx[nefx].constant.direction.type = SDL_HAPTIC_POLAR;
|
||||
efx[nefx].constant.direction.dir[0] = 20000; /* Force comes from the south-west. */
|
||||
|
@ -170,14 +172,14 @@ main(int argc, char **argv)
|
|||
efx[nefx].constant.fade_length = 1000;
|
||||
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
|
||||
if (id[nefx] < 0) {
|
||||
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
|
||||
abort_execution();
|
||||
}
|
||||
nefx++;
|
||||
}
|
||||
/* The cute spring effect. */
|
||||
if (supported & SDL_HAPTIC_SPRING) {
|
||||
printf(" effect %d: Condition Spring\n", nefx);
|
||||
SDL_Log(" effect %d: Condition Spring\n", nefx);
|
||||
efx[nefx].type = SDL_HAPTIC_SPRING;
|
||||
efx[nefx].condition.length = 5000;
|
||||
for (i = 0; i < SDL_HapticNumAxes(haptic); i++) {
|
||||
|
@ -189,14 +191,14 @@ main(int argc, char **argv)
|
|||
}
|
||||
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
|
||||
if (id[nefx] < 0) {
|
||||
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
|
||||
abort_execution();
|
||||
}
|
||||
nefx++;
|
||||
}
|
||||
/* The pretty awesome inertia effect. */
|
||||
if (supported & SDL_HAPTIC_INERTIA) {
|
||||
printf(" effect %d: Condition Inertia\n", nefx);
|
||||
SDL_Log(" effect %d: Condition Inertia\n", nefx);
|
||||
efx[nefx].type = SDL_HAPTIC_SPRING;
|
||||
efx[nefx].condition.length = 5000;
|
||||
for (i = 0; i < SDL_HapticNumAxes(haptic); i++) {
|
||||
|
@ -207,7 +209,7 @@ main(int argc, char **argv)
|
|||
}
|
||||
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
|
||||
if (id[nefx] < 0) {
|
||||
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
|
||||
abort_execution();
|
||||
}
|
||||
nefx++;
|
||||
|
@ -215,24 +217,24 @@ main(int argc, char **argv)
|
|||
|
||||
/* Finally we'll try a left/right effect. */
|
||||
if (supported & SDL_HAPTIC_LEFTRIGHT) {
|
||||
printf(" effect %d: Left/Right\n", nefx);
|
||||
SDL_Log(" effect %d: Left/Right\n", nefx);
|
||||
efx[nefx].type = SDL_HAPTIC_LEFTRIGHT;
|
||||
efx[nefx].leftright.length = 5000;
|
||||
efx[nefx].leftright.large_magnitude = 0x3000;
|
||||
efx[nefx].leftright.small_magnitude = 0xFFFF;
|
||||
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
|
||||
if (id[nefx] < 0) {
|
||||
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
|
||||
abort_execution();
|
||||
}
|
||||
nefx++;
|
||||
}
|
||||
|
||||
|
||||
printf
|
||||
SDL_Log
|
||||
("\nNow playing effects for 5 seconds each with 1 second delay between\n");
|
||||
for (i = 0; i < nefx; i++) {
|
||||
printf(" Playing effect %d\n", i);
|
||||
SDL_Log(" Playing effect %d\n", i);
|
||||
SDL_HapticRunEffect(haptic, id[i], 1);
|
||||
SDL_Delay(6000); /* Effects only have length 5000 */
|
||||
}
|
||||
|
@ -252,7 +254,7 @@ main(int argc, char **argv)
|
|||
static void
|
||||
abort_execution(void)
|
||||
{
|
||||
printf("\nAborting program execution.\n");
|
||||
SDL_Log("\nAborting program execution.\n");
|
||||
|
||||
SDL_HapticClose(haptic);
|
||||
SDL_Quit();
|
||||
|
@ -270,42 +272,42 @@ HapticPrintSupported(SDL_Haptic * haptic)
|
|||
unsigned int supported;
|
||||
|
||||
supported = SDL_HapticQuery(haptic);
|
||||
printf(" Supported effects [%d effects, %d playing]:\n",
|
||||
SDL_Log(" Supported effects [%d effects, %d playing]:\n",
|
||||
SDL_HapticNumEffects(haptic), SDL_HapticNumEffectsPlaying(haptic));
|
||||
if (supported & SDL_HAPTIC_CONSTANT)
|
||||
printf(" constant\n");
|
||||
SDL_Log(" constant\n");
|
||||
if (supported & SDL_HAPTIC_SINE)
|
||||
printf(" sine\n");
|
||||
SDL_Log(" sine\n");
|
||||
/* !!! FIXME: put this back when we have more bits in 2.1 */
|
||||
/*if (supported & SDL_HAPTIC_SQUARE)
|
||||
printf(" square\n");*/
|
||||
SDL_Log(" square\n");*/
|
||||
if (supported & SDL_HAPTIC_TRIANGLE)
|
||||
printf(" triangle\n");
|
||||
SDL_Log(" triangle\n");
|
||||
if (supported & SDL_HAPTIC_SAWTOOTHUP)
|
||||
printf(" sawtoothup\n");
|
||||
SDL_Log(" sawtoothup\n");
|
||||
if (supported & SDL_HAPTIC_SAWTOOTHDOWN)
|
||||
printf(" sawtoothdown\n");
|
||||
SDL_Log(" sawtoothdown\n");
|
||||
if (supported & SDL_HAPTIC_RAMP)
|
||||
printf(" ramp\n");
|
||||
SDL_Log(" ramp\n");
|
||||
if (supported & SDL_HAPTIC_FRICTION)
|
||||
printf(" friction\n");
|
||||
SDL_Log(" friction\n");
|
||||
if (supported & SDL_HAPTIC_SPRING)
|
||||
printf(" spring\n");
|
||||
SDL_Log(" spring\n");
|
||||
if (supported & SDL_HAPTIC_DAMPER)
|
||||
printf(" damper\n");
|
||||
SDL_Log(" damper\n");
|
||||
if (supported & SDL_HAPTIC_INERTIA)
|
||||
printf(" intertia\n");
|
||||
SDL_Log(" inertia\n");
|
||||
if (supported & SDL_HAPTIC_CUSTOM)
|
||||
printf(" custom\n");
|
||||
SDL_Log(" custom\n");
|
||||
if (supported & SDL_HAPTIC_LEFTRIGHT)
|
||||
printf(" left/right\n");
|
||||
printf(" Supported capabilities:\n");
|
||||
SDL_Log(" left/right\n");
|
||||
SDL_Log(" Supported capabilities:\n");
|
||||
if (supported & SDL_HAPTIC_GAIN)
|
||||
printf(" gain\n");
|
||||
SDL_Log(" gain\n");
|
||||
if (supported & SDL_HAPTIC_AUTOCENTER)
|
||||
printf(" autocenter\n");
|
||||
SDL_Log(" autocenter\n");
|
||||
if (supported & SDL_HAPTIC_STATUS)
|
||||
printf(" status\n");
|
||||
SDL_Log(" status\n");
|
||||
}
|
||||
|
||||
#else
|
||||
|
@ -313,7 +315,7 @@ HapticPrintSupported(SDL_Haptic * haptic)
|
|||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
fprintf(stderr, "SDL compiled without Haptic support.\n");
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Haptic support.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue