mirror of
https://github.com/joel16/SDL2.git
synced 2024-12-15 23:37:04 +00:00
Allow testing haptic devices by index.
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403201
This commit is contained in:
parent
1051156e2b
commit
2266a03856
@ -19,7 +19,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||||||
|
|
||||||
#include <stdio.h> /* printf */
|
#include <stdio.h> /* printf */
|
||||||
#include <string.h> /* strstr */
|
#include <string.h> /* strstr */
|
||||||
|
#include <ctype.h> /* isdigit */
|
||||||
|
|
||||||
|
|
||||||
static SDL_Haptic *haptic;
|
static SDL_Haptic *haptic;
|
||||||
@ -42,20 +42,29 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *name;
|
char *name;
|
||||||
|
int index;
|
||||||
SDL_HapticEffect efx[5];
|
SDL_HapticEffect efx[5];
|
||||||
int id[5];
|
int id[5];
|
||||||
int nefx;
|
int nefx;
|
||||||
unsigned int supported;
|
unsigned int supported;
|
||||||
|
|
||||||
name = NULL;
|
name = NULL;
|
||||||
|
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 name]\n"
|
printf("USAGE: %s [device]\n"
|
||||||
"If device name is specified, it will try to find a device whose name\n"
|
"If device is a two-digit number it'll use it as an index, otherwise\n"
|
||||||
"contains device name for testing.\n", argv[0]);
|
"it'll use it as if it were part of the device's name.\n",
|
||||||
|
argv[0]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i = strlen(name);
|
||||||
|
if ((i < 3) && isdigit(name[0]) && ((i == 1) || isdigit(name[1]))) {
|
||||||
|
index = atoi(name);
|
||||||
|
name = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize the force feedbackness */
|
/* Initialize the force feedbackness */
|
||||||
@ -63,9 +72,9 @@ main(int argc, char **argv)
|
|||||||
SDL_INIT_HAPTIC);
|
SDL_INIT_HAPTIC);
|
||||||
printf("%d Haptic devices detected.\n", SDL_NumHaptics());
|
printf("%d Haptic devices detected.\n", SDL_NumHaptics());
|
||||||
if (SDL_NumHaptics() > 0) {
|
if (SDL_NumHaptics() > 0) {
|
||||||
/* We'll just use the first force feedback device found */
|
/* We'll just use index or the first force feedback device found */
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
i = 0;
|
i = (index != -1) ? index : 0;
|
||||||
}
|
}
|
||||||
/* Try to find matching device */
|
/* Try to find matching device */
|
||||||
else {
|
else {
|
||||||
@ -83,7 +92,8 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
haptic = SDL_HapticOpen(i);
|
haptic = SDL_HapticOpen(i);
|
||||||
if (haptic == NULL) {
|
if (haptic == NULL) {
|
||||||
perror("Unable to create the haptic device");
|
printf("Unable to create the haptic device: %s\n",
|
||||||
|
SDL_GetError());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
printf("Device: %s\n", SDL_HapticName(i));
|
printf("Device: %s\n", SDL_HapticName(i));
|
||||||
|
Loading…
Reference in New Issue
Block a user