2 * Linux Apple IR Remote input interface
4 * Copyright (C) 2008 Benjamin Zores <ben at geexbox dot org>
6 * This file is part of MPlayer.
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * MPlayer is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 #include <sys/types.h>
37 #include <linux/types.h>
38 #include <linux/input.h>
43 #define EVDEV_MAX_EVENTS 32
45 /* ripped from AppleIR driver */
46 #define USB_VENDOR_APPLE 0x05ac
47 #define USB_DEV_APPLE_IR 0x8240
48 #define USB_DEV_APPLE_IR_2 0x8242
50 /* Apple IR Remote evdev mapping */
51 #define APPLE_IR_MINUS KEY_VOLUMEDOWN
52 #define APPLE_IR_PLUS KEY_VOLUMEUP
53 #define APPLE_IR_MENU KEY_MENU
54 #define APPLE_IR_FORWARD KEY_NEXTSONG
55 #define APPLE_IR_PLAY KEY_PLAYPAUSE
56 #define APPLE_IR_BACKWARD KEY_PREVIOUSSONG
62 } apple_ir_mapping
[] = {
63 { APPLE_IR_PLAY
, 1, AR_PLAY
},
64 { APPLE_IR_PLAY
, 2, AR_PLAY_HOLD
},
65 { APPLE_IR_FORWARD
, 1, AR_NEXT
},
66 { APPLE_IR_FORWARD
, 2, AR_NEXT_HOLD
},
67 { APPLE_IR_BACKWARD
, 1, AR_PREV
},
68 { APPLE_IR_BACKWARD
, 2, AR_PREV_HOLD
},
69 { APPLE_IR_MENU
, 1, AR_MENU
},
70 { APPLE_IR_MENU
, 2, AR_MENU_HOLD
},
71 { APPLE_IR_PLUS
, 1, AR_VUP
},
72 { APPLE_IR_MINUS
, 1, AR_VDOWN
},
76 int mp_input_appleir_init (char *dev
)
82 mp_msg (MSGT_INPUT
, MSGL_V
, MSGTR_INPUT_APPLE_IR_Init
, dev
);
83 fd
= open (dev
, O_RDONLY
| O_NONBLOCK
);
86 mp_msg (MSGT_INPUT
, MSGL_ERR
,
87 MSGTR_INPUT_APPLE_IR_CantOpen
, strerror (errno
));
95 /* look for a valid AppleIR device on system */
96 for (i
= 0; i
< EVDEV_MAX_EVENTS
; i
++)
101 sprintf (file
, "/dev/input/event%d", i
);
102 fd
= open (file
, O_RDONLY
| O_NONBLOCK
);
106 ioctl (fd
, EVIOCGID
, &id
);
107 if (id
.bustype
== BUS_USB
&&
108 id
.vendor
== USB_VENDOR_APPLE
&&
109 (id
.product
== USB_DEV_APPLE_IR
||id
.product
== USB_DEV_APPLE_IR_2
))
111 mp_msg (MSGT_INPUT
, MSGL_V
, MSGTR_INPUT_APPLE_IR_Detect
, file
);
117 mp_msg (MSGT_INPUT
, MSGL_ERR
,
118 MSGTR_INPUT_APPLE_IR_CantOpen
, strerror (errno
));
124 int mp_input_appleir_read (int fd
)
126 struct input_event ev
;
129 r
= read (fd
, &ev
, sizeof (struct input_event
));
130 if (r
<= 0 || r
< sizeof (struct input_event
))
131 return MP_INPUT_NOTHING
;
133 /* check for key press only */
134 if (ev
.type
!= EV_KEY
)
135 return MP_INPUT_NOTHING
;
143 return MP_INPUT_NOTHING
;
145 /* find Linux evdev -> MPlayer keycode mapping */
146 for (i
= 0; apple_ir_mapping
[i
].linux_keycode
!= -1; i
++)
147 if (apple_ir_mapping
[i
].linux_keycode
== ev
.code
&&
148 apple_ir_mapping
[i
].value
== ev
.value
)
149 return apple_ir_mapping
[i
].mp_keycode
;
151 return MP_INPUT_NOTHING
;