~ubuntu-branches/ubuntu/quantal/joystick/quantal

« back to all changes in this revision

Viewing changes to utils/jstest.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Kitt
  • Date: 2010-05-16 16:11:59 UTC
  • mfrom: (3.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100516161159-tf754mo83ojh1yqj
Tags: 20051019-11
evtest: flush standard output, thanks Florian Fainelli! Closes:
#581740.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
#include <linux/input.h>
50
50
#include <linux/joystick.h>
51
51
 
 
52
#include "axbtnmap.h"
 
53
 
52
54
char *axis_names[ABS_MAX + 1] = {
53
55
"X", "Y", "Z", "Rx", "Ry", "Rz", "Throttle", "Rudder", 
54
56
"Wheel", "Gas", "Brake", "?", "?", "?", "?", "?",
74
76
        unsigned char buttons = 2;
75
77
        int version = 0x000800;
76
78
        char name[NAME_LENGTH] = "Unknown";
77
 
        uint16_t btnmap[KEY_MAX - BTN_MISC + 1];
78
 
        uint8_t axmap[ABS_MAX + 1];
 
79
        uint16_t btnmap[BTNMAP_SIZE];
 
80
        uint8_t axmap[AXMAP_SIZE];
 
81
        int btnmapok = 1;
79
82
 
80
83
        if (argc < 2 || argc > 3 || !strcmp("--help", argv[1])) {
81
84
                puts("");
99
102
        ioctl(fd, JSIOCGAXES, &axes);
100
103
        ioctl(fd, JSIOCGBUTTONS, &buttons);
101
104
        ioctl(fd, JSIOCGNAME(NAME_LENGTH), name);
102
 
        ioctl(fd, JSIOCGAXMAP, axmap);
103
 
        ioctl(fd, JSIOCGBTNMAP, btnmap);
104
105
 
 
106
        getaxmap(fd, axmap);
 
107
        getbtnmap(fd, btnmap);
105
108
 
106
109
        printf("Driver version is %d.%d.%d.\n",
107
110
                version >> 16, (version >> 8) & 0xff, version & 0xff);
108
111
 
109
 
        printf("Joystick (%s) has %d axes (", name, axes);
110
 
        for (i = 0; i < axes; i++)
111
 
                printf("%s%s", i > 0 ? ", " : "", axis_names[axmap[i]]);
112
 
        puts(")");
 
112
        /* Determine whether the button map is usable. */
 
113
        for (i = 0; btnmapok && i < buttons; i++) {
 
114
                if (btnmap[i] < BTN_MISC || btnmap[i] > KEY_MAX) {
 
115
                        btnmapok = 0;
 
116
                        break;
 
117
                }
 
118
        }
 
119
        if (!btnmapok) {
 
120
                /* btnmap out of range for names. Don't print any. */
 
121
                puts("jstest is not fully compatible with your kernel. Unable to retrieve button map!");
 
122
                printf("Joystick (%s) has %d axes ", name, axes);
 
123
                printf("and %d buttons.\n", buttons);
 
124
        } else {
 
125
                printf("Joystick (%s) has %d axes (", name, axes);
 
126
                for (i = 0; i < axes; i++)
 
127
                        printf("%s%s", i > 0 ? ", " : "", axis_names[axmap[i]]);
 
128
                puts(")");
113
129
 
114
 
        printf("and %d buttons (", buttons);
115
 
        for (i = 0; i < buttons; i++)
116
 
                printf("%s%s", i > 0 ? ", " : "", button_names[btnmap[i] - BTN_MISC]);
117
 
        puts(").");
 
130
                printf("and %d buttons (", buttons);
 
131
                for (i = 0; i < buttons; i++) {
 
132
                        printf("%s%s", i > 0 ? ", " : "", button_names[btnmap[i] - BTN_MISC]);
 
133
                }
 
134
                puts(").");
 
135
        }
118
136
 
119
137
        printf("Testing ... (interrupt to exit)\n");
120
138