1 /* $Id: hw_uirt2.c,v 5.4 2007/07/29 18:20:11 lirc Exp $ */
3 /****************************************************************************
4 ** hw_uirt2.c **************************************************************
5 ****************************************************************************
7 * routines for UIRT2 receiver using the UIR mode
9 * Copyright (C) 1999 Christoph Bartelmus <lirc@bartelmus.de>
10 * modified for logitech receiver by Isaac Lauer <inl101@alumni.psu.edu>
11 * modified for UIRT2 receiver by
12 * Mikael Magnusson <mikma@users.sourceforge.net>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
41 #include <sys/types.h>
42 #include <sys/ioctl.h>
46 #include "ir_remote.h"
52 static unsigned char b
[NUMBYTES
];
53 static struct timeval start
,end
,last
;
57 static int uirt2_decode(struct ir_remote
*remote
,
58 ir_code
*prep
,ir_code
*codep
,ir_code
*postp
,
60 lirc_t
*min_remaining_gapp
,
61 lirc_t
*max_remaining_gapp
);
62 static int uirt2_init(void);
63 static int uirt2_deinit(void);
64 static char *uirt2_rec(struct ir_remote
*remotes
);
66 struct hardware hw_uirt2
=
68 LIRC_DRIVER_DEVICE
, /* default device */
70 LIRC_CAN_REC_LIRCCODE
, /* features */
72 LIRC_MODE_LIRCCODE
, /* rec_mode */
73 8*NUMBYTES
, /* code_length */
74 uirt2_init
, /* init_func */
75 NULL
, /* config_func */
76 uirt2_deinit
, /* deinit_func */
78 uirt2_rec
, /* rec_func */
79 uirt2_decode
, /* decode_func */
80 NULL
, /* ioctl_func */
86 static int uirt2_decode(struct ir_remote
*remote
,
87 ir_code
*prep
,ir_code
*codep
,ir_code
*postp
,
89 lirc_t
*min_remaining_gapp
,
90 lirc_t
*max_remaining_gapp
)
92 if(!map_code(remote
,prep
,codep
,postp
,
93 0,0,8*NUMBYTES
,code
,0,0))
98 map_gap(remote
, &start
, &last
, 0, repeat_flagp
,
99 min_remaining_gapp
, max_remaining_gapp
);
105 static int uirt2_init(void)
107 if(!tty_create_lock(hw
.device
))
109 logprintf(LOG_ERR
,"uirt2: could not create lock files");
112 if((hw
.fd
=open(hw
.device
,O_RDWR
|O_NONBLOCK
|O_NOCTTY
))<0)
114 logprintf(LOG_ERR
,"uirt2: could not open %s",hw
.device
);
115 logperror(LOG_ERR
,"uirt2: ");
119 if(!tty_reset(hw
.fd
))
121 logprintf(LOG_ERR
,"uirt2: could not reset tty");
125 if(!tty_setbaud(hw
.fd
,115200))
127 logprintf(LOG_ERR
,"uirt2: could not set baud rate");
135 static int uirt2_deinit(void)
142 static char *uirt2_rec(struct ir_remote
*remotes
)
148 gettimeofday(&start
,NULL
);
149 for(i
=0;i
<NUMBYTES
;i
++)
153 if(!waitfordata(TIMEOUT
))
156 "uirt2: timeout reading byte %d",i
);
160 if(read(hw
.fd
,&b
[i
],1)!=1)
163 "uirt2: reading of byte %d failed",i
);
164 logperror(LOG_ERR
,NULL
);
167 LOGPRINTF(1,"byte %d: %02x",i
,b
[i
]);
169 gettimeofday(&end
,NULL
);
175 code
=((ir_code
) b
[0]);
177 code
|=((ir_code
) b
[1]);
179 code
|=((ir_code
) b
[2]);
181 code
|=((ir_code
) b
[3]);
183 code
|=((ir_code
) b
[4]);
185 code
|=((ir_code
) b
[5]);
187 LOGPRINTF(1,"code: %llx",(unsigned long long) code
);
189 m
=decode_all(remotes
);