~alexandre-hardy/linuxjoymap/linuxjoymap

« back to all changes in this revision

Viewing changes to tools/jssetcal.c

  • Committer: Alexandre Hardy
  • Date: 2009-07-17 09:20:57 UTC
  • Revision ID: ah@zenwalk-20090717092057-oxa4o16isawqa7ue
Initial creation of project

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <unistd.h>
 
2
#include <fcntl.h>
 
3
#include <sys/ioctl.h>
 
4
#include <linux/joystick.h>
 
5
#include <stdio.h>
 
6
#include <stdlib.h>
 
7
 
 
8
int main(int argc, char *argv[]) {
 
9
        int fd,i;
 
10
        unsigned char axes,btns;
 
11
        struct js_corr cor[64];
 
12
        if (argc>=2)
 
13
                fd=open(argv[1], O_RDONLY|O_NONBLOCK);
 
14
        else
 
15
                fd=open("/dev/input/js0", O_RDONLY|O_NONBLOCK);
 
16
        if (fd<0) {     
 
17
                perror("Failed to open device");
 
18
                return 1;
 
19
        }
 
20
        ioctl(fd, JSIOCGAXES, &axes);
 
21
        ioctl(fd, JSIOCGBUTTONS, &btns);
 
22
        for (i=0; i<axes; i++) {
 
23
                scanf("%d %d %d %d %d\n",  &cor[i].type,
 
24
                                        &cor[i].coef[0], 
 
25
                                        &cor[i].coef[1],
 
26
                                        &cor[i].coef[2],
 
27
                                        &cor[i].coef[3]);
 
28
        }
 
29
        ioctl(fd, JSIOCSCORR, cor);
 
30
        return 0;
 
31
}