1 /* dvb-usb-remote.c is part of the DVB USB library.
3 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
4 * see dvb-usb-init.c for copyright information.
6 * This file contains functions for initializing the the input-device and for handling remote-control-queries.
8 #include "dvb-usb-common.h"
10 /* Remote-control poll function - called every dib->rc_query_interval ms to see
11 * whether the remote control has received anything.
13 * TODO: Fix the repeat rate of the input device.
15 static void dvb_usb_read_remote_control(void *data
)
17 struct dvb_usb_device
*d
= data
;
21 /* TODO: need a lock here. We can simply skip checking for the remote control
24 if (d
->props
.rc_query(d
,&event
,&state
)) {
25 err("error while querying for an remote control event.");
31 case REMOTE_NO_KEY_PRESSED
:
33 case REMOTE_KEY_PRESSED
:
34 deb_rc("key pressed\n");
35 d
->last_event
= event
;
36 case REMOTE_KEY_REPEAT
:
37 deb_rc("key repeated\n");
38 input_event(&d
->rc_input_dev
, EV_KEY
, event
, 1);
39 input_event(&d
->rc_input_dev
, EV_KEY
, d
->last_event
, 0);
40 input_sync(&d
->rc_input_dev
);
46 /* improved repeat handling ???
48 case REMOTE_NO_KEY_PRESSED:
49 deb_rc("NO KEY PRESSED\n");
50 if (d->last_state != REMOTE_NO_KEY_PRESSED) {
51 deb_rc("releasing event %d\n",d->last_event);
52 input_event(&d->rc_input_dev, EV_KEY, d->last_event, 0);
53 input_sync(&d->rc_input_dev);
55 d->last_state = REMOTE_NO_KEY_PRESSED;
58 case REMOTE_KEY_PRESSED:
59 deb_rc("KEY PRESSED\n");
60 deb_rc("pressing event %d\n",event);
62 input_event(&d->rc_input_dev, EV_KEY, event, 1);
63 input_sync(&d->rc_input_dev);
65 d->last_event = event;
66 d->last_state = REMOTE_KEY_PRESSED;
68 case REMOTE_KEY_REPEAT:
69 deb_rc("KEY_REPEAT\n");
70 if (d->last_state != REMOTE_NO_KEY_PRESSED) {
71 deb_rc("repeating event %d\n",d->last_event);
72 input_event(&d->rc_input_dev, EV_KEY, d->last_event, 2);
73 input_sync(&d->rc_input_dev);
74 d->last_state = REMOTE_KEY_REPEAT;
82 schedule_delayed_work(&d
->rc_query_work
,msecs_to_jiffies(d
->props
.rc_interval
));
85 int dvb_usb_remote_init(struct dvb_usb_device
*d
)
88 if (d
->props
.rc_key_map
== NULL
)
91 /* Initialise the remote-control structures.*/
92 init_input_dev(&d
->rc_input_dev
);
94 d
->rc_input_dev
.evbit
[0] = BIT(EV_KEY
);
95 d
->rc_input_dev
.keycodesize
= sizeof(unsigned char);
96 d
->rc_input_dev
.keycodemax
= KEY_MAX
;
97 d
->rc_input_dev
.name
= "IR-receiver inside an USB DVB receiver";
99 /* set the bits for the keys */
100 deb_rc("key map size: %d\n",d
->props
.rc_key_map_size
);
101 for (i
= 0; i
< d
->props
.rc_key_map_size
; i
++) {
102 deb_rc("setting bit for event %d item %d\n",d
->props
.rc_key_map
[i
].event
, i
);
103 set_bit(d
->props
.rc_key_map
[i
].event
, d
->rc_input_dev
.keybit
);
106 /* Start the remote-control polling. */
107 if (d
->props
.rc_interval
< 40)
108 d
->props
.rc_interval
= 100; /* default */
110 /* setting these two values to non-zero, we have to manage key repeats */
111 d
->rc_input_dev
.rep
[REP_PERIOD
] = d
->props
.rc_interval
;
112 d
->rc_input_dev
.rep
[REP_DELAY
] = d
->props
.rc_interval
+ 150;
114 input_register_device(&d
->rc_input_dev
);
116 INIT_WORK(&d
->rc_query_work
, dvb_usb_read_remote_control
, d
);
118 info("schedule remote query interval to %d msecs.",d
->props
.rc_interval
);
119 schedule_delayed_work(&d
->rc_query_work
,msecs_to_jiffies(d
->props
.rc_interval
));
121 d
->state
|= DVB_USB_STATE_REMOTE
;
126 int dvb_usb_remote_exit(struct dvb_usb_device
*d
)
128 if (d
->state
& DVB_USB_STATE_REMOTE
) {
129 cancel_delayed_work(&d
->rc_query_work
);
130 flush_scheduled_work();
131 input_unregister_device(&d
->rc_input_dev
);
133 d
->state
&= ~DVB_USB_STATE_REMOTE
;
137 #define DVB_USB_RC_NEC_EMPTY 0x00
138 #define DVB_USB_RC_NEC_KEY_PRESSED 0x01
139 #define DVB_USB_RC_NEC_KEY_REPEATED 0x02
140 int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device
*d
,
141 u8 keybuf
[5], u32
*event
, int *state
)
144 struct dvb_usb_rc_key
*keymap
= d
->props
.rc_key_map
;
146 *state
= REMOTE_NO_KEY_PRESSED
;
148 case DVB_USB_RC_NEC_EMPTY
:
150 case DVB_USB_RC_NEC_KEY_PRESSED
:
151 if ((u8
) ~keybuf
[1] != keybuf
[2] ||
152 (u8
) ~keybuf
[3] != keybuf
[4]) {
153 deb_err("remote control checksum failed.\n");
156 /* See if we can match the raw key code. */
157 for (i
= 0; i
< sizeof(keymap
)/sizeof(struct dvb_usb_rc_key
); i
++)
158 if (keymap
[i
].custom
== keybuf
[1] &&
159 keymap
[i
].data
== keybuf
[3]) {
160 *event
= keymap
[i
].event
;
161 *state
= REMOTE_KEY_PRESSED
;
164 deb_err("key mapping failed - no appropriate key found in keymapping\n");
166 case DVB_USB_RC_NEC_KEY_REPEATED
:
167 *state
= REMOTE_KEY_REPEAT
;
170 deb_err("unkown type of remote status: %d\n",keybuf
[0]);
175 EXPORT_SYMBOL(dvb_usb_nec_rc_key_to_event
);