~ubuntu-branches/ubuntu/vivid/libsdl2/vivid

« back to all changes in this revision

Viewing changes to test/testrumble.c

  • Committer: Package Import Robot
  • Author(s): Manuel A. Fernandez Montecelo, Felix Geyer
  • Date: 2013-12-28 12:31:19 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20131228123119-e0k27gckmnzskfgb
Tags: 2.0.1+dfsg1-1
* New upstream release (Closes: #728974)
  - Remove patch applied upstream:
    bug-723797-false_positives_in_mouse_wheel_code.patch
* Bump Standards-Version to 3.9.5, no changes needed.

[ Felix Geyer ]
* Import upstream gpg key for uscan to verify the orig tarball.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 * includes
27
27
 */
28
28
#include <stdlib.h>
29
 
#include <stdio.h>              /* printf */
30
29
#include <string.h>             /* strstr */
31
30
#include <ctype.h>              /* isdigit */
32
31
 
51
50
    char *name;
52
51
    int index;
53
52
 
 
53
        /* Enable standard application logging */
 
54
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
 
55
 
54
56
    name = NULL;
55
57
    index = -1;
56
58
    if (argc > 1) {
57
59
        name = argv[1];
58
60
        if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) {
59
 
            printf("USAGE: %s [device]\n"
 
61
            SDL_Log("USAGE: %s [device]\n"
60
62
                   "If device is a two-digit number it'll use it as an index, otherwise\n"
61
63
                   "it'll use it as if it were part of the device's name.\n",
62
64
                   argv[0]);
73
75
    /* Initialize the force feedbackness */
74
76
    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK |
75
77
             SDL_INIT_HAPTIC);
76
 
    printf("%d Haptic devices detected.\n", SDL_NumHaptics());
 
78
    SDL_Log("%d Haptic devices detected.\n", SDL_NumHaptics());
77
79
    if (SDL_NumHaptics() > 0) {
78
80
        /* We'll just use index or the first force feedback device found */
79
81
        if (name == NULL) {
87
89
            }
88
90
 
89
91
            if (i >= SDL_NumHaptics()) {
90
 
                printf("Unable to find device matching '%s', aborting.\n",
 
92
                SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n",
91
93
                       name);
92
94
                return 1;
93
95
            }
95
97
 
96
98
        haptic = SDL_HapticOpen(i);
97
99
        if (haptic == NULL) {
98
 
            printf("Unable to create the haptic device: %s\n",
 
100
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n",
99
101
                   SDL_GetError());
100
102
            return 1;
101
103
        }
102
 
        printf("Device: %s\n", SDL_HapticName(i));
 
104
        SDL_Log("Device: %s\n", SDL_HapticName(i));
103
105
    } else {
104
 
        printf("No Haptic devices found!\n");
 
106
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n");
105
107
        return 1;
106
108
    }
107
109
 
109
111
    SDL_ClearError();
110
112
 
111
113
    if (SDL_HapticRumbleSupported(haptic) == SDL_FALSE) {
112
 
        printf("\nRumble not supported!\n");
 
114
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Rumble not supported!\n");
113
115
        return 1;
114
116
    }
115
117
    if (SDL_HapticRumbleInit(haptic) != 0) {
116
 
        printf("\nFailed to initialize rumble: %s\n", SDL_GetError());
 
118
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to initialize rumble: %s\n", SDL_GetError());
117
119
        return 1;
118
120
    }
119
 
    printf("Playing 2 second rumble at 0.5 magnitude.\n");
 
121
    SDL_Log("Playing 2 second rumble at 0.5 magnitude.\n");
120
122
    if (SDL_HapticRumblePlay(haptic, 0.5, 5000) != 0) {
121
 
       printf("\nFailed to play rumble: %s\n", SDL_GetError() );
 
123
       SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError() );
122
124
       return 1;
123
125
    }
124
126
    SDL_Delay(2000);
125
 
    printf("Stopping rumble.\n");
 
127
    SDL_Log("Stopping rumble.\n");
126
128
    SDL_HapticRumbleStop(haptic);
127
129
    SDL_Delay(2000);
128
 
    printf("Playing 2 second rumble at 0.3 magnitude.\n");
 
130
    SDL_Log("Playing 2 second rumble at 0.3 magnitude.\n");
129
131
    if (SDL_HapticRumblePlay(haptic, 0.3f, 5000) != 0) {
130
 
       printf("\nFailed to play rumble: %s\n", SDL_GetError() );
 
132
       SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError() );
131
133
       return 1;
132
134
    }
133
135
    SDL_Delay(2000);
145
147
int
146
148
main(int argc, char *argv[])
147
149
{
148
 
    fprintf(stderr, "SDL compiled without Haptic support.\n");
 
150
    SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Haptic support.\n");
149
151
    exit(1);
150
152
}
151
153