test/testhotplug.c
author Edward Rudd <urkle@outoforder.cc>
Fri, 07 Feb 2014 09:35:33 -0500
changeset 8188 47b9ab82bebf
parent 8181 3632013330ad
child 8776 29aac8b813d9
permissions -rw-r--r--
slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
     1
/*
8180
16afd5b764b3 Fixed copyright date.
Ryan C. Gordon <icculus@icculus.org>
parents: 8169
diff changeset
     2
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
     3
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
     4
  This software is provided 'as-is', without any express or implied
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
     5
  warranty.  In no event will the authors be held liable for any damages
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
     6
  arising from the use of this software.
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
     7
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
     8
  Permission is granted to anyone to use this software for any purpose,
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
     9
  including commercial applications, and to alter it and redistribute it
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    10
  freely.
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    11
*/
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    12
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    13
/* Simple program to test the SDL joystick hotplugging */
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    14
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    15
#include <stdio.h>
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    16
#include <stdlib.h>
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    17
#include <string.h>
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    18
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    19
#include "SDL.h"
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    20
#include "SDL_haptic.h"
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    21
8188
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    22
#if !defined SDL_JOYSTICK_DISABLED && !defined SDL_HAPTIC_DISABLED
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    23
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    24
int
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    25
main(int argc, char *argv[])
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    26
{
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    27
    SDL_Joystick *joystick = NULL;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    28
    SDL_Haptic *haptic = NULL;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    29
    SDL_JoystickID instance = -1;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    30
    SDL_bool keepGoing = SDL_TRUE;
8188
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    31
    int i;
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    32
    SDL_bool enable_haptic = SDL_TRUE;
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    33
    Uint32 init_subsystems = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK;
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    34
    
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    35
    for (i = 1; i < argc; ++i) {
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    36
        if (SDL_strcasecmp(argv[i], "--nohaptic") == 0) {
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    37
            enable_haptic = SDL_FALSE;
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    38
        }
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    39
    }
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    40
8188
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    41
    if(enable_haptic) {
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    42
        init_subsystems |= SDL_INIT_HAPTIC;
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    43
    }
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    44
    
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    45
    /* Enable standard application logging */
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    46
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);	
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    47
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    48
    SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    49
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    50
    /* Initialize SDL (Note: video is required to start event loop) */
8188
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    51
    if (SDL_Init(init_subsystems) < 0) {
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    52
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    53
        exit(1);
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    54
    }
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    55
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    56
    //SDL_CreateWindow("Dummy", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 128, 128, 0);
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    57
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    58
    SDL_Log("There are %d joysticks at startup\n", SDL_NumJoysticks());
