File: evtestplus.cpp

package info (click to toggle)
xboxdrv 0.8.4-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,252 kB
  • sloc: cpp: 19,297; xml: 3,202; ansic: 507; python: 483; sh: 89; makefile: 34; ruby: 19
file content (98 lines) | stat: -rw-r--r-- 1,998 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <linux/input.h>

#include <sys/types.h>
#include <dirent.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

void process_device(int fd)
{
  int version;
  if (ioctl(fd, EVIOCGVERSION, &version) < 0) 
    {
      perror("evtest: can't get version");
      exit(1);
    }

  if (1)
    {
      char phys[1024];
      if (ioctl(fd, EVIOCGNAME(sizeof(phys)), &phys) < 0) 
        {
          perror("evtest: can't get name");
          exit(1);
        }
      std::cout << "Name:    " << phys << std::endl;
    }

  if (1) 
    {
      char phys[1024];
      if (ioctl(fd, EVIOCGPHYS(sizeof(phys)), &phys) < 0) 
        {
          perror("evtest: can't get phys");
          exit(1);
        }
      std::cout << "Phys:    " << phys << std::endl;
    }

  if (0) 
    {
      char phys[1024];
      if (ioctl(fd, EVIOCGUNIQ(sizeof(phys)), &phys) < 0) 
        {
          perror("evtest: can't get uniq");
          exit(1);
        }
      std::cout << "Uniq:    " << phys << std::endl;
    }

  

  std::cout << "Version: " << (version >> 16) << "." << ((version >> 8) & 0xff) << "." << (version & 0xff) << std::endl;

  /*  unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
      ioctl(fd, EVIOCGID, id);
      ioctl(fd, EVIOCGNAME(sizeof(name)), name);
      memset(bit, 0, sizeof(bit));
      ioctl(fd, EVIOCGBIT(0, EV_MAX), bit[0]);*/
}

/**
   evtestplus 
    --list          List available devices
    --test DEVICE   Test device
    --info DEVICE   List properties of device
 */
int main(int argc, char** argv)
{
  if (argc != 2)
    {
      std::cout << "Usage: " << argv[0] << " DEVICE" << std::endl;
      exit(EXIT_FAILURE);
    }
  else
    {
      const char* filename = argv[1];
      
      int fd;
      if ((fd = open(filename, O_RDONLY)) < 0) 
        {
          perror(filename);
        }
      else
        {
          process_device(fd);

          close(fd);
        }
    }

  return 0;
}

/* EOF */