1 #include "config.h"
2
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <string.h>
6 #include <fcntl.h>
7 #include <errno.h>
8 #include <pthread.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11
12 #ifdef HAVE_LINUX_JOYSTICK_H
13 # include <linux/joystick.h>
14 #endif
15
16 #include "grab-ng.h"
17 #include "commands.h"
18 #include "joystick.h"
19 #include "event.h"
20
21 /*-----------------------------------------------------------------------*/
22
23 extern int debug;
24
25 #ifdef HAVE_LINUX_JOYSTICK_H
26 struct JOYTAB {
27 int class;
28 int number;
29 int value;
30 char *event;
31 };
32
33 static struct JOYTAB joytab[] = {
34 { JS_EVENT_BUTTON, 0, 1, "joy-button-0" },
35 { JS_EVENT_BUTTON, 1, 1, "joy-button-1" },
36 { JS_EVENT_AXIS, 1, -32767, "joy-axis-up" },
37 { JS_EVENT_AXIS, 1, 32767, "joy-axis-down" },
38 { JS_EVENT_AXIS, 0, 32767, "joy-axis-left" },
39 { JS_EVENT_AXIS, 0, -32767, "joy-axis-right" },
40 };
41 #define NJOYTAB (sizeof(joytab)/sizeof(struct JOYTAB))
42
43 static struct event_entry joy_events[] = {
44 {
45 event: "joy-button-0",
46 action: "quit",
47 },{
48 event: "joy-button-1",
49 action: "fullscreen",
50 },{
51 event: "joy-axis-up",
52 action: "volume inc",
53 },{
54 event: "joy-axis-down",
55 action: "volume dec",
56 },{
57 event: "joy-axis-left",
58 action: "setchannel prev",
59 },{
60 event: "joy-axis-right",
61 action: "setchannel next",
62 },{
63 /* end of list */
64 }
65 };
66
67 #endif
68
69 int joystick_tv_init(char *dev)
70 {
71 #ifdef HAVE_LINUX_JOYSTICK_H
72 int fd;
73
74 if (NULL == dev)
75 return -1;
76 if (-1 == (fd = open(dev, O_NONBLOCK))) {
77 fprintf(stderr, "joystick: open %s: %s\n",dev,strerror(errno));
78 return -1;
79 }
80 fcntl(fd,F_SETFD,FD_CLOEXEC);
81 event_register_list(joy_events);
82 return fd;
83 #else
84 if (debug)
85 fprintf(stderr,"joystick: not enabled at compile time\n");
86 return -1;
87 #endif
88 }
89
90 void joystick_tv_havedata(int js)
91 {
92 #ifdef HAVE_LINUX_JOYSTICK_H
93 unsigned int i;
94 struct js_event event;
95 if (debug)
96 fprintf(stderr, "joystick: received input\n");
97 if (read(js, &event, sizeof(struct js_event))) {
98 for (i = 0; i < NJOYTAB; i++)
99 if (joytab[i].class == (event.type)
100 && joytab[i].number == event.number
101 && joytab[i].value == event.value)
102 break;
103 if (i != NJOYTAB)
104 event_dispatch(joytab[i].event);
105 }
106 #endif
107 }
108
|
This page was automatically generated by the
LXR engine.
|