8188
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    59
    if (enable_haptic)
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    60
        SDL_Log("There are %d haptic devices at startup\n", SDL_NumHaptics());
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    61
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    62
    while(keepGoing)
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    63
    {
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    64
        SDL_Event event;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    65
        while(SDL_PollEvent(&event))
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    66
        {
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    67
            switch(event.type)
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    68
            {
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    69
                case SDL_QUIT:
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    70
                    keepGoing = SDL_FALSE;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    71
                    break;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    72
                case SDL_JOYDEVICEADDED:
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    73
                    if (joystick != NULL)
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    74
                    {
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    75
                        SDL_Log("Only one joystick supported by this test\n");
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    76
                    }
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    77
                    else
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    78
                    {
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    79
                        joystick = SDL_JoystickOpen(event.jdevice.which);
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    80
                        instance = SDL_JoystickInstanceID(joystick);
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    81
                        SDL_Log("Joy Added  : %d : %s\n", event.jdevice.which, SDL_JoystickName(joystick));
8188
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    82
                        if (enable_haptic)
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    83
                        {
8188
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    84
                            if (SDL_JoystickIsHaptic(joystick))
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    85
                            {
8188
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    86
                                haptic = SDL_HapticOpenFromJoystick(joystick);
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    87
                                if (haptic)
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    88
                                {
8188
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    89
                                    SDL_Log("Joy Haptic Opened\n");
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    90
                                    if (SDL_HapticRumbleInit( haptic ) != 0)
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    91
                                    {
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    92
                                        SDL_Log("Could not init Rumble!: %s\n", SDL_GetError());
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    93
                                        SDL_HapticClose(haptic);
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    94
                                        haptic = NULL;
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    95
                                    }
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    96
                                } else {
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
    97
                                    SDL_Log("Joy haptic open FAILED!: %s\n", SDL_GetError());
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    98
                                }
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    99
                            }
8188
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
   100
                            else
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
   101
                            {
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
   102
                                SDL_Log("No haptic found\n");
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
   103
                            }
8165
2b8ba3d53a67 add logging for the case when haptic is not detected on the joystick as well.
Edward Rudd <urkle@outoforder.cc>
parents: 8164
diff changeset
   104
                        }
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   105
                    }
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   106
                    break;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   107
                case SDL_JOYDEVICEREMOVED:
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   108
                    if (instance == event.jdevice.which)
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   109
                    {
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   110
                        SDL_Log("Joy Removed: %d\n", event.jdevice.which);
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   111
                        instance = -1;
8188
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
   112
                        if(enable_haptic && haptic)
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   113
                        {
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   114
                            SDL_HapticClose(haptic);
8165
2b8ba3d53a67 add logging for the case when haptic is not detected on the joystick as well.
Edward Rudd <urkle@outoforder.cc>
parents: 8164
diff changeset
   115
                            haptic = NULL;
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   116
                        }
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   117
                        SDL_JoystickClose(joystick);
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   118
                        joystick = NULL;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   119
                    } else {
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   120
                        SDL_Log("Unknown joystick diconnected\n");
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   121
                    }
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   122
                    break;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   123
                case SDL_JOYAXISMOTION:
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   124
//                    SDL_Log("Axis Move: %d\n", event.jaxis.axis);
8188
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
   125
                    if (enable_haptic)
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
   126
                        SDL_HapticRumblePlay(haptic, 0.25, 250);
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   127
                    break;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   128
                case SDL_JOYBUTTONDOWN:
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   129
                    SDL_Log("Button Press: %d\n", event.jbutton.button);
8188
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
   130
                    if(enable_haptic && haptic)
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   131
                    {
8188
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
   132
                        SDL_HapticRumblePlay(haptic, 0.25, 250);
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   133
                    }
8169
663ba61243ff allow safely quitting the hotplug test by pressing button 0 on the joystick
Edward Rudd <urkle@outoforder.cc>
parents: 8166
diff changeset
   134
					if (event.jbutton.button == 0) {
663ba61243ff allow safely quitting the hotplug test by pressing button 0 on the joystick
Edward Rudd <urkle@outoforder.cc>
parents: 8166
diff changeset
   135
						SDL_Log("Exiting due to button press of button 0\n");
663ba61243ff allow safely quitting the hotplug test by pressing button 0 on the joystick
Edward Rudd <urkle@outoforder.cc>
parents: 8166
diff changeset
   136
						keepGoing = SDL_FALSE;
663ba61243ff allow safely quitting the hotplug test by pressing button 0 on the joystick
Edward Rudd <urkle@outoforder.cc>
parents: 8166
diff changeset
   137
					}
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   138
                    break;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   139
                case SDL_JOYBUTTONUP:
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   140
                    SDL_Log("Button Release: %d\n", event.jbutton.button);
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   141
                    break;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   142
            }
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   143
        }
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   144
    }
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   145
8188
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
   146
    SDL_Quit();
8181
3632013330ad Fixed return values on testhotplug mainline.
Ryan C. Gordon <icculus@icculus.org>
parents: 8180
diff changeset
   147
3632013330ad Fixed return values on testhotplug mainline.
Ryan C. Gordon <icculus@icculus.org>
parents: 8180
diff changeset
   148
    return 0;
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   149
}
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   150
#else
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   151
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   152
int
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   153
main(int argc, char *argv[])
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   154
{
8188
47b9ab82bebf slight adjustment to the hot plug test to allow it to be run with hap tics disabled
Edward Rudd <urkle@outoforder.cc>
parents: 8181
diff changeset
   155
    SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Joystick and haptic support.\n");
8181
3632013330ad Fixed return values on testhotplug mainline.
Ryan C. Gordon <icculus@icculus.org>
parents: 8180
diff changeset
   156
    return 1;
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   157
}
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   158
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   159
#endif