29
29
30
30
#include <linux/bpf.h>
31
31
#include <linux/lirc.h>
32
+ #include <linux/input.h>
32
33
#include <errno.h>
33
34
#include <stdio.h>
34
35
#include <stdlib.h>
47
48
int main (int argc , char * * argv )
48
49
{
49
50
struct bpf_object * obj ;
50
- int ret , lircfd , progfd , mode ;
51
- int testir = 0x1dead ;
51
+ int ret , lircfd , progfd , inputfd ;
52
+ int testir1 = 0x1dead ;
53
+ int testir2 = 0x20101 ;
52
54
u32 prog_ids [10 ], prog_flags [10 ], prog_cnt ;
53
55
54
- if (argc != 2 ) {
55
- printf ("Usage: %s /dev/lircN\n" , argv [0 ]);
56
+ if (argc != 3 ) {
57
+ printf ("Usage: %s /dev/lircN /dev/input/eventM \n" , argv [0 ]);
56
58
return 2 ;
57
59
}
58
60
@@ -76,9 +78,9 @@ int main(int argc, char **argv)
76
78
return 1 ;
77
79
}
78
80
79
- mode = LIRC_MODE_SCANCODE ;
80
- if (ioctl ( lircfd , LIRC_SET_REC_MODE , & mode ) ) {
81
- printf ("failed to set rec mode : %m\n" );
81
+ inputfd = open ( argv [ 2 ], O_RDONLY | O_NONBLOCK ) ;
82
+ if (inputfd == -1 ) {
83
+ printf ("failed to open input device %s : %m\n" , argv [ 1 ] );
82
84
return 1 ;
83
85
}
84
86
@@ -102,29 +104,54 @@ int main(int argc, char **argv)
102
104
}
103
105
104
106
/* Write raw IR */
105
- ret = write (lircfd , & testir , sizeof (testir ));
106
- if (ret != sizeof (testir )) {
107
+ ret = write (lircfd , & testir1 , sizeof (testir1 ));
108
+ if (ret != sizeof (testir1 )) {
107
109
printf ("Failed to send test IR message: %m\n" );
108
110
return 1 ;
109
111
}
110
112
111
- struct pollfd pfd = { .fd = lircfd , .events = POLLIN };
112
- struct lirc_scancode lsc ;
113
+ struct pollfd pfd = { .fd = inputfd , .events = POLLIN };
114
+ struct input_event event ;
113
115
114
- poll (& pfd , 1 , 100 );
116
+ for (;;) {
117
+ poll (& pfd , 1 , 100 );
115
118
116
- /* Read decoded IR */
117
- ret = read (lircfd , & lsc , sizeof (lsc ));
118
- if (ret != sizeof (lsc )) {
119
- printf ("Failed to read decoded IR: %m\n" );
120
- return 1 ;
119
+ /* Read decoded IR */
120
+ ret = read (inputfd , & event , sizeof (event ));
121
+ if (ret != sizeof (event )) {
122
+ printf ("Failed to read decoded IR: %m\n" );
123
+ return 1 ;
124
+ }
125
+
126
+ if (event .type == EV_MSC && event .code == MSC_SCAN &&
127
+ event .value == 0xdead ) {
128
+ break ;
129
+ }
121
130
}
122
131
123
- if (lsc .scancode != 0xdead || lsc .rc_proto != 64 ) {
124
- printf ("Incorrect scancode decoded\n" );
132
+ /* Write raw IR */
133
+ ret = write (lircfd , & testir2 , sizeof (testir2 ));
134
+ if (ret != sizeof (testir2 )) {
135
+ printf ("Failed to send test IR message: %m\n" );
125
136
return 1 ;
126
137
}
127
138
139
+ for (;;) {
140
+ poll (& pfd , 1 , 100 );
141
+
142
+ /* Read decoded IR */
143
+ ret = read (inputfd , & event , sizeof (event ));
144
+ if (ret != sizeof (event )) {
145
+ printf ("Failed to read decoded IR: %m\n" );
146
+ return 1 ;
147
+ }
148
+
149
+ if (event .type == EV_REL && event .code == REL_Y &&
150
+ event .value == 1 ) {
151
+ break ;
152
+ }
153
+ }
154
+
128
155
prog_cnt = 10 ;
129
156
ret = bpf_prog_query (lircfd , BPF_LIRC_MODE2 , 0 , prog_flags , prog_ids ,
130
157
& prog_cnt );
0 commit comments