test/testhotplug.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 12 Aug 2016 19:59:00 -0400
changeset 10266 c09f06c4e8c8
parent 9998 f67cf37e9cd4
permissions -rw-r--r--
emscripten: send fake mouse events for touches, like other targets do. (This really should be handled at the higher level and not in the individual targets, but this fixes the immediate bug.)
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
/*
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9922
diff changeset
     2
  Copyright (C) 1997-2016 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
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
    21
#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
    22
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    23
int
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    24
main(int argc, char *argv[])
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    25
{
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    26
    SDL_Joystick *joystick = NULL;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    27
    SDL_Haptic *haptic = NULL;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    28
    SDL_JoystickID instance = -1;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    29
    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
    30
    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
    31
    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
    32
    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
    33
    
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
    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
    35
        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
    36
            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
    37
        }
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
    }
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    39
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
    40
    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
    41
        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
    42
    }
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
    
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    44
    /* Enable standard application logging */
9922
b066d5fd5fa7 Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9619
diff changeset
    45
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    46
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    47
    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
    48
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    49
    /* 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
    50
    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
    51
        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
    52
        exit(1);
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    53
    }
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    54
8776
29aac8b813d9 Changed C++ style comments to fix pedantic warnings.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8188
diff changeset
    55
    /*
8164
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);
8776
29aac8b813d9 Changed C++ style comments to fix pedantic warnings.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8188
diff changeset
    57
    */
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    58
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    59
    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
    60
    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
    61
        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
    62
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    63
    while(keepGoing)
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    64
    {
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    65
        SDL_Event event;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    66
        while(SDL_PollEvent(&event))
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    67
        {
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    68
            switch(event.type)
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    69
            {
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    70
                case SDL_QUIT:
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    71
                    keepGoing = SDL_FALSE;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    72
                    break;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    73
                case SDL_JOYDEVICEADDED:
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    74
                    if (joystick != NULL)
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    75
                    {
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    76
                        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
    77
                    }
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    78
                    else
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    79
                    {
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    80
                        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
    81
                        instance = SDL_JoystickInstanceID(joystick);
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    82
                        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
    83
                        if (enable_haptic)
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    84
                        {
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
    85
                            if (SDL_JoystickIsHaptic(joystick))
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    86
                            {
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
    87
                                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
    88
                                if (haptic)
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
    89
                                {
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
    90
                                    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
    91
                                    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
    92
                                    {
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_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
    94
                                        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
    95
                                        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
    96
                                    }
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
                                } 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
    98
                                    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
    99
                                }
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   100
                            }
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
   101
                            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
   102
                            {
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
                                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
   104
                            }
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
   105
                        }
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   106
                    }
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   107
                    break;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   108
                case SDL_JOYDEVICEREMOVED:
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   109
                    if (instance == event.jdevice.which)
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   110
                    {
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   111
                        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
   112
                        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
   113
                        if(enable_haptic && haptic)
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   114
                        {
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   115
                            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
   116
                            haptic = NULL;
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   117
                        }
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   118
                        SDL_JoystickClose(joystick);
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   119
                        joystick = NULL;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   120
                    } else {
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   121
                        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
   122
                    }
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   123
                    break;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   124
                case SDL_JOYAXISMOTION:
8778
d67a044fbec6 Changed C++ style comments.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8776
diff changeset
   125
/*
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   126
//                    SDL_Log("Axis Move: %d\n", event.jaxis.axis);
8778
d67a044fbec6 Changed C++ style comments.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8776
diff changeset
   127
*/
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
   128
                    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
   129
                        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
   130
                    break;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   131
                case SDL_JOYBUTTONDOWN:
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   132
                    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
   133
                    if(enable_haptic && haptic)
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   134
                    {
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
   135
                        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
   136
                    }
9922
b066d5fd5fa7 Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9619
diff changeset
   137
                    if (event.jbutton.button == 0) {
b066d5fd5fa7 Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9619
diff changeset
   138
                        SDL_Log("Exiting due to button press of button 0\n");
b066d5fd5fa7 Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9619
diff changeset
   139
                        keepGoing = SDL_FALSE;
b066d5fd5fa7 Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9619
diff changeset
   140
                    }
8164
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
                case SDL_JOYBUTTONUP:
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   143
                    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
   144
                    break;
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   145
            }
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   146
        }
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   147
    }
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   148
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
   149
    SDL_Quit();
8181
3632013330ad Fixed return values on testhotplug mainline.
Ryan C. Gordon <icculus@icculus.org>
parents: 8180
diff changeset
   150
3632013330ad Fixed return values on testhotplug mainline.
Ryan C. Gordon <icculus@icculus.org>
parents: 8180
diff changeset
   151
    return 0;
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   152
}
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   153
#else
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   154
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   155
int
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   156
main(int argc, char *argv[])
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   157
{
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
   158
    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
   159
    return 1;
8164
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   160
}
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   161
478fbe1f032f add simple test showing off hotplugging of joysticks w/ haptic.
Edward Rudd <urkle@outoforder.cc>
parents:
diff changeset
   162
#endif