2 * Support for builtin key panel and remote control on
3 * AOpen XC Cube EA65, EA65-II
5 * Copyright (C) 2004 Max Krasnyansky <maxk@qualcomm.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Library General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * $Id: hw_ea65.c,v 5.4 2007/07/29 18:20:07 lirc Exp $
36 #include <sys/types.h>
37 #include <sys/ioctl.h>
41 #include "ir_remote.h"
47 #define CODE_LENGTH 24
49 struct timeval start
, end
, last
;
52 struct hardware hw_ea65
=
54 LIRC_IRTTY
, /* default device */
56 LIRC_CAN_REC_LIRCCODE
, /* features */
58 LIRC_MODE_LIRCCODE
, /* rec_mode */
59 CODE_LENGTH
, /* code_length */
60 ea65_init
, /* init_func */
61 NULL
, /* config_func */
62 ea65_release
, /* deinit_func */
64 ea65_receive
, /* rec_func */
65 ea65_decode
, /* decode_func */
66 NULL
, /* ioctl_func */
71 int ea65_decode(struct ir_remote
*remote
,
72 ir_code
*prep
,ir_code
*codep
,ir_code
*postp
,
74 lirc_t
*min_remaining_gapp
,
75 lirc_t
*max_remaining_gapp
)
79 if (!map_code(remote
, prep
, codep
, postp
,
80 0, 0, CODE_LENGTH
, code
, 0, 0))
83 if (start
.tv_sec
- last
.tv_sec
>= 2) {
86 d
= (start
.tv_sec
- last
.tv_sec
) * 1000000 +
87 start
.tv_usec
- last
.tv_usec
;
98 *min_remaining_gapp
= 0;
99 *max_remaining_gapp
= 0;
106 logprintf(LOG_INFO
, "EA65: device %s", hw
.device
);
108 if (!tty_create_lock(hw
.device
)) {
109 logprintf(LOG_ERR
,"EA65: could not create lock files");
113 hw
.fd
= open(hw
.device
, O_RDWR
| O_NONBLOCK
| O_NOCTTY
);
115 logprintf(LOG_ERR
,"EA65: could not open %s",hw
.device
);
120 if (!tty_reset(hw
.fd
)) {
121 logprintf(LOG_ERR
,"EA65: could not reset tty");
126 if (!tty_setbaud(hw
.fd
, 9600)) {
127 logprintf(LOG_ERR
,"EA65: could not set baud rate");
135 int ea65_release(void)
143 char *ea65_receive(struct ir_remote
*remote
)
149 gettimeofday(&start
, NULL
);
151 if (!waitfordata(TIMEOUT
)) {
152 logprintf(LOG_ERR
, "EA65: timeout reading code data");
156 r
= read(hw
.fd
, data
, sizeof(data
));
158 logprintf(LOG_ERR
, "EA65: read failed. %s(%d)",
163 LOGPRINTF(1, "EA65: data(%d): %02x %02x %02x %02x %02x", r
,
164 data
[0], data
[1], data
[2], data
[3], data
[4]);
173 code
= (data
[2] << 16) | (data
[3] << 8) | data
[4];
177 code
= (0xff << 16) | (data
[2] << 8) | data
[3];
180 logprintf(LOG_INFO
, "EA65: receive code: %llx",
181 (unsigned long long) code
);
183 gettimeofday(&end
, NULL
);
185 return decode_all(remote
);