|
@@ -26,7 +26,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
* includes
|
|
* includes
|
|
*/
|
|
*/
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
-#include <stdio.h> /* printf */
|
|
|
|
#include <string.h> /* strstr */
|
|
#include <string.h> /* strstr */
|
|
#include <ctype.h> /* isdigit */
|
|
#include <ctype.h> /* isdigit */
|
|
|
|
|
|
@@ -62,12 +61,15 @@ main(int argc, char **argv)
|
|
int nefx;
|
|
int nefx;
|
|
unsigned int supported;
|
|
unsigned int supported;
|
|
|
|
|
|
|
|
+ /* Enable standard application logging */
|
|
|
|
+ SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
|
|
|
+
|
|
name = NULL;
|
|
name = NULL;
|
|
index = -1;
|
|
index = -1;
|
|
if (argc > 1) {
|
|
if (argc > 1) {
|
|
name = argv[1];
|
|
name = argv[1];
|
|
if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) {
|
|
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"
|
|
"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",
|
|
"it'll use it as if it were part of the device's name.\n",
|
|
argv[0]);
|
|
argv[0]);
|
|
@@ -84,7 +86,7 @@ main(int argc, char **argv)
|
|
/* Initialize the force feedbackness */
|
|
/* Initialize the force feedbackness */
|
|
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK |
|
|
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK |
|
|
SDL_INIT_HAPTIC);
|
|
SDL_INIT_HAPTIC);
|
|
- printf("%d Haptic devices detected.\n", SDL_NumHaptics());
|
|
|
|
|
|
+ SDL_Log("%d Haptic devices detected.\n", SDL_NumHaptics());
|
|
if (SDL_NumHaptics() > 0) {
|
|
if (SDL_NumHaptics() > 0) {
|
|
/* We'll just use index or the first force feedback device found */
|
|
/* We'll just use index or the first force feedback device found */
|
|
if (name == NULL) {
|
|
if (name == NULL) {
|
|
@@ -98,7 +100,7 @@ main(int argc, char **argv)
|
|
}
|
|
}
|
|
|
|
|
|
if (i >= SDL_NumHaptics()) {
|
|
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);
|
|
name);
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
@@ -106,14 +108,14 @@ main(int argc, char **argv)
|
|
|
|
|
|
haptic = SDL_HapticOpen(i);
|
|
haptic = SDL_HapticOpen(i);
|
|
if (haptic == NULL) {
|
|
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());
|
|
SDL_GetError());
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
- printf("Device: %s\n", SDL_HapticName(i));
|
|
|
|
|
|
+ SDL_Log("Device: %s\n", SDL_HapticName(i));
|
|
HapticPrintSupported(haptic);
|
|
HapticPrintSupported(haptic);
|
|
} else {
|
|
} else {
|
|
- printf("No Haptic devices found!\n");
|
|
|
|
|
|
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n");
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -125,10 +127,10 @@ main(int argc, char **argv)
|
|
nefx = 0;
|
|
nefx = 0;
|
|
supported = SDL_HapticQuery(haptic);
|
|
supported = SDL_HapticQuery(haptic);
|
|
|
|
|
|
- printf("\nUploading effects\n");
|
|
|
|
|
|
+ SDL_Log("\nUploading effects\n");
|
|
/* First we'll try a SINE effect. */
|
|
/* First we'll try a SINE effect. */
|
|
if (supported & SDL_HAPTIC_SINE) {
|
|
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].type = SDL_HAPTIC_SINE;
|
|
efx[nefx].periodic.period = 1000;
|
|
efx[nefx].periodic.period = 1000;
|
|
efx[nefx].periodic.magnitude = 0x4000;
|
|
efx[nefx].periodic.magnitude = 0x4000;
|
|
@@ -137,14 +139,14 @@ main(int argc, char **argv)
|
|
efx[nefx].periodic.fade_length = 1000;
|
|
efx[nefx].periodic.fade_length = 1000;
|
|
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
|
|
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
|
|
if (id[nefx] < 0) {
|
|
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();
|
|
abort_execution();
|
|
}
|
|
}
|
|
nefx++;
|
|
nefx++;
|
|
}
|
|
}
|
|
/* Now we'll try a SAWTOOTHUP */
|
|
/* Now we'll try a SAWTOOTHUP */
|
|
if (supported & SDL_HAPTIC_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].type = SDL_HAPTIC_SAWTOOTHUP;
|
|
efx[nefx].periodic.period = 500;
|
|
efx[nefx].periodic.period = 500;
|
|
efx[nefx].periodic.magnitude = 0x5000;
|
|
efx[nefx].periodic.magnitude = 0x5000;
|
|
@@ -153,14 +155,14 @@ main(int argc, char **argv)
|
|
efx[nefx].periodic.fade_length = 1000;
|
|
efx[nefx].periodic.fade_length = 1000;
|
|
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
|
|
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
|
|
if (id[nefx] < 0) {
|
|
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();
|
|
abort_execution();
|
|
}
|
|
}
|
|
nefx++;
|
|
nefx++;
|
|
}
|
|
}
|
|
/* Now the classical constant effect. */
|
|
/* Now the classical constant effect. */
|
|
if (supported & SDL_HAPTIC_CONSTANT) {
|
|
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].type = SDL_HAPTIC_CONSTANT;
|
|
efx[nefx].constant.direction.type = SDL_HAPTIC_POLAR;
|
|
efx[nefx].constant.direction.type = SDL_HAPTIC_POLAR;
|
|
efx[nefx].constant.direction.dir[0] = 20000; /* Force comes from the south-west. */
|
|
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;
|
|
efx[nefx].constant.fade_length = 1000;
|
|
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
|
|
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
|
|
if (id[nefx] < 0) {
|
|
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();
|
|
abort_execution();
|
|
}
|
|
}
|
|
nefx++;
|
|
nefx++;
|
|
}
|
|
}
|
|
/* The cute spring effect. */
|
|
/* The cute spring effect. */
|
|
if (supported & SDL_HAPTIC_SPRING) {
|
|
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].type = SDL_HAPTIC_SPRING;
|
|
efx[nefx].condition.length = 5000;
|
|
efx[nefx].condition.length = 5000;
|
|
for (i = 0; i < SDL_HapticNumAxes(haptic); i++) {
|
|
for (i = 0; i < SDL_HapticNumAxes(haptic); i++) {
|
|
@@ -189,14 +191,14 @@ main(int argc, char **argv)
|
|
}
|
|
}
|
|
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
|
|
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
|
|
if (id[nefx] < 0) {
|
|
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();
|
|
abort_execution();
|
|
}
|
|
}
|
|
nefx++;
|
|
nefx++;
|
|
}
|
|
}
|
|
/* The pretty awesome inertia effect. */
|
|
/* The pretty awesome inertia effect. */
|
|
if (supported & SDL_HAPTIC_INERTIA) {
|
|
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].type = SDL_HAPTIC_SPRING;
|
|
efx[nefx].condition.length = 5000;
|
|
efx[nefx].condition.length = 5000;
|
|
for (i = 0; i < SDL_HapticNumAxes(haptic); i++) {
|
|
for (i = 0; i < SDL_HapticNumAxes(haptic); i++) {
|
|
@@ -207,7 +209,7 @@ main(int argc, char **argv)
|
|
}
|
|
}
|
|
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
|
|
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
|
|
if (id[nefx] < 0) {
|
|
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();
|
|
abort_execution();
|
|
}
|
|
}
|
|
nefx++;
|
|
nefx++;
|
|
@@ -215,24 +217,24 @@ main(int argc, char **argv)
|
|
|
|
|
|
/* Finally we'll try a left/right effect. */
|
|
/* Finally we'll try a left/right effect. */
|
|
if (supported & SDL_HAPTIC_LEFTRIGHT) {
|
|
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].type = SDL_HAPTIC_LEFTRIGHT;
|
|
efx[nefx].leftright.length = 5000;
|
|
efx[nefx].leftright.length = 5000;
|
|
efx[nefx].leftright.large_magnitude = 0x3000;
|
|
efx[nefx].leftright.large_magnitude = 0x3000;
|
|
efx[nefx].leftright.small_magnitude = 0xFFFF;
|
|
efx[nefx].leftright.small_magnitude = 0xFFFF;
|
|
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
|
|
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
|
|
if (id[nefx] < 0) {
|
|
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();
|
|
abort_execution();
|
|
}
|
|
}
|
|
nefx++;
|
|
nefx++;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- printf
|
|
|
|
|
|
+ SDL_Log
|
|
("\nNow playing effects for 5 seconds each with 1 second delay between\n");
|
|
("\nNow playing effects for 5 seconds each with 1 second delay between\n");
|
|
for (i = 0; i < nefx; i++) {
|
|
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_HapticRunEffect(haptic, id[i], 1);
|
|
SDL_Delay(6000); /* Effects only have length 5000 */
|
|
SDL_Delay(6000); /* Effects only have length 5000 */
|
|
}
|
|
}
|
|
@@ -252,7 +254,7 @@ main(int argc, char **argv)
|
|
static void
|
|
static void
|
|
abort_execution(void)
|
|
abort_execution(void)
|
|
{
|
|
{
|
|
- printf("\nAborting program execution.\n");
|
|
|
|
|
|
+ SDL_Log("\nAborting program execution.\n");
|
|
|
|
|
|
SDL_HapticClose(haptic);
|
|
SDL_HapticClose(haptic);
|
|
SDL_Quit();
|
|
SDL_Quit();
|
|
@@ -270,42 +272,42 @@ HapticPrintSupported(SDL_Haptic * haptic)
|
|
unsigned int supported;
|
|
unsigned int supported;
|
|
|
|
|
|
supported = SDL_HapticQuery(haptic);
|
|
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));
|
|
SDL_HapticNumEffects(haptic), SDL_HapticNumEffectsPlaying(haptic));
|
|
if (supported & SDL_HAPTIC_CONSTANT)
|
|
if (supported & SDL_HAPTIC_CONSTANT)
|
|
- printf(" constant\n");
|
|
|
|
|
|
+ SDL_Log(" constant\n");
|
|
if (supported & SDL_HAPTIC_SINE)
|
|
if (supported & SDL_HAPTIC_SINE)
|
|
- printf(" sine\n");
|
|
|
|
|
|
+ SDL_Log(" sine\n");
|
|
/* !!! FIXME: put this back when we have more bits in 2.1 */
|
|
/* !!! FIXME: put this back when we have more bits in 2.1 */
|
|
/*if (supported & SDL_HAPTIC_SQUARE)
|
|
/*if (supported & SDL_HAPTIC_SQUARE)
|
|
- printf(" square\n");*/
|
|
|
|
|
|
+ SDL_Log(" square\n");*/
|
|
if (supported & SDL_HAPTIC_TRIANGLE)
|
|
if (supported & SDL_HAPTIC_TRIANGLE)
|
|
- printf(" triangle\n");
|
|
|
|
|
|
+ SDL_Log(" triangle\n");
|
|
if (supported & SDL_HAPTIC_SAWTOOTHUP)
|
|
if (supported & SDL_HAPTIC_SAWTOOTHUP)
|
|
- printf(" sawtoothup\n");
|
|
|
|
|
|
+ SDL_Log(" sawtoothup\n");
|
|
if (supported & SDL_HAPTIC_SAWTOOTHDOWN)
|
|
if (supported & SDL_HAPTIC_SAWTOOTHDOWN)
|
|
- printf(" sawtoothdown\n");
|
|
|
|
|
|
+ SDL_Log(" sawtoothdown\n");
|
|
if (supported & SDL_HAPTIC_RAMP)
|
|
if (supported & SDL_HAPTIC_RAMP)
|
|
- printf(" ramp\n");
|
|
|
|
|
|
+ SDL_Log(" ramp\n");
|
|
if (supported & SDL_HAPTIC_FRICTION)
|
|
if (supported & SDL_HAPTIC_FRICTION)
|
|
- printf(" friction\n");
|
|
|
|
|
|
+ SDL_Log(" friction\n");
|
|
if (supported & SDL_HAPTIC_SPRING)
|
|
if (supported & SDL_HAPTIC_SPRING)
|
|
- printf(" spring\n");
|
|
|
|
|
|
+ SDL_Log(" spring\n");
|
|
if (supported & SDL_HAPTIC_DAMPER)
|
|
if (supported & SDL_HAPTIC_DAMPER)
|
|
- printf(" damper\n");
|
|
|
|
|
|
+ SDL_Log(" damper\n");
|
|
if (supported & SDL_HAPTIC_INERTIA)
|
|
if (supported & SDL_HAPTIC_INERTIA)
|
|
- printf(" intertia\n");
|
|
|
|
|
|
+ SDL_Log(" inertia\n");
|
|
if (supported & SDL_HAPTIC_CUSTOM)
|
|
if (supported & SDL_HAPTIC_CUSTOM)
|
|
- printf(" custom\n");
|
|
|
|
|
|
+ SDL_Log(" custom\n");
|
|
if (supported & SDL_HAPTIC_LEFTRIGHT)
|
|
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)
|
|
if (supported & SDL_HAPTIC_GAIN)
|
|
- printf(" gain\n");
|
|
|
|
|
|
+ SDL_Log(" gain\n");
|
|
if (supported & SDL_HAPTIC_AUTOCENTER)
|
|
if (supported & SDL_HAPTIC_AUTOCENTER)
|
|
- printf(" autocenter\n");
|
|
|
|
|
|
+ SDL_Log(" autocenter\n");
|
|
if (supported & SDL_HAPTIC_STATUS)
|
|
if (supported & SDL_HAPTIC_STATUS)
|
|
- printf(" status\n");
|
|
|
|
|
|
+ SDL_Log(" status\n");
|
|
}
|
|
}
|
|
|
|
|
|
#else
|
|
#else
|
|
@@ -313,7 +315,7 @@ HapticPrintSupported(SDL_Haptic * haptic)
|
|
int
|
|
int
|
|
main(int argc, char *argv[])
|
|
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);
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
|